@Override public void onPlayerEggThrow(final PlayerEggThrowEvent event) { final User user = ess.getUser(event.getPlayer()); final ItemStack is = new ItemStack(Material.EGG, 1); if (user.hasUnlimited(is)) { user.getInventory().addItem(is); user.updateInventory(); } }
@Override public void run( final Server server, final User user, final String commandLabel, final String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } if (args[0].equalsIgnoreCase("hand")) { final ItemStack item = user.getItemInHand(); if (item == null) { throw new Exception(Util.i18n("repairInvalidType")); } final String itemName = item.getType().toString().toLowerCase(); final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess); charge.isAffordableFor(user); repairItem(item); charge.charge(user); user.sendMessage(Util.format("repair", itemName.replace('_', ' '))); } else if (args[0].equalsIgnoreCase("all")) { final List<String> repaired = new ArrayList<String>(); repairItems(user.getInventory().getContents(), user, repaired); repairItems(user.getInventory().getArmorContents(), user, repaired); if (repaired.isEmpty()) { throw new Exception(Util.format("repairNone")); } else { user.sendMessage(Util.format("repair", Util.joinList(repaired))); } } else { throw new NotEnoughArgumentsException(); } }
protected final Trade getTrade( final ISign sign, final int amountIndex, final int itemIndex, final User player, final IEssentials ess) throws SignException { final ItemStack item = getItemStack(sign.getLine(itemIndex), 1, ess); final int amount = Math.min( getIntegerPositive(sign.getLine(amountIndex)), item.getType().getMaxStackSize() * player.getInventory().getSize()); if (item.getTypeId() == 0 || amount < 1) { throw new SignException(Util.i18n("moreThanZero")); } item.setAmount(amount); return new Trade(item, ess); }
@Override public void onPlayerQuit(final PlayerQuitEvent event) { final User user = ess.getUser(event.getPlayer()); if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) { user.toggleGodModeEnabled(); } if (user.getSavedInventory() != null) { user.getInventory().setContents(user.getSavedInventory()); user.setSavedInventory(null); } user.updateActivity(false); user.dispose(); if (!ess.getSettings().getReclaimSetting()) { return; } final Thread thread = new Thread( new Runnable() { public void run() { try { Thread.sleep(1000); Runtime rt = Runtime.getRuntime(); double mem = rt.freeMemory(); rt.runFinalization(); rt.gc(); mem = rt.freeMemory() - mem; mem /= 1024 * 1024; LOGGER.log(Level.INFO, Util.format("freedMemory", mem)); } catch (InterruptedException ex) { return; } } }); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
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")); } }
@Override public void run(Server server, User user, String commandLabel, String[] args) throws Exception { if (args.length < 1) { throw new NotEnoughArgumentsException(); } User target = user; if (args.length > 1 && user.isAuthorized("essentials.unlimited.others")) { target = getPlayer(server, args, 1); } if (args[0].equalsIgnoreCase("list")) { StringBuilder sb = new StringBuilder(); sb.append(Util.i18n("unlimitedItems")).append(" "); boolean first = true; List<Integer> items = target.getUnlimited(); if (items.isEmpty()) { sb.append(Util.i18n("none")); } for (Integer integer : items) { if (!first) { sb.append(", "); } first = false; String matname = Material.getMaterial(integer).toString().toLowerCase().replace("_", ""); sb.append(matname); } user.sendMessage(sb.toString()); return; } final ItemStack stack = ess.getItemDb().get(args[0], 1); stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2)); String itemname = stack.getType().toString().toLowerCase().replace("_", ""); if (!user.isAuthorized("essentials.unlimited.item-all") && !user.isAuthorized("essentials.unlimited.item-" + itemname) && !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId()) && !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET) && user.isAuthorized("essentials.unlimited.item-bucket"))) { user.sendMessage(Util.format("unlimitedItemPermission", itemname)); return; } if (target.hasUnlimited(stack)) { if (user != target) { user.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName())); } target.sendMessage(Util.format("disableUnlimited", itemname, target.getDisplayName())); target.setUnlimited(stack, false); return; } charge(user); if (user != target) { user.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName())); } target.sendMessage(Util.format("enableUnlimited", itemname, target.getDisplayName())); if (!InventoryWorkaround.containsItem(target.getInventory(), true, stack)) { target.getInventory().addItem(stack); } target.setUnlimited(stack, true); }