1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-10-05 02:21:38 +02:00

Round 1 of fixing getPlayer in commands

This commit is contained in:
Iaccidentally
2012-07-22 14:54:18 -04:00
parent 13b9bc600a
commit fc6acc9af8
32 changed files with 38 additions and 36 deletions

View File

@@ -20,7 +20,7 @@ public class Commandban extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
@Cleanup @Cleanup
final IUser user = getPlayer(args, 0, true); final IUser user = ess.getUserMap().matchUser(args[0], false, true);
if (!user.isOnline()) if (!user.isOnline())
{ {
if (sender instanceof Player && Permissions.BAN_OFFLINE.isAuthorized(user)) if (sender instanceof Player && Permissions.BAN_OFFLINE.isAuthorized(user))

View File

@@ -34,7 +34,7 @@ public class Commandclearinventory extends EssentialsCommand
} }
else else
{ {
Player p = server.getPlayer(args[0]); Player p = ess.getUserMap().matchUser(args[0], false, false);
if (p != null) if (p != null)
{ {
p.getInventory().clear(); p.getInventory().clear();

View File

@@ -37,7 +37,7 @@ public class Commanddelhome extends EssentialsCommand
if (expandedArg.length > 1 && (user == null || Permissions.DELHOME_OTHERS.isAuthorized(user))) if (expandedArg.length > 1 && (user == null || Permissions.DELHOME_OTHERS.isAuthorized(user)))
{ {
user = getPlayer(expandedArg, 0, true); user = ess.getUserMap().matchUser(expandedArg[1], false, true);
name = expandedArg[1]; name = expandedArg[1];
} }
else if (user == null) else if (user == null)

View File

@@ -88,7 +88,7 @@ public class Commandeco extends EssentialsCommand
} }
else else
{ {
final IUser player = getPlayer(args, 1, true); final IUser player = ess.getUserMap().matchUser(args[0], true, true);
switch (cmd) switch (cmd)
{ {
case GIVE: case GIVE:

View File

@@ -68,7 +68,7 @@ public class Commandenchant extends EssentialsCommand
{ {
stack.addEnchantment(enchantment, level); stack.addEnchantment(enchantment, level);
} }
user.getInventory().setItemInHand(stack); user.getInventory().setxItemInHand(stack);
user.updateInventory(); user.updateInventory();
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH); final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
if (level == 0) if (level == 0)

View File

@@ -15,7 +15,7 @@ public class Commandgetpos extends EssentialsCommand
if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user)) if (args.length > 0 && Permissions.GETPOS_OTHERS.isAuthorized(user))
{ {
//todo permissions //todo permissions
final IUser otherUser = getPlayer(args, 0); final IUser otherUser = ess.getUserMap().matchUser(args[0], false, false);
if (!otherUser.isHidden() || Permissions.LIST_HIDDEN.isAuthorized(user)) if (!otherUser.isHidden() || Permissions.LIST_HIDDEN.isAuthorized(user))
{ {
outputPosition(user, otherUser.getLocation(), user.getLocation()); outputPosition(user, otherUser.getLocation(), user.getLocation());
@@ -33,7 +33,7 @@ public class Commandgetpos extends EssentialsCommand
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser user = getPlayer(args, 0); final IUser user = ess.getUserMap().matchUser(args[0], false, false);
outputPosition(sender, user.getLocation(), null); outputPosition(sender, user.getLocation(), null);
} }

View File

@@ -33,7 +33,7 @@ public class Commandhome extends EssentialsCommand
} }
else else
{ {
player = getPlayer(nameParts, 0, true); player = ess.getUserMap().matchUser(nameParts[0], false, true);
if (nameParts.length > 1) if (nameParts.length > 1)
{ {
homeName = nameParts[1]; homeName = nameParts[1];

View File

@@ -16,7 +16,7 @@ public class Commandignore extends EssentialsCommand
IUser player; IUser player;
try try
{ {
player = getPlayer(args, 0); player = ess.getUserMap().matchUser(args[0], false, false);
} }
catch (NoSuchFieldException ex) catch (NoSuchFieldException ex)
{ {

View File

@@ -21,7 +21,7 @@ public class Commandinvsee extends EssentialsCommand
IUser invUser = user; IUser invUser = user;
if (args.length == 1) if (args.length == 1)
{ {
invUser = getPlayer(args, 0); invUser = ess.getUserMap().matchUser(args[0], false, false);
} }
user.acquireWriteLock(); user.acquireWriteLock();
if (invUser == user && user.getData().getInventory() != null) if (invUser == user && user.getData().getInventory() != null)

View File

@@ -18,7 +18,7 @@ public class Commandkick extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser user = getPlayer(args, 0); final IUser user = ess.getUserMap().matchUser(args[0], false, false);
if (Permissions.KICK_EXEMPT.isAuthorized(user)) if (Permissions.KICK_EXEMPT.isAuthorized(user))
{ {
throw new Exception(_("kickExempt")); throw new Exception(_("kickExempt"));

View File

@@ -62,7 +62,7 @@ public class Commandmsg extends EssentialsCommand
return; return;
} }
final List<Player> matchedPlayers = server.matchPlayer(args[0]); final List<Player> matchedPlayers = ess.getUserMap().matchUser(args[0], false, false);
if (matchedPlayers.isEmpty()) if (matchedPlayers.isEmpty())
{ {

View File

@@ -20,7 +20,7 @@ public class Commandmute extends EssentialsCommand
} }
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0, true); final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isMuted() && Permissions.MUTE_EXEMPT.isAuthorized(player)) if (!player.getData().isMuted() && Permissions.MUTE_EXEMPT.isAuthorized(player))
{ {

View File

@@ -22,7 +22,7 @@ public class Commandnear extends EssentialsCommand
{ {
try try
{ {
otherUser = getPlayer(args, 0); otherUser = ess.getUserMap().matchUser(args[0], false, false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -62,7 +62,7 @@ public class Commandnear extends EssentialsCommand
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser otherUser = getPlayer(args, 0); final IUser otherUser = ess.getUserMap().matchUser(args[0], false, false);
long radius = 200; long radius = 200;
if (args.length > 1) if (args.length > 1)
{ {

View File

@@ -34,7 +34,7 @@ public class Commandnick extends EssentialsCommand
{ {
throw new Exception(_("nickOthersPermission")); throw new Exception(_("nickOthersPermission"));
} }
setNickname(getPlayer(args, 0), formatNickname(user, args[1])); setNickname(ess.getUserMap().matchUser(args[0], false, false), formatNickname(user, args[1]));
user.sendMessage(_("nickChanged")); user.sendMessage(_("nickChanged"));
return; return;
} }
@@ -61,7 +61,7 @@ public class Commandnick extends EssentialsCommand
} }
else else
{ {
setNickname(getPlayer(args, 0), formatNickname(null, args[1])); setNickname(ess.getUserMap().matchUser(args[0], false, false), formatNickname(null, args[1]));
} }
sender.sendMessage(_("nickChanged")); sender.sendMessage(_("nickChanged"));
} }

View File

@@ -31,7 +31,7 @@ public class Commandseen extends EssentialsCommand
} }
try try
{ {
IUser u = getPlayer(args, 0); IUser u = ess.getUserMap().matchUser(args[0], false, false);
sender.sendMessage(_("seenOnline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGIN)))); sender.sendMessage(_("seenOnline", u.getDisplayName(), DateUtil.formatDateDiff(u.getTimestamp(TimestampType.LOGIN))));
} }
catch (NoSuchFieldException e) catch (NoSuchFieldException e)

View File

@@ -20,7 +20,7 @@ public class Commandspawn extends EssentialsCommand
charge.isAffordableFor(user); charge.isAffordableFor(user);
if (args.length > 0 && Permissions.SPAWN_OTHERS.isAuthorized(user)) if (args.length > 0 && Permissions.SPAWN_OTHERS.isAuthorized(user))
{ {
final IUser otherUser = getPlayer(args, 0); final IUser otherUser = ess.getUserMap().matchUser(args[0], false, false);
respawn(otherUser, null); respawn(otherUser, null);
if (!otherUser.equals(user)) if (!otherUser.equals(user))
{ {
@@ -41,7 +41,7 @@ public class Commandspawn extends EssentialsCommand
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser user = getPlayer(args, 0); final IUser user = ess.getUserMap().matchUser(args[0], false, false);
respawn(user, null); respawn(user, null);
user.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); user.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn"));
sender.sendMessage(_("teleporting")); sender.sendMessage(_("teleporting"));

View File

@@ -16,7 +16,7 @@ public class Commandsudo extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser user = getPlayer(args, 0, false); final IUser user = ess.getUserMap().matchUser(args[0], false, false);
final String command = args[1]; final String command = args[1];
final String[] arguments = new String[args.length - 2]; final String[] arguments = new String[args.length - 2];
if (arguments.length > 0) if (arguments.length > 0)

View File

@@ -20,7 +20,7 @@ public class Commandtempban extends EssentialsCommand
{ {
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser user = getPlayer(args, 0, true); final IUser user = ess.getUserMap().matchUser(args[0], false, true);
if (!user.isOnline()) if (!user.isOnline())
{ {
if (Permissions.TEMPBAN_OFFLINE.isAuthorized(sender)) if (Permissions.TEMPBAN_OFFLINE.isAuthorized(sender))

View File

@@ -21,7 +21,7 @@ public class Commandtogglejail extends EssentialsCommand
} }
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0, true); final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireReadLock(); player.acquireReadLock();
if (args.length >= 2 && !player.getData().isJailed()) if (args.length >= 2 && !player.getData().isJailed())

View File

@@ -28,7 +28,7 @@ public class Commandtp extends EssentialsCommand
case 1: case 1:
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0); final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isTeleportEnabled()) if (!player.getData().isTeleportEnabled())
{ {
@@ -52,9 +52,9 @@ public class Commandtp extends EssentialsCommand
} }
user.sendMessage(_("teleporting")); user.sendMessage(_("teleporting"));
@Cleanup @Cleanup
final IUser target = getPlayer(args, 0); final IUser target = ess.getUserMap().matchUser(args[0], false, false);
@Cleanup @Cleanup
final IUser toPlayer = getPlayer(args, 1); final IUser toPlayer = ess.getUserMap().matchUser(args[1], false, false);
target.acquireReadLock(); target.acquireReadLock();
toPlayer.acquireReadLock(); toPlayer.acquireReadLock();

View File

@@ -18,7 +18,7 @@ public class Commandtpa extends EssentialsCommand
} }
@Cleanup @Cleanup
IUser player = getPlayer(args, 0); IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isTeleportEnabled()) if (!player.getData().isTeleportEnabled())
{ {

View File

@@ -24,7 +24,7 @@ public class Commandtpaall extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser player = getPlayer(args, 0); final IUser player = ess.getUserMap().matchUser(args[0], false, false);
teleportAAllPlayers(sender, player); teleportAAllPlayers(sender, player);
} }

View File

@@ -18,7 +18,7 @@ public class Commandtpahere extends EssentialsCommand
} }
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0); final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isTeleportEnabled()) if (!player.getData().isTeleportEnabled())
{ {

View File

@@ -26,7 +26,7 @@ public class Commandtpall extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
final IUser player = getPlayer(args, 0); final IUser player = ess.getUserMap().matchUser(args[0], false, false);
teleportAllPlayers(sender, player); teleportAllPlayers(sender, player);
} }

View File

@@ -14,7 +14,7 @@ public class Commandtphere extends EssentialsCommand
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{ {
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0); final IUser player = ess.getUserMap().matchUser(args[0], false, false);
player.acquireReadLock(); player.acquireReadLock();
if (!player.getData().isTeleportEnabled()) if (!player.getData().isTeleportEnabled())
{ {

View File

@@ -18,7 +18,7 @@ public class Commandtpo extends EssentialsCommand
} }
//Just basically the old tp command //Just basically the old tp command
final IUser player = getPlayer(args, 0, true); final IUser player = ess.getUserMap().matchUser(args[0], false, true);
// Check if user is offline // Check if user is offline
if (!player.isOnline()) if (!player.isOnline())
{ {

View File

@@ -21,7 +21,7 @@ public class Commandtpohere extends EssentialsCommand
} }
//Just basically the old tphere command //Just basically the old tphere command
final IUser player = getPlayer(args, 0, true); final IUser player = ess.getUserMap().matchUser(args[0], false, true);
// Check if user is offline // Check if user is offline
if (!player.isOnline()) if (!player.isOnline())

View File

@@ -2,6 +2,7 @@ package net.ess3.commands;
import static net.ess3.I18n._; import static net.ess3.I18n._;
import net.ess3.api.IUser; import net.ess3.api.IUser;
import net.ess3.api.server.CommandSender;
import net.ess3.api.server.Location; import net.ess3.api.server.Location;
import net.ess3.economy.Trade; import net.ess3.economy.Trade;
//TODO: remove bukkit //TODO: remove bukkit

View File

@@ -19,7 +19,7 @@ public class Commandunban extends EssentialsCommand
try try
{ {
@Cleanup @Cleanup
final IUser player = getPlayer(args, 0, true); final IUser player = ess.getUserMap().matchUser(args[0], false, true);
player.acquireWriteLock(); player.acquireWriteLock();
player.getData().setBan(null); player.getData().setBan(null);
player.setBanned(false); player.setBanned(false);

View File

@@ -18,7 +18,7 @@ public class Commandunbanip extends EssentialsCommand
try try
{ {
@Cleanup @Cleanup
final IUser user = getPlayer(args, 0, true); final IUser user = ess.getUserMap().matchUser(args[0], false, true);
user.acquireReadLock(); user.acquireReadLock();
ess.getServer().unbanIP(user.getData().getIpAddress()); ess.getServer().unbanIP(user.getData().getIpAddress());
} }

View File

@@ -26,7 +26,7 @@ public class Commandunlimited extends EssentialsCommand
if (args.length > 1 && Permissions.UNLIMITED_OTHERS.isAuthorized(user)) if (args.length > 1 && Permissions.UNLIMITED_OTHERS.isAuthorized(user))
{ {
target = getPlayer(args, 1); target = ess.getUserMap().matchUser(args[1], false, false);
target.acquireReadLock(); target.acquireReadLock();
} }

View File

@@ -5,6 +5,7 @@ import net.ess3.utils.Util;
import net.ess3.api.IUser; import net.ess3.api.IUser;
import net.ess3.api.server.ItemStack; import net.ess3.api.server.ItemStack;
import java.util.Locale; import java.util.Locale;
import net.ess3.api.server.CommandSender;
public class Commandworth extends EssentialsCommand public class Commandworth extends EssentialsCommand