@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()); }