From e33a19cc4f3ec734c17163a02df503828dc45902 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 13 Jan 2011 17:19:27 -0500 Subject: [PATCH] Totally broken. Factoring out the volume mapping and adding warhubs --- war/.classpath | 3 +- .../main/java/bukkit/tommytony/war/War.java | 7 + .../tommytony/war/WarPlayerListener.java | 503 +++++++++--------- .../main/java/com/tommytony/war/Monument.java | 9 +- .../main/java/com/tommytony/war/WarHub.java | 23 + .../java/com/tommytony/war/ZoneWallGuard.java | 8 +- .../tommytony/war/mappers/VolumeMapper.java | 135 +++++ .../tommytony/war/mappers/WarzoneMapper.java | 45 +- .../tommytony/war/volumes/CenteredVolume.java | 17 +- .../tommytony/war/volumes/VerticalVolume.java | 7 +- .../com/tommytony/war/volumes/Volume.java | 104 +--- 11 files changed, 457 insertions(+), 404 deletions(-) create mode 100644 war/src/main/java/com/tommytony/war/WarHub.java create mode 100644 war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java diff --git a/war/.classpath b/war/.classpath index d0dfb8a..cb8a30d 100644 --- a/war/.classpath +++ b/war/.classpath @@ -1,8 +1,7 @@ - - + diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 43b988e..ac488d2 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -186,6 +186,13 @@ public class War extends JavaPlugin { public List getZoneMakerNames() { return zoneMakerNames; } + + public boolean isZoneMaker(String playerName) { + for(String zoneMaker : zoneMakerNames) { + if(zoneMaker.equals(playerName)) return true; + } + return false; + } public boolean getDefaultDrawZoneOutline() { return defaultDrawZoneOutline ; diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index f720e49..38c0434 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -201,276 +201,277 @@ public class WarPlayerListener extends PlayerListener { event.setCancelled(true); } + if(war.isZoneMaker(player.getName())) { // Mod commands : /nextbattle - // /restartbattle - else if(command.equals("nextbattle") || command.equals("restartbattle")) { - if(!war.inAnyWarzone(player.getLocation())) { - player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone.")); - } else { - Warzone warzone = war.warzone(player.getLocation()); - for(Team team: warzone.getTeams()) { - team.teamcast(war.str("The battle was interrupted. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools...")); - } - int resetBlocks = warzone.getVolume().resetBlocks(); - warzone.initializeZone(); - player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset.")); - war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); - } - event.setCancelled(true); - } - - - // Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone - - // /setzone - else if(command.equals("setzone") || command.equals("setwarzone")) { - if(arguments.length < 2 || arguments.length > 2 - || (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest") - && !arguments[1].equals("se") && !arguments[1].equals("nw")))) { - player.sendMessage(war.str("Usage: /setzone <'southeast'/'northwest'/'se'/'nw'>. " + - "Defines the battleground boundary. " + - "The warzone is reset at the start of every battle. " + - "This command overwrites any previously saved blocks " + - "(i.e. make sure you reset with /restartbattle " + - "or /resetwarzone before changing the boundary). ")); - } else { - Warzone warzone = war.findWarzone(arguments[0]); - if(warzone == null) { - // create the warzone - warzone = new Warzone(war, player.getLocation().getWorld(), arguments[0]); - war.addWarzone(warzone); - WarMapper.save(war); - if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { - warzone.setNorthwest(player.getLocation()); - player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Northwesternmost point set at x=" - + (int)warzone.getNorthwest().getBlockX() + " z=" + (int)warzone.getNorthwest().getBlockZ() + ".")); - } else { - warzone.setSoutheast(player.getLocation()); - player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x=" - + (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + ".")); - } + // /restartbattle + if(command.equals("nextbattle") || command.equals("restartbattle")) { + if(!war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone.")); } else { - String message = ""; - if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { - int reset = warzone.getVolume().resetBlocks(); - warzone.setNorthwest(player.getLocation()); - warzone.saveState(); - warzone.initializeZone(); - message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX() - + " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " + - reset + " blocks reset. New zone saved."; + Warzone warzone = war.warzone(player.getLocation()); + for(Team team: warzone.getTeams()) { + team.teamcast(war.str("The battle was interrupted. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools...")); + } + int resetBlocks = warzone.getVolume().resetBlocks(); + warzone.initializeZone(); + player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset.")); + war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); + } + event.setCancelled(true); + } + + // Warzone maker commands: /setzone, /savezone, /setteam, /setmonument, /resetzone + + // /setzone + else if(command.equals("setzone") || command.equals("setwarzone")) { + if(arguments.length < 2 || arguments.length > 2 + || (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest") + && !arguments[1].equals("se") && !arguments[1].equals("nw")))) { + player.sendMessage(war.str("Usage: /setzone <'southeast'/'northwest'/'se'/'nw'>. " + + "Defines the battleground boundary. " + + "The warzone is reset at the start of every battle. " + + "This command overwrites any previously saved blocks " + + "(i.e. make sure you reset with /restartbattle " + + "or /resetwarzone before changing the boundary). ")); + } else { + Warzone warzone = war.findWarzone(arguments[0]); + if(warzone == null) { + // create the warzone + warzone = new Warzone(war, player.getLocation().getWorld(), arguments[0]); + war.addWarzone(warzone); + WarMapper.save(war); + if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { + warzone.setNorthwest(player.getLocation()); + player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Northwesternmost point set at x=" + + (int)warzone.getNorthwest().getBlockX() + " z=" + (int)warzone.getNorthwest().getBlockZ() + ".")); + } else { + warzone.setSoutheast(player.getLocation()); + player.sendMessage(war.str("Warzone " + warzone.getName() + " added. Southeasternmost point set at x=" + + (int)warzone.getSoutheast().getBlockX() + " z=" + (int)warzone.getSoutheast().getBlockZ() + ".")); + } } else { - int reset = warzone.getVolume().resetBlocks(); - warzone.setSoutheast(player.getLocation()); - warzone.saveState(); - warzone.initializeZone(); - message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX() - + " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " + - reset + " blocks reset. New zone saved."; + String message = ""; + if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { + int reset = warzone.getVolume().resetBlocks(); + warzone.setNorthwest(player.getLocation()); + warzone.saveState(); + warzone.initializeZone(); + message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().getBlockX() + + " z=" + (int)warzone.getNorthwest().getBlockZ() + " on warzone " + warzone.getName() + ". " + + reset + " blocks reset. New zone saved."; + } else { + int reset = warzone.getVolume().resetBlocks(); + warzone.setSoutheast(player.getLocation()); + warzone.saveState(); + warzone.initializeZone(); + message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().getBlockX() + + " z=" + (int)warzone.getSoutheast().getBlockZ() + " on warzone " + warzone.getName() + ". " + + reset + " blocks reset. New zone saved."; + } + + if(warzone.getNorthwest() == null) { + message += " Still missing northwesternmost point."; + } + if(warzone.getSoutheast() == null) { + message += " Still missing southeasternmost point."; + } + if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) { + if(warzone.ready()) { + message += " Warzone " + warzone.getName() + " almost ready. Use /setteam while inside the warzone to create new teams. Make sure to use /savezone to " + + "set the warzone teleport point and initial state."; + } else if (warzone.tooSmall()) { + message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20."; + } else if (warzone.tooBig()) { + message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000."; + } + } + player.sendMessage(war.str(message)); + } + WarzoneMapper.save(war, warzone, false); + + } + event.setCancelled(true); + } + + // /savewarzone + else if(command.equals("savezone") || command.equals("savewarzone")) { + if(!war.inAnyWarzone(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." + + "(i.e. make sure to use /zone or the warzone tp point will change). " + + "Just like /setzone, this command overwrites any previously saved blocks " + + "(i.e. make sure you reset with /restartbattle " + + "or /resetzone before changing start state). ")); + } else { + Warzone warzone = war.warzone(player.getLocation()); + int savedBlocks = warzone.saveState(); + warzone.setTeleport(player.getLocation()); + player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks.")); + WarzoneMapper.save(war, warzone, true); + } + event.setCancelled(true); + } + + // /resetwarzone + else if(command.equals("resetzone") || command.equals("resetwarzone")) { + if(!war.inAnyWarzone(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()); + int resetBlocks = warzone.getVolume().resetBlocks(); + warzone.initializeZone(); + for(Team team: warzone.getTeams()) { + team.teamcast(war.str("The war has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams...")); + for(Player p : team.getPlayers()) { + p.teleportTo(warzone.getTeleport()); + warzone.restorePlayerInventory(p); + player.sendMessage(war.str("You have left the warzone. Your inventory has (hopefully) been restored.")); + } + } + war.getWarzones().remove(warzone); + Warzone resetWarzone = WarzoneMapper.load(war, warzone.getName(), true); + war.getWarzones().add(resetWarzone); + if(arguments.length > 0) { + for(String arg : arguments) { + if(arg.startsWith("pool=")){ + int overrideLifepool = Integer.parseInt(arg.substring(5)); + resetWarzone.setLifePool(overrideLifepool); + } + } + } + resetWarzone.initializeZone(); + player.sendMessage(war.str("Warzone and teams reset. " + resetBlocks + " blocks reset.")); + war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); + } + event.setCancelled(true); + } + + // /deletewarzone + else if(command.equals("deletezone") || command.equals("deletewarzone")) { + if(!war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /deletewarzone." + + " Deletes the warzone. " + + "Must be in the warzone (try /warzones and /warzone). ")); + } else { + Warzone warzone = war.warzone(player.getLocation()); + for(Team t : warzone.getTeams()) { + t.getVolume().resetBlocks(); + } + for(Monument m : warzone.getMonuments()) { + m.remove(); + } + war.getWarzones().remove(warzone); + WarMapper.save(war); + WarzoneMapper.delete(war, warzone.getName()); + player.sendMessage(war.str("Warzone " + warzone.getName() + " removed.")); + } + event.setCancelled(true); + } + + // /setteam + else if(command.equals("setteam") || command.equals("newteam") || command.equals("teamspawn")) { + if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation()) + || (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { + player.sendMessage(war.str("Usage: /setteam ." + + " Sets the team spawn to the current location. " + + "Must be in a warzone (try /zones and /zone). ")); + } else { + Material teamMaterial = TeamMaterials.teamMaterialFromString(arguments[0]); + String name = TeamMaterials.teamMaterialToString(teamMaterial); + Warzone warzone = war.warzone(player.getLocation()); + Team existingTeam = warzone.getTeamByMaterial(teamMaterial); + if(existingTeam != null) { + // relocate + existingTeam.setTeamSpawn(player.getLocation()); + player.sendMessage(war.str("Team " + existingTeam.getName() + " spawn relocated.")); + } else { + // new team + Team newTeam = new Team(name, teamMaterial, player.getLocation(), war, warzone); + newTeam.setRemainingTickets(warzone.getLifePool()); + warzone.getTeams().add(newTeam); + newTeam.setTeamSpawn(player.getLocation()); + player.sendMessage(war.str("Team " + name + " created with spawn here.")); } - if(warzone.getNorthwest() == null) { - message += " Still missing northwesternmost point."; - } - if(warzone.getSoutheast() == null) { - message += " Still missing southeasternmost point."; - } - if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) { - if(warzone.ready()) { - message += " Warzone " + warzone.getName() + " almost ready. Use /setteam while inside the warzone to create new teams. Make sure to use /savezone to " + - "set the warzone teleport point and initial state."; - } else if (warzone.tooSmall()) { - message += " Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20."; - } else if (warzone.tooBig()) { - message += " Warzone " + warzone.getName() + " is too Big. Max north-south size: 1000. Max east-west size: 1000."; + WarzoneMapper.save(war, warzone, false); + } + event.setCancelled(true); + } + + // /deleteteam + else if(command.equals("deleteteam")) { + if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /deleteteam ." + + " Deletes the team and its spawn. " + + "Must be in a warzone (try /zones and /zone). ")); + } else { + String name = TeamMaterials.teamMaterialToString(TeamMaterials.teamMaterialFromString(arguments[1])); + Warzone warzone = war.warzone(player.getLocation()); + List teams = warzone.getTeams(); + Team team = null; + for(Team t : teams) { + if(name.equals(t.getName())) { + team = t; } } - player.sendMessage(war.str(message)); - } - WarzoneMapper.save(war, warzone, false); - - } - event.setCancelled(true); - } - - // /savewarzone - else if(command.equals("savezone") || command.equals("savewarzone")) { - if(!war.inAnyWarzone(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." + - "(i.e. make sure to use /zone or the warzone tp point will change). " + - "Just like /setzone, this command overwrites any previously saved blocks " + - "(i.e. make sure you reset with /restartbattle " + - "or /resetzone before changing start state). ")); - } else { - Warzone warzone = war.warzone(player.getLocation()); - int savedBlocks = warzone.saveState(); - warzone.setTeleport(player.getLocation()); - player.sendMessage(war.str("Warzone " + warzone.getName() + " initial state and teleport location changed. Saved " + savedBlocks + " blocks.")); - WarzoneMapper.save(war, warzone, true); - } - event.setCancelled(true); - } - - // /resetwarzone - else if(command.equals("resetzone") || command.equals("resetwarzone")) { - if(!war.inAnyWarzone(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()); - int resetBlocks = warzone.getVolume().resetBlocks(); - warzone.initializeZone(); - for(Team team: warzone.getTeams()) { - team.teamcast(war.str("The war has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams...")); - for(Player p : team.getPlayers()) { - p.teleportTo(warzone.getTeleport()); - warzone.restorePlayerInventory(p); - player.sendMessage(war.str("You have left the warzone. Your inventory has (hopefully) been restored.")); + if(team != null) { + team.getVolume().resetBlocks(); + warzone.getTeams().remove(team); + WarzoneMapper.save(war, warzone, false); + player.sendMessage(war.str("Team " + name + " removed.")); + } else { + player.sendMessage(war.str("No such team.")); } } - war.getWarzones().remove(warzone); - Warzone resetWarzone = WarzoneMapper.load(war, warzone.getName(), true); - war.getWarzones().add(resetWarzone); - if(arguments.length > 0) { - for(String arg : arguments) { - if(arg.startsWith("pool=")){ - int overrideLifepool = Integer.parseInt(arg.substring(5)); - resetWarzone.setLifePool(overrideLifepool); - } - } - } - resetWarzone.initializeZone(); - player.sendMessage(war.str("Warzone and teams reset. " + resetBlocks + " blocks reset.")); - war.getLogger().info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); + event.setCancelled(true); } - event.setCancelled(true); - } - - // /deletewarzone - else if(command.equals("deletezone") || command.equals("deletewarzone")) { - if(!war.inAnyWarzone(player.getLocation())) { - player.sendMessage(war.str("Usage: /deletewarzone." + - " Deletes the warzone. " + - "Must be in the warzone (try /warzones and /warzone). ")); - } else { - Warzone warzone = war.warzone(player.getLocation()); - for(Team t : warzone.getTeams()) { - t.getVolume().resetBlocks(); - } - for(Monument m : warzone.getMonuments()) { - m.remove(); - } - war.getWarzones().remove(warzone); - WarMapper.save(war); - WarzoneMapper.delete(war, warzone.getName()); - player.sendMessage(war.str("Warzone " + warzone.getName() + " removed.")); - } - event.setCancelled(true); - } - - // /setteam - else if(command.equals("setteam") || command.equals("newteam") || command.equals("teamspawn")) { - if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation()) - || (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { - player.sendMessage(war.str("Usage: /setteam ." + - " Sets the team spawn to the current location. " + - "Must be in a warzone (try /zones and /zone). ")); - } else { - Material teamMaterial = TeamMaterials.teamMaterialFromString(arguments[0]); - String name = TeamMaterials.teamMaterialToString(teamMaterial); - Warzone warzone = war.warzone(player.getLocation()); - Team existingTeam = warzone.getTeamByMaterial(teamMaterial); - if(existingTeam != null) { - // relocate - existingTeam.setTeamSpawn(player.getLocation()); - player.sendMessage(war.str("Team " + existingTeam.getName() + " spawn relocated.")); + + // /monument + else if(command.equals("setmonument")) { + if(!war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /setmonument . Creates or moves a monument. Must be in warzone.")); } else { - // new team - Team newTeam = new Team(name, teamMaterial, player.getLocation(), war, warzone); - newTeam.setRemainingTickets(warzone.getLifePool()); - warzone.getTeams().add(newTeam); - newTeam.setTeamSpawn(player.getLocation()); - player.sendMessage(war.str("Team " + name + " created with spawn here.")); - } - - WarzoneMapper.save(war, warzone, false); - } - event.setCancelled(true); - } - - // /deleteteam - else if(command.equals("deleteteam")) { - if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) { - player.sendMessage(war.str("Usage: /deleteteam ." + - " Deletes the team and its spawn. " + - "Must be in a warzone (try /zones and /zone). ")); - } else { - String name = TeamMaterials.teamMaterialToString(TeamMaterials.teamMaterialFromString(arguments[1])); - Warzone warzone = war.warzone(player.getLocation()); - List teams = warzone.getTeams(); - Team team = null; - for(Team t : teams) { - if(name.equals(t.getName())) { - team = t; + Warzone warzone = war.warzone(player.getLocation()); + String monumentName = arguments[0]; + if(warzone.hasMonument(monumentName)) { + // move the existing monument + Monument monument = warzone.getMonument(monumentName); + monument.setLocation(player.getLocation()); + player.sendMessage(war.str("Monument " + monument.getName() + " was moved.")); + } else { + // create a new monument + Monument monument = new Monument(arguments[0], war, warzone, player.getLocation()); + warzone.getMonuments().add(monument); + player.sendMessage(war.str("Monument " + monument.getName() + " created.")); } - } - if(team != null) { - team.getVolume().resetBlocks(); - warzone.getTeams().remove(team); WarzoneMapper.save(war, warzone, false); - player.sendMessage(war.str("Team " + name + " removed.")); - } else { - player.sendMessage(war.str("No such team.")); } + event.setCancelled(true); } - event.setCancelled(true); - } - - // /monument - else if(command.equals("setmonument")) { - if(!war.inAnyWarzone(player.getLocation())) { - player.sendMessage(war.str("Usage: /setmonument . Creates or moves a monument. Must be in warzone.")); - } else { - Warzone warzone = war.warzone(player.getLocation()); - String monumentName = arguments[0]; - if(warzone.hasMonument(monumentName)) { - // move the existing monument - Monument monument = warzone.getMonument(monumentName); - monument.setLocation(player.getLocation()); - player.sendMessage(war.str("Monument " + monument.getName() + " was moved.")); + + // /deletemonument + else if(command.equals("deletemonument")) { + if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /deletemonument ." + + " Deletes the monument. " + + "Must be in a warzone (try /warzones and /warzone). ")); } else { - // create a new monument - Monument monument = new Monument(arguments[0], war, warzone, player.getLocation()); - warzone.getMonuments().add(monument); - player.sendMessage(war.str("Monument " + monument.getName() + " created.")); + String name = arguments[0]; + Warzone warzone = war.warzone(player.getLocation()); + Monument monument = warzone.getMonument(name); + if(monument != null) { + monument.remove(); + warzone.getMonuments().remove(monument); + WarzoneMapper.save(war, warzone, false); + player.sendMessage(war.str("Monument " + name + " removed.")); + } else { + player.sendMessage(war.str("No such monument.")); + } } - WarzoneMapper.save(war, warzone, false); + event.setCancelled(true); } - event.setCancelled(true); - } - - // /deletemonument - else if(command.equals("deletemonument")) { - if(arguments.length < 1 || !war.inAnyWarzone(player.getLocation())) { - player.sendMessage(war.str("Usage: /deletemonument ." + - " Deletes the monument. " + - "Must be in a warzone (try /warzones and /warzone). ")); - } else { - String name = arguments[0]; - Warzone warzone = war.warzone(player.getLocation()); - Monument monument = warzone.getMonument(name); - if(monument != null) { - monument.remove(); - warzone.getMonuments().remove(monument); - WarzoneMapper.save(war, warzone, false); - player.sendMessage(war.str("Monument " + name + " removed.")); - } else { - player.sendMessage(war.str("No such monument.")); - } - } - event.setCancelled(true); } } } diff --git a/war/src/main/java/com/tommytony/war/Monument.java b/war/src/main/java/com/tommytony/war/Monument.java index acd8806..0e481db 100644 --- a/war/src/main/java/com/tommytony/war/Monument.java +++ b/war/src/main/java/com/tommytony/war/Monument.java @@ -15,7 +15,7 @@ import com.tommytony.war.volumes.Volume; */ public class Monument { private Location location; - private CenteredVolume volume; + private Volume volume; private Team ownerTeam = null; private final String name; @@ -29,7 +29,7 @@ public class Monument { warzone.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 2, location.getBlockZ()), - 7, war, warzone); + 7, war, warzone.getWorld()); volume.saveBlocks(); this.addMonumentBlocks(); } @@ -155,5 +155,8 @@ public class Monument { return volume; } - + public void setVolume(Volume newVolume) { + this.volume = newVolume; + + } } diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java new file mode 100644 index 0000000..d7c75c4 --- /dev/null +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -0,0 +1,23 @@ +package com.tommytony.war; + +import org.bukkit.Location; +import org.bukkit.World; + +import com.tommytony.war.volumes.Volume; + +import bukkit.tommytony.war.War; + +public class WarHub { + private final War war; + private final World world; + private final Location location; + private Volume volume; + + public WarHub(War war, World world, Location location) { + this.war = war; + this.world = world; + this.location = location; + this.volume = new Volume("warHub", war, warzone); + } + +} diff --git a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java index 64329fd..5547c07 100644 --- a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java +++ b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java @@ -4,15 +4,17 @@ import java.util.List; import org.bukkit.Block; import org.bukkit.BlockFace; -import org.bukkit.HumanEntity; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Player; import bukkit.tommytony.war.War; -import com.tommytony.war.volumes.CenteredVolume; - +/** + * + * @author tommytony + * + */ public class ZoneWallGuard { private Player player; private Warzone warzone; diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java new file mode 100644 index 0000000..e357fed --- /dev/null +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -0,0 +1,135 @@ +package com.tommytony.war.mappers; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +import org.bukkit.Material; +import org.bukkit.World; + +import bukkit.tommytony.war.War; + +import com.tommytony.war.volumes.BlockInfo; +import com.tommytony.war.volumes.Volume; + +public class VolumeMapper { + public static Volume load(String zoneName, String volumeName, War war, World world) { + BufferedReader in = null; + Volume volume = null; + try { + in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volumeName))); + String firstLine = in.readLine(); + if(firstLine != null && !firstLine.equals("")) { + int x1 = Integer.parseInt(in.readLine()); + int y1 = Integer.parseInt(in.readLine()); + int z1 = Integer.parseInt(in.readLine()); + int x2 = Integer.parseInt(in.readLine()); + int y2 = Integer.parseInt(in.readLine()); + int z2 = Integer.parseInt(in.readLine()); + + volume = new Volume(volumeName, war, world); + volume.setCornerOne(world.getBlockAt(x1, y1, z1)); + volume.setCornerTwo(world.getBlockAt(x2, y2, z2)); + + volume.setBlockInfos(new BlockInfo[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]); + for(int i = 0; i < volume.getSizeX(); i++){ + for(int j = 0; j < volume.getSizeY(); j++) { + for(int k = 0; k < volume.getSizeZ(); k++) { + String blockLine = in.readLine(); + String[] blockSplit = blockLine.split(","); + + int typeID = Integer.parseInt(blockSplit[0]); + byte data = Byte.parseByte(blockSplit[1]); + String[] lines = null; + if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) { + String signLines = blockSplit[2]; + if(blockSplit.length > 3) { + // sign includes commas + for(int splitI = 3; splitI < blockSplit.length; splitI++) { + signLines.concat(blockSplit[splitI]); + } + } + String[] signLinesSplit = signLines.split("[line]"); + lines = new String[4]; + lines[0] = signLinesSplit[0]; + lines[1] = signLinesSplit[1]; + lines[2] = signLinesSplit[2]; + lines[3] = signLinesSplit[3]; + } + volume.getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines); + } + } + } + } + } catch (IOException e) { + war.getLogger().warning("Failed to read volume file " + volumeName + + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } finally { + if(in != null) + try { + in.close(); + } catch (IOException e) { + war.getLogger().warning("Failed to close file reader for volume " + volumeName + + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } + } + return volume; + } + + public static void save(Volume volume, String zoneName, War war) { + if(volume.isSaved() && volume.getBlockInfos() != null) { + BufferedWriter out = null; + try { + out = new BufferedWriter(new FileWriter(new File("War/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); + out.write("corner1"); out.newLine(); + out.write(volume.getCornerOne().getX()); out.newLine(); + out.write(volume.getCornerOne().getY()); out.newLine(); + out.write(volume.getCornerOne().getZ()); out.newLine(); + out.write("corner2"); out.newLine(); + out.write(volume.getCornerTwo().getX()); out.newLine(); + out.write(volume.getCornerTwo().getY()); out.newLine(); + out.write(volume.getCornerTwo().getZ()); out.newLine(); + + for(int i = 0; i < volume.getSizeX(); i++){ + for(int j = 0; j < volume.getSizeY(); j++) { + for(int k = 0; k < volume.getSizeZ(); k++) { + BlockInfo info = volume.getBlockInfos()[i][j][k]; + if(info == null) { + out.write("0,0,"); out.newLine(); + } else { + if(info.getType() == Material.Sign || info.getType() == Material.SignPost) { + String[] lines = info.getSignLines(); + out.write(info.getTypeID() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1] + + "[line]" + lines[2] + "[line]"+ lines[3]); + + } else { + out.write(info.getTypeID() + "," + info.getData() + ","); + } + } + } + } + } + } catch (IOException e) { + war.getLogger().warning("Failed to write volume file " + zoneName + + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } + finally { + if(out != null) + try { + out.close(); + } catch (IOException e) { + war.getLogger().warning("Failed to close file writer for volume " + volume.getName() + + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } + } + } + } + +} 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 67956cd..b14dc9a 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -16,6 +16,7 @@ import com.tommytony.war.Team; import com.tommytony.war.TeamMaterials; import com.tommytony.war.Warzone; import com.tommytony.war.volumes.VerticalVolume; +import com.tommytony.war.volumes.Volume; /** * @@ -26,7 +27,7 @@ public class WarzoneMapper { public static Warzone load(War war, String name, boolean loadBlocks) { //war.getLogger().info("Loading warzone " + name + " config and blocks..."); - PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt"); + PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + "/warzone-" + name + ".txt"); try { warzoneConfig.load(); } catch (IOException e) { @@ -152,17 +153,11 @@ public class WarzoneMapper { if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) { // zone blocks - VerticalVolume zoneVolume = new VerticalVolume("zone", war, warzone); - try { - zoneVolume.fromDisk(); - } catch (IOException e) { - war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() + - " for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + VerticalVolume zoneVolume = VolumeMapper.load(warzone.getName(), "zone", war, warzone.getWorld()); // monument blocks for(Monument monument: warzone.getMonuments()) { + monument.setVolume(VolumeMapper.load(warzone.getName(), monument.getName(), war, world)); try { monument.getVolume().fromDisk(); } catch (IOException e) { @@ -193,7 +188,7 @@ public class WarzoneMapper { } public static void save(War war, Warzone warzone, boolean saveBlocks) { - PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt"); + PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + "/warzone-" + warzone.getName() + ".txt"); //war.getLogger().info("Saving warzone " + warzone.getName() + "..."); // name @@ -264,34 +259,16 @@ public class WarzoneMapper { if(saveBlocks) { (new File(war.getName()+"/"+warzone.getName())).mkdir(); // zone blocks - try { - warzone.getVolume().toDisk(); - } catch (IOException e) { - war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() + - " for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + VolumeMapper.save(warzone.getVolume(), "zone", war); // monument blocks for(Monument monument: monuments) { - try { - monument.getVolume().toDisk(); - } catch (IOException e) { - war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() + - " for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + VolumeMapper.save(monument.getVolume(), warzone.getName(), war); } // team spawn blocks for(Team team : teams) { - try { - team.getVolume().toDisk(); - } catch (IOException e) { - war.getLogger().warning("Failed to write volume file " + warzone.getVolume().getName() + - " for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + VolumeMapper.save(team.getVolume(), warzone.getName(), war); } } @@ -303,12 +280,6 @@ public class WarzoneMapper { } public static void delete(War war, String name) { - File warzoneConfig = new File(war.getName() + "/warzone-" + name + ".txt"); - boolean deletedConfig = warzoneConfig.delete(); - if(!deletedConfig) { - war.getLogger().warning("Failed to delete file " + war.getName() + "/warzone-"+name+".txt"); - } - File zoneFolder = new File(war.getName() + "/warzone-" + name); File[] files = zoneFolder.listFiles(); for(File file : files) { diff --git a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java index 8c1261f..bf69340 100644 --- a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java @@ -2,24 +2,25 @@ package com.tommytony.war.volumes; import org.bukkit.Block; import org.bukkit.Location; +import org.bukkit.World; import bukkit.tommytony.war.War; -import com.tommytony.war.Warzone; - public class CenteredVolume extends Volume { private Block center; private int sideSize = -1; + private final World world; - public CenteredVolume(String name, Block center, int sideSize, War war, Warzone warzone) { - super(name, war, warzone); + public CenteredVolume(String name, Block center, int sideSize, War war, World world) { + super(name, war, world); + this.world = world; setCenter(center); setSideSize(sideSize); } public void changeCenter(Location newCenter) { - changeCenter(getWarzone().getWorld().getBlockAt(newCenter.getBlockX(), + changeCenter(world.getBlockAt(newCenter.getBlockX(), newCenter.getBlockY(), newCenter.getBlockZ()), this.sideSize); @@ -42,7 +43,7 @@ public class CenteredVolume extends Volume { int x = center.getX() + topHalfOfSide; int y = center.getY() + topHalfOfSide; int z = center.getZ() + topHalfOfSide; - Block cornerOne = getWarzone().getWorld().getBlockAt(x, y, z); + Block cornerOne = world.getBlockAt(x, y, z); setCornerOne(cornerOne); if(sideSize % 2 == 0) { // not a real center, bottom half is larger by 1 @@ -50,13 +51,13 @@ public class CenteredVolume extends Volume { x = center.getX() - bottomHalfOfSide; y = center.getY() - bottomHalfOfSide; z = center.getZ() - bottomHalfOfSide; - Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z); + Block cornerTwo = world.getBlockAt(x, y, z); setCornerTwo(cornerTwo); } else { x = center.getX() - topHalfOfSide; y = center.getY() - topHalfOfSide; z = center.getZ() - topHalfOfSide; - Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z); + Block cornerTwo = world.getBlockAt(x, y, z); setCornerTwo(cornerTwo); } } diff --git a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java index b527c04..ca88c1c 100644 --- a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java @@ -3,17 +3,16 @@ package com.tommytony.war.volumes; import org.bukkit.Block; import org.bukkit.BlockFace; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; import bukkit.tommytony.war.War; -import com.tommytony.war.Warzone; - public class VerticalVolume extends Volume{ - public VerticalVolume(String name, War war, Warzone warzone) { - super(name, war, warzone); + public VerticalVolume(String name, War war, World world) { + super(name, war, world); } diff --git a/war/src/main/java/com/tommytony/war/volumes/Volume.java b/war/src/main/java/com/tommytony/war/volumes/Volume.java index 5dadd71..51658f2 100644 --- a/war/src/main/java/com/tommytony/war/volumes/Volume.java +++ b/war/src/main/java/com/tommytony/war/volumes/Volume.java @@ -32,17 +32,16 @@ import com.tommytony.war.Warzone; public class Volume { private final String name; private final World world; - private final Warzone warzone; + //private final Warzone warzone; private Block cornerOne; private Block cornerTwo; private BlockInfo[][][] blockInfos = null; private final War war; - public Volume(String name, War war, Warzone warzone) { + public Volume(String name, War war, World world) { this.name = name; this.war = war; - this.warzone = warzone; - this.world = warzone.getWorld(); + this.world = world; } public World getWorld() { @@ -280,100 +279,13 @@ public class Volume { // } // } - public void fromDisk() throws IOException { - BufferedReader in = null; - try { - in = new BufferedReader(new FileReader(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name))); - ; - String firstLine = in.readLine(); - if(firstLine != null && !firstLine.equals("")) { - int x1 = Integer.parseInt(in.readLine()); - int y1 = Integer.parseInt(in.readLine()); - int z1 = Integer.parseInt(in.readLine()); - int x2 = Integer.parseInt(in.readLine()); - int y2 = Integer.parseInt(in.readLine()); - int z2 = Integer.parseInt(in.readLine()); - cornerOne = getWorld().getBlockAt(x1, y1, z1); - cornerTwo = getWorld().getBlockAt(x2, y2, z2); - - setBlockInfos(new BlockInfo[getSizeX()][getSizeY()][getSizeZ()]); - for(int i = 0; i < getSizeX(); i++){ - for(int j = 0; j < getSizeY(); j++) { - for(int k = 0; k < getSizeZ(); k++) { - String blockLine = in.readLine(); - String[] blockSplit = blockLine.split(","); - - int typeID = Integer.parseInt(blockSplit[0]); - byte data = Byte.parseByte(blockSplit[1]); - String[] lines = null; - if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) { - String signLines = blockSplit[2]; - if(blockSplit.length > 3) { - // sign includes commas - for(int splitI = 3; splitI < blockSplit.length; splitI++) { - signLines.concat(blockSplit[splitI]); - } - } - String[] signLinesSplit = signLines.split("[line]"); - lines = new String[4]; - lines[0] = signLinesSplit[0]; - lines[1] = signLinesSplit[1]; - lines[2] = signLinesSplit[2]; - lines[3] = signLinesSplit[3]; - } - getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines); - } - } - } - } - } finally { - if(in != null) in.close(); - } + + public Block getCornerOne() { + return cornerOne; } - public void toDisk() throws IOException { - if(isSaved() && getBlockInfos() != null) { - BufferedWriter out = null; - try { - out = new BufferedWriter(new FileWriter(new File(war.getName() + "/warzone-" + warzone.getName() + "/" + name))); - out.write("corner1"); out.newLine(); - out.write(cornerOne.getX()); out.newLine(); - out.write(cornerOne.getY()); out.newLine(); - out.write(cornerOne.getZ()); out.newLine(); - out.write("corner2"); out.newLine(); - out.write(cornerTwo.getX()); out.newLine(); - out.write(cornerTwo.getY()); out.newLine(); - out.write(cornerTwo.getZ()); out.newLine(); - - for(int i = 0; i < getSizeX(); i++){ - for(int j = 0; j < getSizeY(); j++) { - for(int k = 0; k < getSizeZ(); k++) { - BlockInfo info = getBlockInfos()[i][j][k]; - if(info == null) { - out.write("0,0,"); out.newLine(); - } else { - if(info.getType() == Material.Sign || info.getType() == Material.SignPost) { - String[] lines = info.getSignLines(); - out.write(info.getTypeID() + "," + info.getData() + "," + lines[0] + "[line]" + lines[1] + "[line]" + lines[2] + "[line]"+ lines[3]); - - } else { - out.write(info.getTypeID() + "," + info.getData() + ","); - } - } - } - } - } - } finally { - if(out != null) out.close(); - } - - - - } - } - - public Warzone getWarzone() { - return warzone; + public Block getCornerTwo() { + return cornerOne; } public boolean contains(Location location) {