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 f36300564..ab0df1375 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 f4e32fb11..e8a1a0517 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/commands/RegionsCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/RegionsCommand.java new file mode 100644 index 000000000..844c8173d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/RegionsCommand.java @@ -0,0 +1,30 @@ +package mineplex.game.clans.clans.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.regions.ClansRegions; + +public class RegionsCommand extends CommandBase +{ + + private ClansManager _manager; + + public RegionsCommand(ClansManager plugin) + { + super(plugin, Rank.ADMIN, "region-reset"); + + _manager = plugin; + } + + @Override + public void Execute(Player caller, String[] args) + { + UtilPlayer.message(caller, F.main("Regions", "Resetting clans regions!")); + _manager.getClanRegions().resetRegions(); + } +} 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) {