From fbf4dc26fc850c964b2ccd2309f2015ea071cd6f Mon Sep 17 00:00:00 2001 From: taoneill Date: Mon, 17 Jan 2011 01:13:50 -0500 Subject: [PATCH] Working signs on lobbies and the warhub. They spam-destroy a lot though. --- .../main/java/bukkit/tommytony/war/War.java | 2 + .../tommytony/war/WarPlayerListener.java | 5 ++ war/src/main/java/com/tommytony/war/Team.java | 24 +++--- .../main/java/com/tommytony/war/WarHub.java | 28 ++++++- .../main/java/com/tommytony/war/Warzone.java | 2 +- .../java/com/tommytony/war/ZoneLobby.java | 81 +++++++++++++++++++ 6 files changed, 131 insertions(+), 11 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 9bf2fe5..9128cb7 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -204,6 +204,7 @@ public class War extends JavaPlugin { } if(team.getPlayers().size() < warzone.getTeamCap()) { team.addPlayer(player); + team.resetSign(); Warzone zone = this.warzone(player.getLocation()); zone.respawnPlayer(team, player); foundTeam = true; @@ -231,6 +232,7 @@ public class War extends JavaPlugin { } else { Team playerTeam = this.getPlayerTeam(player.getName()); playerTeam.removePlayer(player.getName()); + playerTeam.resetSign(); Warzone zone = this.warzone(player.getLocation()); player.teleportTo(zone.getTeleport()); diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index d306955..ba94554 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -47,6 +47,7 @@ public class WarPlayerListener extends PlayerListener { Team team = war.getPlayerTeam(player.getName()); if(team != null) { team.removePlayer(player.getName()); + team.resetSign(); } } @@ -178,6 +179,7 @@ public class WarPlayerListener extends PlayerListener { Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND); if(diamondTeam.getPlayers().size() < zone.getTeamCap()) { diamondTeam.addPlayer(player); + diamondTeam.resetSign(); zone.keepPlayerInventory(player); player.sendMessage(war.str("Your inventory is is storage until you /leave.")); zone.respawnPlayer(event, diamondTeam, player); @@ -193,6 +195,7 @@ public class WarPlayerListener extends PlayerListener { Team ironTeam = zone.getTeamByMaterial(TeamMaterials.TEAMIRON); if(ironTeam.getPlayers().size() < zone.getTeamCap()) { ironTeam.addPlayer(player); + ironTeam.resetSign(); zone.keepPlayerInventory(player); player.sendMessage(war.str("Your inventory is is storage until you /leave.")); zone.respawnPlayer(event, ironTeam, player); @@ -208,6 +211,7 @@ public class WarPlayerListener extends PlayerListener { Team goldTeam = zone.getTeamByMaterial(TeamMaterials.TEAMGOLD); if(goldTeam.getPlayers().size() < zone.getTeamCap()) { goldTeam.addPlayer(player); + goldTeam.resetSign(); zone.keepPlayerInventory(player); player.sendMessage(war.str("Your inventory is is storage until you /leave.")); zone.respawnPlayer(event, goldTeam, player); @@ -231,6 +235,7 @@ public class WarPlayerListener extends PlayerListener { // same as leave, except event.setTo Team playerTeam = war.getPlayerTeam(player.getName()); playerTeam.removePlayer(player.getName()); + playerTeam.resetSign(); event.setTo(playerWarzone.getTeleport()); player.sendMessage(war.str("Left the zone.")); playerWarzone.restorePlayerInventory(player); diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index 20de0e7..6bdd084 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -6,9 +6,11 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import org.bukkit.entity.Player; +import org.bukkit.material.MaterialData; import bukkit.tommytony.war.War; @@ -196,22 +198,26 @@ public class Team { return volume; } - public void resetSign(){ int x = teamSpawn.getBlockX(); int y = teamSpawn.getBlockY(); int z = teamSpawn.getBlockZ(); - Block block = warzone.getWorld().getBlockAt(x, y, z); - block.setType(Material.SIGN_POST); + Block block = warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST, 2); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + block.setData((byte)6); BlockState state = block.getState(); - Sign sign = (Sign) state; - sign.setLine(0, "Team"); - sign.setLine(1, name); - sign.setLine(2, points + " pts"); - sign.setLine(3, remainingTickets + "/" + warzone.getLifePool() + " lives left"); - state.update(true); + Sign sign = (Sign) state; + sign.setLine(0, "Team " + name); + sign.setLine(1, remainingTickets + "/" + warzone.getLifePool() + " lives left"); + sign.setLine(2, points + "/" + warzone.getScoreCap() + " pts"); + sign.setLine(3, players.size() + "/" + warzone.getTeamCap() + " players"); + state.update(true); + + if(warzone.getLobby() != null) { + warzone.getLobby().resetTeamGateSign(this); + } } public void setVolume(Volume volume) { diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java index cb97755..535037d 100644 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -7,6 +7,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; import bukkit.tommytony.war.War; @@ -93,8 +95,32 @@ public class WarHub { } } - public void resetSigns() { + public void resetZoneSign(Warzone zone) { // TODO Signs + int i = 0; + for(i = 0; i < war.getWarzones().size(); i++) { + if(zone.getName() == war.getWarzones().get(i).getName()) break; + } + + Block zoneGate = zoneGateBlocks.get(i); + Block block = zoneGate.getFace(BlockFace.SOUTH).getFace(BlockFace.EAST, 1); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + block.setData((byte)8); + + int zoneCap = 0; + int zonePlayers = 0; + for(Team t : zone.getTeams()) { + zonePlayers += t.getPlayers().size(); + zoneCap += zone.getTeamCap(); + } + + BlockState state = block.getState(); + Sign sign = (Sign) state; + sign.setLine(0, "Warzone"); + sign.setLine(1, zone.getName()); + sign.setLine(2, zonePlayers + "/" + zoneCap + " players"); + sign.setLine(3, zone.getTeams().size() + " teams"); + state.update(true); } public void setVolume(Volume vol) { diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 950043f..345c084 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -702,6 +702,7 @@ public class Warzone { } if(lowestNoOfPlayers != null) { lowestNoOfPlayers.addPlayer(player); + lowestNoOfPlayers.resetSign(); if(!hasPlayerInventory(player.getName())) { keepPlayerInventory(player); } @@ -745,6 +746,5 @@ public class Warzone { return drawZoneOutline; } - } diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index 8718aa1..b43f491 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -4,6 +4,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.Sign; import bukkit.tommytony.war.War; @@ -149,6 +151,13 @@ public class ZoneLobby { // add war hub link gate if(war.getWarHub() != null) { placeGate(warHubLinkGate, Material.OBSIDIAN); + // add warhub sign + String[] lines = new String[4]; + lines[0] = ""; + lines[1] = "War hub"; + lines[2] = ""; + lines[3] = ""; + resetGateSign(warHubLinkGate, lines, false); } // add team gates or single auto assign gate @@ -156,6 +165,9 @@ public class ZoneLobby { placeGate(diamondGate, TeamMaterials.TEAMDIAMOND); placeGate(ironGate, TeamMaterials.TEAMIRON); placeGate(goldGate, TeamMaterials.TEAMGOLD); + for(Team t : warzone.getTeams()) { + resetTeamGateSign(t); + } // set zone tp zoneTeleportBlock = lobbyMiddleWallBlock.getFace(wall, 6); @@ -447,4 +459,73 @@ public class ZoneLobby { public Warzone getZone() { return this.warzone; } + + public void resetTeamGateSign(Team team) { + if(team.getMaterial() == TeamMaterials.TEAMDIAMOND) { + resetTeamGateSign(team, diamondGate); + } else if(team.getMaterial() == TeamMaterials.TEAMIRON) { + resetTeamGateSign(team, ironGate); + } else if(team.getMaterial() == TeamMaterials.TEAMGOLD) { + resetTeamGateSign(team, goldGate); + } + + if(war.getWarHub() != null) { + war.getWarHub().resetZoneSign(warzone); + } + } + + private void resetTeamGateSign(Team team, Block gate) { + if(gate != null) { + String[] lines = new String[4]; + lines[0] = "Team " + team.getName(); + lines[1] = team.getPlayers().size() + "/" + warzone.getTeamCap() + " players"; + lines[2] = team.getPoints() + "/" + warzone.getScoreCap() + " pts"; + lines[3] = team.getRemainingTickets() + "/" + warzone.getLifePool() + " lives left"; + resetGateSign(gate, lines, true); + } + } + + private void resetGateSign(Block gate, String[] lines, boolean awayFromWall) { + Block block = null; + BlockFace direction = null; + if(awayFromWall) { + direction = wall; + } else if (wall == BlockFace.NORTH) { + direction = BlockFace.SOUTH; + } else if (wall == BlockFace.EAST) { + direction = BlockFace.WEST; + } else if (wall == BlockFace.SOUTH) { + direction = BlockFace.NORTH; + } else if (wall == BlockFace.WEST) { + direction = BlockFace.EAST; + } + if(wall == BlockFace.NORTH) { + block = gate.getFace(direction).getFace(BlockFace.EAST); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + if(awayFromWall) block.setData((byte)4); + else block.setData((byte)12); + } else if(wall == BlockFace.EAST) { + block = gate.getFace(direction).getFace(BlockFace.SOUTH); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + if(awayFromWall) block.setData((byte)8); + else block.setData((byte)0); + } else if(wall == BlockFace.SOUTH) { + block = gate.getFace(direction).getFace(BlockFace.WEST); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + if(awayFromWall) block.setData((byte)12); + else block.setData((byte)4); + } else if(wall == BlockFace.WEST) { + block = gate.getFace(direction).getFace(BlockFace.NORTH); + if(block.getType() != Material.SIGN_POST) block.setType(Material.SIGN_POST); + if(awayFromWall) block.setData((byte)0); + else block.setData((byte)8); + } + BlockState state = block.getState(); + Sign sign = (Sign) state; + sign.setLine(0, lines[0]); + sign.setLine(1, lines[1]); + sign.setLine(2, lines[2]); + sign.setLine(3, lines[3]); + state.update(true); + } }