Ban management plugin interoperability.

Added config options to use ban commands instead of directly adding to
the server's ban list.
This commit is contained in:
ryanhamshire 2015-12-16 15:07:30 -08:00
parent 709bb55e98
commit 6db3e11ab1
3 changed files with 37 additions and 11 deletions

View File

@ -36,6 +36,8 @@ import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Achievement;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
@ -43,6 +45,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.BanList.Type;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -186,6 +189,10 @@ public class GriefPrevention extends JavaPlugin
public boolean config_logs_adminEnabled;
public boolean config_logs_debugEnabled;
//ban management plugin interop settings
public boolean config_ban_useCommand;
public String config_ban_commandFormat;
private String databaseUrl;
private String databaseUserName;
private String databasePassword;
@ -571,6 +578,8 @@ public class GriefPrevention extends JavaPlugin
this.config_creaturesTrampleCrops = config.getBoolean("GriefPrevention.CreaturesTrampleCrops", false);
this.config_rabbitsEatCrops = config.getBoolean("GriefPrevention.RabbitsEatCrops", true);
this.config_zombiesBreakDoors = config.getBoolean("GriefPrevention.HardModeZombiesBreakDoors", false);
this.config_ban_useCommand = config.getBoolean("GriefPrevention.UseBanCommand", false);
this.config_ban_commandFormat = config.getString("GriefPrevention.BanCommandPattern", "ban %name% %reason%");
this.config_mods_ignoreClaimsAccounts = config.getStringList("GriefPrevention.Mods.PlayersIgnoringAllClaims");
@ -819,6 +828,9 @@ public class GriefPrevention extends JavaPlugin
outConfig.set("GriefPrevention.Database.UserName", this.databaseUserName);
outConfig.set("GriefPrevention.Database.Password", this.databasePassword);
outConfig.set("GriefPrevention.UseBanCommand", this.config_ban_useCommand);
outConfig.set("GriefPrevention.BanCommandPattern", this.config_ban_commandFormat);
outConfig.set("GriefPrevention.Mods.BlockIdsRequiringAccessTrust", this.config_mods_accessTrustIds);
outConfig.set("GriefPrevention.Mods.BlockIdsRequiringContainerTrust", this.config_mods_containerTrustIds);
outConfig.set("GriefPrevention.Mods.BlockIdsExplodable", this.config_mods_explodableIds);
@ -3066,4 +3078,25 @@ public class GriefPrevention extends JavaPlugin
return true;
}
static void banPlayer(Player player, String reason, String source)
{
if(GriefPrevention.instance.config_ban_useCommand)
{
Bukkit.getServer().dispatchCommand(
Bukkit.getConsoleSender(),
GriefPrevention.instance.config_ban_commandFormat.replace("%name%", player.getName()).replace("%reason%", reason));
}
else
{
BanList bans = Bukkit.getServer().getBanList(Type.NAME);
bans.addBan(player.getName(), reason, null, source);
//kick
if(player.isOnline())
{
player.kickPlayer(reason);
}
}
}
}

View File

@ -830,7 +830,7 @@ class PlayerEventHandler implements Listener
//otherwise if that account is still banned, ban this account, too
else
{
GriefPrevention.AddLogEntry("Auto-banned " + player.getName() + " because that account is using an IP address very recently used by banned player " + info.bannedAccountName + " (" + info.address.toString() + ").", CustomLogEntryTypes.AdminActivity);
GriefPrevention.AddLogEntry("Auto-banned new player " + player.getName() + " because that account is using an IP address very recently used by banned player " + info.bannedAccountName + " (" + info.address.toString() + ").", CustomLogEntryTypes.AdminActivity);
//notify any online ops
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();

View File

@ -54,14 +54,7 @@ class PlayerKickBanTask implements Runnable
if(this.ban)
{
//ban
BanList bans = Bukkit.getServer().getBanList(Type.NAME);
bans.addBan(this.player.getName(), this.reason, null, source);
//kick
if(this.player.isOnline())
{
this.player.kickPlayer(this.reason);
}
GriefPrevention.banPlayer(this.player, this.reason, this.source);
}
else if(this.player.isOnline())
{