@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); }
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)); }
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); } } }
@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."); } } } } }
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); }
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; }
@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); }
@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()); } }
@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"))); }
/** * 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)); }
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; } }
/** * 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 !"); }
@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��"); }
/** * 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(" "); }
@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); }
@EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); event.setJoinMessage(null); if (!Skywars.getInstance().isSingleServerMode()) { player.setGameMode(GameMode.ADVENTURE); player.getInventory().clear(); player.setMaxHealth(20); player.setHealth(player.getMaxHealth()); player.setFoodLevel(25); player.teleport(Skywars.getInstance().getLobbyPoint()); } }
@EventHandler public void leave(final PlayerQuitEvent event) { if(GameState.current() != GameState.LOBBY && event.getPlayer().getGameMode() != GameMode.SPECTATOR){ event.setQuitMessage(colour("&6" + event.getPlayer().getName() + " has quit! " + "They have " + UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds() + "s to reconnect.")); bukkitRunnable(() -> disqualified(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getPlayer().getLocation(), event.getPlayer().getInventory())).runTaskLater(UHC.getInstance(), TimeUnit.MILLISECONDS.convert(UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds(), TimeUnit.SECONDS)); //Zombie Spawning Zombie zombie = (Zombie) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.ZOMBIE); zombie.setCustomName(event.getPlayer().getName()); zombie.setCustomNameVisible(true); //TODO Make no AI and invulnerable cough cough Proxi cough cough deadRepresentatives.put(event.getPlayer().getUniqueId(), zombie); } }
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR) public void onBlockBreak(BlockPlaceEvent event) { if (event.isCancelled()) { Player player = event.getPlayer(); if (player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight()) { return; } Block block = event.getBlockPlaced(); if (block.getType().isSolid() && !(block.getState() instanceof Sign)) { int playerY = player.getLocation().getBlockY(); int blockY = block.getLocation().getBlockY(); if (playerY > blockY) { Vector vector = player.getVelocity(); vector.setX(-0.1); vector.setZ(-0.1); player.setVelocity(vector.setY(vector.getY() - 0.41999998688697815D)); // Magic number acquired from EntityLiving#bj() } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onConsumeCake(PlayerInteractEvent event) { if(event.isCancelled()) return; Player player = event.getPlayer(); if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { Block cake = event.getClickedBlock(); if(cake.getType().equals(Material.CAKE_BLOCK)) { if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE)) { addStats(player, carbon, 171); addStats(player, protein, 114); addStats(player, salts, 3); } } } }
@EventHandler public void playerJoin(final PlayerJoinEvent event) { Optional<User> joinedUser; if ((joinedUser = UserManager.getInstance().getUser(event.getPlayer().getUniqueId())).isPresent()) { if(joinedUser.get().getParticipation() != Participation.SPECTATOR && GameState.current() != GameState.LOBBY){ event.setJoinMessage(colour("&b" + event.getPlayer().getName() + " has reconnected.")); deadRepresentatives.get(event.getPlayer().getUniqueId()).remove(); deadRepresentatives.remove(event.getPlayer().getUniqueId()); } return; } User user = new User(event.getPlayer(), GameState.current() == GameState.LOBBY ? Participation.PARTICIPATOR : Participation.SPECTATOR); if (event.getPlayer().getGameMode() == GameMode.CREATIVE || event.getPlayer().isOp()) { user.setParticipation(Participation.ADMIN); } else if(GameState.current() != GameState.LOBBY) event.getPlayer().setGameMode(GameMode.SPECTATOR); UserManager.getInstance().addUser(user); }
@Override public boolean doAction(Player player, Command command, String s, String[] args) { if (!SamaGamesAPI.get().getPermissionsManager().hasPermission(player, "hub.fly")) { player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.RED + "Vous n'avez pas le grade nécéssaire pour utiliser cette commande."); return true; } if (player.getGameMode() != GameMode.ADVENTURE || this.hub.getPlayerManager().isBusy(player)) { player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.RED + "Vous ne pouvez pas utiliser cette commande actuellement."); return true; } boolean now = !player.getAllowFlight(); player.setAllowFlight(now); if (now) player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.GREEN + "Vous pouvez maintenant voler."); else player.sendMessage(PlayerManager.SETTINGS_TAG + ChatColor.GREEN + "Vous ne pouvez plus voler."); return true; }
public static void lockSlots(Player player, boolean force) { if (!force && player.getGameMode() == GameMode.CREATIVE) { return; } if (isEnabled()) { int maxSlot = getSlots(player) + 8; for (int i = 35; i > maxSlot; i--) { player.getInventory().setItem(i, lockedSlot); } if (maxSlot < 35) { player.getInventory().setItem(maxSlot + 1, getBuyableSlotForLine(getLine(maxSlot + 1))); } } InventoryManager.lockQuickSlots(player); InventoryManager.lockEmptySlots(player); }
public static void runCheck(Player player, Distance distance) { if (distance.getYDifference() > 400 || player.isFlying() || player.getGameMode().equals(GameMode.CREATIVE)) { return; //This is to prevent a player using /fly getting AC'd } final double y1 = distance.fromY(); final double y2 = distance.toY(); if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities .cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock() .getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material .COBBLE_WALL})) { //prevents fancy minecraft magicky crap for(double i = player.getLocation().getY(); new Location(player.getWorld(),player .getLocation().getX(),i, player.getLocation().getZ()).getBlock().getType() != Material.AIR; i--) { if(player.getVelocity().getY() >= 0 && player.getLocation() .add(0,-2,0).getBlock().getType() != Material.AIR) { repeated.put(player,repeated.containsKey(player)?repeated.put(player,repeated.get(player) + 1) :repeated.put(player,1)); } } if (repeated.containsKey(player) && repeated.get(player) > MagicNumbers.MAX_FLY){ for (Player pla : DynamicAC.instance.onlinestaff) { pla.sendMessage(DynamicAC.prefix + player.getName() + " failed Fly!"); } DACManager.getUserManager().incrementUser(DACManager.getUserManager().getUser(player.getName()), "Flight"); } } }
public void spell(TOAUser u) { l = u.getLoc(); u.getPlayer().setGameMode(GameMode.SPECTATOR); plugin.getServer().getScheduler().runTaskLater(plugin, () -> { u.teleport(l); u.getPlayer().setGameMode(GameMode.ADVENTURE); }, 100); }
public void applySpectatorKit(PlayerContext playerContext) { Players.reset(playerContext.getPlayer(), false); playerContext.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100000, 255, false, false)); playerContext.getPlayer().setGameMode(GameMode.ADVENTURE); playerContext.getPlayer().setAllowFlight(true); playerContext.getPlayer().setFlying(true); playerContext.getPlayer().setInvulnerable(true); playerContext.getPlayer().setCanPickupItems(false); playerContext.getPlayer().setCollidable(false); playerContext.getPlayer().getInventory().setItem(0, compassItem); playerContext.getPlayer().getInventory().setItem(2, teamSelectionItem); }
public void setGameMode(GameMode gameMode) { if(isOnline()){ player.setGameMode(gameMode); }else{ this.gameMode = gameMode; } }
private void refresh(PlayerContext playerContext, MatchTeam matchTeam) { Players.reset(playerContext.getPlayer(), true); matchTeam.getKits().forEach(kit -> kit.apply(playerContext.getPlayer(), matchTeam)); playerContext.getPlayer().updateInventory(); playerContext.getPlayer().teleport(matchTeam.getSpawnPoints().get(0).getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN); playerContext.getPlayer().setGameMode(GameMode.ADVENTURE); playerContext.getPlayer().addPotionEffects(Collections.singleton(new PotionEffect(PotionEffectType.JUMP, 10000, 2, true, false))); }
@EventHandler public void onTeamChange(TeamChangeEvent event) { if (teamManager.getTeamById("humans").getMembers().size() == 0 && match.getMatchStatus().equals(MatchStatus.MID)) { TGM.get().getMatchManager().endMatch(teamManager.getTeamById("infected")); } event.getPlayerContext().getPlayer().setGameMode(GameMode.ADVENTURE); if (event.getTeam().getId().equalsIgnoreCase("infected")) { event.getPlayerContext().getPlayer().addPotionEffects(Collections.singleton(new PotionEffect(PotionEffectType.JUMP, 50000, 1, true, false))); } }
@EventHandler public void on(PlayerJoinEvent event){ Player player = event.getPlayer(); player.setGameMode(GameMode.ADVENTURE); ItemStack item = itemFactory.getWeapon(AirBow.class); player.getInventory().setItemInMainHand(item); }
@SuppressWarnings("deprecation") public static void QuitTeam(Player player){ String worldconfig = plugin.getConfig().getString("lobby.world"); World world = Bukkit.getServer().getWorld(worldconfig); String Location = plugin.getConfig().getString("lobby.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); Team team = PlayerInWhereArea.get(player); team.removePlayer(player); PlayerInWhereArea.remove(player); player.sendMessage(ChatColor.BLUE + "�A�h�X�F�C��"); player.playSound(player.getLocation(), Sound.NOTE_PIANO, 2F, 15F); player.setGameMode(GameMode.SURVIVAL); Spawn.cancel(player); Spawn2.cancel(player); }
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreak(final BlockBreakEvent event) { Player player = event.getPlayer(); if (player.getGameMode() != GameMode.CREATIVE) { if (player.hasPermission("hcf.listener.autosmeltore")) { ItemStack stack = player.getItemInHand(); if (stack != null && stack.getType() != Material.AIR && !stack.containsEnchantment(Enchantment.SILK_TOUCH)) { Block block = event.getBlock(); Material dropType = null; switch (block.getType()) { case IRON_ORE: { dropType = Material.IRON_INGOT; break; } case GOLD_ORE: { dropType = Material.GOLD_INGOT; break; } default: { return; } } Location location = block.getLocation(); World world = location.getWorld(); ItemStack drop = new ItemStack(dropType, 1); world.dropItemNaturally(location, drop); block.setType(Material.AIR); block.getState().update(); } } } }
public static void breakBlock(Player player, Block block) { if (player.getGameMode() == GameMode.CREATIVE) return; PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player); if (playerBlockTracking.isBlock(block)) { playerBlockTracking.decrementHackingIndicator(2); } }
@EventHandler public void onBlockBreak(BlockBreakEvent event) { PlayerDataRPG pd = plugin.getPD(event.getPlayer()); if (pd == null) event.setCancelled(true); if (event.getPlayer().getGameMode() != GameMode.CREATIVE) event.setCancelled(true); if (!canBuild(pd)) event.setCancelled(true); }
@EventHandler public void onBucketEmpty(PlayerBucketEmptyEvent event) { PlayerDataRPG pd = plugin.getPD(event.getPlayer()); if (pd == null) event.setCancelled(true); if (event.getPlayer().getGameMode() != GameMode.CREATIVE) event.setCancelled(true); if (!canBuild(pd)) event.setCancelled(true); event.getPlayer().updateInventory(); }
@EventHandler public void onBucketFill(PlayerBucketFillEvent event) { PlayerDataRPG pd = plugin.getPD(event.getPlayer()); if (pd == null) event.setCancelled(true); if (event.getPlayer().getGameMode() != GameMode.CREATIVE) event.setCancelled(true); if (!canBuild(pd)) event.setCancelled(true); event.getPlayer().updateInventory(); }
@EventHandler public void onHangingBreak(HangingBreakByEntityEvent event) { if (!(event.getRemover() instanceof Player)) event.setCancelled(true); PlayerDataRPG pd = plugin.getPD((Player) event.getRemover()); if (pd == null) event.setCancelled(true); if (((Player) event.getRemover()).getGameMode() != GameMode.CREATIVE) event.setCancelled(true); if (!canBuild(pd)) event.setCancelled(true); }
/** * Is the player in a state or situation that we should deem them not flying? * @param player * @return immune */ private static boolean isImmune(Player player) { return player.getGameMode() != GameMode.SURVIVAL || Utils.getRank(player).isAtLeast(EnumRank.MEDIA) // Don't bypass this check. || player.isGliding() // Not using Elytra || player.hasPotionEffect(PotionEffectType.LEVITATION) // Doesn't have a levitation potion || player.getVehicle() != null // Not in a vehicle || player.getVelocity().getY() > 0 // Not being launched up || player.getNearbyEntities(1, 2, 1).stream().anyMatch(e -> e.getType() == EntityType.BOAT) // Not standing on a boat. || player.getLocation().getBlock().isLiquid(); // Not in water. }
@EventHandler public void onItemFrameInteract(PlayerInteractEntityEvent event) { Player p = event.getPlayer(); Entity e = event.getRightClicked(); if (e instanceof ItemFrame && p.getGameMode() != GameMode.CREATIVE) { event.setCancelled(true); } }
@EventHandler public void onDrop(PlayerDropItemEvent event) { Player player = event.getPlayer(); if ((modMode.contains(player)) && (player.getGameMode().equals(GameMode.CREATIVE))) { event.setCancelled(true); } }