diff options
author | Tahg <tahgtahv@gmail.com> | 2011-01-17 15:50:37 -0500 |
---|---|---|
committer | Tahg <tahgtahv@gmail.com> | 2011-01-17 15:50:37 -0500 |
commit | 42099e737979ccb1143c9c8765d8030f86322fb4 (patch) | |
tree | 2cb6a39fd24803d718ede96d95bf80217e299e86 /src/main/java/org | |
parent | ca9d523646236c032faa5f6a7bf630bbd4d86b01 (diff) | |
download | craftbukkit-42099e737979ccb1143c9c8765d8030f86322fb4.tar craftbukkit-42099e737979ccb1143c9c8765d8030f86322fb4.tar.gz craftbukkit-42099e737979ccb1143c9c8765d8030f86322fb4.tar.lz craftbukkit-42099e737979ccb1143c9c8765d8030f86322fb4.tar.xz craftbukkit-42099e737979ccb1143c9c8765d8030f86322fb4.zip |
allowed partial name matching
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index d52e468e..04019347 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -17,12 +17,12 @@ import org.bukkit.plugin.SimpleCommandManager; import org.bukkit.plugin.SimplePluginManager; import org.bukkit.plugin.java.JavaPluginLoader; -public final class CraftServer implements Server { +public final class CraftServer implements Server +{ private final String serverName = "Craftbukkit"; private final String serverVersion = "1.2_01"; private final PluginManager pluginManager = new SimplePluginManager(this); private final CommandManager commandManager = new SimpleCommandManager(); - protected final MinecraftServer console; protected final ServerConfigurationManager server; @@ -32,9 +32,9 @@ public final class CraftServer implements Server { pluginManager.RegisterInterface(JavaPluginLoader.class); } - + public void loadPlugins() { - File pluginFolder = (File)console.options.valueOf("plugins"); + File pluginFolder = (File) console.options.valueOf("plugins"); if (pluginFolder.exists()) { try { @@ -42,7 +42,7 @@ public final class CraftServer implements Server { for (Plugin plugin : plugins) { if (commandManager.registerCommands(plugin)) { - pluginManager.enablePlugin(plugin); + pluginManager.enablePlugin(plugin); } else { Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, "Plugin " + plugin.getDescription().getName() + " failed to load. Reason: Requested commands already in use."); } @@ -77,15 +77,22 @@ public final class CraftServer implements Server { public Player getPlayer(final String name) { Player[] players = getOnlinePlayers(); + Player found = null; + String lowerName = name.toLowerCase(); + int delta = Integer.MAX_VALUE; for (Player player : players) { - if (player.getName().equalsIgnoreCase(name)) { - return player; + if (player.getName().toLowerCase().startsWith(lowerName)) { + int curDelta = player.getName().length() - lowerName.length(); + if(curDelta == 0) break; + if (curDelta < delta) { + found = player; + delta = curDelta; + } } } - - return null; + return found; } - + public int broadcastMessage(String message) { Player[] players = getOnlinePlayers(); @@ -99,10 +106,10 @@ public final class CraftServer implements Server { public Player getPlayer(final EntityPlayerMP entity) { return entity.a.getPlayer(); } - + public List<Player> matchPlayer(String partialName) { List<Player> matchedPlayers = new ArrayList<Player>(); - + for (Player iterPlayer : this.getOnlinePlayers()) { String iterPlayerName = iterPlayer.getName(); @@ -126,7 +133,7 @@ public final class CraftServer implements Server { } public World[] getWorlds() { - return new World[] { console.e.getWorld() }; + return new World[]{console.e.getWorld()}; } public long getTime() { |