From 3b999d2660de36673497ff8b8aa8e28253675cf7 Mon Sep 17 00:00:00 2001 From: Ty Sayers Date: Wed, 26 Aug 2015 14:54:15 -0700 Subject: [PATCH] Add new /region-reset command to reset and re-claim all admin-based regions such as Spawn, Shops, Borderlands, and Fields. --- .../mineplex/game/clans/clans/ClansGame.java | 2 + .../game/clans/clans/ClansManager.java | 7 +++ .../clans/clans/regions/ClansRegions.java | 61 ++++++++++++++++--- .../clans/repository/ClanRepository.java | 6 ++ 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index 6ecd529f5..492c8f16f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -68,6 +68,7 @@ public class ClansGame extends MiniPlugin return; for (Player cur : UtilServer.getPlayers()) + { if (Clans.getClanUtility().isSafe(cur.getLocation())) { long lastDamager = Clans.getCombatManager().Get(cur).GetLastCombat(); @@ -80,6 +81,7 @@ public class ClansGame extends MiniPlugin Clans.getCondition().Factory().Custom("Unsafe", cur, cur, ConditionType.CUSTOM, 1, 0, false, Material.FIRE, (byte)0, true); } } + } } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index ce878d18d..b2fb9d8fe 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -47,6 +47,7 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand; import mineplex.game.clans.clans.commands.ClansChatCommand; import mineplex.game.clans.clans.commands.ClansCommand; import mineplex.game.clans.clans.commands.MapCommand; +import mineplex.game.clans.clans.commands.RegionsCommand; import mineplex.game.clans.clans.commands.ServerTimeCommand; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; @@ -220,12 +221,18 @@ public class ClansManager extends MiniClientPlugin implements IRelat public void addCommands() { addCommand(new ClansCommand(this)); + addCommand(new RegionsCommand(this)); addCommand(new ClansChatCommand(this)); addCommand(new ClansAllyChatCommand(this)); addCommand(new ServerTimeCommand(this)); addCommand(new ClanManagementCommand(this)); addCommand(new MapCommand(this)); } + + public ClansRegions getClanRegions() + { + return _clanRegions; + } public ItemMapManager getItemMapManager() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index ae37d582c..c2dc59644 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -1,5 +1,8 @@ package mineplex.game.clans.clans.regions; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Set; import org.bukkit.Bukkit; @@ -15,10 +18,12 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilWorld; import mineplex.core.packethandler.PacketPlayOutWorldBorder; import mineplex.game.clans.clans.ClanInfo; @@ -51,19 +56,47 @@ public class ClansRegions extends MiniPlugin } public void initializeRegions() + { + initializeRegions(false); + } + + public void initializeRegions(boolean overrideCreation) { Location worldCenter = new Location(_world, 0, 0, 0); - + // Initialize Spawn faction and claims - Set spawns = Spawn.getInstance().getSpawnLocations(); - Location[] spawnsArray = spawns.toArray(new Location[spawns.size()]); - Location[] shopsArray = {Spawn.getEastShop(), Spawn.getWestShop()}; - claimArea("Spawn", SPAWN_RADIUS, 0, true, spawnsArray); - claimArea("Shops", SHOP_RADIUS, 0, true, shopsArray); + claimArea("Spawn", SPAWN_RADIUS, 0, true, overrideCreation, new Location[]{Spawn.getNorthSpawn(), Spawn.getSouthSpawn()}); + claimArea("Shops", SHOP_RADIUS, 0, true, overrideCreation, new Location[]{Spawn.getEastShop(), Spawn.getWestShop()}); // Initialize Fields and Borderlands factions and claims - claimArea("Fields", FIELDS_RADIUS, 0, false, worldCenter); - claimArea("Borderlands", BORDERLANDS_RADIUS, 32, false, worldCenter); + claimArea("Fields", FIELDS_RADIUS, 0, false, overrideCreation, worldCenter); + claimArea("Borderlands", BORDERLANDS_RADIUS, 32, false, overrideCreation, worldCenter); + } + + public void resetRegions() + { + clearClaims("Spawn"); + clearClaims("Shops"); + clearClaims("Fields"); + clearClaims("Borderlands"); + initializeRegions(true); + } + + private void clearClaims(String name) + { + System.out.println("Clearing claims for " + name + "!"); + ClanInfo clan = _manager.getClan(name); + + if (clan != null) + { + for (String chunk : clan.getClaimSet()) + { + _manager.getClaimMap().remove(chunk); + } + + clan.getClaimSet().clear(); + _manager.getClanDataAccess().getRepository().removeTerritoryClaims(clan.getId()); + } } /** @@ -75,11 +108,12 @@ public class ClansRegions extends MiniPlugin * @param claimOffset - the initial offset in claim (creating a 'hole' with chunk offset radius) * @param safe - whether the chunk claimed is considered a 'safe' (pvp-free) region. */ - private void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final Location... locations) + private void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, + boolean overrideCreation, final Location... locations) { final ClanInfo clan = _manager.getClan(clanName); - if (clan == null) + if (clan == null ) { _manager.getClanDataAccess().create("ClansRegions", clanName, true, new Callback() { @@ -102,6 +136,13 @@ public class ClansRegions extends MiniPlugin } }); } + else if (overrideCreation) + { + for (Location location : locations) + { + claimArea(clan, location, chunkRadius, claimOffset, safe); + } + } } private void claimArea(ClanInfo clan, Location location, int chunkRadius, int claimOffset, boolean safe) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java index c297cd6a8..8ccaabbf0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/repository/ClanRepository.java @@ -43,6 +43,7 @@ public class ClanRepository extends RepositoryBase private static String DELETE_CLAN_MEMBER = "DELETE aC FROM accountClan AS aC INNER JOIN accounts ON accounts.id = aC.accountId WHERE aC.clanId = ? AND accounts.name = ?;"; private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan WHERE clanId = ?;"; private static String DELETE_CLAN_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND serverId = ? AND chunk = ?;"; + private static String DELETE_CLAN_ALL_TERRITORY = "DELETE FROM clanTerritory WHERE clanId = ? AND serverId = ?;"; private static String DELETE_CLAN_TERRITORIES = "DELETE FROM clanTerritory WHERE clanId = ?;"; private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;"; private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances WHERE clanId = ? OR otherClanId = ?;"; @@ -346,6 +347,11 @@ public class ClanRepository extends RepositoryBase { executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnInt("serverId", _serverId), new ColumnVarChar("chunk", 100, chunk)); } + + public void removeTerritoryClaims(int clanId) + { + executeUpdate(DELETE_CLAN_ALL_TERRITORY, new ColumnInt("clanId", clanId), new ColumnInt("serverId", _serverId)); + } public void updateClan(int clanId, String name, String desc, String home, boolean admin, int energy, int kills, int murder, int deaths, int warWins, int warLosses, Timestamp lastOnline) {