diff options
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java | 2 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandwarp.java | 80 |
2 files changed, 54 insertions, 28 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index ca9fee47b..e98a613ff 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -18,6 +18,6 @@ public class Commandsuicide extends EssentialsCommand user.setHealth(0); user.sendMessage(Util.i18n("suicideMessage")); ess.broadcastMessage(user, - Util.format("suicideSuccess",user.getDisplayName())); + Util.format("suicideSuccess", user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 36d1d0df0..accbca4b0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.Warps; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.bukkit.command.CommandSender; public class Commandwarp extends EssentialsCommand @@ -28,33 +29,7 @@ public class Commandwarp extends EssentialsCommand { throw new Exception(Util.i18n("warpListPermission")); } - - Warps warps = ess.getWarps(); - if (warps.isEmpty()) - { - throw new Exception(Util.i18n("noWarpsDefined")); - } - final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames()); - final Iterator<String> iterator = warpNameList.iterator(); - while (iterator.hasNext()) - { - final String warpName = iterator.next(); - if (ess.getSettings().getPerWarpPermission() && !user.isAuthorized("essentials.warp." + warpName)) - { - iterator.remove(); - } - } - int page = 1; - if (args.length > 0) - { - page = Integer.parseInt(args[0]); - } - if (warpNameList.size() > WARPS_PER_PAGE) - { - user.sendMessage(Util.format("warpsCount", warpNameList.size(), page, (int)Math.ceil(warpNameList.size() / (double)WARPS_PER_PAGE))); - } - final int warpPage = (page - 1) * WARPS_PER_PAGE; - user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage+Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE)))); + warpList(user, args); throw new NoChargeException(); } if (args.length > 0) @@ -75,6 +50,57 @@ public class Commandwarp extends EssentialsCommand } } + public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception + { + if (args.length < 2 || args[0].matches("[0-9]+")) + { + warpList(null, args); + throw new NoChargeException(); + } + User otherUser = ess.getUser(server.getPlayer(args[1])); + if (otherUser == null) + { + throw new Exception(Util.i18n("playerNotFound")); + } + warpUser(otherUser, args[0]); + throw new NoChargeException(); + + } + + private void warpList(User user, String[] args) throws Exception + { + Warps warps = ess.getWarps(); + if (warps.isEmpty()) + { + throw new Exception(Util.i18n("noWarpsDefined")); + } + final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames()); + + if (user != null) + { + final Iterator<String> iterator = warpNameList.iterator(); + while (iterator.hasNext()) + { + final String warpName = iterator.next(); + if (ess.getSettings().getPerWarpPermission() && !user.isAuthorized("essentials.warp." + warpName)) + { + iterator.remove(); + } + } + } + int page = 1; + if (args.length > 0) + { + page = Integer.parseInt(args[0]); + } + if (warpNameList.size() > WARPS_PER_PAGE) + { + user.sendMessage(Util.format("warpsCount", warpNameList.size(), page, (int)Math.ceil(warpNameList.size() / (double)WARPS_PER_PAGE))); + } + final int warpPage = (page - 1) * WARPS_PER_PAGE; + user.sendMessage(Util.joinList(warpNameList.subList(warpPage, warpPage + Math.min(warpNameList.size() - warpPage, WARPS_PER_PAGE)))); + } + private void warpUser(User user, String name) throws Exception { Trade charge = new Trade(this.getName(), ess); |