public boolean isPurchaseAble(GameKit kit) { boolean economy = SkyWarsReloaded.get().getConfig().getBoolean("gameVariables.useEconomy"); if (economy) { return kit.getCost() > 0; } return false; }
public void openKitMenu(final GamePlayer gamePlayer) { List<GameKit> availableKits = Lists.newArrayList(kitMap.values()); int rowCount = menuSlotsPerRow; while (rowCount < availableKits.size() && rowCount < menuSize) { rowCount += menuSlotsPerRow; } SkyWarsReloaded.getIC() .create( gamePlayer.getP(), menuName, rowCount, new IconMenu.OptionClickEventHandler() { @Override public void onOptionClick(IconMenu.OptionClickEvent event) { if (gamePlayer.isPlaying()) { event .getPlayer() .sendMessage( new Messaging.MessageFormatter().format("error.can-not-pick-kit")); return; } if (gamePlayer.getGame().getState() != GameState.INLOBBY) { event .getPlayer() .sendMessage( new Messaging.MessageFormatter().format("error.can-not-pick-kit")); return; } GameKit kit = SkyWarsReloaded.getKC().getByName(ChatColor.stripColor(event.getName())); if (kit == null) { return; } if (!hasPermission(event.getPlayer(), kit) && !hasFreePermission(event.getPlayer(), kit)) { event .getPlayer() .sendMessage( new Messaging.MessageFormatter().format("error.no-permission-kit")); return; } if (!hasFreePermission(event.getPlayer(), kit)) { if (!canPurchase(gamePlayer, kit)) { event .getPlayer() .sendMessage( new Messaging.MessageFormatter().format("error.not-enough-balance")); return; } else { SkyWarsReloaded.econ.withdrawPlayer(gamePlayer.getP(), kit.getCost()); } } event.setWillClose(true); event.setWillDestroy(true); gamePlayer.setSelectedKit(kit); gamePlayer.setKitSelected(true); event .getPlayer() .sendMessage( new Messaging.MessageFormatter() .setVariable("kit", kit.getName()) .format("game.enjoy-kit")); } }); for (int iii = 0; iii < availableKits.size(); iii++) { if (iii >= menuSize) { break; } GameKit kit = availableKits.get(iii); List<String> loreList = Lists.newLinkedList(); boolean canPurchase = false; if (isPurchaseAble(kit)) { loreList.add( "\247r\2476Price\247f: \247" + (SkyWarsReloaded.econ.getBalance(gamePlayer.getP()) >= kit.getCost() ? 'a' : 'c') + kit.getCost()); loreList.add(" "); if (canPurchase(gamePlayer, kit)) { canPurchase = true; } } else if (!hasPermission(gamePlayer.getP(), kit)) { loreList.add("No permission"); loreList.add(" "); } else { canPurchase = true; } loreList.addAll(kit.getLores()); SkyWarsReloaded.getIC() .setOption( gamePlayer.getP(), kit.getPosition(), kit.getIcon(), "\247r\247" + (canPurchase ? 'a' : 'c') + kit.getName(), loreList.toArray(new String[loreList.size()])); } SkyWarsReloaded.getIC().show(gamePlayer.getP()); }
public void givePotionEffects(GamePlayer gamePlayer, GameKit kit) { for (PotionEffect pEffect : kit.getPotionEffects()) { gamePlayer.getP().addPotionEffect(pEffect); } }
public void populateInventory(Inventory inventory, GameKit kit) { for (ItemStack itemStack : kit.getItems()) { inventory.addItem(itemStack); } }
public boolean canPurchase(GamePlayer gamePlayer, GameKit kit) { return kit.getCost() > 0 && (SkyWarsReloaded.econ.getBalance(gamePlayer.getP()) >= kit.getCost()); }
public boolean hasFreePermission(Player player, GameKit kit) { return player.isOp() || SkyWarsReloaded.perms.has( player, premissionPrefix + "free." + kit.getName().toLowerCase()); }