private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) { for (ItemStack item : items) { if (item == null) { continue; } final String itemName = item.getType().toString().toLowerCase(); final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess); try { charge.isAffordableFor(user); } catch (ChargeException ex) { user.sendMessage(ex.getMessage()); continue; } try { repairItem(item); } catch (Exception e) { continue; } try { charge.charge(user); } catch (ChargeException ex) { user.sendMessage(ex.getMessage()); } repaired.add(itemName.replace('_', ' ')); } }
@Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.sendMessage(_("backUsageMsg")); user.getTeleport().back(charge); }
@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(); } }
@Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { switch (args.length) { case 0: throw new NotEnoughArgumentsException(); case 1: final User player = getPlayer(server, args, 0); if (!player.isTeleportEnabled()) { throw new Exception(_("teleportDisabled", player.getDisplayName())); } if (user.getWorld() != player.getWorld() && ess.getSettings().getIsWorldTeleportPermissions() && !user.isAuthorized("essentials.world." + player.getWorld().getName())) { throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName())); } user.sendMessage(_("teleporting")); final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); user.getTeleport().teleport(player, charge, TeleportCause.COMMAND); throw new NoChargeException(); default: if (!user.isAuthorized("essentials.tp.others")) { throw new Exception(_("noPerm", "essentials.tp.others")); } user.sendMessage(_("teleporting")); final User target = getPlayer(server, args, 0); final User toPlayer = getPlayer(server, args, 1); target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND); target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName())); break; } }