Reduce calls to bukkit getPlayer();

This commit is contained in:
KHobbits 2012-10-26 21:34:36 +01:00
parent 0bc33554f3
commit 48d04216a7
4 changed files with 17 additions and 64 deletions

View File

@ -467,15 +467,21 @@ public class Essentials extends JavaPlugin implements IEssentials
}
if (base instanceof String)
{
final User user = userMap.getUser((String)base);
if (user != null && user.getBase() instanceof OfflinePlayer)
{
((OfflinePlayer)user.getBase()).setName((String)base);
}
return user;
return getOfflineUser((String)base);
}
return null;
}
@Override
public User getOfflineUser(final String name)
{
final User user = userMap.getUser(name);
if (user != null && user.getBase() instanceof OfflinePlayer)
{
((OfflinePlayer)user.getBase()).setName(name);
}
return user;
}
private <T extends Player> User getUser(final T base)
{
@ -508,17 +514,6 @@ public class Essentials extends JavaPlugin implements IEssentials
return user;
}
@Override
public User getOfflineUser(final String name)
{
final User user = userMap.getUser(name);
if (user != null && user.getBase() instanceof OfflinePlayer)
{
((OfflinePlayer)user.getBase()).setName(name);
}
return user;
}
@Override
public World getWorld(final String name)
{

View File

@ -8,7 +8,6 @@ import com.earth2me.essentials.Util;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
/**
@ -72,17 +71,7 @@ public final class Economy
{
throw new RuntimeException(noCallBeforeLoad);
}
User user;
Player player = ess.getServer().getPlayer(name);
if (player != null)
{
user = ess.getUser(player);
}
else
{
user = ess.getOfflineUser(name);
}
return user;
return ess.getUser(name);
}
/**

View File

@ -45,16 +45,7 @@ public class Commandmail extends EssentialsCommand
throw new Exception(_("noPerm", "essentials.mail.send"));
}
Player player = server.getPlayer(args[1]);
User u;
if (player != null)
{
u = ess.getUser(player);
}
else
{
u = ess.getOfflineUser(args[1]);
}
User u = ess.getUser(args[0]);
if (u == null)
{
throw new Exception(_("playerNeverOnServer", args[1]));
@ -113,16 +104,7 @@ public class Commandmail extends EssentialsCommand
}
else if (args.length >= 3 && "send".equalsIgnoreCase(args[0]))
{
Player player = server.getPlayer(args[1]);
User u;
if (player != null)
{
u = ess.getUser(player);
}
else
{
u = ess.getOfflineUser(args[1]);
}
User u = ess.getUser(args[0]);
if (u == null)
{
throw new Exception(_("playerNeverOnServer", args[1]));
@ -138,16 +120,7 @@ public class Commandmail extends EssentialsCommand
else if (args.length >= 2)
{
//allow sending from console without "send" argument, since it's the only thing the console can do
Player player = server.getPlayer(args[0]);
User u;
if (player != null)
{
u = ess.getUser(player);
}
else
{
u = ess.getOfflineUser(args[0]);
}
User u = ess.getUser(args[0]);
if (u == null)
{
throw new Exception(_("playerNeverOnServer", args[0]));

View File

@ -39,11 +39,7 @@ public class Commandsethome extends EssentialsCommand
{
if (user.isAuthorized("essentials.sethome.others"))
{
usersHome = ess.getUser(ess.getServer().getPlayer(args[0]));
if (usersHome == null)
{
usersHome = ess.getOfflineUser(args[0]);
}
usersHome = ess.getUser(args[0]);
if (usersHome == null)
{
throw new NoSuchFieldException(_("playerNotFound"));