Implement banning API. Adds BUKKIT-3535

Previously no implementation existed to access various additional
information fields regarding bans. This implementation expands on the
information outlined in the sister Bukkit commit to provide access to
the Minecraft implementation of the ban system.

This implementation of the banning API contains 2 new classes which
provide access to the internal workings of the built-in banning
system within Minecraft.

The CraftBanEntry class simply supports the representation of an internal
Minecraft BanEntry object. The data that may be modified within this new
object must be manually saved to the list contained within the
CraftBanEntry using it's save() method.

The CraftBanList class supports the representation of an internal
Minecraft BanList object through proxy methods. These methods do
validation on the passed objects where needed to ensure safe input to the
backed Minecraft objects.

These changes additionally re-route the existing banning API to the newer,
more detailed, system. Functionality prior to this change still behaves
as documented by the contract defined by the methods changed.
This commit is contained in:
mbax
2014-02-04 20:52:50 -07:00
committed by turt2live
parent 66471a5326
commit b18bedd848
5 changed files with 184 additions and 20 deletions

View File

@@ -56,6 +56,7 @@ import net.minecraft.util.io.netty.buffer.ByteBufOutputStream;
import net.minecraft.util.io.netty.buffer.Unpooled;
import net.minecraft.util.io.netty.handler.codec.base64.Base64;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -129,12 +130,11 @@ import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.scheduler.BukkitWorker;
import org.bukkit.util.StringUtil;
import org.bukkit.util.permissions.DefaultPermissions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
import org.yaml.snakeyaml.error.MarkedYAMLException;
import org.apache.commons.lang.Validate;
import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.SQLitePlatform;
@@ -1139,20 +1139,19 @@ public final class CraftServer implements Server {
@SuppressWarnings("unchecked")
public Set<String> getIPBans() {
return playerList.getIPBans().getEntries().keySet();
return new HashSet<String>(playerList.getIPBans().getEntries().keySet());
}
public void banIP(String address) {
Validate.notNull(address, "Address cannot be null.");
BanEntry entry = new BanEntry(address);
playerList.getIPBans().add(entry);
playerList.getIPBans().save();
this.getBanList(org.bukkit.BanList.Type.IP).addBan(address, null, null, null);
}
public void unbanIP(String address) {
playerList.getIPBans().remove(address);
playerList.getIPBans().save();
Validate.notNull(address, "Address cannot be null.");
this.getBanList(org.bukkit.BanList.Type.IP).pardon(address);
}
public Set<OfflinePlayer> getBannedPlayers() {
@@ -1165,6 +1164,19 @@ public final class CraftServer implements Server {
return result;
}
@Override
public BanList getBanList(BanList.Type type){
Validate.notNull(type, "Type cannot be null");
switch(type){
case IP:
return new CraftBanList(playerList.getIPBans());
case NAME:
default: // Fall through as a player name list for safety
return new CraftBanList(playerList.getNameBans());
}
}
public void setWhitelist(boolean value) {
playerList.hasWhitelist = value;
console.getPropertyManager().a("white-list", value);