Add new /region-reset command to reset and re-claim all admin-based regions such as Spawn, Shops, Borderlands, and Fields.

This commit is contained in:
Ty Sayers 2015-08-26 14:54:15 -07:00
parent fc5f57803e
commit 3b999d2660
4 changed files with 66 additions and 10 deletions

View File

@ -68,6 +68,7 @@ public class ClansGame extends MiniPlugin
return; return;
for (Player cur : UtilServer.getPlayers()) for (Player cur : UtilServer.getPlayers())
{
if (Clans.getClanUtility().isSafe(cur.getLocation())) if (Clans.getClanUtility().isSafe(cur.getLocation()))
{ {
long lastDamager = Clans.getCombatManager().Get(cur).GetLastCombat(); 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); Clans.getCondition().Factory().Custom("Unsafe", cur, cur, ConditionType.CUSTOM, 1, 0, false, Material.FIRE, (byte)0, true);
} }
} }
}
} }
@EventHandler @EventHandler

View File

@ -47,6 +47,7 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand; import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand; import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.commands.MapCommand; 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.commands.ServerTimeCommand;
import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.map.ItemMapManager; import mineplex.game.clans.clans.map.ItemMapManager;
@ -220,12 +221,18 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
public void addCommands() public void addCommands()
{ {
addCommand(new ClansCommand(this)); addCommand(new ClansCommand(this));
addCommand(new RegionsCommand(this));
addCommand(new ClansChatCommand(this)); addCommand(new ClansChatCommand(this));
addCommand(new ClansAllyChatCommand(this)); addCommand(new ClansAllyChatCommand(this));
addCommand(new ServerTimeCommand(this)); addCommand(new ServerTimeCommand(this));
addCommand(new ClanManagementCommand(this)); addCommand(new ClanManagementCommand(this));
addCommand(new MapCommand(this)); addCommand(new MapCommand(this));
} }
public ClansRegions getClanRegions()
{
return _clanRegions;
}
public ItemMapManager getItemMapManager() public ItemMapManager getItemMapManager()
{ {

View File

@ -1,5 +1,8 @@
package mineplex.game.clans.clans.regions; package mineplex.game.clans.clans.regions;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -15,10 +18,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.core.packethandler.PacketPlayOutWorldBorder; import mineplex.core.packethandler.PacketPlayOutWorldBorder;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
@ -51,19 +56,47 @@ public class ClansRegions extends MiniPlugin
} }
public void initializeRegions() public void initializeRegions()
{
initializeRegions(false);
}
public void initializeRegions(boolean overrideCreation)
{ {
Location worldCenter = new Location(_world, 0, 0, 0); Location worldCenter = new Location(_world, 0, 0, 0);
// Initialize Spawn faction and claims // Initialize Spawn faction and claims
Set<Location> spawns = Spawn.getInstance().getSpawnLocations(); claimArea("Spawn", SPAWN_RADIUS, 0, true, overrideCreation, new Location[]{Spawn.getNorthSpawn(), Spawn.getSouthSpawn()});
Location[] spawnsArray = spawns.toArray(new Location[spawns.size()]); claimArea("Shops", SHOP_RADIUS, 0, true, overrideCreation, new Location[]{Spawn.getEastShop(), Spawn.getWestShop()});
Location[] shopsArray = {Spawn.getEastShop(), Spawn.getWestShop()};
claimArea("Spawn", SPAWN_RADIUS, 0, true, spawnsArray);
claimArea("Shops", SHOP_RADIUS, 0, true, shopsArray);
// Initialize Fields and Borderlands factions and claims // Initialize Fields and Borderlands factions and claims
claimArea("Fields", FIELDS_RADIUS, 0, false, worldCenter); claimArea("Fields", FIELDS_RADIUS, 0, false, overrideCreation, worldCenter);
claimArea("Borderlands", BORDERLANDS_RADIUS, 32, false, 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 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. * @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); final ClanInfo clan = _manager.getClan(clanName);
if (clan == null) if (clan == null )
{ {
_manager.getClanDataAccess().create("ClansRegions", clanName, true, new Callback<ClanInfo>() _manager.getClanDataAccess().create("ClansRegions", clanName, true, new Callback<ClanInfo>()
{ {
@ -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) private void claimArea(ClanInfo clan, Location location, int chunkRadius, int claimOffset, boolean safe)

View File

@ -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_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_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_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_TERRITORIES = "DELETE FROM clanTerritory WHERE clanId = ?;";
private static String DELETE_CLAN_ALLIANCE = "DELETE FROM clanAlliances WHERE clanId = ? AND otherClanId = ?;"; 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 = ?;"; 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)); 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) 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)
{ {