@Override public void run() { for (CustomPlayer customPlayer : Core.getCustomPlayers()) { Player p = customPlayer.getPlayer(); try { if (!((List<String>) SettingsManager.getConfig().get("Enabled-Worlds")) .contains(p.getWorld().getName())) { customPlayer.clear(); customPlayer.removeMenuItem(); } } catch (Exception exc) { } } }
@EventHandler protected void onPlayerInteract(final PlayerInteractEvent EVENT) { Player player = EVENT.getPlayer(); UUID uuid = player.getUniqueId(); CustomPlayer cp = Core.getCustomPlayer(getPlayer()); if (!uuid.equals(gadget.owner)) return; ItemStack itemStack = player.getItemInHand(); if (itemStack.getType() != gadget.getMaterial()) return; if (itemStack.getData().getData() != gadget.getData()) return; if (player.getInventory().getHeldItemSlot() != (int) SettingsManager.getConfig().get("Gadget-Slot")) return; if (Core.getCustomPlayer(getPlayer()).currentGadget != gadget) return; if (EVENT.getAction() == Action.PHYSICAL) return; EVENT.setCancelled(true); player.updateInventory(); if (!Core.getCustomPlayer(getPlayer()).hasGadgetsEnabled()) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets-Enabled-Needed")); return; } if (Core.getCustomPlayer(getPlayer()).currentTreasureChest != null) return; if (Core.isAmmoEnabled() && getType().requiresAmmo()) { if (Core.getCustomPlayer(getPlayer()).getAmmo(getType().toString().toLowerCase()) < 1) { openAmmoPurchaseMenu(); return; } } if (type == GadgetType.PORTALGUN) { if (getPlayer().getTargetBlock((Set<Material>) null, 20).getType() == Material.AIR) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.PortalGun.No-Block-Range")); return; } } if (type == GadgetType.ROCKET) { boolean pathClear = true; Cuboid c = new Cuboid( getPlayer().getLocation().add(-1, 0, -1), getPlayer().getLocation().add(1, 75, 1)); if (!c.isEmpty()) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space")); return; } if (!getPlayer().isOnGround()) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-On-Ground")); return; } } if (type == GadgetType.DISCOBALL) { if (Core.discoBalls.size() > 0) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.DiscoBall.Already-Active")); return; } if (getPlayer().getLocation().add(0, 4, 0).getBlock() != null && getPlayer().getLocation().add(0, 4, 0).getBlock().getType() != Material.AIR) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.DiscoBall.Not-Space-Above")); return; } } if (type == GadgetType.CHRISTMASTREE) { if (EVENT.getClickedBlock() == null || EVENT.getClickedBlock().getType() == Material.AIR) { getPlayer() .sendMessage(MessageManager.getMessage("Gadgets.ChristmasTree.Click-On-Block")); return; } } if (type == GadgetType.TRAMPOLINE) { // Check blocks above. Location loc1 = getPlayer().getLocation().add(2, 15, 2); Location loc2 = getPlayer().getLocation().clone().add(-2, 0, -2); Block block = loc1.getBlock().getRelative(3, 0, 0); Block block2 = loc1.getBlock().getRelative(3, 1, 0); Cuboid checkCuboid = new Cuboid(loc1, loc2); if (!checkCuboid.isEmpty() || block.getType() != Material.AIR || block2.getType() != Material.AIR) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space")); return; } } // Check for the parachute if there is space 30-40 blocks above the player to avoid problems. if (type == GadgetType.PARACHUTE) { // Check blocks above. Location loc1 = getPlayer().getLocation().add(2, 28, 2); Location loc2 = getPlayer().getLocation().clone().add(-2, 40, -2); Cuboid checkCuboid = new Cuboid(loc1, loc2); if (!checkCuboid.isEmpty()) { getPlayer().sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-Enough-Space")); return; } } if (type == GadgetType.EXPLOSIVESHEEP) { if (Core.explosiveSheep.size() > 0) { getPlayer() .sendMessage(MessageManager.getMessage("Gadgets.ExplosiveSheep.Already-Active")); return; } } double coolDown = cp.canUse(getType()); if (coolDown != -1) { String timeLeft = new DecimalFormat("#.#").format(coolDown); if (type.getCountdown() > 1) getPlayer() .sendMessage( MessageManager.getMessage("Gadgets.Countdown-Message") .replace( "%gadgetname%", (Core.placeHolderColor) ? getName() : Core.filterColor(getName())) .replace("%time%", timeLeft)); return; } else cp.setCoolDown(getType(), type.getCountdown()); if (Core.isAmmoEnabled() && getType().requiresAmmo()) { Core.getCustomPlayer(getPlayer()).removeAmmo(getType().toString().toLowerCase()); itemStack = ItemFactory.create( type.getMaterial(), type.getData(), "§f§l" + Core.getCustomPlayer(getPlayer()).getAmmo(type.toString().toLowerCase()) + " " + getName(), MessageManager.getMessage("Gadgets.Lore")); getPlayer() .getInventory() .setItem((int) SettingsManager.getConfig().get("Gadget-Slot"), itemStack); } if (EVENT.getClickedBlock() != null && EVENT.getClickedBlock().getType() != Material.AIR) lastClickedBlock = EVENT.getClickedBlock(); if (asyncAction) { Bukkit.getScheduler() .runTaskAsynchronously( Core.getPlugin(), new BukkitRunnable() { @Override public void run() { if (useTwoInteractMethods) { if (EVENT.getAction() == Action.RIGHT_CLICK_AIR || EVENT.getAction() == Action.RIGHT_CLICK_BLOCK) onRightClick(); else if (EVENT.getAction() == Action.LEFT_CLICK_BLOCK || EVENT.getAction() == Action.LEFT_CLICK_AIR) onLeftClick(); } else { onRightClick(); } } }); } else { if (useTwoInteractMethods) { if (EVENT.getAction() == Action.RIGHT_CLICK_AIR || EVENT.getAction() == Action.RIGHT_CLICK_BLOCK) onRightClick(); else if (EVENT.getAction() == Action.LEFT_CLICK_BLOCK || EVENT.getAction() == Action.LEFT_CLICK_AIR) onLeftClick(); } else { onRightClick(); } } }