@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.NORMAL) public void onPlayerInteract(PlayerInteractEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Block block = event.getClickedBlock(); final ItemStack item = event.getItem(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (block != null) { final Material t = block.getType(); plugin.debug("Interact with block: " + t.getId() + " : " + block); if (!(plugin.getConfig().getBoolean("flags.use-switches", false) && isSwitch(t))) { if (!(isOnAllowedList(t) || plugin.canBuildOnLocation(player, block.getLocation()))) event.setCancelled(true); } } else { if (item != null) { plugin.debug("Using item: " + item.getTypeId()); if (!(isOnAllowedList(item.getType()) || plugin.canBuildOnLocation(player, player.getLocation()))) event.setCancelled(true); } } plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.NORMAL) public void onRightHandPlayerInteact(PlayerInteractEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); if (player != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) { Location loc = player.getLocation(); // If block is not null use block location, if null use player loc final Block block = event.getClickedBlock(); if (block != null) loc = block.getLocation(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (player.getItemInHand().getType() == Material.MONSTER_EGG) { if (!(plugin.canBuildOnLocation(player, loc))) event.setCancelled(true); } else if (player.getItemInHand().getType() == Material.FIREBALL) { if (!plugin.canBuildOnLocation(player, loc)) event.setCancelled(true); } } plugin.debug("Evento :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@SuppressWarnings("deprecation") private boolean isOnAllowedList(Material t) { if (Config.ALLOWED_ITEM_LIST != null && !Config.ALLOWED_ITEM_LIST.isEmpty()) { for (String blockDescr : Config.ALLOWED_ITEM_LIST) { if (blockDescr == null || blockDescr.isEmpty()) continue; String[] split = blockDescr.split(":"); if (split.length > 0 && isDigit(split[0]) && Integer.parseInt(split[0]) == t.getId()) { plugin.debug("Is on allowed list: " + t.getId()); return true; } } } plugin.debug("Is not on allowed list: " + t.getId()); return false; }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.isCancelled()) return; final Entity target = event.getEntity(); Player attacker = null; if (event.getDamager() instanceof Player) { attacker = (Player) event.getDamager(); } else if (event.getDamager() instanceof Projectile) { if (((Projectile) event.getDamager()).getShooter() instanceof Player) attacker = (Player) ((Projectile) event.getDamager()).getShooter(); } if (target != null && attacker != null) { plugin.debug("Attacker: " + attacker + ", Target: " + target + ""); if (attacker.getWorld() != plugin.getIslandWorld()) return; if (attacker.isOp()) return; if (attacker.hasPermission("islandworld.bypass.damage")) return; if (target instanceof Player) { if (!Config.FLAG_PVP) event.setCancelled(true); } else { if (target instanceof ItemFrame) { if (!plugin.canBuildOnLocation(attacker, target.getLocation())) event.setCancelled(true); } else if (target instanceof Monster || target instanceof WaterMob) { if (plugin.canBuildOnLocation(attacker, target.getLocation()) || plugin.getConfig().getBoolean("flags.kill-monster", false)) { } else { event.setCancelled(true); } } else if (target instanceof Animals || target instanceof NPC) { if (plugin.canBuildOnLocation(attacker, target.getLocation()) || plugin.getConfig().getBoolean("flags.kill-animals", false)) { } else { event.setCancelled(true); } } } } plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Block block = event.getBlock(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (block != null && !plugin.canBuildOnLocation(player, block.getLocation())) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerPortal(PlayerPortalEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (!(plugin.getConfig().getBoolean("flags.use-portal", false) || plugin.canBuildOnLocation(player, event.getFrom()))) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.LOWEST) public void onItemDrop(PlayerDropItemEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Item item = event.getItemDrop(); if (item == null) return; if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (!(plugin.canBuildOnLocation(player, item.getLocation()))) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerShearEntity(PlayerShearEntityEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Entity entity = event.getEntity(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (entity != null && !plugin.canBuildOnLocation(player, entity.getLocation())) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Item item = event.getItem(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (item != null && !(plugin.getConfig().getBoolean("flags.item-pickup", false) || plugin.canBuildOnLocation(player, item.getLocation()))) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onProjectileLaunchEvent(ProjectileLaunchEvent event) { if (event.isCancelled()) return; if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof ThrownPotion) { final Player player = (Player) event.getEntity().getShooter(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (player != null && !(plugin.getConfig().getBoolean("flags.potion-throw", false) || plugin.canBuildOnLocation(player, player.getLocation()))) event.setCancelled(true); } plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.LOWEST) public void onInventoryOpenEvent(InventoryOpenEvent event) { if (event.isCancelled() || event.getInventory() == null || event.getInventory().getHolder() == null) return; final Player player = (Player) event.getPlayer(); final InventoryHolder h = event.getInventory().getHolder(); if (h instanceof Chest || h instanceof DoubleChest || h instanceof Furnace || h instanceof Dispenser) { if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; Location loc = player.getLocation(); if (event.getInventory().getHolder() instanceof Chest) { final Chest chest = (Chest) event.getInventory().getHolder(); loc = chest.getLocation(); } else if (event.getInventory().getHolder() instanceof Furnace) { final Furnace fur = (Furnace) event.getInventory().getHolder(); loc = fur.getLocation(); } else if (event.getInventory().getHolder() instanceof DoubleChest) { final DoubleChest chest = (DoubleChest) event.getInventory().getHolder(); loc = chest.getLocation(); } else if (event.getInventory().getHolder() instanceof Dispenser) { final Dispenser disp = (Dispenser) event.getInventory().getHolder(); loc = disp.getLocation(); } if (!(plugin.canBuildOnLocation(player, loc))) event.setCancelled(true); } plugin.debug( "Event :" + event.getEventName() + ", class: " + h.getClass() + ", cancelled:" + event.isCancelled()); }
@EventHandler(priority = EventPriority.HIGHEST) public void onVehicleDamage(VehicleDamageEvent event) { if (event.isCancelled()) return; if (event.getAttacker() instanceof Player) { final Player player = (Player) event.getAttacker(); final Vehicle vehicle = event.getVehicle(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (vehicle != null && !(plugin.getConfig().getBoolean("flags.use-vehicle", false) || plugin.canBuildOnLocation(player, vehicle.getLocation()))) event.setCancelled(true); plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (event.isCancelled()) return; final Player player = event.getPlayer(); final Entity e = event.getRightClicked(); if (player.getWorld() != plugin.getIslandWorld()) return; if (player.isOp()) return; if (player.hasPermission("islandworld.bypass.island")) return; if (e instanceof Vehicle) { if (!(plugin.getConfig().getBoolean("flags.use-vehicle", false) || plugin.canBuildOnLocation(player, e.getLocation()))) event.setCancelled(true); } else { if (e != null && !plugin.canBuildOnLocation(player, e.getLocation())) event.setCancelled(true); } plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled()); }
private void checkCoords(PlayerMoveEvent event, Player player, boolean isTeleport) { plugin.debug("FlyingListener Check Coords : " + isTeleport); if (!player.getAllowFlight()) return; SimpleIsland isle = plugin.getPlayerIsland(player); final SimpleIsland isleh = plugin.getHelpingIsland(player); if (isle == null && isleh != null && plugin.getOurConfig().isHelperAllowed("home")) isle = isleh; if (isle != null) { if (plugin.isInsideIslandCuboid(event.getFrom(), isle) && !plugin.isInsideIslandCuboid(event.getTo(), isle)) { if (isTeleport) { plugin.showMessage(player, ChatColor.AQUA + plugin.getLoc("info-flying-dis-tele")); player.setAllowFlight(false); } else { plugin.showMessage(player, ChatColor.AQUA + plugin.getLoc("info-flying-dis")); event.setCancelled(true); } } } }