moved completely to database managed clan blacklist, instead of the old hard-coded way

This commit is contained in:
Ben 2016-03-21 22:37:35 +00:00
parent 264e5d34b2
commit 2e41f906d0
12 changed files with 86 additions and 122 deletions

View File

@ -226,9 +226,9 @@ public class ClansAdmin
return;
}
if (!ClansBlacklist.isValidClanName(args[2]))
if (!Clans.getBlacklist().allowed(args[2]))
{
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name cannot be a Clan command."));
UtilPlayer.message(caller, F.main("Clans Admin", "That name is blacklisted, please choose another one."));
}
if (Clans.getClan(args[2]) != null)

View File

@ -1,46 +0,0 @@
package mineplex.game.clans.clans;
import java.util.Arrays;
import java.util.List;
/**
* ClansBlacklist represents the blacklist of all disallowed names for clan creation.
* @author MrTwiggy
*
*/
public class ClansBlacklist
{
// Set of all blacklisted clan names that are NOT valid.
private final static List<String> BLACKLISTED_NAMES = Arrays.asList(new String[]
{
"Youtube", "Owner", "Admin", "Mod", "Trainee", "Twitch",
"Wilderness", "Shops", "Builder", "Spawn", "Clan", "Clans",
"Fields", "Sr.Mod", "Sr. Mod", "Dev", "Jr.Dev", "Jr. Dev", "create",
"join", "leave", "map", "cc", "ac", "invite", "kick", "neutral",
"enemy", "trust", "unclaim", "claim", "delete", "SrMod", "Twitch", "YouTube", "Event",
"Media", "MapLead", "JrDev", "Developer", "Leader", "LT", "Support", "Borderlands"
});
/**
* @param clanName - the name of the clan to validate
* @return true, if {@code clanName} is a valid and non-blacklisted clan name, false otherwise.
*/
public static boolean isValidClanName(String clanName)
{
if (!ClansManager.getInstance().getClanBlacklist().allowed(clanName))
{
return false;
}
for (String blacklistedName : BLACKLISTED_NAMES)
{
if (blacklistedName.equalsIgnoreCase(clanName))
{
return false;
}
}
return true;
}
}

View File

