summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-05-05 07:05:43 +0100
committerKHobbits <rob@khobbits.co.uk>2013-05-05 07:15:33 +0100
commit162b67aaa66a9aef2c41ec63aad7f71a1b8730a4 (patch)
tree2cb1be6dbf3274b4420927c59a24767183141fbe
parent2d70bb19f72933d52eef1f2fc5e1397c0168a60e (diff)
downloadEssentials-162b67aaa66a9aef2c41ec63aad7f71a1b8730a4.tar
Essentials-162b67aaa66a9aef2c41ec63aad7f71a1b8730a4.tar.gz
Essentials-162b67aaa66a9aef2c41ec63aad7f71a1b8730a4.tar.lz
Essentials-162b67aaa66a9aef2c41ec63aad7f71a1b8730a4.tar.xz
Essentials-162b67aaa66a9aef2c41ec63aad7f71a1b8730a4.zip
Cleanup player argument matching in loops
Cleanup ess cleanup timestamp matching
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandessentials.java13
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandext.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandfeed.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandfly.java8
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandgod.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandheal.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandlightning.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpweather.java338
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandspeed.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java6
10 files changed, 231 insertions, 175 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
index d900b276a..1fd0720ee 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandessentials.java
@@ -237,6 +237,7 @@ public class Commandessentials extends EssentialsCommand
@Override
public void run()
{
+ Long currTime = System.currentTimeMillis();
for (String u : userMap.getAllUniqueUsers())
{
final User user = ess.getUserMap().getUser(u);
@@ -246,8 +247,18 @@ public class Commandessentials extends EssentialsCommand
}
int ban = user.getBanReason().equals("") ? 0 : 1;
+
long lastLog = user.getLastLogout();
- long timeDiff = System.currentTimeMillis() - lastLog;
+ if (lastLog == 0)
+ {
+ lastLog = user.getLastLogin();
+ }
+ if (lastLog == 0)
+ {
+ user.setLastLogin(currTime);
+ }
+
+ long timeDiff = currTime - lastLog;
long milliDays = daysArg * 24L * 60L * 60L * 1000L;
int homeCount = user.getHomes().size();
double moneyCount = user.getMoney().doubleValue();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandext.java b/Essentials/src/com/earth2me/essentials/commands/Commandext.java
index 552f74db2..16190f7ee 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandext.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandext.java
@@ -36,7 +36,12 @@ public class Commandext extends EssentialsCommand
return;
}
- extinguishPlayers(server, user, commandLabel);
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
+
+ extinguishPlayers(server, user, args[0]);
}
private void extinguishPlayers(final Server server, final CommandSender sender, final String name) throws Exception
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java
index e37a659b6..4b9f79452 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandfeed.java
@@ -21,12 +21,23 @@ public class Commandfeed extends EssentialsCommand
{
if (args.length > 0 && user.isAuthorized("essentials.feed.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
+ if (!user.isAuthorized("essentials.heal.cooldown.bypass"))
+ {
+ user.healCooldown();
+ }
feedOtherPlayers(server, user, args[0]);
+ return;
}
- else
+
+ if (!user.isAuthorized("essentials.heal.cooldown.bypass"))
{
- feedPlayer(user, user);
+ user.healCooldown();
}
+ feedPlayer(user, user);
}
@Override
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java
index 1d5353fb1..126d7e5d1 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandfly.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandfly.java
@@ -41,12 +41,20 @@ public class Commandfly extends EssentialsCommand
}
else if (user.isAuthorized("essentials.fly.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
flyOtherPlayers(server, user, args);
return;
}
}
else if (args.length == 2 && user.isAuthorized("essentials.fly.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
flyOtherPlayers(server, user, args);
return;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java
index a77648c86..efe2a7f42 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java
@@ -29,8 +29,12 @@ public class Commandgod extends EssentialsCommand
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.god.others"))
+ if (args.length > 0 && user.isAuthorized("essentials.god.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
godOtherPlayers(server, user, args);
return;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java
index c95ad6a81..a3c80b512 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandheal.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandheal.java
@@ -24,6 +24,10 @@ public class Commandheal extends EssentialsCommand
if (args.length > 0 && user.isAuthorized("essentials.heal.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
if (!user.isAuthorized("essentials.heal.cooldown.bypass"))
{
user.healCooldown();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java
index 449c94930..ff22051e7 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandlightning.java
@@ -43,6 +43,11 @@ public class Commandlightning extends EssentialsCommand
}
}
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
+
final List<Player> matchedPlayers = server.matchPlayer(args[0]);
for (Player matchPlayer : matchedPlayers)
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
index a3e1944c4..be5fa114a 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
@@ -11,173 +11,173 @@ import org.bukkit.entity.Player;
public class Commandpweather extends EssentialsCommand
{
- public static final Set<String> getAliases = new HashSet<String>();
- public static final Map<String, WeatherType> weatherAliases = new HashMap<String, WeatherType>();
-
- static
- {
- getAliases.add("get");
- getAliases.add("list");
- getAliases.add("show");
- getAliases.add("display");
- weatherAliases.put("sun", WeatherType.CLEAR);
- weatherAliases.put("clear", WeatherType.CLEAR);
- weatherAliases.put("storm", WeatherType.DOWNFALL);
- weatherAliases.put("thunder", WeatherType.DOWNFALL);
- }
-
- public Commandpweather()
- {
- super("pweather");
- }
-
- @Override
- public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
- {
- // Which Players(s) / Users(s) are we interested in?
- String userSelector = null;
- if (args.length == 2)
- {
- userSelector = args[1];
- }
- Set<User> users = getUsers(server, sender, userSelector);
-
- if (args.length == 0)
- {
- getUsersWeather(sender, users);
- return;
- }
-
- if (getAliases.contains(args[0]))
- {
- getUsersWeather(sender, users);
- return;
- }
-
- User user = ess.getUser(sender);
- if (user != null && (!users.contains(user) || users.size() > 1)&& !user.isAuthorized("essentials.pweather.others"))
- {
- user.sendMessage(_("pWeatherOthersPermission"));
- return;
- }
-
- setUsersWeather(sender, users, args[0].toLowerCase());
- }
-
- /**
- * Used to get the time and inform
- */
- private void getUsersWeather(final CommandSender sender, final Collection<User> users)
- {
- if (users.size() > 1)
- {
- sender.sendMessage(_("pWeatherPlayers"));
- }
-
- for (User user : users)
- {
- if (user.getPlayerWeather() == null)
- {
- sender.sendMessage(_("pWeatherNormal", user.getName()));
- }
- else
- {
- sender.sendMessage(_("pWeatherCurrent", user.getName(), user.getPlayerWeather().toString().toLowerCase(Locale.ENGLISH)));
- }
- }
- }
-
- /**
- * Used to set the time and inform of the change
- */
- private void setUsersWeather(final CommandSender sender, final Collection<User> users, final String weatherType ) throws Exception
- {
-
- final StringBuilder msg = new StringBuilder();
- for (User user : users)
- {
- if (msg.length() > 0)
- {
- msg.append(", ");
- }
-
- msg.append(user.getName());
- }
-
- if (weatherType.equalsIgnoreCase("reset"))
- {
- for (User user : users)
- {
- user.resetPlayerWeather();
- }
-
- sender.sendMessage(_("pWeatherReset", msg));
- }
- else
- {
- if (!weatherAliases.containsKey(weatherType))
- {
- throw new NotEnoughArgumentsException(_("pWeatherInvalidAlias"));
- }
-
- for (User user : users)
- {
- user.setPlayerWeather(weatherAliases.get(weatherType));
- }
- sender.sendMessage(_("pWeatherSet", weatherType, msg.toString()));
- }
- }
-
- /**
- * Used to parse an argument of the type "users(s) selector"
- */
- private Set<User> getUsers(final Server server, final CommandSender sender, final String selector) throws Exception
- {
- final Set<User> users = new TreeSet<User>(new UserNameComparator());
- // If there is no selector we want the sender itself. Or all users if sender isn't a user.
- if (selector == null)
- {
- final User user = ess.getUser(sender);
- if (user == null)
- {
- for (Player player : server.getOnlinePlayers())
- {
- users.add(ess.getUser(player));
- }
- }
- else
- {
- users.add(user);
- }
- return users;
- }
-
- // Try to find the user with name = selector
- User user = null;
- final List<Player> matchedPlayers = server.matchPlayer(selector);
- if (!matchedPlayers.isEmpty())
- {
- user = ess.getUser(matchedPlayers.get(0));
- }
-
- if (user != null)
- {
- users.add(user);
- }
- // If that fails, Is the argument something like "*" or "all"?
- else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all"))
- {
- for (Player player : server.getOnlinePlayers())
- {
- users.add(ess.getUser(player));
- }
- }
- // We failed to understand the world target...
- else
- {
- throw new Exception(_("playerNotFound"));
- }
-
- return users;
- }
+ public static final Set<String> getAliases = new HashSet<String>();
+ public static final Map<String, WeatherType> weatherAliases = new HashMap<String, WeatherType>();
+
+ static
+ {
+ getAliases.add("get");
+ getAliases.add("list");
+ getAliases.add("show");
+ getAliases.add("display");
+ weatherAliases.put("sun", WeatherType.CLEAR);
+ weatherAliases.put("clear", WeatherType.CLEAR);
+ weatherAliases.put("storm", WeatherType.DOWNFALL);
+ weatherAliases.put("thunder", WeatherType.DOWNFALL);
+ }
+
+ public Commandpweather()
+ {
+ super("pweather");
+ }
+
+ @Override
+ public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ {
+ // Which Players(s) / Users(s) are we interested in?
+ String userSelector = null;
+ if (args.length == 2)
+ {
+ userSelector = args[1];
+ }
+ Set<User> users = getUsers(server, sender, userSelector);
+
+ if (args.length == 0)
+ {
+ getUsersWeather(sender, users);
+ return;
+ }
+
+ if (getAliases.contains(args[0]))
+ {
+ getUsersWeather(sender, users);
+ return;
+ }
+
+ User user = ess.getUser(sender);
+ if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others"))
+ {
+ user.sendMessage(_("pWeatherOthersPermission"));
+ return;
+ }
+
+ setUsersWeather(sender, users, args[0].toLowerCase());
+ }
+
+ /**
+ * Used to get the time and inform
+ */
+ private void getUsersWeather(final CommandSender sender, final Collection<User> users)
+ {
+ if (users.size() > 1)
+ {
+ sender.sendMessage(_("pWeatherPlayers"));
+ }
+
+ for (User user : users)
+ {
+ if (user.getPlayerWeather() == null)
+ {
+ sender.sendMessage(_("pWeatherNormal", user.getName()));
+ }
+ else
+ {
+ sender.sendMessage(_("pWeatherCurrent", user.getName(), user.getPlayerWeather().toString().toLowerCase(Locale.ENGLISH)));
+ }
+ }
+ }
+
+ /**
+ * Used to set the time and inform of the change
+ */
+ private void setUsersWeather(final CommandSender sender, final Collection<User> users, final String weatherType) throws Exception
+ {
+
+ final StringBuilder msg = new StringBuilder();
+ for (User user : users)
+ {
+ if (msg.length() > 0)
+ {
+ msg.append(", ");
+ }
+
+ msg.append(user.getName());
+ }
+
+ if (weatherType.equalsIgnoreCase("reset"))
+ {
+ for (User user : users)
+ {
+ user.resetPlayerWeather();
+ }
+
+ sender.sendMessage(_("pWeatherReset", msg));
+ }
+ else
+ {
+ if (!weatherAliases.containsKey(weatherType))
+ {
+ throw new NotEnoughArgumentsException(_("pWeatherInvalidAlias"));
+ }
+
+ for (User user : users)
+ {
+ user.setPlayerWeather(weatherAliases.get(weatherType));
+ }
+ sender.sendMessage(_("pWeatherSet", weatherType, msg.toString()));
+ }
+ }
+
+ /**
+ * Used to parse an argument of the type "users(s) selector"
+ */
+ private Set<User> getUsers(final Server server, final CommandSender sender, final String selector) throws Exception
+ {
+ final Set<User> users = new TreeSet<User>(new UserNameComparator());
+ // If there is no selector we want the sender itself. Or all users if sender isn't a user.
+ if (selector == null)
+ {
+ final User user = ess.getUser(sender);
+ if (user == null)
+ {
+ for (Player player : server.getOnlinePlayers())
+ {
+ users.add(ess.getUser(player));
+ }
+ }
+ else
+ {
+ users.add(user);
+ }
+ return users;
+ }
+
+ // Try to find the user with name = selector
+ User user = null;
+ final List<Player> matchedPlayers = server.matchPlayer(selector);
+ if (!matchedPlayers.isEmpty())
+ {
+ user = ess.getUser(matchedPlayers.get(0));
+ }
+
+ if (user != null)
+ {
+ users.add(user);
+ }
+ // If that fails, Is the argument something like "*" or "all"?
+ else if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all"))
+ {
+ for (Player player : server.getOnlinePlayers())
+ {
+ users.add(ess.getUser(player));
+ }
+ }
+ // We failed to understand the world target...
+ else
+ {
+ throw new Exception(_("playerNotFound"));
+ }
+
+ return users;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java
index 591ea638e..a13ba60c1 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandspeed.java
@@ -49,6 +49,10 @@ public class Commandspeed extends EssentialsCommand
speed = getMoveSpeed(args[1]);
if (args.length > 2 && user.isAuthorized("essentials.speed.others"))
{
+ if (args[2].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
speedOtherPlayers(server, user, isFly, isBypass, speed, args[2]);
return;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java
index 948ead391..302d357e4 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtptoggle.java
@@ -29,8 +29,12 @@ public class Commandtptoggle extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.tptoggle.others"))
+ if (args.length > 0 && user.isAuthorized("essentials.tptoggle.others"))
{
+ if (args[0].trim().length() < 2)
+ {
+ throw new Exception(_("playerNotFound"));
+ }
toggleOtherPlayers(server, user, args);
return;
}