@Override protected void handleClick(GUI gui, Player p, ItemStack item) { Balloons config = plugin.getBalloons(); if (gui.getName().equals(Placeholders.parse(config.getGuiName(), p))) { CosmeticsAPI api = plugin.getApi(); if (config.getHomeItem().getItem().isSimilar(item)) { if (plugin.getBabies().getGuiClickSound() != null) Sounds.playSound(p, plugin.getBabies().getGuiClickSound()); CosmeticsGuiHandler.open(p); return; } if (config.getRemoveItem().getItem().isSimilar(item)) { if (api.hasBalloon(p)) api.getBalloon(p).remove(); Sounds.playSound(p, config.getRemoveSound()); p.closeInventory(); return; } if (Methods.isNoPermissionItem(config.getNoPermissionItem(), item)) { plugin.informPlayerNoPermission(p, config.getNoPermissionMessage()); return; } if (config.getPreviousItem().getItem().isSimilar(item)) { if (plugin.getBabies().getGuiClickSound() != null) Sounds.playSound(p, plugin.getBabies().getGuiClickSound()); int currPage = PAGEMAP.get(p.getName()); if (currPage == 0) open(p, config.getMaxPage()); else open(p, currPage - 1); return; } if (config.getNextItem().getItem().isSimilar(item)) { if (plugin.getBabies().getGuiClickSound() != null) Sounds.playSound(p, plugin.getBabies().getGuiClickSound()); int currPage = PAGEMAP.get(p.getName()); if (currPage == config.getMaxPage()) open(p, 0); else open(p, currPage + 1); return; } BalloonStorage balloon = api.getBalloonByItemStack(item); if (!Methods.hasPermission(p, balloon.getPermission())) { plugin.informPlayerNoPermission(p, config.getNoPermissionMessage()); return; } new BalloonImpl(p, balloon).give(); Sounds.playSound(p, config.getGiveSound()); p.closeInventory(); } }
@EventHandler public void onSongEnd(SongEndEvent e) { CosmeticsAPI api = this.plugin.getApi(); e.getSongPlayer() .getPlayerList() .stream() .filter(p -> api.hasMusic(Bukkit.getPlayer(p))) .forEach( p -> { Music musicc = api.getMusic(Bukkit.getPlayer(p)); if (this.plugin.getMusic().isLoop()) { musicc.give(); } else { musicc.remove(); } }); }
public static void open(Player p, int page) { Player p1 = p; Balloons config = plugin.getBalloons(); CosmeticsAPI api = plugin.getApi(); GUI gui = buildGui( config.getGuiName(), config.getGuiSize(), config.getHomeItem(), config.getPreviousItem(), config.getNextItem()); for (BalloonStorage balloon : config.getBalloons()) { int position = getRealPosition(balloon.getPosition(), page, config.getGuiSize()); if (position != -1) { ItemStack item = balloon.getItem().clone(); if (api.hasBalloon(p1)) { if (api.getBalloon(p1) .getBalloonStorage() .getIdentifier() .equals(balloon.getIdentifier())) item.addUnsafeEnchantment(glow, 1); } gui.setItem(position, item); if (config.isNoPermissionItemEnabled() && !Methods.hasPermission(p1, balloon.getPermission())) { gui.setItem(position, config.getNoPermissionItem(balloon)); } } } gui.setItem(config.getRemoveItem()); PlayerOpenGuiEvent event = new PlayerOpenGuiEvent(p1, gui); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return; gui = event.getGui(); p1 = event.getPlayer(); PAGEMAP.put(p1.getName(), page); gui.open(p1); }