From 09d90e639bc08db84e1456351a08a896208b026c Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sat, 3 Sep 2011 02:13:07 +0100 Subject: [PATCH] Implemented new ban and unban methods --- .../server/ServerConfigurationManager.java | 2 +- .../bukkit/craftbukkit/CraftOfflinePlayer.java | 18 +++++++++++++++--- .../org/bukkit/craftbukkit/CraftServer.java | 10 ++++++++++ .../bukkit/craftbukkit/entity/CraftPlayer.java | 12 ++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index 977b29936e..956962cd73 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -33,7 +33,7 @@ public class ServerConfigurationManager { public MinecraftServer server; // CraftBukkit - private -> public // private PlayerManager[] d = new PlayerManager[2]; // CraftBukkit - removed public int maxPlayers; // CraftBukkit - private -> public - private Set banByName = new HashSet(); + public Set banByName = new HashSet(); // CraftBukkit - private -> public public Set banByIP = new HashSet(); // CraftBukkit - private -> public private Set h = new HashSet(); private Set i = new HashSet(); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 01a9ec1cb7..1357ac7e98 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -25,16 +25,28 @@ public class CraftOfflinePlayer implements OfflinePlayer { } public boolean isOp() { - return server.getHandle().isOp(getName()); + return server.getHandle().isOp(getName().toLowerCase()); } public void setOp(boolean value) { if (value == isOp()) return; if (value) { - server.getHandle().e(getName()); + server.getHandle().e(getName().toLowerCase()); } else { - server.getHandle().f(getName()); + server.getHandle().f(getName().toLowerCase()); + } + } + + public boolean isBanned() { + return server.getHandle().banByName.contains(name.toLowerCase()); + } + + public void setBanned(boolean value) { + if (value) { + server.getHandle().a(name.toLowerCase()); + } else { + server.getHandle().b(name.toLowerCase()); } } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index ef0863745f..bb53e4b141 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -829,4 +829,14 @@ public final class CraftServer implements Server { public void unbanIP(String address) { server.d(address); } + + public Set getBannedPlayers() { + Set result = new HashSet(); + + for (Object name : server.banByName) { + result.add(getOfflinePlayer((String)name)); + } + + return result; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 76eefc3401..f587f3b340 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -354,4 +354,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void resetPlayerTime() { setPlayerTime(0, true); } + + public boolean isBanned() { + return server.getHandle().banByName.contains(getName().toLowerCase()); + } + + public void setBanned(boolean value) { + if (value) { + server.getHandle().a(getName().toLowerCase()); + } else { + server.getHandle().b(getName().toLowerCase()); + } + } }