From 1e6d8d1e1d8b2173a6df90aa3cff83214a44305f Mon Sep 17 00:00:00 2001 From: taoneill Date: Sat, 15 Jan 2011 02:03:04 -0500 Subject: [PATCH] Just missing death tp, better lobby height management and a non buggy way to let normal players thru the gate and the wall guard. --- .../main/java/bukkit/tommytony/war/War.java | 33 ++++++-- .../tommytony/war/WarPlayerListener.java | 35 ++++++-- .../main/java/com/tommytony/war/Warzone.java | 4 + .../java/com/tommytony/war/ZoneLobby.java | 80 +++++++++++++++++-- .../java/com/tommytony/war/ZoneWallGuard.java | 32 ++++---- .../tommytony/war/mappers/WarzoneMapper.java | 3 +- 6 files changed, 151 insertions(+), 36 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index e37bbfa..8585664 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -11,6 +11,7 @@ import org.bukkit.plugin.java.JavaPlugin; import com.tommytony.war.Team; import com.tommytony.war.WarHub; import com.tommytony.war.Warzone; +import com.tommytony.war.ZoneLobby; import com.tommytony.war.mappers.WarMapper; import java.io.File; @@ -76,10 +77,7 @@ public class War extends JavaPlugin { this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD)); this.defaultLoadout.put(1, new ItemStack(Material.BOW)); this.defaultLoadout.put(2, new ItemStack(Material.ARROW, 7)); - this.defaultLoadout.put(3, new ItemStack(Material.STONE_PICKAXE)); - this.defaultLoadout.put(4, new ItemStack(Material.STONE_SPADE)); - this.defaultLoadout.put(5, new ItemStack(Material.STONE_AXE)); - this.defaultLoadout.put(6, new ItemStack(Material.BREAD, 2)); + this.defaultLoadout.put(3, new ItemStack(Material.IRON_PICKAXE)); this.defaultLifepool = 7; this.defaultFriendlyFire = false; this.defaultAutoAssignOnly = false; @@ -210,7 +208,6 @@ public class War extends JavaPlugin { } public WarHub getWarHub() { - // TODO Auto-generated method stub return warHub; } @@ -218,5 +215,31 @@ public class War extends JavaPlugin { this.warHub = warHub; } + public ZoneLobby lobby(Location location) { + for(Warzone warzone : warzones) { + if(warzone.getLobby() != null + && warzone.getLobby().getVolume() != null + && warzone.getLobby().getVolume().contains(location)) + return warzone.getLobby(); + } + return null; + } + + public boolean inAnyWarzoneLobby(Location location) { + if(lobby(location) == null) { + return false; + } + return true; + } + + public boolean inWarzoneLobby(String warzoneName, Location location) { + ZoneLobby currentLobby = lobby(location); + if(currentLobby == null) { + return false; + } else if (warzoneName.equals(currentLobby.getZone().getName())){ + return true; + } + return false; + } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index f5ffed1..f673247 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -316,16 +316,24 @@ public class WarPlayerListener extends PlayerListener { } else if(command.equals("setzonelobby")) { - if(!war.inAnyWarzone(player.getLocation()) || arguments.length < 2 || arguments.length > 2 - || (arguments.length == 2 && (!arguments[0].equals("north") && !arguments[0].equals("n") + if((!war.inAnyWarzone(player.getLocation()) + && !war.inAnyWarzoneLobby(player.getLocation())) + || arguments.length < 1 || arguments.length > 1 + || (arguments.length == 1 && !arguments[0].equals("north") && !arguments[0].equals("n") && !arguments[0].equals("east") && !arguments[0].equals("e") && !arguments[0].equals("south") && !arguments[0].equals("s") - && !arguments[0].equals("west") && !arguments[0].equals("w")))) { + && !arguments[0].equals("west") && !arguments[0].equals("w"))) { player.sendMessage(war.str("Usage: /setzonelobby . Must be in warzone." + "Defines on which side the zone lobby lies. " + "Removes any previously set lobby.")); } else { Warzone warzone = war.warzone(player.getLocation()); + ZoneLobby lobby = war.lobby(player.getLocation()); + if(warzone == null && lobby != null) { + warzone = lobby.getZone(); + } else { + lobby = warzone.getLobby(); + } BlockFace wall = null; String wallStr = ""; if(arguments[0].equals("north") || arguments[0].equals("n")) { @@ -340,8 +348,7 @@ public class WarPlayerListener extends PlayerListener { } else if(arguments[0].equals("west") || arguments[0].equals("w")) { wall = BlockFace.West; wallStr = "west"; - } - ZoneLobby lobby = warzone.getLobby(); + } if(lobby != null) { // reset existing lobby lobby.getVolume().resetBlocks(); @@ -361,7 +368,7 @@ public class WarPlayerListener extends PlayerListener { // /savewarzone else if(command.equals("savezone") || command.equals("savewarzone")) { - if(!war.inAnyWarzone(player.getLocation())) { + if(!war.inAnyWarzone(player.getLocation()) && !war.inAnyWarzoneLobby(player.getLocation())) { player.sendMessage(war.str("Usage: /savezone. Must be in warzone. " + "Changes the warzone state loaded at the beginning of every battle. " + "Also sets the teleport point for this warzone where you're standing." + @@ -371,10 +378,16 @@ public class WarPlayerListener extends PlayerListener { "or /resetzone before changing start state). ")); } else { Warzone warzone = war.warzone(player.getLocation()); + ZoneLobby lobby = war.lobby(player.getLocation()); + if(warzone == null && lobby != null) { + warzone = lobby.getZone(); + } else { + lobby = warzone.getLobby(); + } int savedBlocks = warzone.saveState(); if(warzone.getLobby() == null) { // Set default lobby on south side - ZoneLobby lobby = new ZoneLobby(war, warzone, BlockFace.South); + lobby = new ZoneLobby(war, warzone, BlockFace.South); warzone.setLobby(lobby); lobby.initialize(); player.sendMessage(war.str("Default lobby created on south side of zone.")); @@ -388,10 +401,16 @@ public class WarPlayerListener extends PlayerListener { // /resetwarzone else if(command.equals("resetzone") || command.equals("resetwarzone")) { - if(!war.inAnyWarzone(player.getLocation())) { + if(!war.inAnyWarzone(player.getLocation()) && !war.inAnyWarzoneLobby(player.getLocation())) { player.sendMessage(war.str("Usage: /resetzone pool=10. Reloads the zone. All named parameter are optional. Defaults: pool=7 maxScore=-1 (infinite). Must be in warzone.")); } else { Warzone warzone = war.warzone(player.getLocation()); + ZoneLobby lobby = war.lobby(player.getLocation()); + if(warzone == null && lobby != null) { + warzone = lobby.getZone(); + } else { + lobby = warzone.getLobby(); + } int resetBlocks = warzone.getVolume().resetBlocks(); warzone.initializeZone(); for(Team team: warzone.getTeams()) { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 1186b78..751f4b6 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -616,6 +616,10 @@ public class Warzone { if(guard.getPlayer().getName().equals(player.getName())){ playerGuards.add(guard); int reset = volume.resetWallBlocks(guard.getWall()); // this should restore old blocks + if(lobby != null) { + lobby.getVolume().resetBlocks(); + lobby.initialize(); + } if(drawZoneOutline) { addZoneOutline(guard.getWall()); } diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index e2be3d6..049d289 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -5,12 +5,12 @@ import org.bukkit.BlockFace; import org.bukkit.Location; import org.bukkit.Material; +import bukkit.tommytony.war.War; + import com.tommytony.war.mappers.VolumeMapper; import com.tommytony.war.volumes.VerticalVolume; import com.tommytony.war.volumes.Volume; -import bukkit.tommytony.war.War; - /** * * @author tommytony @@ -60,7 +60,7 @@ public class ZoneLobby { int wallCenterPos = wallStart + wallLength / 2; int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos); lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter+1, wallCenterPos); - corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter+1, wallCenterPos + lobbyHalfSide); + corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos + lobbyHalfSide); corner2 = warzone.getWorld().getBlockAt(x - lobbyDepth, highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos - lobbyHalfSide); setGatePositions(lobbyMiddleWallBlock); } else if (wall == BlockFace.East){ @@ -71,7 +71,7 @@ public class ZoneLobby { int wallCenterPos = wallStart + wallLength / 2; int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z); lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z); - corner1 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter+1, z); + corner1 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter, z); corner2 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z - lobbyDepth); setGatePositions(lobbyMiddleWallBlock); } else if (wall == BlockFace.South){ @@ -82,7 +82,7 @@ public class ZoneLobby { int wallCenterPos = wallStart + wallLength / 2; int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(x, wallCenterPos); lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter + 1, wallCenterPos); - corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter+1, wallCenterPos - lobbyHalfSide); + corner1 = warzone.getWorld().getBlockAt(x, highestNonAirBlockAtCenter, wallCenterPos - lobbyHalfSide); corner2 = warzone.getWorld().getBlockAt(x + lobbyDepth, highestNonAirBlockAtCenter + 1 + lobbyHeight, wallCenterPos + lobbyHalfSide); setGatePositions(lobbyMiddleWallBlock); } else if (wall == BlockFace.West){ @@ -93,7 +93,7 @@ public class ZoneLobby { int wallCenterPos = wallStart + wallLength / 2; int highestNonAirBlockAtCenter = warzone.getWorld().getHighestBlockYAt(wallCenterPos, z); lobbyMiddleWallBlock = warzone.getWorld().getBlockAt(wallCenterPos, highestNonAirBlockAtCenter + 1, z); - corner1 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter+1, z); + corner1 = warzone.getWorld().getBlockAt(wallCenterPos + lobbyHalfSide, highestNonAirBlockAtCenter, z); corner2 = warzone.getWorld().getBlockAt(wallCenterPos - lobbyHalfSide, highestNonAirBlockAtCenter + 1 + lobbyHeight, z + lobbyDepth); setGatePositions(lobbyMiddleWallBlock); } @@ -107,7 +107,7 @@ public class ZoneLobby { // flatten the area (set all but floor to air, then replace any floor air blocks with glass) this.volume.setToMaterial(Material.AIR); - this.volume.setFaceMaterial(BlockFace.Down, Material.AIR); // beautiful + this.volume.setFaceMaterial(BlockFace.Down, Material.GLASS); // beautiful // add war hub link gate if(war.getWarHub() != null) { @@ -324,4 +324,70 @@ public class ZoneLobby { } return false; } + + public boolean blockIsAGateBlock(Block block, BlockFace blockWall) { + if(blockWall == wall) { + return isPartOfGate(diamondGate, block) + || isPartOfGate(ironGate, block) + || isPartOfGate(goldGate, block); + } + return false; + } + + private boolean isPartOfGate(Block gateBlock, Block block) { + BlockFace leftSide = null; // look at the zone + BlockFace rightSide = null; + if(wall == BlockFace.North) { + leftSide = BlockFace.East; + rightSide = BlockFace.West; + } else if(wall == BlockFace.East) { + leftSide = BlockFace.South; + rightSide = BlockFace.North; + } else if(wall == BlockFace.South) { + leftSide = BlockFace.West; + rightSide = BlockFace.East; + } else if(wall == BlockFace.West) { + leftSide = BlockFace.North; + rightSide = BlockFace.South; + } + return (block.getX() == gateBlock.getX() + && block.getY() == gateBlock.getY() + && block.getZ() == gateBlock.getZ()) + || + (block.getX() == gateBlock.getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(leftSide).getX() + && block.getY() == gateBlock.getFace(leftSide).getY() + && block.getZ() == gateBlock.getFace(leftSide).getZ()) + || + (block.getX() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(leftSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(BlockFace.Up).getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(BlockFace.Up).getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(BlockFace.Up).getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getX() + && block.getY() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getY() + && block.getZ() == gateBlock.getFace(rightSide).getFace(BlockFace.Up).getFace(BlockFace.Up).getZ()) + || + (block.getX() == gateBlock.getFace(rightSide).getX() + && block.getY() == gateBlock.getFace(rightSide).getY() + && block.getZ() == gateBlock.getFace(rightSide).getZ()); + } + + public Warzone getZone() { + return this.warzone; + } } diff --git a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java index 83a8eb0..158e323 100644 --- a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java +++ b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java @@ -76,21 +76,23 @@ public class ZoneWallGuard { private void toGlass(Block block, BlockFace wall) { // face here means which wall we are working on - if(wall == BlockFace.North) { - if(warzone.getVolume().isNorthWallBlock(block)) { - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.South) { - if(warzone.getVolume().isSouthWallBlock(block)) { - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.East) { - if(warzone.getVolume().isEastWallBlock(block)) { - block.setType(Material.GLASS); - } - } else if (wall == BlockFace.West) { - if(warzone.getVolume().isWestWallBlock(block)) { - block.setType(Material.GLASS); + if(warzone.getLobby() == null || (warzone.getLobby() != null && !warzone.getLobby().blockIsAGateBlock(block, wall))){ + if(wall == BlockFace.North) { + if(warzone.getVolume().isNorthWallBlock(block)) { + block.setType(Material.GLASS); + } + } else if (wall == BlockFace.South) { + if(warzone.getVolume().isSouthWallBlock(block)) { + block.setType(Material.GLASS); + } + } else if (wall == BlockFace.East) { + if(warzone.getVolume().isEastWallBlock(block)) { + block.setType(Material.GLASS); + } + } else if (wall == BlockFace.West) { + if(warzone.getVolume().isWestWallBlock(block)) { + block.setType(Material.GLASS); + } } } } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index 9392518..42495cb 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -163,7 +163,8 @@ public class WarzoneMapper { } else if(lobbyStr.equals("west")) { lobbyFace = BlockFace.West; } - warzone.setLobby(new ZoneLobby(war, warzone, lobbyFace)); + ZoneLobby lobby = new ZoneLobby(war, warzone, lobbyFace); + warzone.setLobby(lobby); } warzoneConfig.close();