/** Sends the current cooldown in action bar. */ private void sendCooldownBar() { if (getPlayer() == null) return; StringBuilder stringBuilder = new StringBuilder(); double currentCooldown = Core.getCustomPlayer(getPlayer()).canUse(type); double maxCooldown = type.getCountdown(); int res = (int) (currentCooldown / maxCooldown * 10); ChatColor color; for (int i = 0; i < 10; i++) { color = ChatColor.RED; if (i < 10 - res) color = ChatColor.GREEN; stringBuilder.append(color + "â–�"); } DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator('.'); otherSymbols.setPatternSeparator('.'); final DecimalFormat decimalFormat = new DecimalFormat("0.0", otherSymbols); String timeLeft = decimalFormat.format(currentCooldown) + "s"; PlayerUtils.sendInActionBar( getPlayer(), getName() + " §f" + stringBuilder.toString() + " §f" + timeLeft); }
/** * Cancel players from removing, picking the hat in their inventory. * * @param EVENT */ @EventHandler public void cancelHatClick(final InventoryClickEvent EVENT) { if (EVENT.getCurrentItem() != null && EVENT.getCurrentItem().hasItemMeta() && EVENT.getCurrentItem().getItemMeta().hasDisplayName() && EVENT.getCurrentItem().getItemMeta().getDisplayName().equals("§8§oHat")) { EVENT.setCancelled(true); EVENT.setResult(Event.Result.DENY); EVENT.getWhoClicked().closeInventory(); Bukkit.getScheduler() .runTaskLaterAsynchronously( Core.getPlugin(), new Runnable() { @Override public void run() { for (ItemStack itemStack : EVENT.getWhoClicked().getInventory().getContents()) { if (itemStack != null && itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() && itemStack.getItemMeta().getDisplayName().equals("§8§oHat") && itemStack != EVENT.getWhoClicked().getInventory().getHelmet()) EVENT.getWhoClicked().getInventory().remove(itemStack); } } }, 1); } }
@Override void onUpdate() { final Item ITEM = ent.getWorld() .dropItem( ((Sheep) ent).getEyeLocation(), ItemFactory.create( Material.WOOL, (byte) r.nextInt(017), UUID.randomUUID().toString())); ITEM.setPickupDelay(30000); ITEM.setVelocity( new Vector(r.nextDouble() - 0.5, r.nextDouble() / 2.0 + 0.3, r.nextDouble() - 0.5) .multiply(0.4)); items.add(ITEM); Bukkit.getScheduler() .runTaskLater( Core.getPlugin(), new Runnable() { @Override public void run() { ITEM.remove(); items.remove(ITEM); } }, 5); }
public static Hat getHatByType(String name) { for (Hat hat : Core.getHats()) { if (hat.getName().replace(" ", "").equals(name.replace(" ", ""))) { return hat; } } return null; }
/** * Gets the max amount of pages. * * @return the maximum amount of pages. */ private static int getMaxPagesAmount() { int max = 21; int i = Core.getHats().size(); if (i % max == 0) return i / max; double j = i / 21; int h = (int) Math.floor(j * 100) / 100; return h + 1; }
public static void activateHat(Hat hat, final Player PLAYER) { if (!PLAYER.hasPermission(hat.getPermission())) { if (!playerList.contains(PLAYER)) { PLAYER.sendMessage(MessageManager.getMessage("No-Permission")); playerList.add(PLAYER); Bukkit.getScheduler() .runTaskLaterAsynchronously( Core.getPlugin(), new Runnable() { @Override public void run() { playerList.remove(PLAYER); } }, 1); } return; } Core.getCustomPlayer(PLAYER).setHat(hat); }
@EventHandler public void onInventoryClickAmmo(final InventoryClickEvent event) { if (event.getWhoClicked() == getPlayer() && inv != null && isSameInventory(event.getWhoClicked().getOpenInventory().getTopInventory(), inv)) { event.setCancelled(true); if (event.getCurrentItem() != null && event.getCurrentItem().hasItemMeta() && event.getCurrentItem().getItemMeta().hasDisplayName()) { String displayName = event.getCurrentItem().getItemMeta().getDisplayName(); String purchase = MessageManager.getMessage("Purchase"); String cancel = MessageManager.getMessage("Cancel"); if (displayName.equals(purchase)) { if (Core.getCustomPlayer((Player) event.getWhoClicked()).getBalance() >= getPrice()) { Core.economy.withdrawPlayer((Player) event.getWhoClicked(), getPrice()); Core.getCustomPlayer((Player) event.getWhoClicked()) .addAmmo(type.toString().toLowerCase(), getResultAmmoAmount()); event.getWhoClicked().sendMessage(MessageManager.getMessage("Successful-Purchase")); if (openGadgetsInvAfterAmmo) Bukkit.getScheduler() .runTaskLater( Core.getPlugin(), new Runnable() { @Override public void run() { GadgetManager.openMenu((Player) event.getWhoClicked(), lastPage); openGadgetsInvAfterAmmo = false; lastPage = 1; } }, 1); } else { getPlayer().sendMessage(MessageManager.getMessage("Not-Enough-Money")); } event.getWhoClicked().closeInventory(); } else if (displayName.equals(cancel)) { event.getWhoClicked().closeInventory(); } } } }
@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 onItemDrop(PlayerDropItemEvent event) { if (event.getItemDrop().getItemStack().getType() == type.getMaterial()) { if (event.getItemDrop().getItemStack().getData().getData() == type.getData()) { if (event.getItemDrop().getItemStack().getItemMeta().hasDisplayName()) { if (event .getItemDrop() .getItemStack() .getItemMeta() .getDisplayName() .endsWith(getName())) { if (SettingsManager.getConfig().getBoolean("Remove-Gadget-With-Drop")) { Core.getCustomPlayer(getPlayer()).removeGadget(); event.getItemDrop().remove(); return; } event.setCancelled(true); } } } } }
public Pumpling(World world) { super(world); final Pumpling instance = this; Bukkit.getScheduler() .runTaskLaterAsynchronously( Core.getPlugin(), new Runnable() { @Override public void run() { if (Pet.customEntities.contains(instance)) { isCustomEntity = true; removeSelectors(); setInvisible(true); setBaby(true); setEquipment(4, new ItemStack(Blocks.PUMPKIN)); } } }, 4); }
public Gadget(final UUID owner, final GadgetType type) { this.permission = type.permission; this.type = type; this.affectPlayers = type.affectPlayers(); if (!type.isEnabled()) return; this.useTwoInteractMethods = false; if (owner != null) { this.owner = owner; if (Core.getCustomPlayer(getPlayer()).currentGadget != null) Core.getCustomPlayer(getPlayer()).removeGadget(); if (!getPlayer().hasPermission(permission)) { getPlayer().sendMessage(MessageManager.getMessage("No-Permission")); return; } DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US); otherSymbols.setDecimalSeparator('.'); otherSymbols.setGroupingSeparator('.'); otherSymbols.setPatternSeparator('.'); final DecimalFormat decimalFormat = new DecimalFormat("0.0", otherSymbols); BukkitRunnable runnable = new BukkitRunnable() { @Override public void run() { try { if (Bukkit.getPlayer(owner) != null && Core.getCustomPlayer(Bukkit.getPlayer(owner)).currentGadget != null && Core.getCustomPlayer(Bukkit.getPlayer(owner)).currentGadget.getType() == type) { onUpdate(); if (Core.cooldownInBar) { if (getPlayer().getItemInHand() != null && itemStack != null && getPlayer().getItemInHand().hasItemMeta() && getPlayer().getItemInHand().getItemMeta().hasDisplayName() && getPlayer() .getItemInHand() .getItemMeta() .getDisplayName() .contains(getType().getName()) && Core.getCustomPlayer(getPlayer()).canUse(type) != -1) sendCooldownBar(); double left = Core.getCustomPlayer(getPlayer()).canUse(type); if (left > -0.1) { String leftRounded = decimalFormat.format(left); double decimalRoundedValue = Double.parseDouble(leftRounded); if (decimalRoundedValue == 0) { PlayerUtils.sendInActionBar( getPlayer(), MessageManager.getMessage("Gadgets.Gadget-Ready-ActionBar") .replace( "%gadgetname%", (Core.placeHolderColor) ? getName() : Core.filterColor(getName()))); getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_STICKS, 1f, 1f); } } } } else { cancel(); unregisterListeners(); } } catch (NullPointerException exc) { removeItem(); onClear(); removeListener(); getPlayer() .sendMessage( MessageManager.getMessage("Gadgets.Unequip") .replace( "%gadgetname%", (Core.placeHolderColor) ? getName() : Core.filterColor(getName()))); cancel(); } } }; runnable.runTaskTimerAsynchronously(Core.getPlugin(), 0, 1); listener = new GadgetListener(this); Core.registerListener(listener); Core.registerListener(this); if (getPlayer().getInventory().getItem((int) SettingsManager.getConfig().get("Gadget-Slot")) != null) { getPlayer() .getWorld() .dropItem( getPlayer().getLocation(), getPlayer() .getInventory() .getItem((int) SettingsManager.getConfig().get("Gadget-Slot"))); getPlayer().getInventory().remove((int) SettingsManager.getConfig().get("Gadget-Slot")); } String d = Core.isAmmoEnabled() && getType().requiresAmmo() ? "§f§l" + Core.getCustomPlayer(getPlayer()).getAmmo(type.toString().toLowerCase()) + " " : ""; itemStack = ItemFactory.create( type.getMaterial(), type.getData(), d + getName(), MessageManager.getMessage("Gadgets.Lore")); getPlayer() .getInventory() .setItem((int) SettingsManager.getConfig().get("Gadget-Slot"), itemStack); getPlayer() .sendMessage( MessageManager.getMessage("Gadgets.Equip") .replace( "%gadgetname%", (Core.placeHolderColor) ? getName() : Core.filterColor(getName()))); Core.getCustomPlayer(getPlayer()).currentGadget = this; } }
@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(); } } }
public static void openHatsMenu(final Player p, final int page) { Bukkit.getScheduler() .runTaskAsynchronously( Core.getPlugin(), new Runnable() { @Override public void run() { int listSize = 0; for (Hat hat : Core.getHats()) { if (!hat.isEnabled()) continue; listSize++; } int slotAmount = 54; if (listSize < 22) slotAmount = 54; if (listSize < 15) slotAmount = 45; if (listSize < 8) slotAmount = 36; final Inventory inv = Bukkit.createInventory( null, slotAmount, MessageManager.getMessage("Menus.Hats") + " §7§o(" + page + "/" + getMaxPagesAmount() + ")"); int i = 0; int from = 1; if (page > 1) from = 21 * (page - 1) + 1; int to = 21 * page; for (int h = from; h <= to; h++) { if (h > Core.getHats().size()) break; Hat hat = Core.getHats().get(h - 1); if (!hat.isEnabled() && (boolean) SettingsManager.getConfig() .get("Disabled-Items.Show-Custom-Disabled-Item")) { Material material = Material.valueOf( (String) SettingsManager.getConfig() .get("Disabled-Items.Custom-Disabled-Item.Type")); Byte data = Byte.valueOf( String.valueOf( SettingsManager.getConfig() .get("Disabled-Items.Custom-Disabled-Item.Data"))); String name = String.valueOf( SettingsManager.getConfig() .get("Disabled-Items.Custom-Disabled-Item.Name")) .replace("&", "§"); inv.setItem(COSMETICS_SLOTS[i], ItemFactory.create(material, data, name)); i++; continue; } if (!hat.isEnabled()) continue; if (SettingsManager.getConfig().getBoolean("No-Permission.Dont-Show-Item")) if (!p.hasPermission(hat.getPermission())) continue; if ((boolean) SettingsManager.getConfig().get("No-Permission.Custom-Item.enabled") && !p.hasPermission(hat.getPermission())) { Material material = Material.valueOf( (String) SettingsManager.getConfig().get("No-Permission.Custom-Item.Type")); Byte data = Byte.valueOf( String.valueOf( SettingsManager.getConfig().get("No-Permission.Custom-Item.Data"))); String name = String.valueOf( SettingsManager.getConfig().get("No-Permission.Custom-Item.Name")) .replace("&", "§"); inv.setItem(COSMETICS_SLOTS[i], ItemFactory.create(material, data, name)); i++; continue; } String lore = null; if (SettingsManager.getConfig().getBoolean("No-Permission.Show-In-Lore")) lore = ChatColor.translateAlternateColorCodes( '&', String.valueOf( SettingsManager.getConfig() .get( "No-Permission.Lore-Message-" + ((p.hasPermission(hat.getPermission()) ? "Yes" : "No"))))); String toggle = MessageManager.getMessage("Menu.Equip"); CustomPlayer cp = Core.getCustomPlayer(p); if (cp.currentHat != null && cp.currentHat == hat) toggle = MessageManager.getMessage("Menu.Unequip"); ItemStack is = hat.getItemStack().clone(); ItemMeta im = is.getItemMeta(); im.setDisplayName(toggle + " " + hat.getName()); is.setItemMeta(im); if (cp.currentHat != null && cp.currentHat == hat) is = ItemFactory.addGlow(is); ItemMeta itemMeta = is.getItemMeta(); List<String> loreList = new ArrayList<>(); if (hat.showsDescription()) { loreList.add(""); for (String s : hat.getDescription()) loreList.add(s); loreList.add(""); } if (lore != null) loreList.add(lore); itemMeta.setLore(loreList); is.setItemMeta(itemMeta); inv.setItem(COSMETICS_SLOTS[i], is); i++; } if (page > 1) inv.setItem( inv.getSize() - 18, ItemFactory.create( Material.ENDER_PEARL, (byte) 0, MessageManager.getMessage("Menu.Previous-Page"))); if (page < getMaxPagesAmount()) inv.setItem( inv.getSize() - 10, ItemFactory.create( Material.EYE_OF_ENDER, (byte) 0, MessageManager.getMessage("Menu.Next-Page"))); if (Category.HATS.hasGoBackArrow()) inv.setItem( inv.getSize() - 6, ItemFactory.create( Material.ARROW, (byte) 0x0, MessageManager.getMessage("Menu.Main-Menu"))); inv.setItem( inv.getSize() - (Category.HATS.hasGoBackArrow() ? 4 : 5), ItemFactory.create( Material.TNT, (byte) 0x0, MessageManager.getMessage("Clear-Hat"))); ItemFactory.fillInventory(inv); Bukkit.getScheduler() .runTask( Core.getPlugin(), new Runnable() { @Override public void run() { p.openInventory(inv); } }); } }); }
@EventHandler public void hatSelection(InventoryClickEvent event) { if (event.getInventory().getTitle().startsWith(MessageManager.getMessage("Menus.Hats"))) { event.setCancelled(true); if (event.getCurrentItem() == null || !event.getCurrentItem().hasItemMeta() || !event.getCurrentItem().getItemMeta().hasDisplayName()) return; if (event.getCurrentItem().getItemMeta().hasDisplayName()) { if (event .getCurrentItem() .getItemMeta() .getDisplayName() .equals(MessageManager.getMessage("Menu.Hats")) || event.getCurrentItem().getType() == Material.STAINED_GLASS_PANE) { return; } if (event .getCurrentItem() .getItemMeta() .getDisplayName() .equals(MessageManager.getMessage("Menu.Main-Menu"))) { MainMenuManager.openMainMenu((Player) event.getWhoClicked()); return; } else if (event .getCurrentItem() .getItemMeta() .getDisplayName() .equals(MessageManager.getMessage("Clear-Hat"))) { if (Core.getCustomPlayer((Player) event.getWhoClicked()).currentHat != null) { int currentPage = getCurrentPage((Player) event.getWhoClicked()); event.getWhoClicked().closeInventory(); Core.getCustomPlayer((Player) event.getWhoClicked()).removeHat(); openHatsMenu((Player) event.getWhoClicked(), currentPage); } else return; return; } else if (event .getCurrentItem() .getItemMeta() .getDisplayName() .equalsIgnoreCase(MessageManager.getMessage("Menu.Next-Page"))) { openHatsMenu( (Player) event.getWhoClicked(), getCurrentPage((Player) event.getWhoClicked()) + 1); return; } else if (event .getCurrentItem() .getItemMeta() .getDisplayName() .equalsIgnoreCase(MessageManager.getMessage("Menu.Previous-Page"))) { openHatsMenu( (Player) event.getWhoClicked(), getCurrentPage((Player) event.getWhoClicked()) - 1); return; } event.getWhoClicked().closeInventory(); if (event .getCurrentItem() .getItemMeta() .getDisplayName() .startsWith(MessageManager.getMessage("Menu.Unequip"))) { Core.getCustomPlayer((Player) event.getWhoClicked()).removeHat(); return; } else if (event .getCurrentItem() .getItemMeta() .getDisplayName() .startsWith(MessageManager.getMessage("Menu.Equip"))) { Core.getCustomPlayer((Player) event.getWhoClicked()).removeHat(); StringBuilder sb = new StringBuilder(); String name = event .getCurrentItem() .getItemMeta() .getDisplayName() .replace(MessageManager.getMessage("Menu.Equip"), ""); int j = name.split(" ").length; if (name.contains("(")) j--; for (int i = 1; i < j; i++) { sb.append(name.split(" ")[i]); try { if (event.getCurrentItem().getItemMeta().getDisplayName().split(" ")[i + 1] != null) sb.append(" "); } catch (Exception exc) { } } activateHat(getHatByType(sb.toString()), (Player) event.getWhoClicked()); } } } }