summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandptime.java
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-10-16 20:59:39 +0100
committerKHobbits <rob@khobbits.co.uk>2013-10-16 21:05:33 +0100
commit6f85761f7fc7949b478c0dec44240f93d4b08a02 (patch)
tree1da56d3d8ca883cfb71e766600f336d39ecbccb2 /Essentials/src/com/earth2me/essentials/commands/Commandptime.java
parentcf9d79d24c8b33d10585a3fc97bc38554dee6d8b (diff)
downloadEssentials-6f85761f7fc7949b478c0dec44240f93d4b08a02.tar
Essentials-6f85761f7fc7949b478c0dec44240f93d4b08a02.tar.gz
Essentials-6f85761f7fc7949b478c0dec44240f93d4b08a02.tar.lz
Essentials-6f85761f7fc7949b478c0dec44240f93d4b08a02.tar.xz
Essentials-6f85761f7fc7949b478c0dec44240f93d4b08a02.zip
Extract CommandSender to CommandSource, this should prevent Ess user object leaks.
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/commands/Commandptime.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandptime.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java
index 8c0fd7dfa..050a012ad 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandptime.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandptime.java
@@ -1,12 +1,12 @@
package com.earth2me.essentials.commands;
+import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DescParseTickFormat;
import java.util.*;
import org.bukkit.Server;
import org.bukkit.World;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -28,7 +28,7 @@ public class Commandptime extends EssentialsCommand
}
@Override
- public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
// Which Players(s) / Users(s) are we interested in?
String userSelector = null;
@@ -45,11 +45,14 @@ public class Commandptime extends EssentialsCommand
return;
}
- User user = ess.getUser(sender);
- if (user != null && (!users.contains(user) || users.size() > 1)&& !user.isAuthorized("essentials.ptime.others"))
+ if (sender.isPlayer())
{
- user.sendMessage(_("pTimeOthersPermission"));
- return;
+ User user = ess.getUser(sender.getPlayer());
+ if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.ptime.others"))
+ {
+ user.sendMessage(_("pTimeOthersPermission"));
+ return;
+ }
}
Long ticks;
@@ -89,7 +92,7 @@ public class Commandptime extends EssentialsCommand
/**
* Used to get the time and inform
*/
- private void getUsersTime(final CommandSender sender, final Collection<User> users)
+ private void getUsersTime(final CommandSource sender, final Collection<User> users)
{
if (users.size() > 1)
{
@@ -120,7 +123,7 @@ public class Commandptime extends EssentialsCommand
/**
* Used to set the time and inform of the change
*/
- private void setUsersTime(final CommandSender sender, final Collection<User> users, final Long ticks, Boolean relative)
+ private void setUsersTime(final CommandSource sender, final Collection<User> users, final Long ticks, Boolean relative)
{
// Update the time
if (ticks == null)
@@ -181,24 +184,24 @@ public class Commandptime extends EssentialsCommand
/**
* 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
+ private Set<User> getUsers(final Server server, final CommandSource 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)
+ if (sender.isPlayer())
+ {
+ final User user = ess.getUser(sender.getPlayer());
+ users.add(user);
+ }
+ else
{
for (Player player : server.getOnlinePlayers())
{
users.add(ess.getUser(player));
}
}
- else
- {
- users.add(user);
- }
return users;
}