// TODO: Convert this to use one of the new text classes? public static String listKits(final IEssentials ess, final User user) throws Exception { try { final ConfigurationSection kits = ess.getSettings().getKits(); final StringBuilder list = new StringBuilder(); for (String kitItem : kits.getKeys(false)) { if (user == null) { list.append(" ").append(capitalCase(kitItem)); } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) { String cost = ""; String name = capitalCase(kitItem); BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user); if (costPrice.signum() > 0) { cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess)); } Kit kit = new Kit(kitItem, ess); if (kit.getNextUse(user) != 0) { name = tl("kitDelay", name); } list.append(" ").append(name).append(cost); } } return list.toString().trim(); } catch (Exception ex) { throw new Exception(tl("kitError"), ex); } }
//TODO: Convert this to use one of the new text classes? public static String listKits(final IEssentials ess, final User user) throws Exception { try { final ConfigurationSection kits = ess.getSettings().getKits(); final StringBuilder list = new StringBuilder(); for (String kiteItem : kits.getKeys(false)) { if (user.isAuthorized("essentials.kit." + kiteItem.toLowerCase(Locale.ENGLISH))) { list.append(" ").append(capitalCase(kiteItem)); } } return list.toString().trim(); } catch (Exception ex) { throw new Exception(_("kitError")); } }
public long getNextUse(final User user) throws Exception { if (user.isAuthorized("essentials.kit.exemptdelay")) { return 0L; } final Calendar time = new GregorianCalendar(); double delay = 0; try { // Make sure delay is valid delay = kit.containsKey("delay") ? ((Number) kit.get("delay")).doubleValue() : 0.0d; } catch (Exception e) { throw new Exception(tl("kitError2")); } // When was the last kit used? final long lastTime = user.getKitTimestamp(kitName); // When can be use the kit again? final Calendar delayTime = new GregorianCalendar(); delayTime.setTimeInMillis(lastTime); delayTime.add(Calendar.SECOND, (int) delay); delayTime.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0)); if (lastTime == 0L || lastTime > time.getTimeInMillis()) { // If we have no record of kit use, or its corrupted, give them benefit of the doubt. return 0L; } else if (delay < 0d) { // If the kit has a negative kit time, it can only be used once. return -1; } else if (delayTime.before(time)) { // If the kit was used in the past, but outside the delay time, it can be used. return 0L; } else { // If the kit has been used recently, return the next time it can be used. return delayTime.getTimeInMillis(); } }
public static void expandItems(final IEssentials ess, final User user, final List<String> items) throws Exception { try { boolean spew = false; for (String d : items) { final String[] parts = d.split(" "); final String[] item = parts[0].split("[:+',;.]", 2); final int id = Material.getMaterial(Integer.parseInt(item[0])).getId(); final short data = item.length > 1 ? Short.parseShort(item[1]) : 0; final int amount = parts.length > 1 ? Integer.parseInt(parts[1]) : 1; final ItemStack stack = new ItemStack(id, amount, data); if (parts.length > 2) { for (int i = 2; i < parts.length; i++) { final String[] split = parts[i].split("[:+',;.]", 2); if (split.length < 1) { continue; } final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user); int level; if (split.length > 1) { level = Integer.parseInt(split[1]); } else { level = enchantment.getMaxLevel(); } stack.addEnchantment(enchantment, level); } } final Map<Integer, ItemStack> overfilled; if (user.isAuthorized("essentials.oversizedstacks")) { overfilled = InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack); } else { overfilled = InventoryWorkaround.addItem(user.getInventory(), true, new ItemStack(id, amount, data)); } for (ItemStack itemStack : overfilled.values()) { user.getWorld().dropItemNaturally(user.getLocation(), itemStack); spew = true; } } user.updateInventory(); if (spew) { user.sendMessage(_("kitInvFull")); } } catch (Exception e) { user.updateInventory(); throw new Exception(_("kitError2")); } }
public void checkPerms(final User user) throws Exception { if (!user.isAuthorized("essentials.kits." + kitName)) { throw new Exception(tl("noKitPermission", "essentials.kits." + kitName)); } }
public void expandItems(final User user, final List<String> items) throws Exception { try { IText input = new SimpleTextInput(items); IText output = new KeywordReplacer(input, user.getSource(), ess); boolean spew = false; final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments(); for (String kitItem : output.getLines()) { if (kitItem.startsWith(ess.getSettings().getCurrencySymbol())) { BigDecimal value = new BigDecimal( kitItem.substring(ess.getSettings().getCurrencySymbol().length()).trim()); Trade t = new Trade(value, ess); t.pay(user, OverflowType.DROP); continue; } if (kitItem.startsWith("/")) { String command = kitItem.substring(1); String name = user.getName(); command = command.replace("{player}", name); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); continue; } final String[] parts = kitItem.split(" +"); final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); if (parseStack.getType() == Material.AIR) { continue; } final MetaItemStack metaStack = new MetaItemStack(parseStack); if (parts.length > 2) { // We pass a null sender here because kits should not do perm checks metaStack.parseStringMeta(null, allowUnsafe, parts, 2, ess); } final Map<Integer, ItemStack> overfilled; final boolean allowOversizedStacks = user.isAuthorized("essentials.oversizedstacks"); if (allowOversizedStacks) { overfilled = InventoryWorkaround.addOversizedItems( user.getBase().getInventory(), ess.getSettings().getOversizedStackSize(), metaStack.getItemStack()); } else { overfilled = InventoryWorkaround.addItems(user.getBase().getInventory(), metaStack.getItemStack()); } for (ItemStack itemStack : overfilled.values()) { int spillAmount = itemStack.getAmount(); if (!allowOversizedStacks) { itemStack.setAmount( spillAmount < itemStack.getMaxStackSize() ? spillAmount : itemStack.getMaxStackSize()); } while (spillAmount > 0) { user.getWorld().dropItemNaturally(user.getLocation(), itemStack); spillAmount -= itemStack.getAmount(); } spew = true; } } user.getBase().updateInventory(); if (spew) { user.sendMessage(tl("kitInvFull")); } } catch (Exception e) { user.getBase().updateInventory(); ess.getLogger().log(Level.WARNING, e.getMessage()); throw new Exception(tl("kitError2"), e); } }