@ -674,7 +674,7 @@ public class ClansGame extends MiniPlugin
if (claim != null)
{
if (ClansBlacklist.isValidClanName(claim.Owner))
if (_clans.getBlacklist().allowed(claim.Owner))
{
blockClan = _clans.getClan(claim.Owner);
}

View File

@ -88,7 +88,7 @@ import mineplex.game.clans.clans.gui.ClanShop;
import mineplex.game.clans.clans.invsee.Invsee;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager;
import mineplex.game.clans.clans.nameblacklist.ClanNameBlacklist;
import mineplex.game.clans.clans.nameblacklist.ClansBlacklist;
import mineplex.game.clans.clans.nether.NetherManager;
import mineplex.game.clans.clans.observer.ObserverManager;
import mineplex.game.clans.clans.playtime.Playtime;
@ -171,7 +171,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
private NetherManager _netherManager;
private DamageManager _damageManager;
private ClanNameBlacklist _blacklist;
private ClansBlacklist _blacklist;
private Playtime _playTracker;
@ -242,7 +242,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_donationManager = donationManager;
_blacklist = new ClanNameBlacklist(plugin);
_blacklist = new ClansBlacklist(plugin);
_goldManager = new GoldManager(this, _clientManager, donationManager);
_gearManager = gearManager;
@ -1301,7 +1301,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
public PvpTimer getPvpTimer() { return _pvpTimer; }
public ClanNameBlacklist getClanBlacklist()
public ClansBlacklist getBlacklist()
{
return _blacklist;
}

View File

@ -33,7 +33,6 @@ import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClanRole;
import mineplex.game.clans.clans.ClanTips.TipType;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClientClan;
import mineplex.game.clans.clans.event.ClanJoinEvent;
@ -299,7 +298,7 @@ public class ClansCommand extends CommandBase<ClansManager>
return;
}
if (!ClansBlacklist.isValidClanName(args[1]))
if (!Plugin.getBlacklist().allowed(args[1]))
{
UtilPlayer.message(caller, F.main("Clans", "Clan name is blacklisted! Please try a different name."));
return;

View File

@ -1,44 +0,0 @@
package mineplex.game.clans.clans.nameblacklist;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.game.clans.clans.nameblacklist.repository.AddBlacklistCommand;
public class ClanNameBlacklist extends MiniPlugin
{
private List<String> _blacklist;
private ClanNameBlacklistRepository _repository;
public ClanNameBlacklist(JavaPlugin plugin)
{
super("Clan Name Blacklist", plugin);
_repository = new ClanNameBlacklistRepository(plugin, this);
_repository.loadNames(list -> _blacklist = list);
addCommand(new AddBlacklistCommand(this));
}
public boolean allowed(String name)
{
return !_blacklist.contains(name);
}
public void add(String name)
{
_blacklist.add(name);
}
public void enable()
{
}
public ClanNameBlacklistRepository getRepository()
{
return _repository;
}
}

View File

@ -0,0 +1,58 @@
package mineplex.game.clans.clans.nameblacklist;
import java.util.List;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.nameblacklist.commands.AddBlacklistCommand;
import mineplex.game.clans.clans.nameblacklist.repository.ClanNameBlacklistRepository;
public class ClansBlacklist extends MiniPlugin
{
private List<String> _blacklist;
private ClanNameBlacklistRepository _repository;
public ClansBlacklist(JavaPlugin plugin)
{
super("Clan Name Blacklist", plugin);
}
// Fetch new blacklisted clans every 16 seconds (in case someone blacklists a clan name on a different server)
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOWER)
{
runAsync(() -> _repository.loadNames(this::setBlacklist));
}
}
private void setBlacklist(List<String> blacklist)
{
_blacklist = blacklist;
}
public boolean allowed(String name)
{
return !_blacklist.contains(name.toLowerCase());
}
public void add(String name)
{
_blacklist.add(name);
}
public void addCommands()
{
addCommand(new AddBlacklistCommand(this));
}
public ClanNameBlacklistRepository getRepository()
{
return _repository;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.nameblacklist.repository;
package mineplex.game.clans.clans.nameblacklist.commands;
import org.bukkit.entity.Player;
@ -7,11 +7,11 @@ import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.nameblacklist.ClanNameBlacklist;
import mineplex.game.clans.clans.nameblacklist.ClansBlacklist;
public class AddBlacklistCommand extends CommandBase<ClanNameBlacklist>
public class AddBlacklistCommand extends CommandBase<ClansBlacklist>
{
public AddBlacklistCommand(ClanNameBlacklist plugin)
public AddBlacklistCommand(ClansBlacklist plugin)
{
super(plugin, Rank.CMOD, "blacklistname");
}
@ -29,7 +29,7 @@ public class AddBlacklistCommand extends CommandBase<ClanNameBlacklist>
Plugin.runAsync(() -> {
Plugin.getRepository().add(blacklist, caller.getName());
UtilPlayer.message(caller, "Successfully added " + F.elem(blacklist) + " to the clan name blacklist.");
UtilPlayer.message(caller, F.main("Clans", "Successfully added " + F.elem(blacklist) + " to the clan name blacklist."));
});
}
else

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.nameblacklist;
package mineplex.game.clans.clans.nameblacklist.repository;
import java.sql.Timestamp;
import java.util.ArrayList;
@ -8,7 +8,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.database.MinecraftRepository;
import mineplex.game.clans.clans.nameblacklist.repository.AddBlacklistCommand;
import mineplex.game.clans.clans.nameblacklist.ClansBlacklist;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
@ -25,9 +25,9 @@ public class ClanNameBlacklistRepository extends MinecraftRepository
private static final String ADD = "INSERT INTO clanNameBlacklist (clanName, admin, added) VALUES (?, ?, ?);";
private static final String REMOVE = "DELETE FROM clanNameBlacklist WHERE clanName=?;";
private ClanNameBlacklist _blacklist;
private ClansBlacklist _blacklist;
public ClanNameBlacklistRepository(JavaPlugin plugin, ClanNameBlacklist blacklist)
public ClanNameBlacklistRepository(JavaPlugin plugin, ClansBlacklist blacklist)
{
super(plugin, DBPool.getAccount());
@ -36,9 +36,9 @@ public class ClanNameBlacklistRepository extends MinecraftRepository
public void add(String name, String mod)
{
_blacklist.add(name);
_blacklist.add(name.toLowerCase());
executeInsert(ADD, null,
new ColumnVarChar("clanName", 20, name),
new ColumnVarChar("clanName", 20, name.toLowerCase()),
new ColumnVarChar("admin", 16, mod),
new ColumnTimestamp("added", new Timestamp(System.currentTimeMillis()))
);

View File

@ -52,7 +52,6 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.event.ClansWaterPlaceEvent;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
@ -504,7 +503,7 @@ public class Outpost implements Listener
{
ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ));
if (territory != null && ClansBlacklist.isValidClanName(territory.Owner))
if (territory != null && _outpostManager.getClansManager().getBlacklist().allowed(territory.Owner))
{
ClanInfo clan = _ownerClan.Clans.getClanUtility().getClanByClanName(territory.Owner);

View File

@ -12,13 +12,10 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
@ -29,9 +26,9 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.analytics.Profiler;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.nameblacklist.ClansBlacklist;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.repository.OutpostRepository;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
@ -136,7 +133,7 @@ public class OutpostManager extends MiniPlugin
if (claim != null)
{
if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner))
if (!claim.Owner.equals(clan.getName()) && _clansManager.getBlacklist().allowed(claim.Owner))
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory."));
return false;
@ -157,7 +154,7 @@ public class OutpostManager extends MiniPlugin
{
System.out.println(claim.Owner + ", " + clan.getName());
if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner))
if (!claim.Owner.equals(clan.getName()) && _clansManager.getBlacklist().allowed(claim.Owner))
{
gut = true; /* das ist gut!!! */
break;

View File

@ -25,7 +25,8 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.nameblacklist.ClansBlacklist;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.core.repository.ClanTerritory;
@ -102,7 +103,7 @@ public class Crater implements Listener
{
ClanTerritory terr = _weapon.getClans().getClanUtility().getClaim(_origin);
if (terr != null && !ClansBlacklist.isValidClanName(terr.Owner))
if (terr != null && !ClansManager.getInstance().getBlacklist().allowed(terr.Owner))
{
return;
}
@ -136,7 +137,7 @@ public class Crater implements Listener
ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation());
if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner))
if (territory != null && !ClansManager.getInstance().getBlacklist().allowed(territory.Owner))
{
continue;
}
@ -178,7 +179,7 @@ public class Crater implements Listener
ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation());
if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner))
if (territory != null && !ClansManager.getInstance().getBlacklist().allowed(territory.Owner))
{
continue;
}