diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-10-26 21:34:36 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-10-26 21:34:36 +0100 |
commit | 0acaff8a85da676b6d67223e14b6f726bf88c368 (patch) | |
tree | c4d42cfcac89754a7ba20c3a61db2cf034814e7e | |
parent | 2dccfdb53cb6958790dd4c73fab369aa9072d9d1 (diff) | |
download | Essentials-0acaff8a85da676b6d67223e14b6f726bf88c368.tar Essentials-0acaff8a85da676b6d67223e14b6f726bf88c368.tar.gz Essentials-0acaff8a85da676b6d67223e14b6f726bf88c368.tar.lz Essentials-0acaff8a85da676b6d67223e14b6f726bf88c368.tar.xz Essentials-0acaff8a85da676b6d67223e14b6f726bf88c368.zip |
Reduce calls to bukkit getPlayer();
4 files changed, 17 insertions, 64 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 2419d8209..c1d4e9f74 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -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) { @@ -509,17 +515,6 @@ public class Essentials extends JavaPlugin implements IEssentials } @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) { if (name.matches("[0-9]+")) diff --git a/Essentials/src/com/earth2me/essentials/api/Economy.java b/Essentials/src/com/earth2me/essentials/api/Economy.java index 6ed1829b3..579afd4d1 100644 --- a/Essentials/src/com/earth2me/essentials/api/Economy.java +++ b/Essentials/src/com/earth2me/essentials/api/Economy.java @@ -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); } /** diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index e2c95afab..66d8ced17 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -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])); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java index eb151077f..1e27e7e3b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsethome.java @@ -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")); |