From 46fd5ff1bb5734bfc93597f33dad525a63b233ae Mon Sep 17 00:00:00 2001 From: taoneill Date: Tue, 15 Feb 2011 18:04:10 -0500 Subject: [PATCH] Closes gh-25. Closes gh-60. Order of zone creation (or order in war.txt) dictates the order of the zone on the warhub. Can now disable/enable a warzone so that is dissapears form the warhub and players cant join. This lets the zone maker work in peace. --- .../main/java/bukkit/tommytony/war/War.java | 75 ++++++++++++------- .../tommytony/war/WarPlayerListener.java | 59 ++++++++++----- .../main/java/com/tommytony/war/WarHub.java | 53 +++++++------ .../main/java/com/tommytony/war/Warzone.java | 9 +++ .../tommytony/war/mappers/WarzoneMapper.java | 6 ++ 5 files changed, 130 insertions(+), 72 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index be0a775..2465155 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -610,6 +610,11 @@ public class War extends JavaPlugin { } warzone.initializeZone(); // bring back team spawns etc this.msg(player, "Warzone config saved. Zone reset."); + + if(warHub != null) { // maybe the zone was disabled/enabled + warHub.getVolume().resetBlocks(); + warHub.initialize(); + } } else { this.badMsg(player, "Failed to read named parameters."); } @@ -638,6 +643,11 @@ public class War extends JavaPlugin { } warzone.initializeZone(); // bring back team spawns etc + if(warHub != null) { // maybe the zone was disabled/enabled + warHub.getVolume().resetBlocks(); + warHub.initialize(); + } + this.msg(player, "Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks."); } } @@ -928,34 +938,38 @@ public class War extends JavaPlugin { } else { lobby = warzone.getLobby(); } - List teams = warzone.getTeams(); - boolean foundTeam = false; - for(Team team : teams) { - if(team.getName().equals(name)) { - if(!warzone.hasPlayerInventory(player.getName())) { - warzone.keepPlayerInventory(player); - this.msg(player, "Your inventory is is storage until you /leave."); - } - if(team.getPlayers().size() < warzone.getTeamCap()) { - team.addPlayer(player); - team.resetSign(); - warzone.respawnPlayer(team, player); - if(warHub != null) { - warHub.resetZoneSign(warzone); - } - foundTeam = true; - } else { - this.badMsg(player, "Team " + name + " is full."); - foundTeam = true; - } - } - } - if(foundTeam) { - for(Team team : teams){ - team.teamcast("" + player.getName() + " joined " + name); - } + if(warzone.isDisabled()) { + badMsg(player, "This warzone is disabled."); } else { - this.badMsg(player, "No such team. Try /teams."); + List teams = warzone.getTeams(); + boolean foundTeam = false; + for(Team team : teams) { + if(team.getName().equals(name)) { + if(!warzone.hasPlayerInventory(player.getName())) { + warzone.keepPlayerInventory(player); + this.msg(player, "Your inventory is is storage until you /leave."); + } + if(team.getPlayers().size() < warzone.getTeamCap()) { + team.addPlayer(player); + team.resetSign(); + warzone.respawnPlayer(team, player); + if(warHub != null) { + warHub.resetZoneSign(warzone); + } + foundTeam = true; + } else { + this.badMsg(player, "Team " + name + " is full."); + foundTeam = true; + } + } + } + if(foundTeam) { + for(Team team : teams){ + team.teamcast("" + player.getName() + " joined " + name); + } + } else { + this.badMsg(player, "No such team. Try /teams."); + } } } } @@ -1061,6 +1075,10 @@ public class War extends JavaPlugin { String onOff = namedParams.get("unbreakable"); warzone.setUnbreakableZoneBlocks(onOff.equals("on") || onOff.equals("true")); } + if(namedParams.containsKey("disabled")) { + String onOff = namedParams.get("disabled"); + warzone.setDisabled(onOff.equals("on") || onOff.equals("true")); + } // if(namedParams.containsKey("dropLootOnDeath")){ // String onOff = namedParams.get("dropLootOnDeath"); // warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); @@ -1221,13 +1239,14 @@ public class War extends JavaPlugin { this.getLogger().log(Level.WARNING, "[War] " + str); } + // the only way to find a zone that has only one corner public Warzone findWarzone(String warzoneName) { for(Warzone warzone : warzones) { if(warzone.getName().equals(warzoneName)) { return warzone; } } - for(Warzone warzone : incompleteZones) { + for(Warzone warzone : incompleteZones) { if(warzone.getName().equals(warzoneName)) { return warzone; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index df86360..52dd74f 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -126,24 +126,28 @@ public class WarPlayerListener extends PlayerListener { if(oldTeam == null && canPlay) { // trying to counter spammy player move isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc); if(isAutoAssignGate) { - enteredGate = true; - dropFromOldTeamIfAny(player); - int noOfPlayers = 0; - for(Team t : zone.getTeams()) { - noOfPlayers += t.getPlayers().size(); - } - if(noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) { - Team team = zone.autoAssign(player); - event.setFrom(team.getTeamSpawn()); - event.setCancelled(true); - if(war.getWarHub() != null) { - war.getWarHub().resetZoneSign(zone); - } + if(zone.isDisabled()){ + handleDisabledZone(event, player, zone); } else { - event.setFrom(zone.getTeleport()); - player.teleportTo(zone.getTeleport()); - event.setCancelled(true); - war.badMsg(player, "All teams are full."); + enteredGate = true; + dropFromOldTeamIfAny(player); + int noOfPlayers = 0; + for(Team t : zone.getTeams()) { + noOfPlayers += t.getPlayers().size(); + } + if(noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) { + Team team = zone.autoAssign(player); + event.setFrom(team.getTeamSpawn()); + event.setCancelled(true); + if(war.getWarHub() != null) { + war.getWarHub().resetZoneSign(zone); + } + } else { + event.setFrom(zone.getTeleport()); + player.teleportTo(zone.getTeleport()); + event.setCancelled(true); + war.badMsg(player, "All teams are full."); + } } return; } @@ -153,7 +157,9 @@ public class WarPlayerListener extends PlayerListener { enteredGate = true; dropFromOldTeamIfAny(player); Team diamondTeam = zone.getTeamByMaterial(TeamMaterials.TEAMDIAMOND); - if(diamondTeam.getPlayers().size() < zone.getTeamCap()) { + if(zone.isDisabled()){ + handleDisabledZone(event, player, zone); + } else if(diamondTeam.getPlayers().size() < zone.getTeamCap()) { diamondTeam.addPlayer(player); diamondTeam.resetSign(); if(war.getWarHub() != null) { @@ -181,7 +187,9 @@ public class WarPlayerListener extends PlayerListener { enteredGate = true; dropFromOldTeamIfAny(player); Team ironTeam = zone.getTeamByMaterial(TeamMaterials.TEAMIRON); - if(ironTeam.getPlayers().size() < zone.getTeamCap()) { + if(zone.isDisabled()){ + handleDisabledZone(event, player, zone); + } else if(ironTeam.getPlayers().size() < zone.getTeamCap()) { ironTeam.addPlayer(player); ironTeam.resetSign(); if(war.getWarHub() != null) { @@ -209,7 +217,9 @@ public class WarPlayerListener extends PlayerListener { enteredGate = true; dropFromOldTeamIfAny(player); Team goldTeam = zone.getTeamByMaterial(TeamMaterials.TEAMGOLD); - if(goldTeam.getPlayers().size() < zone.getTeamCap()) { + if(zone.isDisabled()){ + handleDisabledZone(event, player, zone); + } else if(goldTeam.getPlayers().size() < zone.getTeamCap()) { goldTeam.addPlayer(player); goldTeam.resetSign(); if(war.getWarHub() != null) { @@ -365,6 +375,15 @@ public class WarPlayerListener extends PlayerListener { } + private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) { + if(zone.getLobby() != null) { + war.badMsg(player, "This warzone is disabled."); + event.setFrom(zone.getTeleport()); + player.teleportTo(zone.getTeleport()); + event.setCancelled(true); + } + } + private void dropFromOldTeamIfAny(Player player) { // drop from old team if any Team previousTeam = war.getPlayerTeam(player.getName()); diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java index 2e36d17..1fd663b 100644 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -1,7 +1,9 @@ package com.tommytony.war; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bukkit.Location; import org.bukkit.Material; @@ -24,7 +26,7 @@ public class WarHub { private final War war; private Location location; private Volume volume; - private List zoneGateBlocks = new ArrayList(); + private Map zoneGateBlocks = new HashMap(); public WarHub(War war, Location location) { this.war = war; @@ -46,12 +48,12 @@ public class WarHub { public Warzone getDestinationWarzoneForLocation(Location playerLocation) { Warzone zone = null; - for(Block gate : zoneGateBlocks) { + for(String zoneName : zoneGateBlocks.keySet()) { + Block gate = zoneGateBlocks.get(zoneName); if(gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) { - int zoneIndex = zoneGateBlocks.indexOf(gate); - zone = war.getWarzones().get(zoneIndex); + zone = war.findWarzone(zoneName); } } return zone; @@ -60,7 +62,11 @@ public class WarHub { public void initialize() { // for now, draw the wall of gates to the west zoneGateBlocks.clear(); - int noOfWarzones = war.getWarzones().size(); + int disabled = 0; + for(Warzone zone : war.getWarzones()) { + if(zone.isDisabled()) disabled++; + } + int noOfWarzones = war.getWarzones().size() - disabled; if(noOfWarzones > 0) { int hubWidth = noOfWarzones * 4 + 2; int halfHubWidth = hubWidth / 2; @@ -80,19 +86,22 @@ public class WarHub { // draw gates Block currentGateBlock = volume.getCornerOne().getFace(BlockFace.UP).getFace(BlockFace.WEST, hubDepth).getFace(BlockFace.NORTH, 2); - for(int i = 0;i < war.getWarzones().size(); i++) { // gonna use the index to find it again - zoneGateBlocks.add(0, currentGateBlock); - currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE); - currentGateBlock.setType(Material.PORTAL); - currentGateBlock.getFace(BlockFace.UP).setType(Material.PORTAL); - currentGateBlock.getFace(BlockFace.SOUTH).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.NORTH).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); - currentGateBlock = currentGateBlock.getFace(BlockFace.NORTH, 4); + for(Warzone zone : war.getWarzones()) { // gonna use the index to find it again + if(!zone.isDisabled()) { + zoneGateBlocks.put(zone.getName(), currentGateBlock); + currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE); + currentGateBlock.setType(Material.PORTAL); + currentGateBlock.getFace(BlockFace.UP).setType(Material.PORTAL); + currentGateBlock.getFace(BlockFace.SOUTH).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.NORTH).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.SOUTH).getFace(BlockFace.UP).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.NORTH).getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); + currentGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP).setType(Material.OBSIDIAN); + currentGateBlock = currentGateBlock.getFace(BlockFace.NORTH, 4); + + } } // War hub sign @@ -115,7 +124,7 @@ public class WarHub { // Warzone signs for(Warzone zone : war.getWarzones()) { - if(zone.ready()) { + if(!zone.isDisabled() && zone.ready()) { this.resetZoneSign(zone); } } @@ -123,12 +132,8 @@ public class WarHub { } public void resetZoneSign(Warzone zone) { - 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 zoneGate = zoneGateBlocks.get(zone.getName()); 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); diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 00daff0..08f9bf1 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -56,6 +56,7 @@ public class Warzone { private boolean blockHeads; private boolean dropLootOnDeath; private boolean unbreakableZoneBlocks; + private boolean disabled = false; public Warzone(War war, World world, String name) { @@ -1114,5 +1115,13 @@ public class Warzone { return unbreakableZoneBlocks; } + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public boolean isDisabled() { + return disabled; + } + } 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 df6d8b7..9ce5281 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -211,6 +211,9 @@ public class WarzoneMapper { // unbreakableZoneBlocks warzone.setUnbreakableZoneBlocks(warzoneConfig.getBoolean("unbreakableZoneBlocks")); + // disabled + warzone.setDisabled(warzoneConfig.getBoolean("disabled")); + // dropLootOnDeath //warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath")); @@ -395,6 +398,9 @@ public class WarzoneMapper { // unbreakableZoneBlocks warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks()); + // disabled + warzoneConfig.setBoolean("disabled", warzone.isDisabled()); + // defaultDropLootOnDeath //warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());