本文整理匯總了Java中org.bukkit.GameMode類的典型用法代碼示例。如果您正苦於以下問題:Java GameMode類的具體用法?Java GameMode怎麽用?Java GameMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
GameMode類屬於org.bukkit包,在下文中一共展示了GameMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPlayerMove
import org.bukkit.GameMode; //導入依賴的package包/類
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (!event.getFrom().getWorld().getName().equalsIgnoreCase("cave")) {
return;
}
if (event.getTo().getBlock().getLightFromSky() == 0) {
return;
}
if (event.getPlayer().getGameMode() == GameMode.CREATIVE) {
return;
}
event.getPlayer().setHealth(0.0D);
TextComponent message = new TextComponent("DU VOLLIDIOT! SONNE IST GEFÄHRLICH! HOFFE DU LERNST DARAUS");
message.setColor(ChatColor.DARK_RED);
event.getPlayer().spigot().sendMessage(message);
}
示例2: endMatch
import org.bukkit.GameMode; //導入依賴的package包/類
public void endMatch(MatchTeam winningTeam) {
List<MatchTeam> losers = new ArrayList<>();
for (MatchTeam matchTeam : TGM.get().getModule(TeamManagerModule.class).getTeams()) {
if (!matchTeam.isSpectator()) {
matchTeam.getMembers().forEach(playerContext -> {
playerContext.getPlayer().setGameMode(GameMode.ADVENTURE);
playerContext.getPlayer().setAllowFlight(true);
playerContext.getPlayer().setVelocity(new Vector(playerContext.getPlayer().getVelocity().getX(),
playerContext.getPlayer().getVelocity().getZ() + 1.0, playerContext.getPlayer().getVelocity().getZ()));
playerContext.getPlayer().setFlying(true);
});
if (matchTeam != winningTeam) {
losers.add(matchTeam);
}
}
}
match.disable();
Bukkit.getPluginManager().callEvent(new MatchResultEvent(match, winningTeam, losers));
}
示例3: spawnPlayer
import org.bukkit.GameMode; //導入依賴的package包/類
public void spawnPlayer(PlayerContext playerContext, MatchTeam matchTeam, boolean teleport) {
Players.reset(playerContext.getPlayer(), true);
if (matchTeam.isSpectator()) {
spectatorModule.applySpectatorKit(playerContext);
if (teleport) {
playerContext.getPlayer().teleport(getTeamSpawn(matchTeam).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
}
} else {
matchTeam.getKits().forEach(kit -> kit.apply(playerContext.getPlayer(), matchTeam));
playerContext.getPlayer().updateInventory();
if (teleport) {
playerContext.getPlayer().teleport(getTeamSpawn(matchTeam).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
playerContext.getPlayer().setGameMode(GameMode.SURVIVAL);
}
}
}
示例4: onPlayerInteract
import org.bukkit.GameMode; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK && event.hasItem()) {
// The player didn't click an enchantment table, Creative players will instantly destroy.
Player player = event.getPlayer();
if (event.getClickedBlock().getType() == Material.ENCHANTMENT_TABLE && player.getGameMode() != GameMode.CREATIVE) {
// The player didn't click with an enchanted book.
ItemStack stack = event.getItem();
if (stack != null && stack.getType() == Material.ENCHANTED_BOOK) {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof EnchantmentStorageMeta) {
EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) meta;
for (Enchantment enchantment : enchantmentStorageMeta.getStoredEnchants().keySet()) {
enchantmentStorageMeta.removeStoredEnchant(enchantment);
}
event.setCancelled(true);
player.setItemInHand(EMPTY_BOOK);
player.sendMessage(ChatColor.GREEN + "You reverted this item to its original form.");
}
}
}
}
}
示例5: message
import org.bukkit.GameMode; //導入依賴的package包/類
public void message(CommandContext context) {
String targetString = context.getArgs().get(0);
Player target = Bukkit.getPlayer(targetString);
if (target == null) {
context.send(colour("&cNobody was found with name '" + targetString + "'."));
return;
}
if (context.getSender() instanceof Player &&
Conditionals.ofBoth(((Player) context.getSender()).getGameMode(), target.getGameMode(), GameMode.SURVIVAL, GameMode.SPECTATOR)) {
context.send(colour("&cGhosting is not allowed!"));
return;
}
String finalMessage = String.join(" ", context.getArgs().subList(1, context.getArgs().size()));
target.sendMessage(colour("&f<" + context.getSender().getName() + "&f -> Me&f> ") + finalMessage);
context.send(colour("&f<Me -> " + target.getName() + "&f> ") + finalMessage);
Bukkit.getOnlinePlayers().stream().filter(it -> UserManager.getInstance().getUser(it.getUniqueId()).orElseThrow(() -> new RuntimeException("An offline player is in Bukkit#getOnlinePlayers.")).getParticipation() == Participation.ADMIN)
.forEach(it -> it.sendMessage(colour("&f<" + context.getSender().getName() + " -> " + target.getName() + "> ") + finalMessage));
lastMessaged.put(context.getSender(), target);
}
示例6: hitBlock
import org.bukkit.GameMode; //導入依賴的package包/類
public static boolean hitBlock(Player player, Block block) {
if (player.getGameMode() == GameMode.CREATIVE)
return true;
PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
if (playerBlockTracking.isBlock(block)) {
return true;
}
long time = playerBlockTracking.getTimeDifference();
playerBlockTracking.incrementHackingIndicator();
playerBlockTracking.setBlock(block);
playerBlockTracking.updateTime();
int decrement = (int) (time / OrebfuscatorConfig.AntiHitHackDecrementFactor);
playerBlockTracking.decrementHackingIndicator(decrement);
if (playerBlockTracking.getHackingIndicator() == OrebfuscatorConfig.AntiHitHackMaxViolation)
playerBlockTracking.incrementHackingIndicator(OrebfuscatorConfig.AntiHitHackMaxViolation);
if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
return false;
return true;
}
示例7: testGameMode
import org.bukkit.GameMode; //導入依賴的package包/類
@Test
public void testGameMode() throws InputException {
Class[] inputTypes = {GameMode.class, GameMode.class};
String[] input = {"1", "adventure"};
Object[] output = InputFormatter.getTypesFromInput(inputTypes, Arrays.asList(input), null);
// First let's make sure we didn't lose anything, or get anything
assertEquals(inputTypes.length, output.length);
// Next let's make sure everything is the right type
for (Object object : output) {
assertTrue(object instanceof GameMode);
}
// Finally, let's make sure the values are correct
assertSame(output[0], GameMode.CREATIVE);
assertSame(output[1], GameMode.ADVENTURE);
}
示例8: onModerationJoin
import org.bukkit.GameMode; //導入依賴的package包/類
@Override
public void onModerationJoin(Player player)
{
player.sendMessage(ChatColor.GOLD + "Vous avez rejoint cette arène en mode modération.");
player.setGameMode(GameMode.SPECTATOR);
List<Player> players = new ArrayList<>();
players.addAll(Bukkit.getOnlinePlayers());
players.stream().filter(gamePlayer -> !gamePlayer.getName().equals(player.getName())).forEach(gamePlayer -> {
gamePlayer.hidePlayer(player);
});
if (teleportTargets.containsKey(player.getUniqueId()))
{
UUID target = teleportTargets.get(player.getUniqueId());
Player tar = Bukkit.getPlayer(target);
if (tar != null)
player.teleport(tar);
teleportTargets.remove(player.getUniqueId());
}
}
示例9: onPreStart
import org.bukkit.GameMode; //導入依賴的package包/類
@Override
public void onPreStart() {
Location spawnLocation = Utils.parseLocation((String) this.getGameMap().fetchSetting("startPosition"));
MaterialData materialData = Utils.parseMaterialData((String) this.getGameMap().fetchSetting("item"));
ItemStack itemStack = new ItemStack(materialData.getItemType(), 1, materialData.getData());
itemStack.addUnsafeEnchantment(Enchantment.KNOCKBACK,
Integer.parseInt((String) this.getGameMap().fetchSetting("knockbackAmount")));
for(Player player : Bukkit.getOnlinePlayers()) {
if(!this.getAPI().getGameManager().isAlive(player)) continue;
player.teleport(spawnLocation);
player.setGameMode(GameMode.ADVENTURE);
player.getInventory().addItem(itemStack);
}
this.hill = new Cuboid(Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsA")),
Utils.parseLocation((String) this.getGameMap().fetchSetting("hillBoundsB")));
}
示例10: setSpectating
import org.bukkit.GameMode; //導入依賴的package包/類
/**
* Toggles whether a player is in Spectator Mode.
* @param player
* @param toggle
*/
public void setSpectating(Player player, boolean toggle) {
if(toggle && spec.contains(player)) return;
if(!toggle && !spec.contains(player)) return;
if(toggle) {
player.setAllowFlight(true);
player.setFlying(true);
player.setGameMode(GameMode.SPECTATOR);
spec.add(player);
} else {
player.setGameMode(GameMode.ADVENTURE);
spec.remove(player);
}
this.setAlive(player, false);
Bukkit.getServer().getPluginManager().callEvent(new PlayerAliveStatusEvent(player, false, toggle));
}
示例11: parseGamemode
import org.bukkit.GameMode; //導入依賴的package包/類
private GameMode parseGamemode(String gamemode) {
switch (gamemode) {
case "creativo":
case "1":
case "c":
return GameMode.CREATIVE;
case "survival":
case "0":
case "s":
return GameMode.SURVIVAL;
case "adventura":
case "2":
case "a":
return GameMode.ADVENTURE;
case "espectador":
case "3":
case "e":
return GameMode.SPECTATOR;
default:
return GameMode.SURVIVAL;
}
}
示例12: handleModeratorLogin
import org.bukkit.GameMode; //導入依賴的package包/類
/**
* Override this to execute something when a moderator joins the game.
*
* You need to call the {@code super} method at the beginning of your own one.
*
* @param player The player who logged in.
*/
public void handleModeratorLogin(Player player)
{
for (GamePlayer gamePlayer : this.gamePlayers.values())
{
Player p = gamePlayer.getPlayerIfOnline();
if (p != null)
p.hidePlayer(player);
}
this.gameModerators.add(player.getUniqueId());
player.setGameMode(GameMode.SPECTATOR);
player.sendMessage(ChatColor.GREEN + "Vous êtes invisibles aux yeux de tous, attention à vos actions !");
}
示例13: JoinTeam
import org.bukkit.GameMode; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public static void JoinTeam(Player player,String area){
String worldconfig = plugin.getConfig().getString("area."+area+".world");
World world = Bukkit.getServer().getWorld(worldconfig);
String Location = plugin.getConfig().getString("area."+area+".Location");
String[] location = Location.split(",");
int x = Integer.parseInt(location[0]);
int y = Integer.parseInt(location[1]);
int z = Integer.parseInt(location[2]);
Location location2 = new Location(world, x, y, z);
player.teleport(location2);
player.setGameMode(GameMode.SURVIVAL);
Team team = board.getTeam(area);
PlayerInWhereArea.put(player, team);
team.addPlayer(player);
player.playSound(player.getLocation(), Sound.CLICK, 2F, 15F);
player.sendMessage(ChatColor.BLUE + "�A�[�J�F�C��");
}
示例14: finallyStart
import org.bukkit.GameMode; //導入依賴的package包/類
/**
* Finally starts the game after the countdown
*
* You have to load the chunk because the player could probably spawn in the
* ground if the chunk is not loaded when the player is teleported
*/
public void finallyStart() {
game.setStatus(GameStatus.INGAME);
Chambers.getInstance().getTeamManager().getAllPlayerTeams().stream().forEach(team -> {
if (!team.getHome().getChunk().isLoaded()) {
team.getHome().getChunk().load();
}
team.getOnlinePlayers().stream().forEach(player -> {
giveStartingItems(player);
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false);
player.setFlying(false);
player.teleport(team.getHome());
});
});
new GameTask().runTaskTimerAsynchronously(Chambers.getInstance(), 0L, 20L);
Bukkit.broadcastMessage(" ");
Bukkit.broadcastMessage(ChatColor.YELLOW + "The game has now started! Good luck!");
Bukkit.broadcastMessage(" ");
}
示例15: onInventoryMove
import org.bukkit.GameMode; //導入依賴的package包/類
@EventHandler
public void onInventoryMove(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) {
return;
}
Player player = (Player) event.getWhoClicked();
PracticeProfile profile = ManagerHandler.getPlayerManager().getPlayerProfile(player);
if (profile.getStatus() == PlayerStatus.EDITING_KITS || profile.getStatus() == PlayerStatus.PLAYING) {
return;
}
if ((player.hasPermission("practice.admin") || player.isOp()) && player.getGameMode() == GameMode.CREATIVE) {
return;
}
event.setCancelled(true);
}