summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/commands/Commandpweather.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
commitff46b39f2b42abbe4ce8dc39e564f3dc71a2a104 (patch)
treed4438b241ea1b251105a2622aada79542c2f41ce /Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
parentd6dfe5da65fdc9bda682615488f5dc9917c394b5 (diff)
downloadEssentials-ff46b39f2b42abbe4ce8dc39e564f3dc71a2a104.tar
Essentials-ff46b39f2b42abbe4ce8dc39e564f3dc71a2a104.tar.gz
Essentials-ff46b39f2b42abbe4ce8dc39e564f3dc71a2a104.tar.lz
Essentials-ff46b39f2b42abbe4ce8dc39e564f3dc71a2a104.tar.xz
Essentials-ff46b39f2b42abbe4ce8dc39e564f3dc71a2a104.zip
Extract CommandSender to CommandSource, this should prevent Ess user object leaks.
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/commands/Commandpweather.java')
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandpweather.java33
1 files changed, 18 insertions, 15 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
index c410bcdfa..0c067b682 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandpweather.java
@@ -1,11 +1,11 @@
package com.earth2me.essentials.commands;
+import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import java.util.*;
import org.bukkit.Server;
import org.bukkit.WeatherType;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -32,7 +32,7 @@ public class Commandpweather 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;
@@ -54,11 +54,14 @@ public class Commandpweather extends EssentialsCommand
return;
}
- User user = ess.getUser(sender);
- if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others"))
+ if (sender.isPlayer())
{
- user.sendMessage(_("pWeatherOthersPermission"));
- return;
+ User user = ess.getUser(sender.getPlayer());
+ if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others"))
+ {
+ user.sendMessage(_("pWeatherOthersPermission"));
+ return;
+ }
}
setUsersWeather(sender, users, args[0].toLowerCase());
@@ -67,7 +70,7 @@ public class Commandpweather extends EssentialsCommand
/**
* Used to get the time and inform
*/
- private void getUsersWeather(final CommandSender sender, final Collection<User> users)
+ private void getUsersWeather(final CommandSource sender, final Collection<User> users)
{
if (users.size() > 1)
{
@@ -90,7 +93,7 @@ public class Commandpweather extends EssentialsCommand
/**
* 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
+ private void setUsersWeather(final CommandSource sender, final Collection<User> users, final String weatherType) throws Exception
{
final StringBuilder msg = new StringBuilder();
@@ -131,24 +134,24 @@ public class Commandpweather 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;
}