summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2011-11-03 16:17:39 +0000
committerKHobbits <rob@khobbits.co.uk>2011-11-03 16:17:39 +0000
commit25a13b823f6bd9a146907918dd0e0e25f02ac79e (patch)
tree9c0e8d1c45f2570207d232284c6ae27791fe61d1
parent9db235056c081adf494bb6d8555a46ea15639b35 (diff)
downloadEssentials-25a13b823f6bd9a146907918dd0e0e25f02ac79e.tar
Essentials-25a13b823f6bd9a146907918dd0e0e25f02ac79e.tar.gz
Essentials-25a13b823f6bd9a146907918dd0e0e25f02ac79e.tar.lz
Essentials-25a13b823f6bd9a146907918dd0e0e25f02ac79e.tar.xz
Essentials-25a13b823f6bd9a146907918dd0e0e25f02ac79e.zip
Allow the use of the warp command from the console
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwarp.java80
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);