From c8d77561b16e9edc75b05a10f546ef919a717a92 Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 3 Sep 2011 15:57:54 +0100 Subject: [PATCH] Added new Server.getPlayerExact() method, added whitelist methods and don't use vanilla commands --- .../server/ServerConfigurationManager.java | 2 +- .../craftbukkit/CraftOfflinePlayer.java | 12 +++ .../org/bukkit/craftbukkit/CraftServer.java | 90 ++++++++----------- .../craftbukkit/entity/CraftPlayer.java | 12 +++ 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index 956962cd73..981f058af3 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -42,7 +42,7 @@ public class ServerConfigurationManager { private File l; private File m; public PlayerFileData playerFileData; // CraftBukkit - private - >public - private boolean o; + public boolean o; // Craftbukkit - private -> public // CraftBukkit start private CraftServer cserver; diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 1357ac7e98..6e5c9c50d1 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -49,4 +49,16 @@ public class CraftOfflinePlayer implements OfflinePlayer { server.getHandle().b(name.toLowerCase()); } } + + public boolean isWhitelisted() { + return server.getHandle().e().contains(name.toLowerCase()); + } + + public void setWhitelisted(boolean value) { + if (value) { + server.getHandle().k(name.toLowerCase()); + } else { + server.getHandle().l(name.toLowerCase()); + } + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index bb53e4b141..038afed5d7 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -46,9 +46,6 @@ import net.minecraft.server.WorldLoaderServer; import net.minecraft.server.WorldManager; import net.minecraft.server.WorldServer; import net.minecraft.server.ServerCommand; -import net.minecraft.server.ICommandListener; -import net.minecraft.server.Packet; -import net.minecraft.server.Packet3Chat; import net.minecraft.server.Item; import net.minecraft.server.ItemStack; import net.minecraft.server.WorldMap; @@ -66,12 +63,10 @@ import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe; import org.bukkit.craftbukkit.inventory.CraftRecipe; import org.bukkit.craftbukkit.inventory.CraftShapedRecipe; import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe; -import org.bukkit.craftbukkit.command.ServerCommandListener; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.scheduler.BukkitWorker; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.util.permissions.DefaultPermissions; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.world.WorldInitEvent; import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginLoadOrder; @@ -227,6 +222,18 @@ public final class CraftServer implements Server { return found; } + public Player getPlayerExact(String name) { + String lname = name.toLowerCase(); + + for (Player player : getOnlinePlayers()) { + if (player.getName().equalsIgnoreCase(lname)) { + return player; + } + } + + return null; + } + public int broadcastMessage(String message) { return broadcast(message, BROADCAST_CHANNEL_USERS); } @@ -332,64 +339,17 @@ public final class CraftServer implements Server { // NOTE: Should only be called from MinecraftServer.b() public boolean dispatchCommand(CommandSender sender, ServerCommand serverCommand) { - if (commandMap.dispatch(sender, serverCommand.command)) { - return true; - } - return console.consoleCommandHandler.handle(serverCommand); + return dispatchCommand(sender, serverCommand.command); } public boolean dispatchCommand(CommandSender sender, String commandLine) { - // CraftBukkit native commands if (commandMap.dispatch(sender, commandLine)) { return true; } - if (sender instanceof Player) { - Player player = (Player)sender; - if (commandLine.toLowerCase().startsWith("me ")) { - if (!player.hasPermission("bukkit.command.me")) { - player.sendMessage(ChatColor.RED + "You do not have permission to perform this command."); - return true; - } + sender.sendMessage("Unknown command. Type \"help\" for help."); - commandLine = "* " + player.getDisplayName() + " " + commandLine.substring(commandLine.indexOf(" ")).trim(); - server.server.serverConfigurationManager.sendAll(new Packet3Chat(commandLine)); - return true; - } else if (commandLine.toLowerCase().startsWith("kill")) { - if (!player.hasPermission("bukkit.command.kill")) { - player.sendMessage(ChatColor.RED + "You do not have permission to perform this command."); - return true; - } - - EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000); - getPluginManager().callEvent(ede); - if (ede.isCancelled()) return true; - - player.damage(ede.getDamage()); - return true; - } else if (commandLine.toLowerCase().startsWith("tell ")) { - if (!player.hasPermission("bukkit.command.tell")) { - player.sendMessage(ChatColor.RED + "You do not have permission to perform this command."); - return true; - } - - String[] astring = commandLine.split(" "); - - if (astring.length >= 3) { - commandLine = commandLine.substring(commandLine.indexOf(" ")).trim(); - commandLine = commandLine.substring(commandLine.indexOf(" ")).trim(); - commandLine = "\u00A77" + player.getDisplayName() + " whispers " + commandLine; - if (!server.server.serverConfigurationManager.a(astring[1], (Packet) (new Packet3Chat(commandLine)))) { - player.sendMessage(ChatColor.RED + "There's no player by that name online."); - } - } - - return true; - } - } - - // See if the server can process this command - return console.consoleCommandHandler.handle(new ServerCommand(commandLine, (ICommandListener) new ServerCommandListener(sender))); + return false; } public void reload() { @@ -839,4 +799,24 @@ public final class CraftServer implements Server { return result; } + + public void setWhitelist(boolean value) { + server.o = value; + console.propertyManager.b("white-list", value); + console.propertyManager.savePropertiesFile(); + } + + public Set getWhitelistedPlayers() { + Set result = new HashSet(); + + for (Object name : server.e()) { + result.add(getOfflinePlayer((String)name)); + } + + return result; + } + + public void reloadWhitelist() { + server.f(); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index f587f3b340..4a1fa601aa 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -366,4 +366,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { server.getHandle().b(getName().toLowerCase()); } } + + public boolean isWhitelisted() { + return server.getHandle().e().contains(getName().toLowerCase()); + } + + public void setWhitelisted(boolean value) { + if (value) { + server.getHandle().k(getName().toLowerCase()); + } else { + server.getHandle().l(getName().toLowerCase()); + } + } }