From 4dfead7ec8046760e7984f7bc8ac262ed8ecc959 Mon Sep 17 00:00:00 2001 From: taoneill Date: Mon, 18 Jun 2012 01:28:49 -0400 Subject: [PATCH] Players can't be trapped in spawn anymore Closes gh-472. The periphery of opponents' spawns can't be built on. In other words, all teams have a "no other team can build right next to my spawn" protection 1 block wide all around their spawn. This should let people exit the spawn with their loadout select, then use their items to dig themselves out of any now-harmless trap. --- .../main/java/com/tommytony/war/Warzone.java | 17 +++++++++++++++++ .../tommytony/war/event/WarBlockListener.java | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 616ecdc..18fe5a1 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -42,6 +42,8 @@ import com.tommytony.war.structure.ZoneWallGuard; import com.tommytony.war.utility.LoadoutSelection; import com.tommytony.war.utility.PlayerState; import com.tommytony.war.utility.PotionEffectHelper; +import com.tommytony.war.volume.BlockInfo; +import com.tommytony.war.volume.Volume; import com.tommytony.war.volume.ZoneVolume; /** @@ -1407,4 +1409,19 @@ public class Warzone { public void setLobbyMaterials(HubLobbyMaterials lobbyMaterials) { this.lobbyMaterials = lobbyMaterials; } + + public boolean isOpponentSpawnPeripheryBlock(Team team, Block block) { + for (Team maybeOpponent : this.getTeams()) { + if (maybeOpponent != team) { + Volume periphery = new Volume("periphery", this.getWorld()); + periphery.setCornerOne(new BlockInfo(maybeOpponent.getSpawnVolume().getMinX()-1 , maybeOpponent.getSpawnVolume().getMinY()-1, maybeOpponent.getSpawnVolume().getMinZ()-1, 0, (byte)0)); + periphery.setCornerTwo(new BlockInfo(maybeOpponent.getSpawnVolume().getMaxX()+1, maybeOpponent.getSpawnVolume().getMaxY()+1, maybeOpponent.getSpawnVolume().getMaxZ()+1, 0, (byte)0)); + + if (periphery.contains(block)) { + return true; + } + } + } + return false; + } } diff --git a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java index 933f301..2d1dc5b 100644 --- a/war/src/main/java/com/tommytony/war/event/WarBlockListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarBlockListener.java @@ -88,7 +88,9 @@ public class WarBlockListener implements Listener { boolean isZoneMaker = War.war.isZoneMaker(player); // prevent build in important parts - if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { + if (zone != null + && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block)) + && (!isZoneMaker || (isZoneMaker && team != null))) { War.war.badMsg(player, "Can't build here."); cancelAndKeepItem(event); return;