Extract CommandSender to CommandSource, this should prevent Ess user object leaks.

This commit is contained in:
KHobbits 2013-10-16 20:59:39 +01:00
parent cf9d79d24c
commit 6f85761f7f
145 changed files with 1848 additions and 590 deletions

View file

@ -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 java.util.List;
import java.util.Locale;
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -18,7 +18,7 @@ public class Commandgamemode extends EssentialsCommand
}
@Override
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
{
GameMode gameMode;
if (args.length == 0)
@ -49,7 +49,7 @@ public class Commandgamemode extends EssentialsCommand
else if (args.length > 1 && args[1].trim().length() > 2 && user.isAuthorized("essentials.gamemode.others"))
{
gameMode = matchGameMode(args[0].toLowerCase(Locale.ENGLISH));
gamemodeOtherPlayers(server, user.getBase(), gameMode, args[1]);
gamemodeOtherPlayers(server, user.getSource(), gameMode, args[1]);
return;
}
else
@ -63,7 +63,7 @@ public class Commandgamemode extends EssentialsCommand
if (user.isAuthorized("essentials.gamemode.others"))
{
gameMode = matchGameMode(commandLabel);
gamemodeOtherPlayers(server, user.getBase(), gameMode, args[0]);
gamemodeOtherPlayers(server, user.getSource(), gameMode, args[0]);
return;
}
throw new NotEnoughArgumentsException();
@ -77,7 +77,7 @@ public class Commandgamemode extends EssentialsCommand
user.sendMessage(_("gameMode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
}
private void gamemodeOtherPlayers(final Server server, final CommandSender sender, final GameMode gameMode, final String name) throws NotEnoughArgumentsException, PlayerNotFoundException
private void gamemodeOtherPlayers(final Server server, final CommandSource sender, final GameMode gameMode, final String name) throws NotEnoughArgumentsException, PlayerNotFoundException
{
//TODO: TL this
if (name.trim().length() < 2 || gameMode == null)
@ -85,7 +85,7 @@ public class Commandgamemode extends EssentialsCommand
throw new NotEnoughArgumentsException("You need to specify a valid player/mode.");
}
boolean skipHidden = sender instanceof Player && !ess.getUser(sender).isAuthorized("essentials.vanish.interact");
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.vanish.interact");
boolean foundUser = false;
final List<Player> matchedPlayers = server.matchPlayer(name);
for (Player matchPlayer : matchedPlayers)