From 2edcb2d302014cbb9b52b7508143c99990d2f491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 16 Jul 2011 19:38:28 +0200 Subject: [PATCH] More reformatting --- .../main/java/bukkit/tommytony/war/War.java | 361 +++++++--------- .../tommytony/war/WarBlockListener.java | 62 ++- .../tommytony/war/WarEntityListener.java | 58 ++- .../tommytony/war/WarPlayerListener.java | 125 +++--- .../main/java/com/tommytony/war/Monument.java | 72 ++-- war/src/main/java/com/tommytony/war/Team.java | 387 +++++++++--------- .../java/com/tommytony/war/TeamKinds.java | 7 +- .../com/tommytony/war/TeamSpawnStyles.java | 4 +- .../main/java/com/tommytony/war/WarHub.java | 20 +- .../main/java/com/tommytony/war/Warzone.java | 259 ++++-------- .../java/com/tommytony/war/ZoneLobby.java | 337 +++++++-------- .../java/com/tommytony/war/ZoneSetter.java | 70 ++-- .../java/com/tommytony/war/ZoneWallGuard.java | 7 +- .../war/jobs/DeferredBlockResetsJob.java | 24 +- .../tommytony/war/jobs/ResetCursorJob.java | 1 - .../tommytony/war/jobs/RestoreWarhubJob.java | 2 +- .../war/jobs/RestoreWarzonesJob.java | 4 +- .../war/jobs/ScoreCapReachedJob.java | 10 +- .../tommytony/war/jobs/ZoneVolumeSaveJob.java | 1 + .../mappers/PreDeGaulleZoneVolumeMapper.java | 207 ++++------ .../tommytony/war/mappers/PropertiesFile.java | 220 +++++----- .../tommytony/war/mappers/VolumeMapper.java | 164 ++++---- .../com/tommytony/war/mappers/WarMapper.java | 30 +- .../tommytony/war/mappers/WarzoneMapper.java | 96 ++--- .../war/mappers/ZoneVolumeMapper.java | 200 ++++----- .../com/tommytony/war/utils/ChatFixUtil.java | 113 ++--- .../tommytony/war/utils/InventoryStash.java | 1 - .../com/tommytony/war/volumes/BlockInfo.java | 62 +-- .../tommytony/war/volumes/CenteredVolume.java | 15 +- .../war/volumes/NotNorthwestException.java | 1 - .../war/volumes/TooBigException.java | 1 - .../war/volumes/TooSmallException.java | 1 - .../tommytony/war/volumes/VerticalVolume.java | 77 ++-- .../com/tommytony/war/volumes/Volume.java | 169 +++----- .../com/tommytony/war/volumes/ZoneVolume.java | 284 +++---------- 35 files changed, 1421 insertions(+), 2031 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index d5c8920..2e85ef0 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -31,14 +31,14 @@ import com.tommytony.war.mappers.*; import com.tommytony.war.utils.*; /** - * + * * @author tommytony - * + * */ public class War extends JavaPlugin { public static PermissionHandler permissionHandler; - public War(){ + public War() { super(); } @@ -81,7 +81,6 @@ public class War extends JavaPlugin { private WarHub warHub; - public void onDisable() { this.unloadWar(); } @@ -124,7 +123,7 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this); + // pm.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Priority.High, this); pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this); pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this); @@ -133,10 +132,10 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this); - //pm.registerEvent(Event.Type.CHUNK_UNLOADED, blockListener, Priority.Normal, this); + // pm.registerEvent(Event.Type.CHUNK_UNLOADED, blockListener, Priority.Normal, this); // Load files from disk or create them (using these defaults) - this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8)); + this.defaultLoadout.put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8)); this.defaultLoadout.put(1, new ItemStack(Material.BOW, 1, (byte) 8)); this.defaultLoadout.put(2, new ItemStack(Material.ARROW, 7)); this.defaultLoadout.put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8)); @@ -146,7 +145,7 @@ public class War extends JavaPlugin { this.defaultAutoAssignOnly = false; this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1)); WarMapper.load(this); - this.logInfo("War v"+ this.desc.getVersion() + " is on."); + this.logInfo("War v" + this.desc.getVersion() + " is on."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { @@ -155,13 +154,12 @@ public class War extends JavaPlugin { String command = cmd.getName(); String[] arguments = null; // Handle both /war and /. I.e. "/war zone temple" == "/zone temple" - String helpMessage = "War is on. Please pick your battle. " + - "Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions."; + String helpMessage = "War is on. Please pick your battle. " + "Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions."; if ((command.equals("war") || command.equals("War")) && args.length > 0) { command = args[0]; arguments = new String[args.length - 1]; for (int i = 1; i <= arguments.length; i++) { - arguments[i-1] = args[i]; + arguments[i - 1] = args[i]; } if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) { this.msg(player, helpMessage); @@ -173,11 +171,11 @@ public class War extends JavaPlugin { } // Player commands: /warzones, /warzone, /teams, /join, /leave - if (command.equals("zones") || command.equals("warzones")){ + if (command.equals("zones") || command.equals("warzones")) { this.performZones(player); } else if (command.equals("zone") || command.equals("warzone")) { this.performZone(player, arguments); - } else if (command.equals("teams")){ + } else if (command.equals("teams")) { this.performTeams(player); } else if (command.equals("join") && this.canPlayWar(player)) { this.performJoin(player, arguments); @@ -228,21 +226,8 @@ public class War extends JavaPlugin { } else if (command.equals("loadwar")) { this.loadWar(); } - } else if (command.equals("setzone") // Not a zone maker but War command. - || command.equals("nextbattle") - || command.equals("setzonelobby") - || command.equals("savezone") - || command.equals("setzoneconfig") - || command.equals("resetzone") - || command.equals("deletezone") - || command.equals("setteam") - || command.equals("deleteteam") - || command.equals("setmonument") - || command.equals("deletemonument") - || command.equals("setwarhub") - || command.equals("deletewarhub") - || command.equals("setwarconfig") - || command.equals("unloadwar")) { + } else if (command.equals("setzone") // Not a zone maker but War command. + || command.equals("nextbattle") || command.equals("setzonelobby") || command.equals("savezone") || command.equals("setzoneconfig") || command.equals("resetzone") || command.equals("deletezone") || command.equals("setteam") || command.equals("deleteteam") || command.equals("setmonument") || command.equals("deletemonument") || command.equals("setwarhub") || command.equals("deletewarhub") || command.equals("setwarconfig") || command.equals("unloadwar")) { this.badMsg(player, "You can't do this if you are not a warzone maker."); } else if (command.equals("zonemaker") || command.equals("zm")) { this.performZonemakerAsPlayer(player); @@ -251,12 +236,11 @@ public class War extends JavaPlugin { return true; } - private void inventoryToLoadout(Player player, - HashMap loadout) { + private void inventoryToLoadout(Player player, HashMap loadout) { loadout.clear(); PlayerInventory inv = player.getInventory(); int i = 0; - for (ItemStack stack : inv.getContents()){ + for (ItemStack stack : inv.getContents()) { if (stack != null && stack.getType() != Material.AIR) { loadout.put(i, stack); i++; @@ -290,9 +274,7 @@ public class War extends JavaPlugin { public void performZonemakerAsZonemaker(Player player, String[] arguments) { if (arguments.length > 2) { - this.badMsg(player, "Usage: /zonemaker , /zonemaker" + - "Elevates the player to zone maker or removes his rights. " + - "If you are already a zonemaker, you can toggle between player and zone maker modes by using the command without arguments."); + this.badMsg(player, "Usage: /zonemaker , /zonemaker" + "Elevates the player to zone maker or removes his rights. " + "If you are already a zonemaker, you can toggle between player and zone maker modes by using the command without arguments."); } else { if (arguments.length == 1) { // make someone zonemaker or remove the right @@ -327,8 +309,7 @@ public class War extends JavaPlugin { public void performSetWarConfig(Player player, String[] arguments) { if (arguments.length == 0) { - this.badMsg(player, "Usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + - "Changes the server defaults for new warzones. Please give at leaset one named parameter."); + this.badMsg(player, "Usage: /setwarconfig pvpinzonesonly:on lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Changes the server defaults for new warzones. Please give at leaset one named parameter."); } else { if (this.updateFromNamedParams(player, arguments)) { WarMapper.save(this); @@ -385,11 +366,8 @@ public class War extends JavaPlugin { } public void performDeleteMonument(Player player, String[] arguments) { - if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) - && !this.inAnyWarzoneLobby(player.getLocation()))) { - this.badMsg(player, "Usage: /deletemonument ." + - " Deletes the monument. " + - "Must be in a warzone or lobby (try /warzones and /warzone). "); + if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation()))) { + this.badMsg(player, "Usage: /deletemonument ." + " Deletes the monument. " + "Must be in a warzone or lobby (try /warzones and /warzone). "); } else { String name = arguments[0]; Warzone warzone = this.warzone(player.getLocation()); @@ -412,9 +390,7 @@ public class War extends JavaPlugin { } public void performSetMonument(Player player, String[] arguments) { - if (!this.inAnyWarzone(player.getLocation()) || arguments.length < 1 || arguments.length > 1 - || (arguments.length == 1 && this.warzone(player.getLocation()) != null - && arguments[0].equals(this.warzone(player.getLocation()).getName()))) { + if (!this.inAnyWarzone(player.getLocation()) || arguments.length < 1 || arguments.length > 1 || (arguments.length == 1 && this.warzone(player.getLocation()) != null && arguments[0].equals(this.warzone(player.getLocation()).getName()))) { this.badMsg(player, "Usage: /setmonument . Creates or moves a monument. Monument can't have same name as zone. Must be in warzone."); } else { Warzone warzone = this.warzone(player.getLocation()); @@ -436,11 +412,8 @@ public class War extends JavaPlugin { } public void performDeleteTeam(Player player, String[] arguments) { - if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) - && !this.inAnyWarzoneLobby(player.getLocation()))) { - this.badMsg(player, "Usage: /deleteteam ." + - " Deletes the team and its spawn. " + - "Must be in a warzone or lobby (try /zones and /zone). "); + if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation()))) { + this.badMsg(player, "Usage: /deleteteam ." + " Deletes the team and its spawn. " + "Must be in a warzone or lobby (try /zones and /zone). "); } else { String name = arguments[0]; Warzone warzone = this.warzone(player.getLocation()); @@ -453,14 +426,14 @@ public class War extends JavaPlugin { Team team = warzone.getTeamByKind(TeamKinds.teamKindFromString(name)); if (team != null) { if (team.getFlagVolume() != null) { - team.getFlagVolume().resetBlocks(); + team.getFlagVolume().resetBlocks(); } team.getSpawnVolume().resetBlocks(); warzone.getTeams().remove(team); if (warzone.getLobby() != null) { warzone.getLobby().getVolume().resetBlocks(); - //warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall()); - //warzone.addZoneOutline(warzone.getLobby().getWall()); + // warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall()); + // warzone.addZoneOutline(warzone.getLobby().getWall()); warzone.getLobby().initialize(); } WarzoneMapper.save(this, warzone, false); @@ -472,11 +445,8 @@ public class War extends JavaPlugin { } public void performSetTeamFlag(Player player, String[] arguments) { - if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) - || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { - this.badMsg(player, "Usage: /setteamflag , e.g. /setteamflag diamond. " + - "Sets the team flag post to the current location. " + - "Must be in a warzone (try /zones and /zone). "); + if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { + this.badMsg(player, "Usage: /setteamflag , e.g. /setteamflag diamond. " + "Sets the team flag post to the current location. " + "Must be in a warzone (try /zones and /zone). "); } else { TeamKind kind = TeamKinds.teamKindFromString(arguments[0]); Warzone warzone = this.warzone(player.getLocation()); @@ -484,12 +454,11 @@ public class War extends JavaPlugin { if (team == null) { // no such team yet this.badMsg(player, "Place the team spawn first."); - } else if (team.getFlagVolume() == null){ + } else if (team.getFlagVolume() == null) { // new team flag team.setTeamFlag(player.getLocation()); Location playerLoc = player.getLocation(); - player.teleport(new Location(playerLoc.getWorld(), - playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ())); + player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ())); this.msg(player, "Team " + team.getName() + " flag added here."); WarzoneMapper.save(this, warzone, false); } else { @@ -497,8 +466,7 @@ public class War extends JavaPlugin { team.getFlagVolume().resetBlocks(); team.setTeamFlag(player.getLocation()); Location playerLoc = player.getLocation(); - player.teleport(new Location(playerLoc.getWorld(), - playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()+1)); + player.teleport(new Location(playerLoc.getWorld(), playerLoc.getBlockX() + 1, playerLoc.getBlockY(), playerLoc.getBlockZ() + 1)); this.msg(player, "Team " + team.getName() + " flag moved."); WarzoneMapper.save(this, warzone, false); } @@ -506,11 +474,8 @@ public class War extends JavaPlugin { } public void performSetTeam(Player player, String[] arguments) { - if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) - || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { - this.badMsg(player, "Usage: /setteam , e.g. /setteam red." + - "Sets the team spawn to the current location. " + - "Must be in a warzone (try /zones and /zone). "); + if (arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { + this.badMsg(player, "Usage: /setteam , e.g. /setteam red." + "Sets the team spawn to the current location. " + "Must be in a warzone (try /zones and /zone). "); } else { TeamKind teamKind = TeamKinds.teamKindFromString(arguments[0]); Warzone warzone = this.warzone(player.getLocation()); @@ -526,8 +491,8 @@ public class War extends JavaPlugin { warzone.getTeams().add(newTeam); if (warzone.getLobby() != null) { warzone.getLobby().getVolume().resetBlocks(); - //warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall()); - //warzone.addZoneOutline(warzone.getLobby().getWall()); + // warzone.getVolume().resetWallBlocks(warzone.getLobby().getWall()); + // warzone.addZoneOutline(warzone.getLobby().getWall()); warzone.getLobby().initialize(); } newTeam.setTeamSpawn(player.getLocation()); @@ -540,9 +505,7 @@ public class War extends JavaPlugin { public void performDeleteZone(Player player, String[] arguments) { if (arguments.length == 0 && !this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - this.badMsg(player, "Usage: /deletezone [warzone-name]. " + - "Deletes the warzone. " + - "Must be in the warzone or name must be provided (try /zones and /zone). "); + this.badMsg(player, "Usage: /deletezone [warzone-name]. " + "Deletes the warzone. " + "Must be in the warzone or name must be provided (try /zones and /zone). "); } else { ZoneLobby lobby = null; Warzone warzone = null; @@ -570,7 +533,7 @@ public class War extends JavaPlugin { for (Team t : warzone.getTeams()) { if (t.getTeamFlag() != null) { - t.getFlagVolume().resetBlocks(); + t.getFlagVolume().resetBlocks(); } t.getSpawnVolume().resetBlocks(); @@ -589,7 +552,7 @@ public class War extends JavaPlugin { this.getWarzones().remove(warzone); WarMapper.save(this); WarzoneMapper.delete(this, warzone.getName()); - if (this.warHub != null) { // warhub has to change + if (this.warHub != null) { // warhub has to change this.warHub.getVolume().resetBlocks(); this.warHub.initialize(); } @@ -609,7 +572,7 @@ public class War extends JavaPlugin { lobby = warzone.getLobby(); } warzone.clearFlagThieves(); - for (Team team: warzone.getTeams()) { + for (Team team : warzone.getTeams()) { team.teamcast("The war has ended. " + this.playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams..."); for (Player p : team.getPlayers()) { warzone.restorePlayerInventory(p); @@ -628,13 +591,13 @@ public class War extends JavaPlugin { resetWarzone = WarzoneMapper.load(this, warzone.getName(), true); this.getWarzones().add(resetWarzone); warzone.getVolume().resetBlocksAsJob(); - if (lobby!=null) { + if (lobby != null) { lobby.getVolume().resetBlocksAsJob(); } resetWarzone.initializeZoneAsJob(); } else { warzone.getVolume().resetBlocksAsJob(); - if (lobby!=null) { + if (lobby != null) { lobby.getVolume().resetBlocksAsJob(); } warzone.initializeZoneAsJob(); @@ -644,10 +607,8 @@ public class War extends JavaPlugin { } public void performSetZoneConfig(Player player, String[] arguments) { - if ((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) - || arguments.length == 0) { - this.badMsg(player, "Usage: /setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + - "Please give at leaset one named parameter. Does not save the blocks of the warzone. Resets the zone with the new config. Must be in warzone."); + if ((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || arguments.length == 0) { + this.badMsg(player, "Usage: /setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Please give at leaset one named parameter. Does not save the blocks of the warzone. Resets the zone with the new config. Must be in warzone."); } else { Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); @@ -663,7 +624,7 @@ public class War extends JavaPlugin { if (lobby != null) { lobby.getVolume().resetBlocks(); } - warzone.initializeZone(); // bring back team spawns etc + warzone.initializeZone(); // bring back team spawns etc this.msg(player, "Warzone config saved. Zone reset."); if (this.warHub != null) { // maybe the zone was disabled/enabled @@ -678,8 +639,7 @@ public class War extends JavaPlugin { public void performSaveZone(Player player, String[] arguments) { if (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - this.badMsg(player, "Usage: /savezone lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + - "All named params optional. Saves the blocks of the warzone (i.e. the current zone state will be reloaded at each battle start). Must be in warzone."); + this.badMsg(player, "Usage: /savezone lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "All named params optional. Saves the blocks of the warzone (i.e. the current zone state will be reloaded at each battle start). Must be in warzone."); } else { Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); @@ -698,7 +658,7 @@ public class War extends JavaPlugin { if (lobby != null) { lobby.getVolume().resetBlocks(); } - warzone.initializeZone(); // bring back team spawns etc + warzone.initializeZone(); // bring back team spawns etc if (this.warHub != null) { // maybe the zone was disabled/enabled this.warHub.getVolume().resetBlocks(); @@ -711,17 +671,12 @@ public class War extends JavaPlugin { } public void performSetZoneLobby(Player player, String[] arguments) { - String usageStr = "Usage: When inside a warzone - /setzonelobby ." + - "Attaches the lobby to the specified zone wall. When outside a warzone - /setzonelobby . " + - "Moves the lobby to your current position."; + String usageStr = "Usage: When inside a warzone - /setzonelobby ." + "Attaches the lobby to the specified zone wall. When outside a warzone - /setzonelobby . " + "Moves the lobby to your current position."; if (arguments.length < 1 || arguments.length > 1) { this.badMsg(player, usageStr); - } else if (this.inAnyWarzone(player.getLocation()) || this.inAnyWarzoneLobby(player.getLocation())){ + } else if (this.inAnyWarzone(player.getLocation()) || this.inAnyWarzoneLobby(player.getLocation())) { // Inside a warzone: use the classic n/s/e/w mode - if (!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")){ + if (!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")) { this.badMsg(player, usageStr); return; } @@ -772,7 +727,7 @@ public class War extends JavaPlugin { this.badMsg(player, "No warzone matches " + arguments[0] + "."); } else { // Move the warzone lobby - ZoneLobby lobby = warzone.getLobby(); + ZoneLobby lobby = warzone.getLobby(); if (lobby != null) { // reset existing lobby lobby.getVolume().resetBlocks(); @@ -796,22 +751,12 @@ public class War extends JavaPlugin { } public void performSetZone(Player player, String[] arguments) { - 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") - && !arguments[1].equals("corner1") && !arguments[1].equals("corner2") - && !arguments[1].equals("c1") && !arguments[1].equals("c2") - && !arguments[1].equals("pos1") && !arguments[1].equals("pos2") - && !arguments[1].equals("wand")))) { + 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") && !arguments[1].equals("corner1") && !arguments[1].equals("corner2") && !arguments[1].equals("c1") && !arguments[1].equals("c2") && !arguments[1].equals("pos1") && !arguments[1].equals("pos2") && !arguments[1].equals("wand")))) { if (arguments.length == 1) { // we only have a zone name, default to wand mode this.addWandBearer(player, arguments[0]); } else { - this.badMsg(player, "Usage: == /setzone <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + - "== /setzone wand (gives you a wooden sword to right and left click, drop to disable). " + - "== /setzone <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " + - "Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " + - "Saves the zone blocks if the outline is valid."); + this.badMsg(player, "Usage: == /setzone <'northwest'/'southeast'/'nw'/'se'> (NW defaults to top block, SE to bottom). " + "== /setzone wand (gives you a wooden sword to right and left click, drop to disable). " + "== /setzone <'corner1'/'corner2'/'c1'/'c2'/'pos1'/'pos2'> (block where you're standing). " + "Set one corner, then the next. Defines the outline of the warzone, which will be reset at the start of every battle. " + "Saves the zone blocks if the outline is valid."); } } else { ZoneSetter setter = new ZoneSetter(this, player, arguments[0]); @@ -835,7 +780,7 @@ public class War extends JavaPlugin { } else { Warzone warzone = this.warzone(player.getLocation()); warzone.clearFlagThieves(); - for (Team team: warzone.getTeams()) { + for (Team team : warzone.getTeams()) { team.teamcast("The battle was interrupted. " + this.playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools..."); } warzone.getVolume().resetBlocksAsJob(); @@ -861,8 +806,7 @@ public class War extends JavaPlugin { public void performTeam(Player player, String[] arguments) { Team playerTeam = this.getPlayerTeam(player.getName()); if (playerTeam == null) { - this.badMsg(player, "Usage: /team . " + - "Sends a message only to your teammates."); + this.badMsg(player, "Usage: /team . " + "Sends a message only to your teammates."); } else { ChatColor color = playerTeam.getKind().getColor(); String teamMessage = color + player.getName() + ": " + ChatColor.WHITE; @@ -875,8 +819,7 @@ public class War extends JavaPlugin { public void performLeave(Player player) { if (!this.inAnyWarzone(player.getLocation()) || this.getPlayerTeam(player.getName()) == null) { - this.badMsg(player, "Usage: /leave. " + - "Must be in a team already."); + this.badMsg(player, "Usage: /leave. " + "Must be in a team already."); } else { Warzone zone = this.getPlayerTeamWarzone(player.getName()); zone.handlePlayerLeave(player, zone.getTeleport(), true); @@ -884,18 +827,14 @@ public class War extends JavaPlugin { } public void performJoin(Player player, String[] arguments) { - if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) - || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { - this.badMsg(player, "Usage: /join ." + - " Teams are warzone specific." + - " You must be inside a warzone or zone lobby to join a team." + - " Use as an alternative to walking through the team gate."); + if (arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || (arguments.length > 0 && TeamKinds.teamKindFromString(arguments[0]) == null)) { + this.badMsg(player, "Usage: /join ." + " Teams are warzone specific." + " You must be inside a warzone or zone lobby to join a team." + " Use as an alternative to walking through the team gate."); } else { // drop from old team if any Team previousTeam = this.getPlayerTeam(player.getName()); if (previousTeam != null) { Warzone zone = this.getPlayerTeamWarzone(player.getName()); - if (!previousTeam.removePlayer(player.getName())){ + if (!previousTeam.removePlayer(player.getName())) { this.logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); } if (zone.isFlagThief(player.getName())) { @@ -912,7 +851,7 @@ public class War extends JavaPlugin { // join new team String name = arguments[0]; - TeamKind kind = TeamKinds.teamKindFromString(arguments[0]); + TeamKind kind = TeamKinds.teamKindFromString(arguments[0]); Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); if (warzone == null && lobby != null) { @@ -946,7 +885,7 @@ public class War extends JavaPlugin { } } if (foundTeam) { - for (Team team : teams){ + for (Team team : teams) { team.teamcast("" + player.getName() + " joined " + team.getName()); } } else { @@ -958,8 +897,7 @@ public class War extends JavaPlugin { public void performTeams(Player player) { if (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - this.badMsg(player, "Usage: /teams. " + - "Must be in a warzone or zone lobby (try /war, /zones and /zone)."); + this.badMsg(player, "Usage: /teams. " + "Must be in a warzone or zone lobby (try /war, /zones and /zone)."); } else { this.msg(player, "" + this.playerListener.getAllTeamsMsg(player)); } @@ -973,7 +911,7 @@ public class War extends JavaPlugin { } else { boolean warped = false; for (Warzone warzone : this.getWarzones()) { - if (warzone.getName().toLowerCase().startsWith(arguments[0].toLowerCase()) && warzone.getTeleport() != null){ + if (warzone.getName().toLowerCase().startsWith(arguments[0].toLowerCase()) && warzone.getTeleport() != null) { Team playerTeam = this.getPlayerTeam(player.getName()); if (playerTeam != null) { Warzone playerWarzone = this.getPlayerTeamWarzone(player.getName()); @@ -993,53 +931,51 @@ public class War extends JavaPlugin { private void performZones(Player player) { String warzonesMessage = "Warzones: "; - if (this.getWarzones().isEmpty()){ + if (this.getWarzones().isEmpty()) { warzonesMessage += "none."; } for (Warzone warzone : this.getWarzones()) { - warzonesMessage += warzone.getName() + " (" - + warzone.getTeams().size() + " teams, "; + warzonesMessage += warzone.getName() + " (" + warzone.getTeams().size() + " teams, "; int playerTotal = 0; for (Team team : warzone.getTeams()) { playerTotal += team.getPlayers().size(); } warzonesMessage += playerTotal + " players) "; } - this.msg(player, warzonesMessage + " Use /zone to " + - "teleport to a warzone. "); + this.msg(player, warzonesMessage + " Use /zone to " + "teleport to a warzone. "); } private boolean updateZoneFromNamedParams(Warzone warzone, Player player, String[] arguments) { try { - Map namedParams = new HashMap(); + Map namedParams = new HashMap(); for (String namedPair : arguments) { String[] pairSplit = namedPair.split(":"); if (pairSplit.length == 2) { namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]); } } - if (namedParams.containsKey("lifepool")){ + if (namedParams.containsKey("lifepool")) { warzone.setLifePool(Integer.parseInt(namedParams.get("lifepool"))); } - if (namedParams.containsKey("monumentheal")){ + if (namedParams.containsKey("monumentheal")) { warzone.setMonumentHeal(Integer.parseInt(namedParams.get("monumentheal"))); } - if (namedParams.containsKey("teamsize")){ + if (namedParams.containsKey("teamsize")) { warzone.setTeamCap(Integer.parseInt(namedParams.get("teamsize"))); } - if (namedParams.containsKey("maxscore")){ + if (namedParams.containsKey("maxscore")) { warzone.setScoreCap(Integer.parseInt(namedParams.get("maxscore"))); } - if (namedParams.containsKey("ff")){ + if (namedParams.containsKey("ff")) { String onOff = namedParams.get("ff"); warzone.setFriendlyFire(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("autoassign")){ + if (namedParams.containsKey("autoassign")) { String onOff = namedParams.get("autoassign"); warzone.setAutoAssignOnly(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("blockheads")){ + if (namedParams.containsKey("blockheads")) { String onOff = namedParams.get("blockheads"); warzone.setBlockHeads(onOff.equals("on") || onOff.equals("true")); } @@ -1047,9 +983,9 @@ public class War extends JavaPlugin { String spawnStyle = namedParams.get("spawnstyle").toLowerCase(); if (spawnStyle.equals(TeamSpawnStyles.SMALL)) { warzone.setSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){ + } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) { warzone.setSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)){ + } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) { warzone.setSpawnStyle(spawnStyle); } else { warzone.setSpawnStyle(TeamSpawnStyles.BIG); @@ -1068,11 +1004,11 @@ public class War extends JavaPlugin { warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("loadout")) { - //String loadoutType = namedParams.get("loadout"); + // String loadoutType = namedParams.get("loadout"); this.inventoryToLoadout(player, warzone.getLoadout()); } if (namedParams.containsKey("reward")) { - //String rewardType = namedParams.get("reward"); + // String rewardType = namedParams.get("reward"); this.inventoryToLoadout(player, warzone.getReward()); } if (namedParams.containsKey("resetonempty")) { @@ -1087,10 +1023,10 @@ public class War extends JavaPlugin { String onOff = namedParams.get("resetonunload"); warzone.setResetOnUnload(onOff.equals("on") || onOff.equals("true")); } -// if (namedParams.containsKey("dropLootOnDeath")){ -// String onOff = namedParams.get("dropLootOnDeath"); -// warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); -// } + // if (namedParams.containsKey("dropLootOnDeath")){ + // String onOff = namedParams.get("dropLootOnDeath"); + // warzone.setDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); + // } return true; } catch (Exception e) { return false; @@ -1099,50 +1035,50 @@ public class War extends JavaPlugin { private boolean updateFromNamedParams(Player player, String[] arguments) { try { - Map namedParams = new HashMap(); + Map namedParams = new HashMap(); for (String namedPair : arguments) { String[] pairSplit = namedPair.split(":"); if (pairSplit.length == 2) { namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]); } } - if (namedParams.containsKey("lifepool")){ + if (namedParams.containsKey("lifepool")) { this.setDefaultLifepool(Integer.parseInt(namedParams.get("lifepool"))); } - if (namedParams.containsKey("monumentheal")){ + if (namedParams.containsKey("monumentheal")) { this.setDefaultMonumentHeal(Integer.parseInt(namedParams.get("monumentheal"))); } - if (namedParams.containsKey("teamsize")){ + if (namedParams.containsKey("teamsize")) { this.setDefaultTeamCap(Integer.parseInt(namedParams.get("teamsize"))); } - if (namedParams.containsKey("maxscore")){ + if (namedParams.containsKey("maxscore")) { this.setDefaultScoreCap(Integer.parseInt(namedParams.get("maxscore"))); } - if (namedParams.containsKey("ff")){ + if (namedParams.containsKey("ff")) { String onOff = namedParams.get("ff"); this.setDefaultFriendlyFire(onOff.equals("on")); } - if (namedParams.containsKey("autoassign")){ + if (namedParams.containsKey("autoassign")) { String onOff = namedParams.get("autoassign"); this.setDefaultAutoAssignOnly(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("pvpinzonesonly")){ + if (namedParams.containsKey("pvpinzonesonly")) { String onOff = namedParams.get("pvpinzonesonly"); this.setPvpInZonesOnly(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("disablepvpmessage")){ + if (namedParams.containsKey("disablepvpmessage")) { String onOff = namedParams.get("disablepvpmessage"); this.setDisablePvpMessage(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("blockheads")){ + if (namedParams.containsKey("blockheads")) { String onOff = namedParams.get("blockheads"); this.setDefaultBlockHeads(onOff.equals("on") || onOff.equals("true")); } - if (namedParams.containsKey("spawnstyle")){ + if (namedParams.containsKey("spawnstyle")) { String spawnStyle = namedParams.get("spawnstyle").toLowerCase(); if (spawnStyle.equals(TeamSpawnStyles.SMALL)) { this.setDefaultSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){ + } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) { this.setDefaultSpawnStyle(spawnStyle); } else { this.setDefaultSpawnStyle(TeamSpawnStyles.BIG); @@ -1161,11 +1097,11 @@ public class War extends JavaPlugin { this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("loadout")) { - //String loadoutType = namedParams.get("loadout"); + // String loadoutType = namedParams.get("loadout"); this.inventoryToLoadout(player, this.getDefaultLoadout()); } if (namedParams.containsKey("reward")) { - //String rewardType = namedParams.get("reward"); + // String rewardType = namedParams.get("reward"); this.inventoryToLoadout(player, this.getDefaultReward()); } if (namedParams.containsKey("resetonempty")) { @@ -1181,13 +1117,13 @@ public class War extends JavaPlugin { this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("rallypoint")) { - //String rewardType = namedParams.get("reward"); + // String rewardType = namedParams.get("reward"); this.setZoneRallyPoint(namedParams.get("rallypoint"), player); } -// if (namedParams.containsKey("dropLootOnDeath")){ -// String onOff = namedParams.get("dropLootOnDeath"); -// setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); -// } + // if (namedParams.containsKey("dropLootOnDeath")){ + // String onOff = namedParams.get("dropLootOnDeath"); + // setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true")); + // } return true; } catch (Exception e) { return false; @@ -1208,7 +1144,7 @@ public class War extends JavaPlugin { for (Warzone warzone : this.warzones) { Team team = warzone.getPlayerTeam(playerName); if (team != null) { - return team; + return team; } } return null; @@ -1218,7 +1154,7 @@ public class War extends JavaPlugin { for (Warzone warzone : this.warzones) { Team team = warzone.getPlayerTeam(playerName); if (team != null) { - return warzone; + return warzone; } } return null; @@ -1230,9 +1166,8 @@ public class War extends JavaPlugin { public Warzone warzone(Location location) { for (Warzone warzone : this.warzones) { - if (location.getWorld().getName().equals(warzone.getWorld().getName()) - && warzone.getVolume() != null && warzone.getVolume().contains(location)) { - return warzone; + if (location.getWorld().getName().equals(warzone.getWorld().getName()) && warzone.getVolume() != null && warzone.getVolume().contains(location)) { + return warzone; } } return null; @@ -1242,10 +1177,9 @@ public class War extends JavaPlugin { Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Warzone currentZone = this.warzone(location); if (currentZone == null) { - return false; - } else if (currentZone.getVolume().isWallBlock(locBlock)) - { - return false; // wall block doesnt count. this lets people in at the lobby side wall because wall gates overlap with the zone. + return false; + } else if (currentZone.getVolume().isWallBlock(locBlock)) { + return false; // wall block doesnt count. this lets people in at the lobby side wall because wall gates overlap with the zone. } return true; } @@ -1253,9 +1187,9 @@ public class War extends JavaPlugin { public boolean inWarzone(String warzoneName, Location location) { Warzone currentZone = this.warzone(location); if (currentZone == null) { - return false; + return false; } else if (warzoneName.toLowerCase().equals(currentZone.getName().toLowerCase())) { - return true; + return true; } return false; } @@ -1297,12 +1231,12 @@ public class War extends JavaPlugin { public Warzone findWarzone(String warzoneName) { for (Warzone warzone : this.warzones) { if (warzone.getName().toLowerCase().equals(warzoneName.toLowerCase())) { - return warzone; + return warzone; } } for (Warzone warzone : this.incompleteZones) { if (warzone.getName().equals(warzoneName)) { - return warzone; + return warzone; } } return null; @@ -1311,14 +1245,14 @@ public class War extends JavaPlugin { public Warzone matchWarzone(String warzoneSubString) { for (Warzone warzone : this.warzones) { if (warzone.getName().toLowerCase().startsWith(warzoneSubString.toLowerCase())) { - return warzone; + return warzone; } } return null; } public void addWandBearer(Player player, String zoneName) { - if (this.wandBearers.containsKey(player.getName())){ + if (this.wandBearers.containsKey(player.getName())) { String alreadyHaveWand = this.wandBearers.get(player.getName()); if (player.getInventory().first(Material.WOOD_SWORD) != -1) { if (zoneName.equals(alreadyHaveWand)) { @@ -1343,7 +1277,7 @@ public class War extends JavaPlugin { } else { this.wandBearers.put(player.getName(), zoneName); player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD, 1, (byte) 8)); - //player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD)); + // player.getWorld().dropItem(player.getLocation(), new ItemStack(Material.WOOD_SWORD)); this.msg(player, "You now have a wand for zone " + zoneName + ". Left-click with wodden sword for corner 1. Right-click for corner 2."); } } @@ -1355,13 +1289,13 @@ public class War extends JavaPlugin { public String getWandBearerZone(Player player) { if (this.isWandBearer(player)) { - return this.wandBearers.get(player.getName()); + return this.wandBearers.get(player.getName()); } return ""; } public void removeWandBearer(Player player) { - if (this.wandBearers.containsKey(player.getName())){ + if (this.wandBearers.containsKey(player.getName())) { this.wandBearers.remove(player.getName()); } } @@ -1401,7 +1335,7 @@ public class War extends JavaPlugin { public Warzone zoneOfZoneWallAtProximity(Location location) { for (Warzone zone : this.warzones) { if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) { - return zone; + return zone; } } return null; @@ -1412,80 +1346,67 @@ public class War extends JavaPlugin { } public boolean canPlayWar(Player player) { - if (War.permissionHandler != null - && (War.permissionHandler.has(player, "war.player") - || War.permissionHandler.has(player, "War.player"))) { - return true; + if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.player") || War.permissionHandler.has(player, "War.player"))) { + return true; } if (War.permissionHandler == null) { - // w/o Permissions, everyone can play - return true; + // w/o Permissions, everyone can play + return true; } return false; } public boolean canWarp(Player player) { - if (War.permissionHandler != null - && (War.permissionHandler.has(player, "war.warp") - || War.permissionHandler.has(player, "War.warp"))) { - return true; + if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.warp") || War.permissionHandler.has(player, "War.warp"))) { + return true; } if (War.permissionHandler == null) { - // w/o Permissions, everyone can warp - return true; + // w/o Permissions, everyone can warp + return true; } return false; } public boolean canBuildOutsideZone(Player player) { if (this.isBuildInZonesOnly()) { - if (War.permissionHandler != null - && (War.permissionHandler.has(player, "war.build") - || War.permissionHandler.has(player, "War.build"))) { - return true; + if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.build") || War.permissionHandler.has(player, "War.build"))) { + return true; } // w/o Permissions, if buildInZonesOnly, no one can build outside the zone except Zonemakers return this.isZoneMaker(player); } else { - return true; + return true; } } public boolean canPvpOutsideZones(Player player) { if (this.isPvpInZonesOnly()) { - if (War.permissionHandler != null - && (War.permissionHandler.has(player, "war.pvp") - || War.permissionHandler.has(player, "War.pvp"))) { - return true; + if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.pvp") || War.permissionHandler.has(player, "War.pvp"))) { + return true; } // w/o Permissions, if pvpInZoneOnly, no one can pvp outside the zone return false; } else { - return true; + return true; } } public boolean isZoneMaker(Player player) { for (String disguised : this.zoneMakersImpersonatingPlayers) { if (disguised.equals(player.getName())) { - return false; + return false; } } for (String zoneMaker : this.zoneMakerNames) { if (zoneMaker.equals(player.getName())) { - return true; + return true; } } - if ( War.permissionHandler != null - && ( - War.permissionHandler.has(player, "war.*") - || War.permissionHandler.has(player, "War.*") - ) - ) { - return true; + if (War.permissionHandler != null && (War.permissionHandler.has(player, "war.*") || War.permissionHandler.has(player, "War.*"))) { + return true; } else { - return player.isOp(); + return player.isOp(); } } @@ -1508,10 +1429,8 @@ public class War extends JavaPlugin { public ZoneLobby lobby(Location location) { for (Warzone warzone : this.warzones) { - if (warzone.getLobby() != null - && warzone.getLobby().getVolume() != null - && warzone.getLobby().getVolume().contains(location)) { - return warzone.getLobby(); + if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null && warzone.getLobby().getVolume().contains(location)) { + return warzone.getLobby(); } } return null; @@ -1519,7 +1438,7 @@ public class War extends JavaPlugin { public boolean inAnyWarzoneLobby(Location location) { if (this.lobby(location) == null) { - return false; + return false; } return true; } @@ -1527,9 +1446,9 @@ public class War extends JavaPlugin { public boolean inWarzoneLobby(String warzoneName, Location location) { ZoneLobby currentLobby = this.lobby(location); if (currentLobby == null) { - return false; + return false; } else if (warzoneName.toLowerCase().equals(currentLobby.getZone().getName().toLowerCase())) { - return true; + return true; } return false; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java index f7471c5..57582a2 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java @@ -17,9 +17,9 @@ import com.tommytony.war.Team; import com.tommytony.war.Warzone; /** - * + * * @author tommytony - * + * */ public class WarBlockListener extends BlockListener { @@ -37,10 +37,7 @@ public class WarBlockListener extends BlockListener { if (player != null && block != null) { Team team = this.war.getPlayerTeam(player.getName()); Warzone zone = this.war.warzone(player.getLocation()); - if (team != null && block != null && zone != null - && zone.isMonumentCenterBlock(block) - && block.getType() == team.getKind().getMaterial() - && block.getData() == team.getKind().getData()) { + if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { Monument monument = zone.getMonumentFromCenterBlock(block); if (monument != null && !monument.hasOwner()) { monument.capture(team); @@ -63,7 +60,7 @@ public class WarBlockListener extends BlockListener { return; } // protect warzone lobbies - for (Warzone wz: this.war.getWarzones()) { + for (Warzone wz : this.war.getWarzones()) { if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) { this.war.badMsg(player, "Can't build here."); event.setCancelled(true); @@ -85,8 +82,7 @@ public class WarBlockListener extends BlockListener { } // can't place a block of your team's color - if (team != null && block.getType() == team.getKind().getMaterial() - && block.getData() == team.getKind().getData()) { + if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { this.war.badMsg(player, "You can only use your team's blocks to capture monuments."); event.setCancelled(true); return; @@ -100,10 +96,7 @@ public class WarBlockListener extends BlockListener { } // unbreakableZoneBlocks - if (zone != null && zone.isUnbreakableZoneBlocks() - && (!isZoneMaker - || (isZoneMaker && team != null)) - ) { + if (zone != null && zone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) { // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks) this.war.badMsg(player, "The blocks in this zone are unbreakable - this also means you can't build!"); event.setCancelled(true); @@ -124,14 +117,14 @@ public class WarBlockListener extends BlockListener { } } -// public void onBlockDamage(BlockDamageEvent event) { -// Player player = event.getPlayer(); -// Block block = event.getBlock(); -// if (player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) { -// handleBreakOrDamage(player,block, event); -// -// } -// } + // public void onBlockDamage(BlockDamageEvent event) { + // Player player = event.getPlayer(); + // Block block = event.getBlock(); + // if (player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) { + // handleBreakOrDamage(player,block, event); + // + // } + // } private void handleBreakOrDamage(Player player, Block block, Cancellable event) { Warzone warzone = this.war.warzone(player.getLocation()); @@ -143,8 +136,7 @@ public class WarBlockListener extends BlockListener { this.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team."); event.setCancelled(true); return; - } else if (team != null && block != null && warzone != null - && warzone.isMonumentCenterBlock(block)){ + } else if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) { Monument monument = warzone.getMonumentFromCenterBlock(block); if (monument.hasOwner()) { @@ -156,7 +148,7 @@ public class WarBlockListener extends BlockListener { } event.setCancelled(false); return; - }else if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { + } else if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { if (team != null && team.getSpawnVolume().contains(block)) { ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData()); @@ -165,7 +157,7 @@ public class WarBlockListener extends BlockListener { event.setCancelled(true); return; } else { - event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down + event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down return; } // let team members loot one block the spawn for monument captures @@ -177,7 +169,7 @@ public class WarBlockListener extends BlockListener { Team lostFlagTeam = warzone.getTeamForFlagBlock(block); if (lostFlagTeam.getPlayers().size() != 0) { // player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air - ItemStack teamKindBlock = new ItemStack(lostFlagTeam.getKind().getMaterial(), 1, (short)1, new Byte(lostFlagTeam.getKind().getData())); + ItemStack teamKindBlock = new ItemStack(lostFlagTeam.getKind().getMaterial(), 1, (short) 1, new Byte(lostFlagTeam.getKind().getData())); player.getInventory().clear(); player.getInventory().addItem(teamKindBlock); warzone.addFlagThief(lostFlagTeam, player.getName()); @@ -185,7 +177,7 @@ public class WarBlockListener extends BlockListener { for (Team t : warzone.getTeams()) { t.teamcast(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag."); - if (t.getName().equals(lostFlagTeam.getName())){ + if (t.getName().equals(lostFlagTeam.getName())) { t.teamcast("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag."); } } @@ -196,7 +188,7 @@ public class WarBlockListener extends BlockListener { } event.setCancelled(true); return; - } else if (!warzone.isMonumentCenterBlock(block)){ + } else if (!warzone.isMonumentCenterBlock(block)) { this.war.badMsg(player, "Can't destroy this."); event.setCancelled(true); return; @@ -205,9 +197,8 @@ public class WarBlockListener extends BlockListener { // protect warzone lobbies if (block != null) { - for (Warzone zone: this.war.getWarzones()) { - if (zone.getLobby() != null && zone.getLobby().getVolume() != null && - zone.getLobby().getVolume().contains(block)) { + for (Warzone zone : this.war.getWarzones()) { + if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) { this.war.badMsg(player, "Can't destroy this."); event.setCancelled(true); return; @@ -224,19 +215,14 @@ public class WarBlockListener extends BlockListener { // buildInZonesOnly Warzone blockZone = this.war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())); - if (blockZone == null - && this.war.isBuildInZonesOnly() - && !this.war.canBuildOutsideZone(player)) { + if (blockZone == null && this.war.isBuildInZonesOnly() && !this.war.canBuildOutsideZone(player)) { this.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); event.setCancelled(true); return; } // unbreakableZoneBlocks - if (blockZone != null && blockZone.isUnbreakableZoneBlocks() - && (!isZoneMaker - || (isZoneMaker && team != null)) - ) { + if (blockZone != null && blockZone.isUnbreakableZoneBlocks() && (!isZoneMaker || (isZoneMaker && team != null))) { // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks this.war.badMsg(player, "The blocks in this zone are unbreakable!"); event.setCancelled(true); diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index e1de054..0d14608 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -22,9 +22,9 @@ import com.tommytony.war.Team; import com.tommytony.war.Warzone; /** - * + * * @author tommytony - * + * */ public class WarEntityListener extends EntityListener { @@ -39,17 +39,17 @@ public class WarEntityListener extends EntityListener { if (this.war.isLoaded()) { Entity e = event.getEntity(); if (e instanceof Player) { - Player player = (Player)e; + Player player = (Player) e; Team team = this.war.getPlayerTeam(player.getName()); if (team != null) { - Warzone zone = this.war.getPlayerTeamWarzone(player.getName()); + Warzone zone = this.war.getPlayerTeamWarzone(player.getName()); zone.handleDeath(player); - // if (zone.isDropLootOnDeath()) { - // war.getServer().getScheduler().scheduleAsyncDelayedTask(war, - // new LootDropperTask(player.getLocation(), event.getDrops()), - // 750); - // } - event.getDrops().clear(); // no loot + // if (zone.isDropLootOnDeath()) { + // war.getServer().getScheduler().scheduleAsyncDelayedTask(war, + // new LootDropperTask(player.getLocation(), event.getDrops()), + // 750); + // } + event.getDrops().clear(); // no loot } } } @@ -61,17 +61,15 @@ public class WarEntityListener extends EntityListener { if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) { // only let adversaries (same warzone, different team) attack each other - Player a = (Player)attacker; - Player d = (Player)defender; + Player a = (Player) attacker; + Player d = (Player) defender; Warzone attackerWarzone = this.war.getPlayerTeamWarzone(a.getName()); Team attackerTeam = this.war.getPlayerTeam(a.getName()); Warzone defenderWarzone = this.war.getPlayerTeamWarzone(d.getName()); Team defenderTeam = this.war.getPlayerTeam(d.getName()); - if (attackerTeam != null && defenderTeam != null - && attackerTeam != defenderTeam - && attackerWarzone == defenderWarzone) { + if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) { // Make sure one of the players isn't in the spawn - if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn + if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn if (!defenderWarzone.isFlagThief(d.getName())) { // thiefs can always be attacked this.war.badMsg(a, "Can't attack a player that's inside his team's spawn."); event.setCancelled(true); @@ -92,30 +90,25 @@ public class WarEntityListener extends EntityListener { } event.setCancelled(true); } - } else if (attackerTeam != null && defenderTeam != null - && attackerTeam == defenderTeam - && attackerWarzone == defenderWarzone - && attacker.getEntityId() != defender.getEntityId()) { + } else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) { // same team, but not same person if (attackerWarzone.getFriendlyFire()) { this.war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through } else { this.war.badMsg(a, "Your attack missed! Your target is on your team."); - event.setCancelled(true); // ff is off + event.setCancelled(true); // ff is off } - } else if (attackerTeam == null && defenderTeam == null && this.war.canPvpOutsideZones(a)){ + } else if (attackerTeam == null && defenderTeam == null && this.war.canPvpOutsideZones(a)) { // let normal PVP through is its not turned off or if you have perms } else if (attackerTeam == null && defenderTeam == null && !this.war.canPvpOutsideZones(a)) { if (!this.war.isDisablePvpMessage()) { this.war.badMsg(a, "You need the 'war.pvp' permission to attack players outside warzones."); } - event.setCancelled(true); // global pvp is off + event.setCancelled(true); // global pvp is off } else { this.war.badMsg(a, "Your attack missed!"); if (attackerTeam == null) { - this.war.badMsg(a, "You must join a team " + - ", then you'll be able to damage people " + - "in the other teams in that warzone."); + this.war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + "in the other teams in that warzone."); } else if (defenderTeam == null) { this.war.badMsg(a, "Your target is not in a team."); } else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) { @@ -174,9 +167,8 @@ public class WarEntityListener extends EntityListener { event.setCancelled(false); } - if (event instanceof EntityDamageByEntityEvent || - event instanceof EntityDamageByProjectileEvent) { - this.handlerAttackDefend((EntityDamageByEntityEvent)event); + if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) { + this.handlerAttackDefend((EntityDamageByEntityEvent) event); } else { // Detect death (from , prevent it and respawn the player if (entity instanceof Player) { @@ -194,15 +186,15 @@ public class WarEntityListener extends EntityListener { @Override public void onEntityCombust(EntityCombustEvent event) { if (this.war.isLoaded()) { - Entity entity = event.getEntity(); + Entity entity = event.getEntity(); if (entity instanceof Player) { Player player = (Player) entity; Team team = this.war.getPlayerTeam(player.getName()); if (team != null && team.getSpawnVolume().contains(player.getLocation())) { // smother out the fire that didn't burn out when you respawned - //Stop fire (upcast, watch out!) + // Stop fire (upcast, watch out!) if (player instanceof CraftPlayer) { - net.minecraft.server.Entity playerEntity = ((CraftPlayer)player).getHandle(); + net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle(); playerEntity.fireTicks = 0; } event.setCancelled(true); @@ -218,7 +210,7 @@ public class WarEntityListener extends EntityListener { Warzone zone = this.war.warzone(location); if (zone != null && zone.isNoCreatures()) { event.setCancelled(true); - //war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName()); + // war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName()); } } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index ec0b296..46fbcc8 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -1,4 +1,5 @@ package bukkit.tommytony.war; + import java.util.Random; import org.bukkit.Location; @@ -27,18 +28,16 @@ import com.tommytony.war.Warzone; import com.tommytony.war.ZoneLobby; import com.tommytony.war.ZoneSetter; - /** - * + * * @author tommytony - * + * */ public class WarPlayerListener extends PlayerListener { private final War war; private Random random = null; - public WarPlayerListener(War war) { this.war = war; this.random = new Random(); @@ -77,10 +76,8 @@ public class WarPlayerListener extends PlayerListener { } else { Item item = event.getItemDrop(); if (item != null) { - ItemStack itemStack = item.getItemStack(); - if (itemStack != null - && itemStack.getType() == team.getKind().getMaterial() - && itemStack.getData().getData() == team.getKind().getData()) { + ItemStack itemStack = item.getItemStack(); + if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && itemStack.getData().getData() == team.getKind().getData()) { // Can't drop your team's kind block this.war.badMsg(player, "Can't drop " + team.getName() + " block blocks."); event.setCancelled(true); @@ -120,13 +117,12 @@ public class WarPlayerListener extends PlayerListener { } else { Item item = event.getItem(); if (item != null && item instanceof CraftItem) { - CraftItem cItem = (CraftItem)item; + CraftItem cItem = (CraftItem) item; if (cItem != null) { ItemStack itemStack = cItem.getItemStack(); - if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() - && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) { + if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) { // Can't pick up a second precious block - //war.badMsg(player, "You already have a " + team.getName() + " block."); + // war.badMsg(player, "You already have a " + team.getName() + " block."); event.setCancelled(true); return; } @@ -167,14 +163,7 @@ public class WarPlayerListener extends PlayerListener { String[] split = msg.split(" "); if (!this.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) { String command = split[0].substring(1); - if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") - && !command.equals("zone") && !command.equals("warzone") - && !command.equals("teams") - && !command.equals("join") - && !command.equals("leave") - && !command.equals("team") - && !command.equals("warhub") - && !command.equals("zonemaker")) { + if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) { this.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone."); event.setCancelled(true); } @@ -237,10 +226,10 @@ public class WarPlayerListener extends PlayerListener { // Zone walls Team currentTeam = this.war.getPlayerTeam(player.getName()); - Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone + Warzone playerWarzone = this.war.getPlayerTeamWarzone(player.getName()); // this uses the teams, so it asks: get the player's team's warzone boolean protecting = false; if (currentTeam != null) { - //Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc); + // Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc); protecting = playerWarzone.protectZoneWallAgainstPlayer(player); } else { Warzone nearbyZone = this.war.zoneOfZoneWallAtProximity(playerLoc); @@ -265,7 +254,7 @@ public class WarPlayerListener extends PlayerListener { if (oldTeam == null && canPlay) { // trying to counter spammy player move isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc); if (isAutoAssignGate) { - if (zone.isDisabled()){ + if (zone.isDisabled()) { this.handleDisabledZone(event, player, zone); } else { this.dropFromOldTeamIfAny(player); @@ -281,7 +270,7 @@ public class WarPlayerListener extends PlayerListener { } } else { event.setTo(zone.getTeleport()); - //player.teleport(zone.getTeleport()); + // player.teleport(zone.getTeleport()); this.war.badMsg(player, "All teams are full."); } } @@ -289,10 +278,10 @@ public class WarPlayerListener extends PlayerListener { } // go through all the team gates - for (Team team : zone.getTeams()){ + for (Team team : zone.getTeams()) { if (zone.getLobby().isInTeamGate(team, playerLoc)) { this.dropFromOldTeamIfAny(player); - if (zone.isDisabled()){ + if (zone.isDisabled()) { this.handleDisabledZone(event, player, zone); } else if (team.getPlayers().size() < zone.getTeamCap()) { team.addPlayer(player); @@ -303,7 +292,7 @@ public class WarPlayerListener extends PlayerListener { zone.keepPlayerInventory(player); this.war.msg(player, "Your inventory is in storage until you /leave."); zone.respawnPlayer(event, team, player); - for (Team t : zone.getTeams()){ + for (Team t : zone.getTeams()) { t.teamcast("" + player.getName() + " joined team " + team.getName() + "."); } } else { @@ -314,11 +303,10 @@ public class WarPlayerListener extends PlayerListener { } } - if (this.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) - && !this.war.getWarHub().getVolume().contains(player.getLocation())){ + if (this.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !this.war.getWarHub().getVolume().contains(player.getLocation())) { this.dropFromOldTeamIfAny(player); event.setTo(this.war.getWarHub().getLocation()); - //player.teleport(war.getWarHub().getLocation()); + // player.teleport(war.getWarHub().getLocation()); this.war.msg(player, "Welcome to the War hub."); return; } @@ -330,12 +318,12 @@ public class WarPlayerListener extends PlayerListener { WarHub hub = this.war.getWarHub(); if (hub != null && hub.getVolume().contains(player.getLocation())) { Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc); - if (zone != null && zone.getTeleport() != null) { - event.setTo(zone.getTeleport()); - //player.teleport(zone.getTeleport()); - this.war.msg(player, "Welcome to warzone " + zone.getName() + "."); - return; - } + if (zone != null && zone.getTeleport() != null) { + event.setTo(zone.getTeleport()); + // player.teleport(zone.getTeleport()); + this.war.msg(player, "Welcome to warzone " + zone.getName() + "."); + return; + } } boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc); @@ -343,9 +331,7 @@ public class WarPlayerListener extends PlayerListener { if (isLeaving) { // already in a team and in warzone, leaving // same as leave if (playerTeam != null) { - boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && - playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && - playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ(); + boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ(); if (!atSpawnAlready) { playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true); return; @@ -355,67 +341,59 @@ public class WarPlayerListener extends PlayerListener { if (playerWarzone != null) { // Player belongs to a warzone team but is outside: he snuck out or is at spawn and died - if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null - && !playerWarzone.getLobby().getVolume().contains(playerLoc) - && !isLeaving) { + if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) { this.war.badMsg(player, "Use /leave to exit the zone."); event.setTo(playerTeam.getTeamSpawn()); return; } // Monuments - if (playerTeam != null - && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) - && player.getHealth() < 20 - && player.getHealth() > 0 // don't heal the dead - && this.random.nextInt(77) == 3 ) { // one chance out of many of getting healed + if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead + && this.random.nextInt(77) == 3) { // one chance out of many of getting healed int currentHp = player.getHealth(); int newHp = currentHp + locZone.getMonumentHeal(); if (newHp > 20) { - newHp = 20; + newHp = 20; } player.setHealth(newHp); - String isS = "s"; // no 's' in 'hearts' when it's just one heart - if (newHp-currentHp==2) { - isS=""; + String isS = "s"; // no 's' in 'hearts' when it's just one heart + if (newHp - currentHp == 2) { + isS = ""; } - String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount - if (newHp-currentHp==2) { - heartNum="1 "; - } else if (newHp-currentHp%2==0) { - heartNum=((newHp-currentHp)/2)+" "; + String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount + if (newHp - currentHp == 2) { + heartNum = "1 "; + } else if (newHp - currentHp % 2 == 0) { + heartNum = ((newHp - currentHp) / 2) + " "; } else { - heartNum=((newHp-currentHp-1)/2)+".5 "; + heartNum = ((newHp - currentHp - 1) / 2) + ".5 "; } - this.war.msg(player, "Your dance pleases the monument's voodoo. You gain "+heartNum+"heart"+isS+"!"); + this.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!"); return; } // Flag capture - if (playerWarzone.isFlagThief(player.getName()) - && (playerTeam.getSpawnVolume().contains(player.getLocation()) - || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) { + if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) { if (playerWarzone.isTeamFlagStolen(playerTeam)) { this.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned."); } else { - synchronized(playerWarzone) { + synchronized (playerWarzone) { // flags can be captured at own spawn or own flag pole playerTeam.addPoint(); if (playerTeam.getPoints() >= playerWarzone.getScoreCap()) { - if (playerWarzone.hasPlayerInventory(player.getName())){ + if (playerWarzone.hasPlayerInventory(player.getName())) { playerWarzone.restorePlayerInventory(player); } playerWarzone.handleScoreCapReached(player, playerTeam.getName()); event.setTo(playerWarzone.getTeleport()); - //player.teleport(playerWarzone.getTeleport()); + // player.teleport(playerWarzone.getTeleport()); } else { // added a point Team victim = playerWarzone.getVictimTeamForThief(player.getName()); - victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it + victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it victim.initializeTeamFlag(); for (Team t : playerWarzone.getTeams()) { - t.teamcast(player.getName() + " captured team " + victim.getName() - + "'s flag. Team " + playerTeam.getName() + " scores one point." ); + t.teamcast(player.getName() + " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point."); } playerWarzone.respawnPlayer(event, playerTeam, player); playerTeam.resetSign(); @@ -426,12 +404,11 @@ public class WarPlayerListener extends PlayerListener { } return; } - } else if (locZone != null && locZone.getLobby() != null - && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) { + } else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) { // player is not in any team, but inside warzone boundaries, get him out Warzone zone = this.war.warzone(playerLoc); event.setTo(zone.getTeleport()); - //player.teleport(zone.getTeleport()); + // player.teleport(zone.getTeleport()); this.war.badMsg(player, "You can't be inside a warzone without a team."); return; } @@ -449,13 +426,13 @@ public class WarPlayerListener extends PlayerListener { // drop from old team if any Team previousTeam = this.war.getPlayerTeam(player.getName()); if (previousTeam != null) { - if (!previousTeam.removePlayer(player.getName())){ + if (!previousTeam.removePlayer(player.getName())) { this.war.logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); } } } - public String getAllTeamsMsg(Player player){ + public String getAllTeamsMsg(Player player) { String teamsMessage = "Teams: "; Warzone warzone = this.war.warzone(player.getLocation()); ZoneLobby lobby = this.war.lobby(player.getLocation()); @@ -464,11 +441,11 @@ public class WarPlayerListener extends PlayerListener { } else { lobby = warzone.getLobby(); } - if (warzone.getTeams().isEmpty()){ + if (warzone.getTeams().isEmpty()) { teamsMessage += "none."; } for (Team team : warzone.getTeams()) { - teamsMessage += team.getName() + " (" + team.getPoints() + " points, "+ team.getRemainingLifes() + "/" + warzone.getLifePool() + " lives left. "; + teamsMessage += team.getName() + " (" + team.getPoints() + " points, " + team.getRemainingLifes() + "/" + warzone.getLifePool() + " lives left. "; for (Player member : team.getPlayers()) { teamsMessage += member.getName() + " "; } diff --git a/war/src/main/java/com/tommytony/war/Monument.java b/war/src/main/java/com/tommytony/war/Monument.java index 1af2d68..050485e 100644 --- a/war/src/main/java/com/tommytony/war/Monument.java +++ b/war/src/main/java/com/tommytony/war/Monument.java @@ -10,9 +10,9 @@ import bukkit.tommytony.war.War; import com.tommytony.war.volumes.Volume; /** - * + * * @author tommytony - * + * */ public class Monument { private Location location; @@ -41,54 +41,54 @@ public class Monument { int z = this.location.getBlockZ(); // center - this.warzone.getWorld().getBlockAt(x, y-1, z).getState().setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z).getState().setType(Material.OBSIDIAN); // inner ring - this.warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN); // outer ring - this.warzone.getWorld().getBlockAt(x+2, y-1, z+2).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x+2, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+2, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+2, y-1, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+2, y-1, z-2).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 2).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x + 2, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 2, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 2, y - 1, z - 2).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x-1, y-1, z+2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z-2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z+2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z-2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z + 2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z - 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z+2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z-2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 2).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 2).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-2, y-1, z+2).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x-2, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-2, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-2, y-1, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-2, y-1, z-2).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 2).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x - 2, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 2, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2).setType(Material.GLOWSTONE); // block holder this.warzone.getWorld().getBlockAt(x, y, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y, z+1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y+1, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y+1, z+1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y+2, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y+2, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y+2, z+1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.OBSIDIAN); } @@ -103,14 +103,14 @@ public class Monument { int diffY = Math.abs(playerY - y); int diffZ = Math.abs(playerZ - z); if (diffX < 6 && diffY < 6 && diffZ < 6) { - return true; + return true; } return false; } public boolean isOwner(Team team) { if (team == this.ownerTeam) { - return true; + return true; } return false; } diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index 73fbaaa..33d10b3 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -15,9 +15,9 @@ import com.tommytony.war.utils.SignHelper; import com.tommytony.war.volumes.Volume; /** - * + * * @author tommytony - * + * */ public class Team { private List players = new ArrayList(); @@ -48,22 +48,22 @@ public class Team { private void setSpawnVolume() { if (this.spawnVolume.isSaved()) { - this.spawnVolume.resetBlocks(); + this.spawnVolume.resetBlocks(); } int x = this.teamSpawn.getBlockX(); int y = this.teamSpawn.getBlockY(); int z = this.teamSpawn.getBlockZ(); if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) { - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y-1, z)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y+3, z)); + this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x, y - 1, z)); + this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x, y + 3, z)); } else if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.SMALL)) { - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x-1, y-1, z-1)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x+1, y+3, z+1)); + this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1)); + this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1)); } else { // flat or big - this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x-2, y-1, z-2)); - this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x+2, y+3, z+2)); + this.spawnVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 2, y - 1, z - 2)); + this.spawnVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 2, y + 3, z + 2)); } } @@ -79,48 +79,48 @@ public class Team { if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) { // nothing but glowstone - this.warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); } else { // first ring - this.setBlock(x+1, y-1, z+1, this.kind); - this.setBlock(x+1, y-1, z, this.kind); - this.setBlock(x+1, y-1, z-1, this.kind); - this.setBlock(x, y-1, z+1, this.kind); - this.warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.GLOWSTONE); - this.setBlock(x, y-1, z-1, this.kind); - this.setBlock(x-1, y-1, z+1, this.kind); - this.setBlock(x-1, y-1, z, this.kind); - this.setBlock(x-1, y-1, z-1, this.kind); + this.setBlock(x + 1, y - 1, z + 1, this.kind); + this.setBlock(x + 1, y - 1, z, this.kind); + this.setBlock(x + 1, y - 1, z - 1, this.kind); + this.setBlock(x, y - 1, z + 1, this.kind); + this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); + this.setBlock(x, y - 1, z - 1, this.kind); + this.setBlock(x - 1, y - 1, z + 1, this.kind); + this.setBlock(x - 1, y - 1, z, this.kind); + this.setBlock(x - 1, y - 1, z - 1, this.kind); } // Orientation int yaw = 0; - if (this.teamSpawn.getYaw() >= 0){ - yaw = (int)(this.teamSpawn.getYaw() % 360); + if (this.teamSpawn.getYaw() >= 0) { + yaw = (int) (this.teamSpawn.getYaw() % 360); } else { - yaw = (int)(360 + (this.teamSpawn.getYaw() % 360)); + yaw = (int) (360 + (this.teamSpawn.getYaw() % 360)); } Block signBlock = null; int signData = 0; - if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)){ + if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.INVISIBLE)) { // INVISIBLE style signBlock = this.warzone.getWorld().getBlockAt(x, y, z); if (yaw >= 0 && yaw < 90) { signData = 10; - }else if (yaw >= 90 && yaw <= 180) { + } else if (yaw >= 90 && yaw <= 180) { signData = 14; } else if (yaw >= 180 && yaw < 270) { signData = 2; } else if (yaw >= 270 && yaw <= 360) { signData = 6; } - } else if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.SMALL)){ + } else if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.SMALL)) { // SMALL style if (yaw >= 0 && yaw < 90) { signData = 10; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH).getFace(BlockFace.WEST); - }else if (yaw >= 90 && yaw <= 180) { + } else if (yaw >= 90 && yaw <= 180) { signData = 14; signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH).getFace(BlockFace.EAST); } else if (yaw >= 180 && yaw < 270) { @@ -132,26 +132,26 @@ public class Team { } } else { // outer ring (FLAT or BIG) - this.setBlock(x+2, y-1, z+2, this.kind); - this.setBlock(x+2, y-1, z+1, this.kind); - this.setBlock(x+2, y-1, z, this.kind); - this.setBlock(x+2, y-1, z-1, this.kind); - this.setBlock(x+2, y-1, z-2, this.kind); + this.setBlock(x + 2, y - 1, z + 2, this.kind); + this.setBlock(x + 2, y - 1, z + 1, this.kind); + this.setBlock(x + 2, y - 1, z, this.kind); + this.setBlock(x + 2, y - 1, z - 1, this.kind); + this.setBlock(x + 2, y - 1, z - 2, this.kind); - this.setBlock(x-1, y-1, z+2, this.kind); - this.setBlock(x-1, y-1, z-2, this.kind); + this.setBlock(x - 1, y - 1, z + 2, this.kind); + this.setBlock(x - 1, y - 1, z - 2, this.kind); - this.setBlock(x, y-1, z+2, this.kind); - this.setBlock(x, y-1, z-2, this.kind); + this.setBlock(x, y - 1, z + 2, this.kind); + this.setBlock(x, y - 1, z - 2, this.kind); - this.setBlock(x+1, y-1, z+2, this.kind); - this.setBlock(x+1, y-1, z-2, this.kind); + this.setBlock(x + 1, y - 1, z + 2, this.kind); + this.setBlock(x + 1, y - 1, z - 2, this.kind); - this.setBlock(x-2, y-1, z+2, this.kind); - this.setBlock(x-2, y-1, z+1, this.kind); - this.setBlock(x-2, y-1, z, this.kind); - this.setBlock(x-2, y-1, z-1, this.kind); - this.setBlock(x-2, y-1, z-2, this.kind); + this.setBlock(x - 2, y - 1, z + 2, this.kind); + this.setBlock(x - 2, y - 1, z + 1, this.kind); + this.setBlock(x - 2, y - 1, z, this.kind); + this.setBlock(x - 2, y - 1, z - 1, this.kind); + this.setBlock(x - 2, y - 1, z - 2, this.kind); BlockFace facing = null; BlockFace opposite = null; @@ -163,30 +163,30 @@ public class Team { if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) { // rim - this.setBlock(x-2, y, z-1, this.kind); - this.setBlock(x-2, y, z-2, this.kind); - this.setBlock(x-1, y, z-2, this.kind); - this.setBlock(x, y, z-2, this.kind); - this.setBlock(x+1, y, z-2, this.kind); - this.setBlock(x+2, y, z-2, this.kind); - this.setBlock(x+2, y, z-1, this.kind); - this.setBlock(x+2, y, z, this.kind); - this.setBlock(x+2, y, z+1, this.kind); - this.setBlock(x+2, y, z+2, this.kind); - this.setBlock(x+1, y, z+2, this.kind); + this.setBlock(x - 2, y, z - 1, this.kind); + this.setBlock(x - 2, y, z - 2, this.kind); + this.setBlock(x - 1, y, z - 2, this.kind); + this.setBlock(x, y, z - 2, this.kind); + this.setBlock(x + 1, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 1, this.kind); + this.setBlock(x + 2, y, z, this.kind); + this.setBlock(x + 2, y, z + 1, this.kind); + this.setBlock(x + 2, y, z + 2, this.kind); + this.setBlock(x + 1, y, z + 2, this.kind); // tower - this.setBlock(x, y+1, z-2, this.kind); - this.setBlock(x+1, y+1, z-2, this.kind); - this.setBlock(x+2, y+1, z-2, this.kind); - this.setBlock(x+2, y+1, z-1, this.kind); - this.setBlock(x+2, y+1, z, this.kind); + this.setBlock(x, y + 1, z - 2, this.kind); + this.setBlock(x + 1, y + 1, z - 2, this.kind); + this.setBlock(x + 2, y + 1, z - 2, this.kind); + this.setBlock(x + 2, y + 1, z - 1, this.kind); + this.setBlock(x + 2, y + 1, z, this.kind); - this.setBlock(x+1, y+2, z-2, this.kind); - this.setBlock(x+2, y+2, z-2, this.kind); - this.setBlock(x+2, y+2, z-1, this.kind); + this.setBlock(x + 1, y + 2, z - 2, this.kind); + this.setBlock(x + 2, y + 2, z - 2, this.kind); + this.setBlock(x + 2, y + 2, z - 1, this.kind); - this.setBlock(x+2, y+3, z-2, this.kind); + this.setBlock(x + 2, y + 3, z - 2, this.kind); } } else if (yaw >= 90 && yaw <= 180) { facing = BlockFace.NORTH_EAST; @@ -195,30 +195,30 @@ public class Team { signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.NORTH, 2).getFace(BlockFace.EAST, 2); if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) { // rim - this.setBlock(x+1, y, z-2, this.kind); - this.setBlock(x+2, y, z-2, this.kind); - this.setBlock(x+2, y, z-1, this.kind); - this.setBlock(x+2, y, z, this.kind); - this.setBlock(x+2, y, z+1, this.kind); - this.setBlock(x+2, y, z+2, this.kind); - this.setBlock(x+1, y, z+2, this.kind); - this.setBlock(x, y, z+2, this.kind); - this.setBlock(x-1, y, z+2, this.kind); - this.setBlock(x-2, y, z+2, this.kind); - this.setBlock(x-2, y, z+1, this.kind); + this.setBlock(x + 1, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 1, this.kind); + this.setBlock(x + 2, y, z, this.kind); + this.setBlock(x + 2, y, z + 1, this.kind); + this.setBlock(x + 2, y, z + 2, this.kind); + this.setBlock(x + 1, y, z + 2, this.kind); + this.setBlock(x, y, z + 2, this.kind); + this.setBlock(x - 1, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 1, this.kind); // tower - this.setBlock(x+2, y+1, z, this.kind); - this.setBlock(x+2, y+1, z+1, this.kind); - this.setBlock(x+2, y+1, z+2, this.kind); - this.setBlock(x+1, y+1, z+2, this.kind); - this.setBlock(x, y+1, z+2, this.kind); + this.setBlock(x + 2, y + 1, z, this.kind); + this.setBlock(x + 2, y + 1, z + 1, this.kind); + this.setBlock(x + 2, y + 1, z + 2, this.kind); + this.setBlock(x + 1, y + 1, z + 2, this.kind); + this.setBlock(x, y + 1, z + 2, this.kind); - this.setBlock(x+2, y+2, z+1, this.kind); - this.setBlock(x+2, y+2, z+2, this.kind); - this.setBlock(x+1, y+2, z+2, this.kind); + this.setBlock(x + 2, y + 2, z + 1, this.kind); + this.setBlock(x + 2, y + 2, z + 2, this.kind); + this.setBlock(x + 1, y + 2, z + 2, this.kind); - this.setBlock(x+2, y+3, z+2, this.kind); + this.setBlock(x + 2, y + 3, z + 2, this.kind); } } else if (yaw >= 180 && yaw < 270) { facing = BlockFace.SOUTH_EAST; @@ -227,30 +227,30 @@ public class Team { signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH, 2).getFace(BlockFace.EAST, 2); if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) { // rim - this.setBlock(x+2, y, z+1, this.kind); - this.setBlock(x+2, y, z+2, this.kind); - this.setBlock(x+1, y, z+2, this.kind); - this.setBlock(x, y, z+2, this.kind); - this.setBlock(x-1, y, z+2, this.kind); - this.setBlock(x-2, y, z+2, this.kind); - this.setBlock(x-2, y, z+1, this.kind); - this.setBlock(x-2, y, z, this.kind); - this.setBlock(x-2, y, z-1, this.kind); - this.setBlock(x-2, y, z-2, this.kind); - this.setBlock(x-1, y, z-2, this.kind); + this.setBlock(x + 2, y, z + 1, this.kind); + this.setBlock(x + 2, y, z + 2, this.kind); + this.setBlock(x + 1, y, z + 2, this.kind); + this.setBlock(x, y, z + 2, this.kind); + this.setBlock(x - 1, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 1, this.kind); + this.setBlock(x - 2, y, z, this.kind); + this.setBlock(x - 2, y, z - 1, this.kind); + this.setBlock(x - 2, y, z - 2, this.kind); + this.setBlock(x - 1, y, z - 2, this.kind); // tower - this.setBlock(x, y+1, z+2, this.kind); - this.setBlock(x-1, y+1, z+2, this.kind); - this.setBlock(x-2, y+1, z+2, this.kind); - this.setBlock(x-2, y+1, z+1, this.kind); - this.setBlock(x-2, y+1, z, this.kind); + this.setBlock(x, y + 1, z + 2, this.kind); + this.setBlock(x - 1, y + 1, z + 2, this.kind); + this.setBlock(x - 2, y + 1, z + 2, this.kind); + this.setBlock(x - 2, y + 1, z + 1, this.kind); + this.setBlock(x - 2, y + 1, z, this.kind); - this.setBlock(x-1, y+2, z+2, this.kind); - this.setBlock(x-2, y+2, z+2, this.kind); - this.setBlock(x-2, y+2, z+1, this.kind); + this.setBlock(x - 1, y + 2, z + 2, this.kind); + this.setBlock(x - 2, y + 2, z + 2, this.kind); + this.setBlock(x - 2, y + 2, z + 1, this.kind); - this.setBlock(x-2, y+3, z+2, this.kind); + this.setBlock(x - 2, y + 3, z + 2, this.kind); } } else if (yaw >= 270 && yaw <= 360) { facing = BlockFace.SOUTH_WEST; @@ -259,43 +259,43 @@ public class Team { signBlock = this.warzone.getWorld().getBlockAt(x, y, z).getFace(BlockFace.SOUTH, 2).getFace(BlockFace.WEST, 2); if (this.warzone.getSpawnStyle().equals(TeamSpawnStyles.BIG)) { // rim - this.setBlock(x-1, y, z+2, this.kind); - this.setBlock(x-2, y, z+2, this.kind); - this.setBlock(x-2, y, z+1, this.kind); - this.setBlock(x-2, y, z, this.kind); - this.setBlock(x-2, y, z-1, this.kind); - this.setBlock(x-2, y, z-2, this.kind); - this.setBlock(x-1, y, z-2, this.kind); - this.setBlock(x, y, z-2, this.kind); - this.setBlock(x+1, y, z-2, this.kind); - this.setBlock(x+2, y, z-2, this.kind); - this.setBlock(x+2, y, z-1, this.kind); + this.setBlock(x - 1, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 2, this.kind); + this.setBlock(x - 2, y, z + 1, this.kind); + this.setBlock(x - 2, y, z, this.kind); + this.setBlock(x - 2, y, z - 1, this.kind); + this.setBlock(x - 2, y, z - 2, this.kind); + this.setBlock(x - 1, y, z - 2, this.kind); + this.setBlock(x, y, z - 2, this.kind); + this.setBlock(x + 1, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 2, this.kind); + this.setBlock(x + 2, y, z - 1, this.kind); // tower - this.setBlock(x-2, y+1, z, this.kind); - this.setBlock(x-2, y+1, z-1, this.kind); - this.setBlock(x-2, y+1, z-2, this.kind); - this.setBlock(x-1, y+1, z-2, this.kind); - this.setBlock(x, y+1, z-2, this.kind); + this.setBlock(x - 2, y + 1, z, this.kind); + this.setBlock(x - 2, y + 1, z - 1, this.kind); + this.setBlock(x - 2, y + 1, z - 2, this.kind); + this.setBlock(x - 1, y + 1, z - 2, this.kind); + this.setBlock(x, y + 1, z - 2, this.kind); - this.setBlock(x-2, y+2, z-1, this.kind); - this.setBlock(x-2, y+2, z-2, this.kind); - this.setBlock(x-1, y+2, z-2, this.kind); + this.setBlock(x - 2, y + 2, z - 1, this.kind); + this.setBlock(x - 2, y + 2, z - 2, this.kind); + this.setBlock(x - 1, y + 2, z - 2, this.kind); - this.setBlock(x-2, y+3, z-2, this.kind); + this.setBlock(x - 2, y + 3, z - 2, this.kind); } } } if (signBlock != null) { -// if (signBlock.getType() != Material.SIGN_POST) { -// signBlock.setType(Material.SIGN_POST); -// } -// else { -// // already a signpost, gotta delete it and create a new one -// signBlock.setType(Material.AIR); -// signBlock.setType(Material.SIGN_POST); -// } + // if (signBlock.getType() != Material.SIGN_POST) { + // signBlock.setType(Material.SIGN_POST); + // } + // else { + // // already a signpost, gotta delete it and create a new one + // signBlock.setType(Material.AIR); + // signBlock.setType(Material.SIGN_POST); + // } String[] lines = new String[4]; lines[0] = "Team " + this.name; @@ -307,7 +307,7 @@ public class Team { lines[3] = this.remainingLives + "/" + this.warzone.getLifePool() + " lives left"; } - SignHelper.setToSign(this.war, signBlock, (byte)signData, lines); + SignHelper.setToSign(this.war, signBlock, (byte) signData, lines); } } @@ -380,8 +380,7 @@ public class Team { boolean atLeastOnePlayerOnTeam = this.players.size() != 0; boolean atLeastOnePlayerOnOtherTeam = false; for (Team team : this.warzone.getTeams()) { - if (!team.getName().equals(this.getName()) - && team.getPlayers().size() > 0) { + if (!team.getName().equals(this.getName()) && team.getPlayers().size() > 0) { atLeastOnePlayerOnOtherTeam = true; } } @@ -401,37 +400,37 @@ public class Team { return this.spawnVolume; } - public void resetSign(){ + public void resetSign() { this.getSpawnVolume().resetBlocks(); this.initializeTeamSpawn(); // reset everything instead of just sign // BUKKIT -// int x = teamSpawn.getBlockX(); -// int y = teamSpawn.getBlockY(); -// int z = teamSpawn.getBlockZ(); -// -// 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); -// } -//// else { -//// // already a signpost, gotta delete it and create a new one -//// block.setType(Material.AIR); -//// block.setType(Material.SIGN_POST); -//// } -//// block.setData((byte)6); -// -// BlockState state = block.getState(); -// if (state instanceof Sign) { -// Sign sign = (Sign) state; -// sign.setType(Material.SIGN_POST); -// sign.setData(new MaterialData(Material.SIGN_POST, (byte)6)); -// 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); -// } + // int x = teamSpawn.getBlockX(); + // int y = teamSpawn.getBlockY(); + // int z = teamSpawn.getBlockZ(); + // + // 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); + // } + // // else { + // // // already a signpost, gotta delete it and create a new one + // // block.setType(Material.AIR); + // // block.setType(Material.SIGN_POST); + // // } + // // block.setData((byte)6); + // + // BlockState state = block.getState(); + // if (state instanceof Sign) { + // Sign sign = (Sign) state; + // sign.setType(Material.SIGN_POST); + // sign.setData(new MaterialData(Material.SIGN_POST, (byte)6)); + // 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 (this.warzone.getLobby() != null) { this.warzone.getLobby().resetTeamGateSign(this); @@ -456,16 +455,16 @@ public class Team { private void setFlagVolume() { if (this.flagVolume == null) { - this.flagVolume = new Volume(this.getName() + "flag", this.war, this.warzone.getWorld()); + this.flagVolume = new Volume(this.getName() + "flag", this.war, this.warzone.getWorld()); } if (this.flagVolume.isSaved()) { - this.flagVolume.resetBlocks(); + this.flagVolume.resetBlocks(); } int x = this.teamFlag.getBlockX(); int y = this.teamFlag.getBlockY(); int z = this.teamFlag.getBlockZ(); - this.flagVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x-1, y-1, z-1)); - this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x+1, y+3, z+1)); + this.flagVolume.setCornerOne(this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1)); + this.flagVolume.setCornerTwo(this.warzone.getWorld().getBlockAt(x + 1, y + 3, z + 1)); } @SuppressWarnings("unused") @@ -479,54 +478,54 @@ public class Team { int z = this.teamFlag.getBlockZ(); // first ring - this.warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.GLOWSTONE); - this.warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.OBSIDIAN); - this.warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x + 1, y - 1, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x, y - 1, z).setType(Material.GLOWSTONE); + this.warzone.getWorld().getBlockAt(x, y - 1, z - 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z + 1).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z).setType(Material.OBSIDIAN); + this.warzone.getWorld().getBlockAt(x - 1, y - 1, z - 1).setType(Material.OBSIDIAN); // flag - this.warzone.getWorld().getBlockAt(x, y+1, z).setType(this.kind.getMaterial()); - this.warzone.getWorld().getBlockAt(x, y+1, z).setData(this.kind.getData()); - this.warzone.getWorld().getBlockAt(x, y+2, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y + 1, z).setType(this.kind.getMaterial()); + this.warzone.getWorld().getBlockAt(x, y + 1, z).setData(this.kind.getData()); + this.warzone.getWorld().getBlockAt(x, y + 2, z).setType(Material.FENCE); // Flag post using Orientation int yaw = 0; - if (this.teamFlag.getYaw() >= 0){ - yaw = (int)(this.teamFlag.getYaw() % 360); + if (this.teamFlag.getYaw() >= 0) { + yaw = (int) (this.teamFlag.getYaw() % 360); } else { - yaw = (int)(360 + (this.teamFlag.getYaw() % 360)); + yaw = (int) (360 + (this.teamFlag.getYaw() % 360)); } BlockFace facing = null; BlockFace opposite = null; if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) { facing = BlockFace.WEST; opposite = BlockFace.EAST; - this.warzone.getWorld().getBlockAt(x, y, z-1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y+1, z-1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y+2, z-1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y, z - 1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y + 1, z - 1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y + 2, z - 1).setType(Material.FENCE); } else if (yaw >= 45 && yaw < 135) { facing = BlockFace.NORTH; opposite = BlockFace.SOUTH; - this.warzone.getWorld().getBlockAt(x+1, y, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x+1, y+1, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x+1, y+2, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x + 1, y, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x + 1, y + 1, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x + 1, y + 2, z).setType(Material.FENCE); } else if (yaw >= 135 && yaw < 225) { facing = BlockFace.EAST; opposite = BlockFace.WEST; - this.warzone.getWorld().getBlockAt(x, y, z+1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y+1, z+1).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x, y+2, z+1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y, z + 1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y + 1, z + 1).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x, y + 2, z + 1).setType(Material.FENCE); } else if (yaw >= 225 && yaw < 315) { facing = BlockFace.SOUTH; opposite = BlockFace.NORTH; - this.warzone.getWorld().getBlockAt(x-1, y, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x-1, y+1, z).setType(Material.FENCE); - this.warzone.getWorld().getBlockAt(x-1, y+2, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x - 1, y, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x - 1, y + 1, z).setType(Material.FENCE); + this.warzone.getWorld().getBlockAt(x - 1, y + 2, z).setType(Material.FENCE); } } @@ -546,10 +545,8 @@ public class Team { int flagX = this.teamFlag.getBlockX(); int flagY = this.teamFlag.getBlockY() + 1; int flagZ = this.teamFlag.getBlockZ(); - if (block.getX() == flagX - && block.getY() == flagY - && block.getZ() == flagZ) { - return true; + if (block.getX() == flagX && block.getY() == flagY && block.getZ() == flagZ) { + return true; } } return false; diff --git a/war/src/main/java/com/tommytony/war/TeamKinds.java b/war/src/main/java/com/tommytony/war/TeamKinds.java index 9de3859..c18bb9d 100644 --- a/war/src/main/java/com/tommytony/war/TeamKinds.java +++ b/war/src/main/java/com/tommytony/war/TeamKinds.java @@ -7,9 +7,9 @@ import org.bukkit.ChatColor; import org.bukkit.Material; /** - * + * * @author tommytony - * + * */ public class TeamKinds { private static final List teamKinds = new ArrayList(); @@ -37,7 +37,7 @@ public class TeamKinds { String lowered = str.toLowerCase(); for (TeamKind kind : TeamKinds.getTeamkinds()) { if (kind.getDefaultName().startsWith(lowered)) { - return kind; + return kind; } } return null; @@ -47,4 +47,3 @@ public class TeamKinds { return TeamKinds.teamKinds; } } - diff --git a/war/src/main/java/com/tommytony/war/TeamSpawnStyles.java b/war/src/main/java/com/tommytony/war/TeamSpawnStyles.java index a7d829c..ff68c55 100644 --- a/war/src/main/java/com/tommytony/war/TeamSpawnStyles.java +++ b/war/src/main/java/com/tommytony/war/TeamSpawnStyles.java @@ -1,9 +1,9 @@ package com.tommytony.war; /** - * + * * @author tommytony - * + * */ public class TeamSpawnStyles { public static final String INVISIBLE = "invisible"; diff --git a/war/src/main/java/com/tommytony/war/WarHub.java b/war/src/main/java/com/tommytony/war/WarHub.java index ed39dbc..7e10876 100644 --- a/war/src/main/java/com/tommytony/war/WarHub.java +++ b/war/src/main/java/com/tommytony/war/WarHub.java @@ -15,9 +15,9 @@ import com.tommytony.war.volumes.BlockInfo; import com.tommytony.war.volumes.Volume; /** - * + * * @author tommytony - * + * */ public class WarHub { private final War war; @@ -47,9 +47,7 @@ public class WarHub { Warzone zone = null; for (String zoneName : this.zoneGateBlocks.keySet()) { Block gate = this.zoneGateBlocks.get(zoneName); - if (gate.getX() == playerLocation.getBlockX() - && gate.getY() == playerLocation.getBlockY() - && gate.getZ() == playerLocation.getBlockZ()) { + if (gate.getX() == playerLocation.getBlockX() && gate.getY() == playerLocation.getBlockY() && gate.getZ() == playerLocation.getBlockZ()) { zone = this.war.findWarzone(zoneName); } } @@ -62,7 +60,7 @@ public class WarHub { int disabled = 0; for (Warzone zone : this.war.getWarzones()) { if (zone.isDisabled()) { - disabled++; + disabled++; } } int noOfWarzones = this.war.getWarzones().size() - disabled; @@ -85,7 +83,7 @@ public class WarHub { // draw gates Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.WEST, hubDepth).getFace(BlockFace.NORTH, 2); - for (Warzone zone : this.war.getWarzones()) { // gonna use the index to find it again + for (Warzone zone : this.war.getWarzones()) { // gonna use the index to find it again if (!zone.isDisabled()) { this.zoneGateBlocks.put(zone.getName(), currentGateBlock); currentGateBlock.getFace(BlockFace.DOWN).setType(Material.GLOWSTONE); @@ -111,7 +109,7 @@ public class WarHub { lines[1] = "(/warhub)"; lines[2] = "Pick your"; lines[3] = "battle!"; - SignHelper.setToSign(this.war, signBlock, (byte)8, lines); + SignHelper.setToSign(this.war, signBlock, (byte) 8, lines); // Warzone signs for (Warzone zone : this.war.getWarzones()) { @@ -127,9 +125,9 @@ public class WarHub { Block zoneGate = this.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.setType(Material.SIGN_POST); } - block.setData((byte)8); + block.setData((byte) 8); int zoneCap = 0; int zonePlayers = 0; @@ -142,7 +140,7 @@ public class WarHub { lines[1] = zone.getName(); lines[2] = zonePlayers + "/" + zoneCap + " players"; lines[3] = zone.getTeams().size() + " teams"; - SignHelper.setToSign(this.war, block, (byte)8, lines); + SignHelper.setToSign(this.war, block, (byte) 8, lines); } 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 6ffdd3c..4fb3272 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -1,4 +1,5 @@ package com.tommytony.war; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -23,9 +24,9 @@ import com.tommytony.war.utils.InventoryStash; import com.tommytony.war.volumes.ZoneVolume; /** - * + * * @author tommytony - * + * */ public class Warzone { private String name; @@ -87,7 +88,7 @@ public class Warzone { public boolean ready() { if (this.volume.hasTwoCorners() && !this.volume.tooSmall() && !this.volume.tooBig()) { - return true; + return true; } return false; } @@ -100,7 +101,7 @@ public class Warzone { for (Team team : this.teams) { for (Player player : team.getPlayers()) { if (player.getName().equals(playerName)) { - return team; + return team; } } } @@ -120,7 +121,7 @@ public class Warzone { } public int saveState(boolean clearArtifacts) { - if (this.ready()){ + if (this.ready()) { if (clearArtifacts) { // removed everything to keep save clean for (ZoneWallGuard guard : this.zoneWallGuards) { @@ -131,7 +132,7 @@ public class Warzone { for (Team team : this.teams) { team.getSpawnVolume().resetBlocks(); if (team.getTeamFlag() != null) { - team.getFlagVolume().resetBlocks(); + team.getFlagVolume().resetBlocks(); } } @@ -146,7 +147,7 @@ public class Warzone { int saved = this.volume.saveBlocks(); if (clearArtifacts) { - this.initializeZone(); // bring back stuff + this.initializeZone(); // bring back stuff } return saved; } @@ -154,8 +155,8 @@ public class Warzone { } /** - * Goes back to the saved state of the warzone (resets only block types, not physics). - * Also teleports all players back to their respective spawns. + * Goes back to the saved state of the warzone (resets only block types, not physics). Also teleports all players back to their respective spawns. + * * @return */ public void initializeZone() { @@ -163,20 +164,19 @@ public class Warzone { } public void initializeZone(Player respawnExempted) { - if (this.ready() && this.volume.isSaved()){ + if (this.ready() && this.volume.isSaved()) { // everyone back to team spawn with full health for (Team team : this.teams) { for (Player player : team.getPlayers()) { if (player != respawnExempted) { - this.respawnPlayer(team, player); + this.respawnPlayer(team, player); } } team.setRemainingLives(this.lifePool); team.initializeTeamSpawn(); - if (team.getTeamFlag() != null) - { - team.setTeamFlag(team.getTeamFlag()); - //team.resetSign(); + if (team.getTeamFlag() != null) { + team.setTeamFlag(team.getTeamFlag()); + // team.resetSign(); } } @@ -184,7 +184,6 @@ public class Warzone { } } - public void initializeZoneAsJob(Player respawnExempted) { InitZoneJob job = new InitZoneJob(this, respawnExempted); this.war.getServer().getScheduler().scheduleSyncDelayedTask(this.war, job); @@ -224,10 +223,10 @@ public class Warzone { this.handleRespawn(team, player); // Teleport the player back to spawn event.setTo(team.getTeamSpawn()); - //player.teleport(team.getTeamSpawn()); + // player.teleport(team.getTeamSpawn()); } - private void handleRespawn(Team team, Player player){ + private void handleRespawn(Team team, Player player) { // Fill hp player.setFireTicks(0); player.setRemainingAir(300); @@ -244,7 +243,7 @@ public class Warzone { playerInv.clear(playerInv.getSize() + 0); playerInv.clear(playerInv.getSize() + 1); playerInv.clear(playerInv.getSize() + 2); - playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead + playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead for (Integer slot : this.loadout.keySet()) { if (slot == 100) { playerInv.setBoots(this.loadout.get(slot)); @@ -260,7 +259,7 @@ public class Warzone { } } if (this.isBlockHeads()) { - playerInv.setHelmet(new ItemStack(team.getKind().getMaterial(), 1, (short)1, new Byte(team.getKind().getData()))); + playerInv.setHelmet(new ItemStack(team.getKind().getMaterial(), 1, (short) 1, new Byte(team.getKind().getData()))); } else { if (team.getKind() == TeamKinds.teamKindFromString("gold")) { playerInv.setHelmet(new ItemStack(Material.GOLD_HELMET)); @@ -280,7 +279,7 @@ public class Warzone { int y = monument.getLocation().getBlockY() + 1; int z = monument.getLocation().getBlockZ(); if (x == block.getX() && y == block.getY() && z == block.getZ()) { - return true; + return true; } } return false; @@ -292,7 +291,7 @@ public class Warzone { int y = monument.getLocation().getBlockY() + 1; int z = monument.getLocation().getBlockZ(); if (x == block.getX() && y == block.getY() && z == block.getZ()) { - return monument; + return monument; } } return null; @@ -301,7 +300,7 @@ public class Warzone { public boolean nearAnyOwnedMonument(Location to, Team team) { for (Monument monument : this.monuments) { if (monument.isNear(to) && monument.isOwner(team)) { - return true; + return true; } } return false; @@ -359,8 +358,7 @@ public class Warzone { public void keepPlayerInventory(Player player) { PlayerInventory inventory = player.getInventory(); ItemStack[] contents = inventory.getContents(); - this.inventories.put(player.getName(), new InventoryStash(contents, inventory.getHelmet(), inventory.getChestplate(), - inventory.getLeggings(), inventory.getBoots())); + this.inventories.put(player.getName(), new InventoryStash(contents, inventory.getHelmet(), inventory.getChestplate(), inventory.getLeggings(), inventory.getBoots())); } public void restorePlayerInventory(Player player) { @@ -371,13 +369,12 @@ public class Warzone { } } - private void playerInvFromInventoryStash(PlayerInventory playerInv, - InventoryStash originalContents) { + private void playerInvFromInventoryStash(PlayerInventory playerInv, InventoryStash originalContents) { playerInv.clear(); playerInv.clear(playerInv.getSize() + 0); playerInv.clear(playerInv.getSize() + 1); playerInv.clear(playerInv.getSize() + 2); - playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead + playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead for (ItemStack item : originalContents.getContents()) { if (item != null && item.getTypeId() != 0) { playerInv.addItem(item); @@ -399,24 +396,24 @@ public class Warzone { public InventoryStash getPlayerInventory(String playerName) { if (this.inventories.containsKey(playerName)) { - return this.inventories.get(playerName); + return this.inventories.get(playerName); } return null; } public boolean hasMonument(String monumentName) { - for (Monument monument: this.monuments) { + for (Monument monument : this.monuments) { if (monument.getName().equals(monumentName)) { - return true; + return true; } } return false; } public Monument getMonument(String monumentName) { - for (Monument monument: this.monuments) { + for (Monument monument : this.monuments) { if (monument.getName().startsWith(monumentName)) { - return monument; + return monument; } } return null; @@ -426,19 +423,18 @@ public class Warzone { if (this.ready()) { for (Monument m : this.monuments) { if (m.getVolume().contains(block)) { - return true; + return true; } } for (Team t : this.teams) { if (t.getSpawnVolume().contains(block)) { - return true; - } else if (t.getFlagVolume() != null - && t.getFlagVolume().contains(block)) { - return true; + return true; + } else if (t.getFlagVolume() != null && t.getFlagVolume().contains(block)) { + return true; } } if (this.volume.isWallBlock(block)) { - return true; + return true; } } return false; @@ -464,7 +460,7 @@ public class Warzone { public Team getTeamByKind(TeamKind kind) { for (Team t : this.teams) { if (t.getKind() == kind) { - return t; + return t; } } return null; @@ -472,43 +468,18 @@ public class Warzone { public boolean isNearWall(Location latestPlayerLocation) { if (this.volume.hasTwoCorners()) { - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near east wall - } else if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near south wall - } else if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near north wall - } else if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { - return true; // near west wall - } else if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { - return true; // near up wall - } else if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) - { - return true; // near down wall + if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + return true; // near east wall + } else if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + return true; // near south wall + } else if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + return true; // near north wall + } else if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + return true; // near west wall + } else if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + return true; // near up wall + } else if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + return true; // near down wall } } return false; @@ -516,61 +487,37 @@ public class Warzone { public List getNearestWallBlocks(Location latestPlayerLocation) { List nearestWallBlocks = new ArrayList(); - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near east wall Block eastWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX() + 1, latestPlayerLocation.getBlockY() + 1, this.volume.getSoutheastZ()); nearestWallBlocks.add(eastWallBlock); } - if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near south wall Block southWallBlock = this.world.getBlockAt(this.volume.getSoutheastX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ()); nearestWallBlocks.add(southWallBlock); } - if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near north wall Block northWallBlock = this.world.getBlockAt(this.volume.getNorthwestX(), latestPlayerLocation.getBlockY() + 1, latestPlayerLocation.getBlockZ()); nearestWallBlocks.add(northWallBlock); } - if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near west wall Block westWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), latestPlayerLocation.getBlockY() + 1, this.volume.getNorthwestZ()); nearestWallBlocks.add(westWallBlock); } - if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { // near up wall Block upWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), this.volume.getMaxY(), latestPlayerLocation.getBlockZ()); nearestWallBlocks.add(upWallBlock); } - if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { // near down wall Block downWallBlock = this.world.getBlockAt(latestPlayerLocation.getBlockX(), this.volume.getMinY(), latestPlayerLocation.getBlockZ()); nearestWallBlocks.add(downWallBlock); @@ -581,56 +528,32 @@ public class Warzone { public List getNearestWalls(Location latestPlayerLocation) { List walls = new ArrayList(); - if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getSoutheastZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near east wall walls.add(BlockFace.EAST); } - if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getSoutheastX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near south wall walls.add(BlockFace.SOUTH); } - if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getNorthwestX() - latestPlayerLocation.getBlockX()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockZ() <= this.volume.getNorthwestZ() && latestPlayerLocation.getBlockZ() >= this.volume.getSoutheastZ() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near north wall walls.add(BlockFace.NORTH); } - if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() - && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() - && latestPlayerLocation.getBlockY() >= this.volume.getMinY() - && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { + if (Math.abs(this.volume.getNorthwestZ() - latestPlayerLocation.getBlockZ()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getSoutheastX() && latestPlayerLocation.getBlockX() >= this.volume.getNorthwestX() && latestPlayerLocation.getBlockY() >= this.volume.getMinY() && latestPlayerLocation.getBlockY() <= this.volume.getMaxY()) { // near west wall walls.add(BlockFace.WEST); } - if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + if (Math.abs(this.volume.getMaxY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { // near up wall walls.add(BlockFace.UP); } - if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall - && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() - && latestPlayerLocation.getBlockX() >= this.volume.getMinX() - && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() - && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { + if (Math.abs(this.volume.getMinY() - latestPlayerLocation.getBlockY()) < this.minSafeDistanceFromWall && latestPlayerLocation.getBlockX() <= this.volume.getMaxX() && latestPlayerLocation.getBlockX() >= this.volume.getMinX() && latestPlayerLocation.getBlockZ() <= this.volume.getMaxZ() && latestPlayerLocation.getBlockZ() >= this.volume.getMinZ()) { // near down wall walls.add(BlockFace.DOWN); } @@ -640,7 +563,7 @@ public class Warzone { public ZoneWallGuard getPlayerZoneWallGuard(String name, BlockFace wall) { for (ZoneWallGuard guard : this.zoneWallGuards) { if (guard.getPlayer().getName().equals(name) && wall == guard.getWall()) { - return guard; + return guard; } } return null; @@ -667,19 +590,19 @@ public class Warzone { public void dropZoneWallGuardIfAny(Player player) { List playerGuards = new ArrayList(); for (ZoneWallGuard guard : this.zoneWallGuards) { - if (guard.getPlayer().getName().equals(player.getName())){ + if (guard.getPlayer().getName().equals(player.getName())) { playerGuards.add(guard); guard.deactivate(); -// BlockFace guardWall = guard.getWall(); -// getVolume().resetWallBlocks(guardWall); -// if (isDrawZoneOutline()) { -// addZoneOutline(guard.getWall()); -// } -// if (lobby != null) { -// lobby.getVolume().resetBlocks(); // always reset the lobby even if the guard is on another wall -// // because player can go around corner -// lobby.initialize(); -// } + // BlockFace guardWall = guard.getWall(); + // getVolume().resetWallBlocks(guardWall); + // if (isDrawZoneOutline()) { + // addZoneOutline(guard.getWall()); + // } + // if (lobby != null) { + // lobby.getVolume().resetBlocks(); // always reset the lobby even if the guard is on another wall + // // because player can go around corner + // lobby.initialize(); + // } } } // now remove those zone guards @@ -704,8 +627,7 @@ public class Warzone { public Team autoAssign(Player player) { Team lowestNoOfPlayers = null; for (Team t : this.teams) { - if (lowestNoOfPlayers == null - || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) { + if (lowestNoOfPlayers == null || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) { lowestNoOfPlayers = t; } } @@ -717,7 +639,7 @@ public class Warzone { } this.war.msg(player, "Your inventory is in storage until you /leave."); this.respawnPlayer(lowestNoOfPlayers, player); - for (Team team : this.teams){ + for (Team team : this.teams) { team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); } } @@ -760,8 +682,7 @@ public class Warzone { List teams = playerWarzone.getTeams(); String scores = ""; for (Team t : teams) { - t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: " - + player.getName() + " died and there were no lives left in their life pool."); + t.teamcast("The battle is over. Team " + playerTeam.getName() + " lost: " + player.getName() + " died and there were no lives left in their life pool."); if (t.getPlayers().size() != 0) { if (!t.getName().equals(playerTeam.getName())) { @@ -769,12 +690,12 @@ public class Warzone { t.addPoint(); t.resetSign(); } - scores += t.getName() + "(" + t.getPoints() + ") " ; + scores += t.getName() + "(" + t.getPoints() + ") "; } } - if (!scores.equals("")){ + if (!scores.equals("")) { for (Team t : teams) { - t.teamcast("New scores - " + scores + " (/" + this.getScoreCap() + ")" ); + t.teamcast("New scores - " + scores + " (/" + this.getScoreCap() + ")"); } } // detect score cap @@ -788,12 +709,12 @@ public class Warzone { String winnersStr = ""; for (Team winner : scoreCapTeams) { if (winner.getPlayers().size() != 0) { - winnersStr += winner.getName() + " "; + winnersStr += winner.getName() + " "; } } playerWarzone.handleScoreCapReached(player, winnersStr); - //player.teleport(playerWarzone.getTeleport()); + // player.teleport(playerWarzone.getTeleport()); // player will die because it took too long :( // we dont restore his inventory in handleScoreCapReached // check out PLAYER_MOVE for the rest of the fix @@ -845,9 +766,9 @@ public class Warzone { private void handlePlayerLeave(Player player, boolean removeFromTeam) { Team playerTeam = this.war.getPlayerTeam(player.getName()); - if (playerTeam !=null) { + if (playerTeam != null) { if (removeFromTeam) { - playerTeam.removePlayer(player.getName()); + playerTeam.removePlayer(player.getName()); } for (Team t : this.getTeams()) { t.teamcast(player.getName() + " left the zone."); @@ -899,9 +820,8 @@ public class Warzone { public boolean isEnemyTeamFlagBlock(Team playerTeam, Block block) { for (Team team : this.teams) { - if (!team.getName().equals(playerTeam.getName()) - && team.isTeamFlagBlock(block)) { - return true; + if (!team.getName().equals(playerTeam.getName()) && team.isTeamFlagBlock(block)) { + return true; } } return false; @@ -910,7 +830,7 @@ public class Warzone { public Team getTeamForFlagBlock(Block block) { for (Team team : this.teams) { if (team.isTeamFlagBlock(block)) { - return team; + return team; } } return null; @@ -922,7 +842,7 @@ public class Warzone { public boolean isFlagThief(String suspect) { if (this.flagThieves.containsKey(suspect)) { - return true; + return true; } return false; } @@ -942,7 +862,7 @@ public class Warzone { public boolean isTeamFlagStolen(Team team) { for (String playerKey : this.flagThieves.keySet()) { if (this.flagThieves.get(playerKey).getName().equals(team.getName())) { - return true; + return true; } } return false; @@ -1023,7 +943,7 @@ public class Warzone { public boolean isDeadMan(String playerName) { if (this.deadMenInventories.containsKey(playerName)) { - return true; + return true; } return false; } @@ -1052,8 +972,7 @@ public class Warzone { } team.getPlayers().clear(); } - if (this.getLobby() != null) - { + if (this.getLobby() != null) { this.getLobby().getVolume().resetBlocks(); this.getLobby().getVolume().finalize(); } diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index fa069a4..10ac7b7 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -17,16 +17,16 @@ import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.ZoneVolume; /** - * + * * @author tommytony - * + * */ public class ZoneLobby { private final War war; private final Warzone warzone; private BlockFace wall; private Volume volume; - BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor + BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor BlockInfo warHubLinkGate = null; @@ -41,9 +41,11 @@ public class ZoneLobby { /** * Use this constructor with /setzonelobby + * * @param war * @param warzone - * @param wall On which wall of the warzone will the lobby be stuck to at mid-weight + * @param wall + * On which wall of the warzone will the lobby be stuck to at mid-weight */ public ZoneLobby(War war, Warzone warzone, BlockFace wall) { this.war = war; @@ -57,11 +59,12 @@ public class ZoneLobby { } /** - * Use this constructor with /setzonelobby . - * Makes sure the lobby is not sticking inside the zone. + * Use this constructor with /setzonelobby . Makes sure the lobby is not sticking inside the zone. + * * @param war * @param warzone - * @param wall On which wall of the warzone will the lobby be stuck to at mid-weight + * @param wall + * On which wall of the warzone will the lobby be stuck to at mid-weight */ public ZoneLobby(War war, Warzone warzone, Location playerLocation) { this.war = war; @@ -74,11 +77,8 @@ public class ZoneLobby { this.setLocation(playerLocation); } - /** - * Convenience ctor when loading form disk. - * This figures out the middle wall block of the lobby from the volume instead - * of the other way around. + * Convenience ctor when loading form disk. This figures out the middle wall block of the lobby from the volume instead of the other way around. */ public ZoneLobby(War war, Warzone warzone, BlockFace wall, Volume volume) { this.war = war; @@ -94,18 +94,18 @@ public class ZoneLobby { // we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own if (wall == BlockFace.NORTH) { this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.EAST, this.lobbyHalfSide)); - } else if (wall == BlockFace.EAST){ + } else if (wall == BlockFace.EAST) { this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.SOUTH, this.lobbyHalfSide)); - } else if (wall == BlockFace.SOUTH){ - this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.WEST, this.lobbyHalfSide)); - } else if (wall == BlockFace.WEST){ + } else if (wall == BlockFace.SOUTH) { + this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.WEST, this.lobbyHalfSide)); + } else if (wall == BlockFace.WEST) { this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getFace(BlockFace.UP).getFace(BlockFace.NORTH, this.lobbyHalfSide)); } } /** - * Changes the lobby's position. Orientation is determined from the player location. - * Creates volume or resets. Saves new lobby blocks. + * Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks. + * * @param playerLocation */ public void setLocation(Location playerLocation) { @@ -113,10 +113,10 @@ public class ZoneLobby { // Lobby orientation int yaw = 0; - if (playerLocation.getYaw() >= 0){ - yaw = (int)(playerLocation.getYaw() % 360); + if (playerLocation.getYaw() >= 0) { + yaw = (int) (playerLocation.getYaw() % 360); } else { - yaw = (int)(360 + (playerLocation.getYaw() % 360)); + yaw = (int) (360 + (playerLocation.getYaw() % 360)); } BlockFace facing = null; BlockFace opposite = null; @@ -134,27 +134,24 @@ public class ZoneLobby { opposite = BlockFace.NORTH; } -// float yaw = playerLocation.getYaw() % 360; -// if (yaw >= 45 && yaw < 135) { -// facing = BlockFace.NORTH; -// opposite = BlockFace.SOUTH; -// } else if (yaw >= 135 && yaw < 225) { -// facing = BlockFace.EAST; -// opposite = BlockFace.WEST; -// } else if (yaw >= 225 && yaw < 315) { -// facing = BlockFace.SOUTH; -// opposite = BlockFace.NORTH; -// } else if (yaw >= 315 || yaw < 45) { -// facing = BlockFace.WEST; -// opposite = BlockFace.EAST; -// } - this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall + // float yaw = playerLocation.getYaw() % 360; + // if (yaw >= 45 && yaw < 135) { + // facing = BlockFace.NORTH; + // opposite = BlockFace.SOUTH; + // } else if (yaw >= 135 && yaw < 225) { + // facing = BlockFace.EAST; + // opposite = BlockFace.WEST; + // } else if (yaw >= 225 && yaw < 315) { + // facing = BlockFace.SOUTH; + // opposite = BlockFace.NORTH; + // } else if (yaw >= 315 || yaw < 45) { + // facing = BlockFace.WEST; + // opposite = BlockFace.EAST; + // } + this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall this.calculateLobbyWidth(); - this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(playerLocation.getBlockX(), - playerLocation.getBlockY(), - playerLocation.getBlockZ()) - .getFace(facing, 6)); + this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getFace(facing, 6)); Block corner1 = null; Block corner2 = null; @@ -163,16 +160,16 @@ public class ZoneLobby { int z = this.lobbyMiddleWallBlock.getZ(); if (this.wall == BlockFace.NORTH) { - //lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(x, y, wallCenterPos)); + // lobbyMiddleWallBlock = new BlockInfo(warzone.getWorld().getBlockAt(x, y, wallCenterPos)); corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, z + this.lobbyHalfSide); corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, z - this.lobbyHalfSide); - } else if (this.wall == BlockFace.EAST){ + } else if (this.wall == BlockFace.EAST) { corner1 = this.warzone.getWorld().getBlockAt(x - this.lobbyHalfSide, y - 1, z); corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth); - } else if (this.wall == BlockFace.SOUTH){ - corner1 = this.warzone.getWorld().getBlockAt(x, y -1 , z - this.lobbyHalfSide); + } else if (this.wall == BlockFace.SOUTH) { + corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, z - this.lobbyHalfSide); corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, z + this.lobbyHalfSide); - } else if (this.wall == BlockFace.WEST){ + } else if (this.wall == BlockFace.WEST) { corner1 = this.warzone.getWorld().getBlockAt(x + this.lobbyHalfSide, y - 1, z); corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth); } @@ -181,8 +178,8 @@ public class ZoneLobby { } /** - * Classic way of creating a lobby. Lobby position goes to middle of zone wall. - * Creates volume or resets. Saves new lobby blocks. + * Classic way of creating a lobby. Lobby position goes to middle of zone wall. Creates volume or resets. Saves new lobby blocks. + * * @param newWall */ public void setWall(BlockFace newWall) { @@ -205,7 +202,7 @@ public class ZoneLobby { this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos)); corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide); corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide); - } else if (this.wall == BlockFace.EAST){ + } else if (this.wall == BlockFace.EAST) { int wallStart = zoneVolume.getMinX(); int wallEnd = zoneVolume.getMaxX(); int z = zoneVolume.getMinZ(); @@ -214,20 +211,18 @@ public class ZoneLobby { int y = zoneVolume.getCenterY(); this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z)); corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z); - corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, - y + 1 + this.lobbyHeight, z - this.lobbyDepth); - } else if (this.wall == BlockFace.SOUTH){ - int wallStart = zoneVolume.getMinZ(); + corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth); + } else if (this.wall == BlockFace.SOUTH) { + int wallStart = zoneVolume.getMinZ(); int wallEnd = zoneVolume.getMaxZ(); int x = zoneVolume.getMaxX(); int wallLength = wallEnd - wallStart + 1; int wallCenterPos = wallStart + wallLength / 2; int y = zoneVolume.getCenterY(); this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos)); - corner1 = this.warzone.getWorld().getBlockAt(x, y -1 , wallCenterPos - this.lobbyHalfSide); - corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, - y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide); - } else if (this.wall == BlockFace.WEST){ + corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide); + corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide); + } else if (this.wall == BlockFace.WEST) { int wallStart = zoneVolume.getMinX(); int wallEnd = zoneVolume.getMaxX(); int z = zoneVolume.getMaxZ(); @@ -270,12 +265,12 @@ public class ZoneLobby { public void initialize() { // maybe the number of teams change, now reset the gate positions - if (this.lobbyMiddleWallBlock != null && this.volume != null /*&& volume.isSaved()*/) { + if (this.lobbyMiddleWallBlock != null && this.volume != null /* && volume.isSaved() */) { this.setGatePositions(BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock)); // flatten the area (set all but floor to air, then replace any floor air blocks with glass) this.volume.clearBlocksThatDontFloat(); this.volume.setToMaterial(Material.AIR); - this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful + this.volume.setFaceMaterial(BlockFace.DOWN, Material.GLASS); // beautiful // add war hub link gate if (this.war.getWarHub() != null) { @@ -318,13 +313,13 @@ public class ZoneLobby { Block zoneSignBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getFace(this.wall, 4); byte data = 0; if (this.wall == BlockFace.NORTH) { - data = (byte)4; + data = (byte) 4; } else if (this.wall == BlockFace.EAST) { - data = (byte)8; + data = (byte) 8; } else if (this.wall == BlockFace.SOUTH) { - data = (byte)12; + data = (byte) 12; } else if (this.wall == BlockFace.WEST) { - data = (byte)0; + data = (byte) 0; } String[] lines = new String[4]; lines[0] = "Warzone"; @@ -352,7 +347,7 @@ public class ZoneLobby { } private void setGatePositions(Block lobbyMiddleWallBlock) { - BlockFace leftSide = null; // look at the zone + BlockFace leftSide = null; // look at the zone BlockFace rightSide = null; if (this.wall == BlockFace.NORTH) { leftSide = BlockFace.EAST; @@ -368,7 +363,7 @@ public class ZoneLobby { rightSide = BlockFace.SOUTH; } this.teamGateBlocks.clear(); - if (this.warzone.getAutoAssignOnly()){ + if (this.warzone.getAutoAssignOnly()) { this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock); } else { this.autoAssignGate = null; @@ -386,8 +381,7 @@ public class ZoneLobby { } else { if (doorIndex == 0) { this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock)); - } - else if (doorIndex % 2 == 0) { + } else if (doorIndex % 2 == 0) { this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(rightSide, doorIndex * 2))); } else { this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getFace(leftSide, doorIndex * 2 + 2))); @@ -398,10 +392,9 @@ public class ZoneLobby { this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getFace(this.wall, 9)); } - private void placeGate(Block block, - TeamKind teamKind) { + private void placeGate(Block block, TeamKind teamKind) { if (block != null) { - BlockFace leftSide = null; // look at the zone + BlockFace leftSide = null; // look at the zone BlockFace rightSide = null; if (this.wall == BlockFace.NORTH) { leftSide = BlockFace.EAST; @@ -427,10 +420,9 @@ public class ZoneLobby { } } - private void placeGate(Block block, - Material material) { + private void placeGate(Block block, Material material) { if (block != null) { - BlockFace leftSide = null; // look at the zone + BlockFace leftSide = null; // look at the zone BlockFace rightSide = null; if (this.wall == BlockFace.NORTH) { leftSide = BlockFace.EAST; @@ -467,7 +459,7 @@ public class ZoneLobby { private void placeAutoAssignGate() { if (this.autoAssignGate != null) { - BlockFace leftSide = null; // look at the zone + BlockFace leftSide = null; // look at the zone BlockFace rightSide = null; if (this.wall == BlockFace.NORTH) { leftSide = BlockFace.EAST; @@ -489,74 +481,69 @@ public class ZoneLobby { int index = 0; TeamKind kind = null; if (index >= size) { - kind = TeamKinds.teamKindFromString("diamond"); + kind = TeamKinds.teamKindFromString("diamond"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(leftSide), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("iron"); + kind = TeamKinds.teamKindFromString("iron"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(leftSide).getFace(BlockFace.UP), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("gold"); + kind = TeamKinds.teamKindFromString("gold"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(leftSide).getFace(BlockFace.UP).getFace(BlockFace.UP), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("diamond"); + kind = TeamKinds.teamKindFromString("diamond"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(BlockFace.UP).getFace(BlockFace.UP), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("iron"); + kind = TeamKinds.teamKindFromString("iron"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(rightSide).getFace(BlockFace.UP).getFace(BlockFace.UP), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("gold"); + kind = TeamKinds.teamKindFromString("gold"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(rightSide).getFace(BlockFace.UP), kind); index++; if (index >= size) { - kind = TeamKinds.teamKindFromString("diamond"); + kind = TeamKinds.teamKindFromString("diamond"); } else { - kind = teams.get(index).getKind(); + kind = teams.get(index).getKind(); } this.setBlock(autoAssignGateBlock.getFace(rightSide), kind); } } public boolean isInTeamGate(Team team, Location location) { - BlockInfo info = this.teamGateBlocks.get(team.getName()); - if (info != null) { - if (location.getBlockX() == info.getX() - && location.getBlockY() == info.getY() - && location.getBlockZ() == info.getZ()) { - return true; + BlockInfo info = this.teamGateBlocks.get(team.getName()); + if (info != null) { + if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) { + return true; } - } + } return false; } public boolean isAutoAssignGate(Location location) { - if (this.autoAssignGate != null - && (location.getBlockX() == this.autoAssignGate.getX() - && location.getBlockY() == this.autoAssignGate.getY() - && location.getBlockZ() == this.autoAssignGate.getZ()) ) { - return true; + if (this.autoAssignGate != null && (location.getBlockX() == this.autoAssignGate.getX() && location.getBlockY() == this.autoAssignGate.getY() && location.getBlockZ() == this.autoAssignGate.getZ())) { + return true; } return false; } @@ -569,32 +556,28 @@ public class ZoneLobby { this.volume = volume; } - public BlockFace getWall() { return this.wall; } public boolean isInWarHubLinkGate(Location location) { - if (this.warHubLinkGate != null - && location.getBlockX() == this.warHubLinkGate.getX() - && location.getBlockY() == this.warHubLinkGate.getY() - && location.getBlockZ() == this.warHubLinkGate.getZ()) { - return true; + if (this.warHubLinkGate != null && location.getBlockX() == this.warHubLinkGate.getX() && location.getBlockY() == this.warHubLinkGate.getY() && location.getBlockZ() == this.warHubLinkGate.getZ()) { + return true; } return false; } public boolean blockIsAGateBlock(Block block, BlockFace blockWall) { if (blockWall == this.wall) { - for (String teamName: this.teamGateBlocks.keySet()) { + for (String teamName : this.teamGateBlocks.keySet()) { BlockInfo gateInfo = this.teamGateBlocks.get(teamName); if (this.isPartOfGate(BlockInfo.getBlock(this.warzone.getWorld(), gateInfo), block)) { - return true; + return true; } } if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.warzone.getWorld(), this.autoAssignGate), block)) { - // auto assign - return true; + // auto assign + return true; } } return false; @@ -602,7 +585,7 @@ public class ZoneLobby { private boolean isPartOfGate(Block gateBlock, Block block) { if (gateBlock != null) { - BlockFace leftSide = null; // look at the zone + BlockFace leftSide = null; // look at the zone BlockFace rightSide = null; if (this.wall == BlockFace.NORTH) { leftSide = BlockFace.EAST; @@ -617,46 +600,7 @@ public class ZoneLobby { 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()) - || - (block.getX() == gateBlock.getX() - && block.getY() == gateBlock.getY() - 1 - && block.getZ() == gateBlock.getZ()) - ; + 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()) || (block.getX() == gateBlock.getX() && block.getY() == gateBlock.getY() - 1 && block.getZ() == gateBlock.getZ()); } return false; } @@ -675,7 +619,7 @@ public class ZoneLobby { private void resetTeamGateSign(Team team, Block gate) { if (gate != null) { String[] lines = new String[4]; - lines[0] = "Team " + team.getName(); + lines[0] = "Team " + team.getName(); lines[1] = team.getPlayers().size() + "/" + this.warzone.getTeamCap() + " players"; lines[2] = team.getPoints() + "/" + this.warzone.getScoreCap() + " pts"; if (this.warzone.getLifePool() == -1) { @@ -705,30 +649,30 @@ public class ZoneLobby { if (this.wall == BlockFace.NORTH) { block = gate.getFace(direction).getFace(BlockFace.EAST); if (awayFromWall) { - data = (byte)4; + data = (byte) 4; } else { - data = (byte)12; + data = (byte) 12; } } else if (this.wall == BlockFace.EAST) { block = gate.getFace(direction).getFace(BlockFace.SOUTH); if (awayFromWall) { - data = (byte)8; + data = (byte) 8; } else { - data = (byte)0; + data = (byte) 0; } } else if (this.wall == BlockFace.SOUTH) { block = gate.getFace(direction).getFace(BlockFace.WEST); if (awayFromWall) { - data = (byte)12; + data = (byte) 12; } else { - data = (byte)4; + data = (byte) 4; } } else if (this.wall == BlockFace.WEST) { block = gate.getFace(direction).getFace(BlockFace.NORTH); if (awayFromWall) { - data = (byte)0; + data = (byte) 0; } else { - data = (byte)8; + data = (byte) 8; } } @@ -757,66 +701,65 @@ public class ZoneLobby { left = BlockFace.SOUTH; right = BlockFace.NORTH; } - if (this.autoAssignGate != null){ + if (this.autoAssignGate != null) { if (this.leaving(location, BlockInfo.getBlock(this.warzone.getWorld(), this.autoAssignGate), inside, left, right)) { - return true; + return true; } } for (String teamName : this.teamGateBlocks.keySet()) { BlockInfo info = this.teamGateBlocks.get(teamName); if (this.leaving(location, BlockInfo.getBlock(this.warzone.getWorld(), info), inside, left, right)) { - return true; + return true; } } return false; } - private boolean leaving(Location location, Block gate, BlockFace inside, - BlockFace left, BlockFace right) { -// int x = location.getBlockX(); -// int y = location.getBlockY(); -// int z = location.getBlockZ(); -// + private boolean leaving(Location location, Block gate, BlockFace inside, BlockFace left, BlockFace right) { + // int x = location.getBlockX(); + // int y = location.getBlockY(); + // int z = location.getBlockZ(); + // // 3x4x1 deep - Volume gateExitVolume = new Volume("tempGateExit", this.war, location.getWorld()); + Volume gateExitVolume = new Volume("tempGateExit", this.war, location.getWorld()); Block out = gate.getFace(inside); gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN)); gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3)); if (gateExitVolume.contains(location)) { - return true; + return true; } // 1 block thick arrow like detection grid: -// Block out = gate.getFace(inside); -// Block outL = out.getFace(left); -// Block outLL = out.getFace(left, 2); -// Block outR = out.getFace(right); -// Block outRR = out.getFace(right, 2); -// Block out2 = gate.getFace(inside, 2); -// Block out2L = out2.getFace(left); -// Block out2R = out2.getFace(right); -// Block out3 = gate.getFace(inside, 3); -// if (out.getX() == x && out.getY() == y && out.getZ() == z) { -// return true; -// } else if (outL.getX() == x && outL.getY() == y && outL.getZ() == z) { -// return true; -// } else if (outR.getX() == x && outR.getY() == y && outR.getZ() == z) { -// return true; -// } else if (outLL.getX() == x && outLL.getY() == y && outLL.getZ() == z) { -// return true; -// } else if (outRR.getX() == x && outRR.getY() == y && outRR.getZ() == z) { -// return true; -// } else if (out2.getX() == x && out2.getY() == y && out2.getZ() == z) { -// return true; -// } else if (out2L.getX() == x && out2L.getY() == y && out2L.getZ() == z) { -// return true; -// } else if (out2R.getX() == x && out2R.getY() == y && out2R.getZ() == z) { -// return true; -// } else if (out3.getX() == x && out3.getY() == y && out3.getZ() == z) { -// return true; -// } + // Block out = gate.getFace(inside); + // Block outL = out.getFace(left); + // Block outLL = out.getFace(left, 2); + // Block outR = out.getFace(right); + // Block outRR = out.getFace(right, 2); + // Block out2 = gate.getFace(inside, 2); + // Block out2L = out2.getFace(left); + // Block out2R = out2.getFace(right); + // Block out3 = gate.getFace(inside, 3); + // if (out.getX() == x && out.getY() == y && out.getZ() == z) { + // return true; + // } else if (outL.getX() == x && outL.getY() == y && outL.getZ() == z) { + // return true; + // } else if (outR.getX() == x && outR.getY() == y && outR.getZ() == z) { + // return true; + // } else if (outLL.getX() == x && outLL.getY() == y && outLL.getZ() == z) { + // return true; + // } else if (outRR.getX() == x && outRR.getY() == y && outRR.getZ() == z) { + // return true; + // } else if (out2.getX() == x && out2.getY() == y && out2.getZ() == z) { + // return true; + // } else if (out2L.getX() == x && out2L.getY() == y && out2L.getZ() == z) { + // return true; + // } else if (out2R.getX() == x && out2R.getY() == y && out2R.getZ() == z) { + // return true; + // } else if (out3.getX() == x && out3.getY() == y && out3.getZ() == z) { + // return true; + // } return false; } } diff --git a/war/src/main/java/com/tommytony/war/ZoneSetter.java b/war/src/main/java/com/tommytony/war/ZoneSetter.java index 95f8585..177aa11 100644 --- a/war/src/main/java/com/tommytony/war/ZoneSetter.java +++ b/war/src/main/java/com/tommytony/war/ZoneSetter.java @@ -29,38 +29,34 @@ public class ZoneSetter { Warzone warzone = this.war.findWarzone(this.zoneName); Block northwestBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); StringBuilder msgString = new StringBuilder(); - try - { + try { if (warzone == null) { // create the warzone warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName); this.war.getIncompleteZones().add(warzone); warzone.getVolume().setNorthwest(northwestBlock); - this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" - + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); + this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); } else { // change existing warzone this.resetWarzone(warzone, msgString); warzone.getVolume().setNorthwest(northwestBlock); - msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" - + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); + msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". "); } this.saveIfReady(warzone, msgString); } catch (NotNorthwestException e) { this.war.badMsg(this.player, "The block you selected is not to the northwest of the existing southeasternmost block."); - if (warzone.getVolume().isSaved()) - { - warzone.initializeZone(); // was reset before changing + if (warzone.getVolume().isSaved()) { + warzone.initializeZone(); // was reset before changing } } catch (TooSmallException e) { this.handleTooSmall(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } catch (TooBigException e) { this.handleTooBig(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } } @@ -69,38 +65,34 @@ public class ZoneSetter { Warzone warzone = this.war.findWarzone(this.zoneName); Block southeastBlock = this.player.getLocation().getWorld().getBlockAt(this.player.getLocation()); StringBuilder msgString = new StringBuilder(); - try - { + try { if (warzone == null) { // create the warzone warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName); this.war.getIncompleteZones().add(warzone); warzone.getVolume().setSoutheast(southeastBlock); - this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" - + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); + this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); } else { // change existing warzone this.resetWarzone(warzone, msgString); warzone.getVolume().setSoutheast(southeastBlock); - msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" - + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); + msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". "); } this.saveIfReady(warzone, msgString); } catch (NotSoutheastException e) { this.war.badMsg(this.player, "The block you selected is not to the southeast of the existing northwestnmost block."); - if (warzone.getVolume().isSaved()) - { - warzone.initializeZone(); // was reset before changing + if (warzone.getVolume().isSaved()) { + warzone.initializeZone(); // was reset before changing } } catch (TooSmallException e) { this.handleTooSmall(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } catch (TooBigException e) { this.handleTooBig(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } } @@ -113,32 +105,29 @@ public class ZoneSetter { public void placeCorner1(Block corner1Block) { Warzone warzone = this.war.findWarzone(this.zoneName); StringBuilder msgString = new StringBuilder(); - try - { + try { if (warzone == null) { // create the warzone warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName); this.war.getIncompleteZones().add(warzone); warzone.getVolume().setZoneCornerOne(corner1Block); - this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" - + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); + this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); } else { // change existing warzone this.resetWarzone(warzone, msgString); warzone.getVolume().setZoneCornerOne(corner1Block); - msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" - + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); + msgString.append("Warzone " + warzone.getName() + " modified. Corner 1 set to x:" + corner1Block.getX() + " y:" + corner1Block.getY() + " z:" + corner1Block.getZ() + ". "); } this.saveIfReady(warzone, msgString); } catch (TooSmallException e) { this.handleTooSmall(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } catch (TooBigException e) { this.handleTooBig(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } } @@ -151,32 +140,29 @@ public class ZoneSetter { public void placeCorner2(Block corner2Block) { Warzone warzone = this.war.findWarzone(this.zoneName); StringBuilder msgString = new StringBuilder(); - try - { + try { if (warzone == null) { // create the warzone warzone = new Warzone(this.war, this.player.getLocation().getWorld(), this.zoneName); this.war.getIncompleteZones().add(warzone); warzone.getVolume().setZoneCornerTwo(corner2Block); - this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" - + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); + this.war.msg(this.player, "Warzone " + warzone.getName() + " created. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); } else { // change existing warzone this.resetWarzone(warzone, msgString); warzone.getVolume().setZoneCornerTwo(corner2Block); - msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" - + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); + msgString.append("Warzone " + warzone.getName() + " modified. Corner 2 set to x:" + corner2Block.getX() + " y:" + corner2Block.getY() + " z:" + corner2Block.getZ() + ". "); } this.saveIfReady(warzone, msgString); } catch (TooSmallException e) { this.handleTooSmall(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } catch (TooBigException e) { this.handleTooBig(); if (warzone.getVolume().isSaved()) { - warzone.initializeZone(); + warzone.initializeZone(); } } } @@ -216,15 +202,15 @@ public class ZoneSetter { // Set default lobby on south side ZoneLobby lobby = new ZoneLobby(this.war, warzone, BlockFace.SOUTH); warzone.setLobby(lobby); - if (this.war.getWarHub() != null) { // warhub has to change + if (this.war.getWarHub() != null) { // warhub has to change this.war.getWarHub().getVolume().resetBlocks(); this.war.getWarHub().initialize(); } this.war.msg(this.player, "Default lobby created on south side of zone. Use /setzonelobby to change its position."); - } //else { + } // else { // gotta move the lobby (or dont because zone.initzon does it for you) - //warzone.getLobby().changeWall(warzone.getLobby().getWall()); - //} + // warzone.getLobby().changeWall(warzone.getLobby().getWall()); + // } warzone.initializeZone(); WarzoneMapper.save(this.war, warzone, true); this.war.msg(this.player, "Warzone saved."); diff --git a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java index 76f09d0..2f7033a 100644 --- a/war/src/main/java/com/tommytony/war/ZoneWallGuard.java +++ b/war/src/main/java/com/tommytony/war/ZoneWallGuard.java @@ -14,9 +14,9 @@ import com.tommytony.war.volumes.BlockInfo; import bukkit.tommytony.war.War; /** - * + * * @author tommytony - * + * */ public class ZoneWallGuard { private Player player; @@ -162,8 +162,7 @@ public class ZoneWallGuard { private void glassify(Block block, BlockFace wall) { // face here means which wall we are working on - if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && - (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))){ + if ((block.getTypeId() == Material.AIR.getId() || block.getTypeId() == Material.WATER.getId()) && (this.warzone.getLobby() == null || (this.warzone.getLobby() != null && !this.warzone.getLobby().blockIsAGateBlock(block, wall)))) { if (wall == BlockFace.NORTH) { if (this.warzone.getVolume().isNorthWallBlock(block)) { this.glassified.add(new BlockInfo(block)); diff --git a/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java b/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java index 6ad6b84..f90f207 100644 --- a/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/DeferredBlockResetsJob.java @@ -29,7 +29,6 @@ public class DeferredBlockResetsJob implements Runnable { return this.deferred.isEmpty(); } - public void run() { for (DeferredBlockReset reset : this.deferred) { Block worldBlock = this.world.getBlockAt(reset.getX(), reset.getY(), reset.getZ()); @@ -39,20 +38,20 @@ public class DeferredBlockResetsJob implements Runnable { BlockState state = worldBlock.getState(); state.setData(new org.bukkit.material.Sign(reset.getBlockType(), reset.getBlockData())); if (state instanceof Sign) { - Sign sign = (Sign)state; - //String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k); + Sign sign = (Sign) state; + // String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k); if (reset.getLines() != null && sign.getLines() != null) { - if (reset.getLines().length>0) { - sign.setLine(0, reset.getLines()[0]); + if (reset.getLines().length > 0) { + sign.setLine(0, reset.getLines()[0]); } - if (reset.getLines().length>1) { - sign.setLine(1, reset.getLines()[1]); + if (reset.getLines().length > 1) { + sign.setLine(1, reset.getLines()[1]); } - if (reset.getLines().length>2) { - sign.setLine(2, reset.getLines()[2]); + if (reset.getLines().length > 2) { + sign.setLine(2, reset.getLines()[2]); } - if (reset.getLines().length>3) { - sign.setLine(3, reset.getLines()[3]); + if (reset.getLines().length > 3) { + sign.setLine(3, reset.getLines()[3]); } sign.update(true); } @@ -62,9 +61,6 @@ public class DeferredBlockResetsJob implements Runnable { worldBlock.setData(reset.getBlockData()); } - - - } } diff --git a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java index ae12613..11fd145 100644 --- a/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ResetCursorJob.java @@ -7,7 +7,6 @@ import com.tommytony.war.volumes.BlockInfo; public class ResetCursorJob implements Runnable { - private final Block cornerBlock; private final BlockInfo[] originalCursorBlocks; private final boolean isSoutheast; diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java index da9ffa6..ba6d001 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarhubJob.java @@ -33,7 +33,7 @@ public class RestoreWarhubJob implements Runnable { world = this.war.getServer().getWorld(worldName); } else { worldName = "DEFAULT"; - world = this.war.getServer().getWorlds().get(0); // default to first world + world = this.war.getServer().getWorlds().get(0); // default to first world } if (world != null) { Location hubLocation = new Location(world, hubX, hubY, hubZ); diff --git a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java index 1fced15..39b6921 100644 --- a/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/RestoreWarzonesJob.java @@ -21,12 +21,12 @@ public class RestoreWarzonesJob implements Runnable { String[] warzoneSplit = this.warzonesStr.split(","); this.war.getWarzones().clear(); for (String warzoneName : warzoneSplit) { - if (warzoneName != null && !warzoneName.equals("")){ + if (warzoneName != null && !warzoneName.equals("")) { this.war.logInfo("Loading zone " + warzoneName + "..."); Warzone zone = WarzoneMapper.load(this.war, warzoneName, !this.newWarInstall); if (zone != null) { // could have failed, would've been logged already this.war.getWarzones().add(zone); - //zone.getVolume().loadCorners(); + // zone.getVolume().loadCorners(); zone.getVolume().loadCorners(); if (zone.getLobby() != null) { zone.getLobby().getVolume().resetBlocks(); diff --git a/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java b/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java index e81bfee..9c47c28 100644 --- a/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ScoreCapReachedJob.java @@ -22,18 +22,18 @@ public class ScoreCapReachedJob implements Runnable { for (Player tp : t.getPlayers()) { // Send everyone to rally point (or zone lobby if not rally point) if (this.zone.getRallyPoint() != null) { - tp.teleport(this.zone.getRallyPoint()); + tp.teleport(this.zone.getRallyPoint()); } else { - tp.teleport(this.zone.getTeleport()); + tp.teleport(this.zone.getTeleport()); } tp.setFireTicks(0); tp.setRemainingAir(300); - if (this.zone.hasPlayerInventory(tp.getName())){ + if (this.zone.hasPlayerInventory(tp.getName())) { this.zone.restorePlayerInventory(tp); } if (this.winnersStr.contains(t.getName())) { // give reward - for (Integer slot : this.zone.getReward().keySet()){ + for (Integer slot : this.zone.getReward().keySet()) { ItemStack item = this.zone.getReward().get(slot); if (item != null) { tp.getInventory().addItem(item); @@ -42,7 +42,7 @@ public class ScoreCapReachedJob implements Runnable { } } t.resetPoints(); - t.getPlayers().clear(); // empty the team + t.getPlayers().clear(); // empty the team } } } diff --git a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java b/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java index a8b944b..058bc95 100644 --- a/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java +++ b/war/src/main/java/com/tommytony/war/jobs/ZoneVolumeSaveJob.java @@ -15,6 +15,7 @@ public class ZoneVolumeSaveJob extends Thread { this.zoneName = zoneName; this.war = war; } + @Override public void run() { ZoneVolumeMapper.save(this.volume, this.zoneName, this.war); diff --git a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java index 1d3d783..acc1648 100644 --- a/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/PreDeGaulleZoneVolumeMapper.java @@ -28,11 +28,10 @@ import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.ZoneVolume; /** - * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since - * the ZoneVolume doesn't hold its blocks in memory like regular Volumes. - * + * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes. + * * @author tommytony - * + * */ public class PreDeGaulleZoneVolumeMapper { @@ -42,28 +41,24 @@ public class PreDeGaulleZoneVolumeMapper { for (String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); } } return items; } - public static int load(ZoneVolume volume, String zoneName, War war, - World world, boolean onlyLoadCorners) { + public static int load(ZoneVolume volume, String zoneName, War war, World world, boolean onlyLoadCorners) { BufferedReader in = null; int noOfResetBlocks = 0; try { @@ -93,7 +88,7 @@ public class PreDeGaulleZoneVolumeMapper { if (!onlyLoadCorners) { DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world); - int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0 , k = 0; + int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0; int diskBlockType; byte diskBlockData; Block worldBlock; @@ -102,7 +97,7 @@ public class PreDeGaulleZoneVolumeMapper { x = volume.getMinX(); String blockLine; String[] blockSplit; - for (i = 0; i < volume.getSizeX(); i++){ + for (i = 0; i < volume.getSizeX(); i++) { y = volume.getMinY(); for (j = 0; j < volume.getSizeY(); j++) { z = volume.getMinZ(); @@ -117,15 +112,8 @@ public class PreDeGaulleZoneVolumeMapper { diskBlockData = Byte.parseByte(blockSplit[1]); worldBlock = volume.getWorld().getBlockAt(x, y, z); worldBlockId = worldBlock.getTypeId(); - if (worldBlockId != diskBlockType || - (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData ) || - (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && - (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() - || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()) - ) - ) { - if (diskBlockType == Material.WALL_SIGN.getId() - || diskBlockType == Material.SIGN_POST.getId()) { + if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) { + if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) { // Signs read String linesStr = ""; if (blockSplit.length > 2) { @@ -136,27 +124,26 @@ public class PreDeGaulleZoneVolumeMapper { // Signs set // A sign post hanging on a wall south of here will - if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) - && i+1 != volume.getSizeX()) { + if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) { deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines)); } else { worldBlock.setType(Material.getMaterial(diskBlockType)); BlockState state = worldBlock.getState(); state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData)); if (state instanceof Sign) { - Sign sign = (Sign)state; + Sign sign = (Sign) state; if (lines != null && sign.getLines() != null) { - if (lines.length>0) { - sign.setLine(0, lines[0]); + if (lines.length > 0) { + sign.setLine(0, lines[0]); } - if (lines.length>1) { - sign.setLine(1, lines[1]); + if (lines.length > 1) { + sign.setLine(1, lines[1]); } - if (lines.length>2) { - sign.setLine(2, lines[2]); + if (lines.length > 2) { + sign.setLine(2, lines[2]); } - if (lines.length>3) { - sign.setLine(3, lines[3]); + if (lines.length > 3) { + sign.setLine(3, lines[3]); } sign.update(true); } @@ -176,7 +163,7 @@ public class PreDeGaulleZoneVolumeMapper { worldBlock.setData(diskBlockData); BlockState state = worldBlock.getState(); if (state instanceof Chest) { - Chest chest = (Chest)state; + Chest chest = (Chest) state; if (items != null) { int ii = 0; chest.getInventory().clear(); @@ -194,7 +181,7 @@ public class PreDeGaulleZoneVolumeMapper { List items = null; if (blockSplit.length > 2) { String itemsStr = blockSplit[2]; - //String itemsStr = lineScanner.nextLine(); + // String itemsStr = lineScanner.nextLine(); items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr); } @@ -203,7 +190,7 @@ public class PreDeGaulleZoneVolumeMapper { worldBlock.setData(diskBlockData); BlockState state = worldBlock.getState(); if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; if (items != null) { int ii = 0; dispenser.getInventory().clear(); @@ -216,11 +203,11 @@ public class PreDeGaulleZoneVolumeMapper { dispenser.update(true); } } - } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()){ + } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) { // Door blocks - if (j-1 > 0) { - Block blockBelow = world.getBlockAt(x, y-1, z); + if (j - 1 > 0) { + Block blockBelow = world.getBlockAt(x, y - 1, z); boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId(); // Set current block to glass if block below isn't glass. // Having a glass block below means the current block is a door top. @@ -235,14 +222,7 @@ public class PreDeGaulleZoneVolumeMapper { } } - } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) - || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) - && i+1 != volume.getSizeX()){ + } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) { // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol // Change the block itself later on: deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData)); @@ -259,11 +239,7 @@ public class PreDeGaulleZoneVolumeMapper { } } catch (Exception e) { - volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " - + "Blocks read: " + blockReads - + ". Visited blocks so far:" + visitedBlocks - + ". Blocks reset: "+ noOfResetBlocks + - ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); + volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); e.printStackTrace(); } finally { z++; @@ -271,8 +247,8 @@ public class PreDeGaulleZoneVolumeMapper { } if (height129Fix && j == volume.getSizeY() - 1) { for (int skip = 0; skip < volume.getSizeZ(); skip++) { - in.readLine(); // throw away the extra vertical block I used to save pre 0.8 - //scanner.nextLine(); + in.readLine(); // throw away the extra vertical block I used to save pre 0.8 + // scanner.nextLine(); } } y++; @@ -285,26 +261,23 @@ public class PreDeGaulleZoneVolumeMapper { } } } catch (IOException e) { - war.logWarn("Failed to read volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { - war.logWarn("Unexpected error caused failure to read volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); - } finally { + } finally { if (in != null) { - //if (scanner != null) - try { - in.close(); - in = null; - //scanner.close(); - //scanner = null; - } catch (IOException e) { - war.logWarn("Failed to close file reader for volume " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + // if (scanner != null) + try { + in.close(); + in = null; + // scanner.close(); + // scanner = null; + } catch (IOException e) { + war.logWarn("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } } } return noOfResetBlocks; @@ -315,22 +288,29 @@ public class PreDeGaulleZoneVolumeMapper { if (volume.hasTwoCorners()) { BufferedWriter out = null; try { - (new File(war.getDataFolder().getPath() +"/dat/warzone-"+zoneName)).mkdir(); + (new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir(); if (zoneName.equals("")) { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); + out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); } else { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + - "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); + out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); } - out.write("corner1"); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getZ())); out.newLine(); - out.write("corner2"); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getX())); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getY())); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getZ())); out.newLine(); + out.write("corner1"); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getX())); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getY())); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getZ())); + out.newLine(); + out.write("corner2"); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getX())); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getY())); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getZ())); + out.newLine(); int x = 0; int y = 0; @@ -341,7 +321,7 @@ public class PreDeGaulleZoneVolumeMapper { BlockState state; x = volume.getMinX(); - for (int i = 0; i < volume.getSizeX(); i++){ + for (int i = 0; i < volume.getSizeX(); i++) { y = volume.getMinY(); for (int j = 0; j < volume.getSizeY(); j++) { z = volume.getMinZ(); @@ -357,7 +337,7 @@ public class PreDeGaulleZoneVolumeMapper { if (state instanceof Sign) { // Signs String extra = ""; - Sign sign = (Sign)state; + Sign sign = (Sign) state; if (sign.getLines() != null) { for (String line : sign.getLines()) { extra += line + ";;"; @@ -367,11 +347,11 @@ public class PreDeGaulleZoneVolumeMapper { } else if (state instanceof Chest) { // Chests - Chest chest = (Chest)state; + Chest chest = (Chest) state; Inventory inv = chest.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -381,11 +361,9 @@ public class PreDeGaulleZoneVolumeMapper { if (items != null) { for (ItemStack item : items) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -394,11 +372,11 @@ public class PreDeGaulleZoneVolumeMapper { } } else if (state instanceof Dispenser) { // Dispensers - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; Inventory inv = dispenser.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -408,11 +386,9 @@ public class PreDeGaulleZoneVolumeMapper { if (items != null) { for (ItemStack item : items) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -422,11 +398,8 @@ public class PreDeGaulleZoneVolumeMapper { } noOfSavedBlocks++; out.newLine(); - } - catch (Exception e) { - war.logWarn("Unexpected error while saving a block to " + - " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks - + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage()); + } catch (Exception e) { + war.logWarn("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } finally { z++; @@ -437,29 +410,23 @@ public class PreDeGaulleZoneVolumeMapper { x++; } } catch (IOException e) { - war.logWarn("Failed to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { - war.logWarn("Unexpected error caused failure to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); - } - finally { + } finally { if (out != null) { - try { - out.close(); - } catch (IOException e) { - war.logWarn("Failed to close file writer for volume " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + try { + out.close(); + } catch (IOException e) { + war.logWarn("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } } } } return noOfSavedBlocks; } - } - diff --git a/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java b/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java index 4230e9c..1812c34 100644 --- a/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java +++ b/war/src/main/java/com/tommytony/war/mappers/PropertiesFile.java @@ -9,9 +9,8 @@ import java.util.Map; import java.util.Properties; /** - * Used for accessing and creating .[properties] files, reads them as utf-8, saves as utf-8. - * Internationalization is key importance especially for character codes. - * + * Used for accessing and creating .[properties] files, reads them as utf-8, saves as utf-8. Internationalization is key importance especially for character codes. + * * @author Nijikokun * @version 1.0.4, %G% */ @@ -22,12 +21,13 @@ public final class PropertiesFile { private Properties props = new Properties(); private FileInputStream inputStream; private FileOutputStream outputStream; -// private List lines = new ArrayList(); -// private Map props = new HashMap(); + + // private List lines = new ArrayList(); + // private Map props = new HashMap(); /** * Creates or opens a properties file using specified filename - * + * * @param fileName */ public PropertiesFile(String fileName) { @@ -47,9 +47,8 @@ public final class PropertiesFile { } /** - * The loader for property files, it reads the file as UTF8 or converts the string into UTF8. - * Used for simple runthrough's, loading, or reloading of the file. - * + * The loader for property files, it reads the file as UTF8 or converts the string into UTF8. Used for simple runthrough's, loading, or reloading of the file. + * * @throws IOException */ public void load() throws IOException { @@ -58,14 +57,13 @@ public final class PropertiesFile { } /** - * Writes out the key=value properties that were changed into - * a .[properties] file in UTF8. + * Writes out the key=value properties that were changed into a .[properties] file in UTF8. */ public void save() { try { - this.outputStream = new FileOutputStream(this.fileName); - this.props.store(this.outputStream, null); - }catch(IOException ex) { + this.outputStream = new FileOutputStream(this.fileName); + this.props.store(this.outputStream, null); + } catch (IOException ex) { PropertiesFile.log.severe("[PropertiesFile] Unable to save " + this.fileName + "!"); } } @@ -87,22 +85,26 @@ public final class PropertiesFile { } /** - * Returns a Map of all key=value properties in the file as <key (java.lang.String), value (java.lang.String)> - *

- * Example: - *
-	 * PropertiesFile settings = new PropertiesFile("settings.properties");
-	 * Map mappedSettings;
-	 *
+	 * Returns a Map of all key=value properties in the file as <key (java.lang.String), value (java.lang.String)> 
+ *
+ * Example:
+ * + *
+	 * PropertiesFile settings = new PropertiesFile("settings.properties");
+	 * Map<String, String> mappedSettings;
+	 * 
 	 * try {
-	 * 	 mappedSettings = settings.returnMap();
+	 * 	mappedSettings = settings.returnMap();
 	 * } catch (Exception ex) {
-	 * 	 log.info("Failed mapping settings.properties");
+	 * 	log.info("Failed mapping settings.properties");
 	 * }
-	 * 
- * + *
+ * + *
+ * * @return map - Simple Map HashMap of the entire key=value as <key (java.lang.String), value (java.lang.String)> - * @throws Exception If the properties file doesn't exist. + * @throws Exception + * If the properties file doesn't exist. */ @SuppressWarnings("unchecked") public Map returnMap() throws Exception { @@ -111,8 +113,9 @@ public final class PropertiesFile { /** * Checks to see if the .[properties] file contains the given key. - * - * @param var The key we are going to be checking the existance of. + * + * @param var + * The key we are going to be checking the existance of. * @return Boolean - True if the key exists, false if it cannot be found. */ public boolean containsKey(String var) { @@ -121,8 +124,9 @@ public final class PropertiesFile { /** * Checks to see if this key exists in the .[properties] file. - * - * @param var The key we are grabbing the value of. + * + * @param var + * The key we are grabbing the value of. * @return java.lang.String - True if the key exists, false if it cannot be found. */ public String getProperty(String var) { @@ -130,11 +134,11 @@ public final class PropertiesFile { } /** - * Remove a key from the file if it exists. - * This will save() which will invoke a load() on the file. - * + * Remove a key from the file if it exists. This will save() which will invoke a load() on the file. + * * @see #save() - * @param var The key that will be removed from the file + * @param var + * The key that will be removed from the file */ public void removeKey(String var) { if (this.props.containsKey(var)) { @@ -145,9 +149,10 @@ public final class PropertiesFile { /** * Checks the existance of a key. - * + * * @see #containsKey(java.lang.String) - * @param key The key in question of existance. + * @param key + * The key in question of existance. * @return Boolean - True for existance, false for key found. */ public boolean keyExists(String key) { @@ -155,33 +160,34 @@ public final class PropertiesFile { } /** - * Returns the value of the key given as a String, - * however we do not set a string if no key is found. - * + * Returns the value of the key given as a String, however we do not set a string if no key is found. + * * @see #getProperty(java.lang.String) - * @param key The key we will retrieve the property from, if no key is found default to "" or empty. + * @param key + * The key we will retrieve the property from, if no key is found default to "" or empty. */ public String getString(String key) { if (this.containsKey(key)) { - return this.getProperty(key); + return this.getProperty(key); } return ""; } /** - * Returns the value of the key given as a String. - * If it is not found, it will invoke saving the default value to the properties file. - * + * Returns the value of the key given as a String. If it is not found, it will invoke saving the default value to the properties file. + * * @see #setString(java.lang.String, java.lang.String) * @see #getProperty(java.lang.String) - * @param key The key that we will be grabbing the value from, if no value is found set and return value - * @param value The default value that we will be setting if no prior key is found. + * @param key + * The key that we will be grabbing the value from, if no value is found set and return value + * @param value + * The default value that we will be setting if no prior key is found. * @return java.lang.String Either we will return the default value or a prior existing value depending on existance. */ public String getString(String key, String value) { if (this.containsKey(key)) { - return this.getProperty(key); + return this.getProperty(key); } this.setString(key, value); @@ -190,10 +196,12 @@ public final class PropertiesFile { /** * Save the value given as a String on the specified key. - * + * * @see #save() - * @param key The key that we will be addressing the value to. - * @param value The value we will be setting inside the .[properties] file. + * @param key + * The key that we will be addressing the value to. + * @param value + * The value we will be setting inside the .[properties] file. */ public void setString(String key, String value) { this.props.put(key, value); @@ -201,15 +209,15 @@ public final class PropertiesFile { } /** - * Returns the value of the key given in a Integer, - * however we do not set a string if no key is found. - * + * Returns the value of the key given in a Integer, however we do not set a string if no key is found. + * * @see #getProperty(String var) - * @param key The key we will retrieve the property from, if no key is found default to 0 + * @param key + * The key we will retrieve the property from, if no key is found default to 0 */ public int getInt(String key) { if (this.containsKey(key)) { - return Integer.parseInt(this.getProperty(key)); + return Integer.parseInt(this.getProperty(key)); } return 0; @@ -217,15 +225,17 @@ public final class PropertiesFile { /** * Returns the int value of a key - * + * * @see #setInt(String key, int value) - * @param key The key that we will be grabbing the value from, if no value is found set and return value - * @param value The default value that we will be setting if no prior key is found. + * @param key + * The key that we will be grabbing the value from, if no value is found set and return value + * @param value + * The default value that we will be setting if no prior key is found. * @return Integer - Either we will return the default value or a prior existing value depending on existance. */ public int getInt(String key, int value) { if (this.containsKey(key)) { - return Integer.parseInt(this.getProperty(key)); + return Integer.parseInt(this.getProperty(key)); } this.setInt(key, value); @@ -235,10 +245,12 @@ public final class PropertiesFile { /** * Save the value given as a int on the specified key. - * + * * @see #save() - * @param key The key that we will be addressing the value to. - * @param value The value we will be setting inside the .[properties] file. + * @param key + * The key that we will be addressing the value to. + * @param value + * The value we will be setting inside the .[properties] file. */ public void setInt(String key, int value) { this.props.put(key, String.valueOf(value)); @@ -247,15 +259,15 @@ public final class PropertiesFile { } /** - * Returns the value of the key given in a Double, - * however we do not set a string if no key is found. - * + * Returns the value of the key given in a Double, however we do not set a string if no key is found. + * * @see #getProperty(String var) - * @param key The key we will retrieve the property from, if no key is found default to 0.0 + * @param key + * The key we will retrieve the property from, if no key is found default to 0.0 */ public double getDouble(String key) { if (this.containsKey(key)) { - return Double.parseDouble(this.getProperty(key)); + return Double.parseDouble(this.getProperty(key)); } return 0; @@ -263,15 +275,17 @@ public final class PropertiesFile { /** * Returns the double value of a key - * + * * @see #setDouble(String key, double value) - * @param key The key that we will be grabbing the value from, if no value is found set and return value - * @param value The default value that we will be setting if no prior key is found. + * @param key + * The key that we will be grabbing the value from, if no value is found set and return value + * @param value + * The default value that we will be setting if no prior key is found. * @return Double - Either we will return the default value or a prior existing value depending on existance. */ public double getDouble(String key, double value) { if (this.containsKey(key)) { - return Double.parseDouble(this.getProperty(key)); + return Double.parseDouble(this.getProperty(key)); } this.setDouble(key, value); @@ -280,10 +294,12 @@ public final class PropertiesFile { /** * Save the value given as a double on the specified key. - * + * * @see #save() - * @param key The key that we will be addressing the value to. - * @param value The value we will be setting inside the .[properties] file. + * @param key + * The key that we will be addressing the value to. + * @param value + * The value we will be setting inside the .[properties] file. */ public void setDouble(String key, double value) { this.props.put(key, String.valueOf(value)); @@ -292,15 +308,15 @@ public final class PropertiesFile { } /** - * Returns the value of the key given in a Long, - * however we do not set a string if no key is found. - * + * Returns the value of the key given in a Long, however we do not set a string if no key is found. + * * @see #getProperty(String var) - * @param key The key we will retrieve the property from, if no key is found default to 0L + * @param key + * The key we will retrieve the property from, if no key is found default to 0L */ public long getLong(String key) { if (this.containsKey(key)) { - return Long.parseLong(this.getProperty(key)); + return Long.parseLong(this.getProperty(key)); } return 0; @@ -308,15 +324,17 @@ public final class PropertiesFile { /** * Returns the long value of a key - * + * * @see #setLong(String key, long value) - * @param key The key that we will be grabbing the value from, if no value is found set and return value - * @param value The default value that we will be setting if no prior key is found. + * @param key + * The key that we will be grabbing the value from, if no value is found set and return value + * @param value + * The default value that we will be setting if no prior key is found. * @return Long - Either we will return the default value or a prior existing value depending on existance. */ public long getLong(String key, long value) { if (this.containsKey(key)) { - return Long.parseLong(this.getProperty(key)); + return Long.parseLong(this.getProperty(key)); } this.setLong(key, value); @@ -325,10 +343,12 @@ public final class PropertiesFile { /** * Save the value given as a long on the specified key. - * + * * @see #save() - * @param key The key that we will be addressing the value to. - * @param value The value we will be setting inside the .[properties] file. + * @param key + * The key that we will be addressing the value to. + * @param value + * The value we will be setting inside the .[properties] file. */ public void setLong(String key, long value) { this.props.put(key, String.valueOf(value)); @@ -337,15 +357,15 @@ public final class PropertiesFile { } /** - * Returns the value of the key given in a Boolean, - * however we do not set a string if no key is found. - * + * Returns the value of the key given in a Boolean, however we do not set a string if no key is found. + * * @see #getProperty(String var) - * @param key The key we will retrieve the property from, if no key is found default to false + * @param key + * The key we will retrieve the property from, if no key is found default to false */ public boolean getBoolean(String key) { if (this.containsKey(key)) { - return Boolean.parseBoolean(this.getProperty(key)); + return Boolean.parseBoolean(this.getProperty(key)); } return false; @@ -353,15 +373,17 @@ public final class PropertiesFile { /** * Returns the boolean value of a key - * + * * @see #setBoolean(String key, boolean value) - * @param key The key that we will be grabbing the value from, if no value is found set and return value - * @param value The default value that we will be setting if no prior key is found. + * @param key + * The key that we will be grabbing the value from, if no value is found set and return value + * @param value + * The default value that we will be setting if no prior key is found. * @return Boolean - Either we will return the default value or a prior existing value depending on existance. */ public boolean getBoolean(String key, boolean value) { if (this.containsKey(key)) { - return Boolean.parseBoolean(this.getProperty(key)); + return Boolean.parseBoolean(this.getProperty(key)); } this.setBoolean(key, value); @@ -370,10 +392,12 @@ public final class PropertiesFile { /** * Save the value given as a boolean on the specified key. - * + * * @see #save() - * @param key The key that we will be addressing the value to. - * @param value The value we will be setting inside the .[properties] file. + * @param key + * The key that we will be addressing the value to. + * @param value + * The value we will be setting inside the .[properties] file. */ public void setBoolean(String key, boolean value) { this.props.put(key, String.valueOf(value)); diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java index 5ad5713..c0f9a95 100644 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -19,34 +19,32 @@ import bukkit.tommytony.war.War; import com.tommytony.war.volumes.Volume; /** - * + * * @author tommytony - * + * */ public class VolumeMapper { - public static Volume loadVolume(String volumeName, String zoneName, - War war, World world) { + public static Volume loadVolume(String volumeName, String zoneName, War war, World world) { Volume volume = new Volume(volumeName, war, world); VolumeMapper.load(volume, zoneName, war, world); return volume; } -// public static ZoneVolume loadZoneVolume(String volumeName, String zoneName, -// War war, World world, Warzone zone) { -// ZoneVolume volume = new ZoneVolume(volumeName, war, world, zone); -// load(volume, zoneName, war, world); -// return volume; -// } + // public static ZoneVolume loadZoneVolume(String volumeName, String zoneName, + // War war, World world, Warzone zone) { + // ZoneVolume volume = new ZoneVolume(volumeName, war, world, zone); + // load(volume, zoneName, war, world); + // return volume; + // } public static void load(Volume volume, String zoneName, War war, World world) { BufferedReader in = null; try { if (zoneName.equals("")) { - in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + - "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub + in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub } else { - in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); + in = new BufferedReader(new FileReader(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); } String firstLine = in.readLine(); if (firstLine != null && !firstLine.equals("")) { @@ -73,7 +71,7 @@ public class VolumeMapper { volume.setBlockTypes(new int[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]); volume.setBlockDatas(new byte[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]); int blockReads = 0; - for (int i = 0; i < volume.getSizeX(); i++){ + for (int i = 0; i < volume.getSizeX(); i++) { for (int j = 0; j < volume.getSizeY(); j++) { for (int k = 0; k < volume.getSizeZ(); k++) { try { @@ -87,8 +85,7 @@ public class VolumeMapper { volume.getBlockTypes()[i][j][k] = typeID; volume.getBlockDatas()[i][j][k] = data; - if (typeID == Material.WALL_SIGN.getId() - || typeID == Material.SIGN_POST.getId()) { + if (typeID == Material.WALL_SIGN.getId() || typeID == Material.SIGN_POST.getId()) { // Signs String linesStr = ""; if (blockSplit.length > 2) { @@ -107,21 +104,18 @@ public class VolumeMapper { for (String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); } } } @@ -135,21 +129,18 @@ public class VolumeMapper { for (String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); } } } @@ -159,37 +150,32 @@ public class VolumeMapper { blockReads++; } } catch (Exception e) { - war.logWarn("Unexpected error while reading block from volume " + volume.getName() + - " file for zone " + zoneName + ". Blocks read so far: " + blockReads - + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } } if (height129Fix && j == volume.getSizeY() - 1) { for (int skip = 0; skip < volume.getSizeZ(); skip++) { - in.readLine(); // throw away the extra vertical block I used to save pre 0.8 + in.readLine(); // throw away the extra vertical block I used to save pre 0.8 } } } } } } catch (IOException e) { - war.logWarn("Failed to read volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { - war.logWarn("Unexpected error caused failure to read volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); - } finally { + } finally { if (in != null) { - try { - in.close(); - } catch (IOException e) { - war.logWarn("Failed to close file reader for volume " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + try { + in.close(); + } catch (IOException e) { + war.logWarn("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } } } } @@ -199,30 +185,36 @@ public class VolumeMapper { BufferedWriter out = null; try { if (zoneName.equals("")) { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); + out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); } else { - out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + - "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); + out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat"))); } - out.write("corner1"); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getX())); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getY())); out.newLine(); - out.write(Integer.toString(volume.getCornerOne().getZ())); out.newLine(); - out.write("corner2"); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getX())); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getY())); out.newLine(); - out.write(Integer.toString(volume.getCornerTwo().getZ())); out.newLine(); + out.write("corner1"); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getX())); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getY())); + out.newLine(); + out.write(Integer.toString(volume.getCornerOne().getZ())); + out.newLine(); + out.write("corner2"); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getX())); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getY())); + out.newLine(); + out.write(Integer.toString(volume.getCornerTwo().getZ())); + out.newLine(); int blockWrites = 0; - for (int i = 0; i < volume.getSizeX(); i++){ + for (int i = 0; i < volume.getSizeX(); i++) { for (int j = 0; j < volume.getSizeY(); j++) { for (int k = 0; k < volume.getSizeZ(); k++) { try { int typeId = volume.getBlockTypes()[i][j][k]; byte data = volume.getBlockDatas()[i][j][k]; out.write(typeId + "," + data + ","); - if (typeId == Material.WALL_SIGN.getId() - || typeId == Material.SIGN_POST.getId()) { + if (typeId == Material.WALL_SIGN.getId() || typeId == Material.SIGN_POST.getId()) { // Signs String extra = ""; String[] lines = volume.getSignLines().get("sign-" + i + "-" + j + "-" + k); @@ -239,11 +231,9 @@ public class VolumeMapper { if (contents != null) { for (ItemStack item : contents) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -257,11 +247,9 @@ public class VolumeMapper { if (contents != null) { for (ItemStack item : contents) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -270,46 +258,38 @@ public class VolumeMapper { } } out.newLine(); - } - catch (Exception e) { - war.logWarn("Unexpected error while writing block into volume " + volume.getName() + - " file for zone " + zoneName + ". Blocks written so far: " + blockWrites - + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage()); + } catch (Exception e) { + war.logWarn("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } } } } } catch (IOException e) { - war.logWarn("Failed to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { - war.logWarn("Unexpected error caused failure to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); - } - finally { + } finally { if (out != null) { - try { - out.close(); - } catch (IOException e) { - war.logWarn("Failed to close file writer for volume " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); - e.printStackTrace(); - } + try { + out.close(); + } catch (IOException e) { + war.logWarn("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + e.printStackTrace(); + } } } } } public static void delete(Volume volume, War war) { - File volFile= new File("War/dat/volume-" + volume.getName()); + File volFile = new File("War/dat/volume-" + volume.getName()); boolean deletedData = volFile.delete(); if (!deletedData) { war.logWarn("Failed to delete file " + volFile.getName()); } } - } diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java index fbd4690..adc1d37 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -1,4 +1,5 @@ package com.tommytony.war.mappers; + import java.io.File; import java.io.IOException; import java.util.HashMap; @@ -14,14 +15,14 @@ import com.tommytony.war.jobs.RestoreWarhubJob; import com.tommytony.war.jobs.RestoreWarzonesJob; /** - * + * * @author tommytony - * + * */ public class WarMapper { public static void load(War war) { - //war.getLogger().info("Loading war config..."); + // war.getLogger().info("Loading war config..."); (war.getDataFolder()).mkdir(); (new File(war.getDataFolder().getPath() + "/dat")).mkdir(); PropertiesFile warConfig = new PropertiesFile(war.getDataFolder().getPath() + "/war.txt"); @@ -58,7 +59,7 @@ public class WarMapper { String[] makersSplit = makersStr.split(","); war.getZoneMakerNames().clear(); for (String makerName : makersSplit) { - if (makerName != null && !makerName.equals("")){ + if (makerName != null && !makerName.equals("")) { war.getZoneMakerNames().add(makerName); } } @@ -70,8 +71,7 @@ public class WarMapper { for (String itemStr : defaultLoadoutSplit) { if (itemStr != null && !itemStr.equals("")) { String[] itemStrSplit = itemStr.split(","); - ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); + ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); war.getDefaultLoadout().put(Integer.parseInt(itemStrSplit[2]), item); } } @@ -108,13 +108,13 @@ public class WarMapper { // defaultSpawnStyle String spawnStyle = warConfig.getString("defaultspawnStyle"); - if (spawnStyle != null && !spawnStyle.equals("")){ + if (spawnStyle != null && !spawnStyle.equals("")) { spawnStyle = spawnStyle.toLowerCase(); if (spawnStyle.equals(TeamSpawnStyles.SMALL)) { war.setDefaultSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){ + } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) { war.setDefaultSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)){ + } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) { war.setDefaultSpawnStyle(spawnStyle); } // default is already initialized to BIG (see Warzone) @@ -128,8 +128,7 @@ public class WarMapper { for (String itemStr : defaultRewardStrSplit) { if (itemStr != null && !itemStr.equals("")) { String[] itemStrSplit = itemStr.split(","); - ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); + ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); war.getDefaultReward().put(Integer.parseInt(itemStrSplit[2]), item); } } @@ -142,7 +141,7 @@ public class WarMapper { war.setDefaultNoCreatures(warConfig.getBoolean("defaultNoCreatures")); // defaultDropLootOnDeath - //war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath")); + // war.setDefaultDropLootOnDeath(warConfig.getBoolean("defaultDropLootOnDeath")); // defaultResetOnEmpty war.setDefaultResetOnEmpty(warConfig.getBoolean("defaultResetOnEmpty")); @@ -176,7 +175,7 @@ public class WarMapper { warConfig.setString("warzones", warzonesStr); // zone makers: default is none and it means everyone can use /setzone - String makersStr = ""; // everyone + String makersStr = ""; // everyone for (String name : war.getZoneMakerNames()) { makersStr += name + ","; } @@ -253,14 +252,13 @@ public class WarMapper { warConfig.setBoolean("defaultResetOnUnload", war.isDefaultResetOnUnload()); // defaultDropLootOnDeath - //warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath()); + // warConfig.setBoolean("defaultDropLootOnDeath", war.isDefaultDropLootOnDeath()); // warhub String hubStr = ""; WarHub hub = war.getWarHub(); if (hub != null) { - hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + "," - + hub.getLocation().getWorld().getName(); + hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + "," + hub.getLocation().getWorld().getName(); VolumeMapper.save(hub.getVolume(), "", war); } warConfig.setString("warhub", hubStr); 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 9e7a0c3..b563fd9 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -22,14 +22,14 @@ import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.ZoneVolume; /** - * + * * @author tommytony - * + * */ public class WarzoneMapper { public static Warzone load(War war, String name, boolean createNewVolume) { - //war.getLogger().info("Loading warzone " + name + " config and blocks..."); + // war.getLogger().info("Loading warzone " + name + " config and blocks..."); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); try { warzoneConfig.load(); @@ -41,7 +41,7 @@ public class WarzoneMapper { // world String worldStr = warzoneConfig.getProperty("world"); World world = null; - if (worldStr == null || worldStr.equals("")){ + if (worldStr == null || worldStr.equals("")) { world = war.getServer().getWorlds().get(0); // default to first world } else { world = war.getServer().getWorld(worldStr); @@ -60,7 +60,7 @@ public class WarzoneMapper { try { warzoneConfig.load(); } catch (IOException e) { - //war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it."); + // war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it."); e.printStackTrace(); } } @@ -82,7 +82,7 @@ public class WarzoneMapper { String[] teamsSplit = teamsStr.split(";"); warzone.getTeams().clear(); for (String teamStr : teamsSplit) { - if (teamStr != null && !teamStr.equals("")){ + if (teamStr != null && !teamStr.equals("")) { String[] teamStrSplit = teamStr.split(","); int teamX = Integer.parseInt(teamStrSplit[1]); int teamY = Integer.parseInt(teamStrSplit[2]); @@ -92,10 +92,7 @@ public class WarzoneMapper { int yaw = Integer.parseInt(teamStrSplit[4]); teamLocation.setYaw(yaw); } - Team team = new Team(teamStrSplit[0], - TeamKinds.teamKindFromString(teamStrSplit[0]), - teamLocation, - war, warzone ); + Team team = new Team(teamStrSplit[0], TeamKinds.teamKindFromString(teamStrSplit[0]), teamLocation, war, warzone); team.setRemainingLives(warzone.getLifePool()); warzone.getTeams().add(team); } @@ -107,8 +104,8 @@ public class WarzoneMapper { if (teamFlagsStr != null && !teamFlagsStr.equals("")) { String[] teamFlagsSplit = teamFlagsStr.split(";"); for (String teamFlagStr : teamFlagsSplit) { - if (teamFlagStr != null && !teamFlagStr.equals("")){ - String[] teamFlagStrSplit =teamFlagStr.split(","); + if (teamFlagStr != null && !teamFlagStr.equals("")) { + String[] teamFlagStrSplit = teamFlagStr.split(","); Team team = warzone.getTeamByKind(TeamKinds.teamKindFromString(teamFlagStrSplit[0])); if (team != null) { int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]); @@ -119,7 +116,7 @@ public class WarzoneMapper { int yaw = Integer.parseInt(teamFlagStrSplit[4]); teamFlagLocation.setYaw(yaw); } - team.setTeamFlag(teamFlagLocation); // this may screw things up + team.setTeamFlag(teamFlagLocation); // this may screw things up } } } @@ -136,8 +133,7 @@ public class WarzoneMapper { for (String itemStr : loadoutStrSplit) { if (itemStr != null && !itemStr.equals("")) { String[] itemStrSplit = itemStr.split(","); - ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); + ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); warzone.getLoadout().put(Integer.parseInt(itemStrSplit[2]), item); } } @@ -163,13 +159,13 @@ public class WarzoneMapper { // spawnStyle String spawnStyle = warzoneConfig.getString("spawnStyle"); - if (spawnStyle != null && !spawnStyle.equals("")){ + if (spawnStyle != null && !spawnStyle.equals("")) { spawnStyle = spawnStyle.toLowerCase(); if (spawnStyle.equals(TeamSpawnStyles.SMALL)) { warzone.setSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)){ + } else if (spawnStyle.equals(TeamSpawnStyles.FLAT)) { warzone.setSpawnStyle(spawnStyle); - } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)){ + } else if (spawnStyle.equals(TeamSpawnStyles.INVISIBLE)) { warzone.setSpawnStyle(spawnStyle); } // default is already initialized to BIG (see Warzone) @@ -183,8 +179,7 @@ public class WarzoneMapper { for (String itemStr : rewardStrSplit) { if (itemStr != null && !itemStr.equals("")) { String[] itemStrSplit = itemStr.split(","); - ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); + ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); warzone.getReward().put(Integer.parseInt(itemStrSplit[2]), item); } } @@ -221,21 +216,20 @@ public class WarzoneMapper { } // dropLootOnDeath - //warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath")); + // warzone.setDropLootOnDeath(warzoneConfig.getBoolean("dropLootOnDeath")); // monuments String monumentsStr = warzoneConfig.getString("monuments"); if (monumentsStr != null && !monumentsStr.equals("")) { String[] monumentsSplit = monumentsStr.split(";"); warzone.getMonuments().clear(); - for (String monumentStr : monumentsSplit) { - if (monumentStr != null && !monumentStr.equals("")){ + for (String monumentStr : monumentsSplit) { + if (monumentStr != null && !monumentStr.equals("")) { String[] monumentStrSplit = monumentStr.split(","); int monumentX = Integer.parseInt(monumentStrSplit[1]); int monumentY = Integer.parseInt(monumentStrSplit[2]); int monumentZ = Integer.parseInt(monumentStrSplit[3]); - Monument monument = new Monument(monumentStrSplit[0], war, warzone, - new Location(world, monumentX, monumentY, monumentZ)); + Monument monument = new Monument(monumentStrSplit[0], war, warzone, new Location(world, monumentX, monumentY, monumentZ)); warzone.getMonuments().add(monument); } } @@ -247,26 +241,26 @@ public class WarzoneMapper { warzoneConfig.close(); if (createNewVolume) { - ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), war, world, warzone); //VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone); + ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), war, world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone); warzone.setVolume(zoneVolume); } // monument blocks - for (Monument monument: warzone.getMonuments()) { - monument.setVolume(VolumeMapper.loadVolume(monument.getName(),warzone.getName(), war, world)); + for (Monument monument : warzone.getMonuments()) { + monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), war, world)); } // team spawn blocks for (Team team : warzone.getTeams()) { team.setSpawnVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world)); if (team.getTeamFlag() != null) { - team.setFlagVolume(VolumeMapper.loadVolume(team.getName()+"flag", warzone.getName(), war, world)); + team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), war, world)); } } // lobby BlockFace lobbyFace = null; - if (lobbyStr != null && !lobbyStr.equals("")){ + if (lobbyStr != null && !lobbyStr.equals("")) { if (lobbyStr.equals("south")) { lobbyFace = BlockFace.SOUTH; } else if (lobbyStr.equals("east")) { @@ -287,25 +281,25 @@ public class WarzoneMapper { } public static void save(War war, Warzone warzone, boolean saveAllBlocks) { - (new File(war.getDataFolder().getPath() +"/dat/warzone-"+warzone.getName())).mkdir(); + (new File(war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir(); PropertiesFile warzoneConfig = new PropertiesFile(war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt"); - //war.getLogger().info("Saving warzone " + warzone.getName() + "..."); + // war.getLogger().info("Saving warzone " + warzone.getName() + "..."); // name warzoneConfig.setString("name", warzone.getName()); // world - warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now + warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now // teleport String teleportStr = ""; Location tele = warzone.getTeleport(); if (tele != null) { int intYaw = 0; - if (tele.getYaw() >= 0){ - intYaw = (int)(tele.getYaw() % 360); + if (tele.getYaw() >= 0) { + intYaw = (int) (tele.getYaw() % 360); } else { - intYaw = (int)(360 + (tele.getYaw() % 360)); + intYaw = (int) (360 + (tele.getYaw() % 360)); } teleportStr = tele.getBlockX() + "," + tele.getBlockY() + "," + tele.getBlockZ() + "," + intYaw; } @@ -317,10 +311,10 @@ public class WarzoneMapper { for (Team team : teams) { Location spawn = team.getTeamSpawn(); int intYaw = 0; - if (spawn.getYaw() >= 0){ - intYaw = (int)(spawn.getYaw() % 360); + if (spawn.getYaw() >= 0) { + intYaw = (int) (spawn.getYaw() % 360); } else { - intYaw = (int)(360 + (spawn.getYaw() % 360)); + intYaw = (int) (360 + (spawn.getYaw() % 360)); } teamsStr += team.getName() + "," + spawn.getBlockX() + "," + spawn.getBlockY() + "," + spawn.getBlockZ() + "," + intYaw + ";"; } @@ -332,10 +326,10 @@ public class WarzoneMapper { if (team.getFlagVolume() != null) { Location flag = team.getTeamFlag(); int intYaw = 0; - if (flag.getYaw() >= 0){ - intYaw = (int)(flag.getYaw() % 360); + if (flag.getYaw() >= 0) { + intYaw = (int) (flag.getYaw() % 360); } else { - intYaw = (int)(360 + (flag.getYaw() % 360)); + intYaw = (int) (360 + (flag.getYaw() % 360)); } teamFlagsStr += team.getName() + "," + flag.getBlockX() + "," + flag.getBlockY() + "," + flag.getBlockZ() + "," + intYaw + ";"; } @@ -415,7 +409,7 @@ public class WarzoneMapper { warzoneConfig.setString("rallyPoint", rpStr); // defaultDropLootOnDeath - //warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath()); + // warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath()); // monuments String monumentsStr = ""; @@ -446,11 +440,11 @@ public class WarzoneMapper { if (saveAllBlocks) { // zone blocks - //VolumeMapper.save(warzone.getVolume(), warzone.getName(), war); + // VolumeMapper.save(warzone.getVolume(), warzone.getName(), war); } // monument blocks - for (Monument monument: monuments) { + for (Monument monument : monuments) { VolumeMapper.save(monument.getVolume(), warzone.getName(), war); } @@ -458,7 +452,7 @@ public class WarzoneMapper { for (Team team : teams) { VolumeMapper.save(team.getSpawnVolume(), warzone.getName(), war); if (team.getFlagVolume() != null) { - VolumeMapper.save(team.getFlagVolume(), warzone.getName(), war); + VolumeMapper.save(team.getFlagVolume(), warzone.getName(), war); } } @@ -466,11 +460,11 @@ public class WarzoneMapper { VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName(), war); } -// if (saveBlocks) { -// war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks."); -// } else { -// war.getLogger().info("Saved warzone " + warzone.getName() + " config."); -// } + // if (saveBlocks) { + // war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks."); + // } else { + // war.getLogger().info("Saved warzone " + warzone.getName() + " config."); + // } } public static void delete(War war, String name) { diff --git a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java index 8c7fb5a..68b8421 100644 --- a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java @@ -32,11 +32,10 @@ import com.tommytony.war.volumes.Volume; import com.tommytony.war.volumes.ZoneVolume; /** - * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since - * the ZoneVolume doesn't hold its blocks in memory like regular Volumes. - * + * The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes. + * * @author tommytony - * + * */ public class ZoneVolumeMapper { @@ -83,48 +82,40 @@ public class ZoneVolumeMapper { volume.setCornerTwo(world.getBlockAt(x2, y2, z2)); // Allocate block byte arrays - int noOfBlocks = volume.getSizeX()*volume.getSizeY()*volume.getSizeZ(); - byte[] blockBytes = new byte[noOfBlocks*2]; // one byte for type, one for data + int noOfBlocks = volume.getSizeX() * volume.getSizeY() * volume.getSizeZ(); + byte[] blockBytes = new byte[noOfBlocks * 2]; // one byte for type, one for data blocksStream.read(blockBytes); // read it all // Now use the block bytes to reset the world blocks if (!onlyLoadCorners) { DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world); - int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0 , k = 0; + int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0; int diskBlockType; byte diskBlockData; Block worldBlock; int worldBlockId; volume.clearBlocksThatDontFloat(); x = volume.getMinX(); - for (i = 0; i < volume.getSizeX(); i++){ + for (i = 0; i < volume.getSizeX(); i++) { y = volume.getMinY(); for (j = 0; j < volume.getSizeY(); j++) { z = volume.getMinZ(); for (k = 0; k < volume.getSizeZ(); k++) { try { - diskBlockType = blockBytes[visitedBlocks*2]; - diskBlockData = blockBytes[visitedBlocks*2+1]; + diskBlockType = blockBytes[visitedBlocks * 2]; + diskBlockData = blockBytes[visitedBlocks * 2 + 1]; worldBlock = volume.getWorld().getBlockAt(x, y, z); worldBlockId = worldBlock.getTypeId(); - if (worldBlockId != diskBlockType || - (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData ) || - (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && - (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() - || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()) - ) - ) { - if (diskBlockType == Material.WALL_SIGN.getId() - || diskBlockType == Material.SIGN_POST.getId()) { + if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) { + if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) { // Signs read String linesStr = signsReader.readLine(); String[] lines = linesStr.split(";;"); // Signs set - if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) - && i+1 != volume.getSizeX()) { + if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) { // A sign post hanging on a wall south of here needs that block to be set first deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines)); } else { @@ -132,19 +123,19 @@ public class ZoneVolumeMapper { BlockState state = worldBlock.getState(); state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData)); if (state instanceof Sign) { - Sign sign = (Sign)state; + Sign sign = (Sign) state; if (lines != null && sign.getLines() != null) { - if (lines.length>0) { - sign.setLine(0, lines[0]); + if (lines.length > 0) { + sign.setLine(0, lines[0]); } - if (lines.length>1) { - sign.setLine(1, lines[1]); + if (lines.length > 1) { + sign.setLine(1, lines[1]); } - if (lines.length>2) { - sign.setLine(2, lines[2]); + if (lines.length > 2) { + sign.setLine(2, lines[2]); } - if (lines.length>3) { - sign.setLine(3, lines[3]); + if (lines.length > 3) { + sign.setLine(3, lines[3]); } sign.update(true); } @@ -159,7 +150,7 @@ public class ZoneVolumeMapper { worldBlock.setData(diskBlockData); BlockState state = worldBlock.getState(); if (state instanceof Chest) { - Chest chest = (Chest)state; + Chest chest = (Chest) state; if (items != null) { int ii = 0; chest.getInventory().clear(); @@ -181,7 +172,7 @@ public class ZoneVolumeMapper { worldBlock.setData(diskBlockData); BlockState state = worldBlock.getState(); if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; if (items != null) { int ii = 0; dispenser.getInventory().clear(); @@ -194,11 +185,11 @@ public class ZoneVolumeMapper { dispenser.update(true); } } - } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()){ + } else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) { // Door blocks - if (j-1 > 0) { - Block blockBelow = world.getBlockAt(x, y-1, z); + if (j - 1 > 0) { + Block blockBelow = world.getBlockAt(x, y - 1, z); boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId(); // Set current block to glass if block below isn't glass. // Having a glass block below means the current block is a door top. @@ -212,14 +203,7 @@ public class ZoneVolumeMapper { worldBlock.setType(Material.GLASS); } } - } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) - || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) - || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) - && i+1 != volume.getSizeX()){ + } else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) { // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol // Change the block itself later on: deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData)); @@ -234,16 +218,12 @@ public class ZoneVolumeMapper { blockReads++; - } catch (Exception e) { - volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " - + "Blocks read: " + blockReads - + ". Visited blocks so far:" + visitedBlocks - + ". Blocks reset: "+ noOfResetBlocks + - ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); - e.printStackTrace(); - } finally { - z++; - } + } catch (Exception e) { + volume.getWar().getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); + e.printStackTrace(); + } finally { + z++; + } } y++; } @@ -254,30 +234,27 @@ public class ZoneVolumeMapper { } } } catch (FileNotFoundException e) { - war.logWarn("Failed to find volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { - war.logWarn("Failed to read volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } finally { try { if (cornersReader != null) { - cornersReader.close(); + cornersReader.close(); } if (blocksStream != null) { - blocksStream.close(); + blocksStream.close(); } if (signsReader != null) { - signsReader.close(); + signsReader.close(); } if (invsReader != null) { - invsReader.close(); + invsReader.close(); } } catch (IOException e) { - war.logWarn("Failed to close volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } } @@ -292,21 +269,18 @@ public class ZoneVolumeMapper { for (String itemStr : itemsStrSplit) { String[] itemStrSplit = itemStr.split(";"); if (itemStrSplit.length == 4) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - stack.setData(new MaterialData(stack.getTypeId(),Byte.parseByte(itemStrSplit[3]))); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3]))); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else if (itemStrSplit.length == 3) { - ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1])); - short durability = (short)Integer.parseInt(itemStrSplit[2]); + ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])); + short durability = (short) Integer.parseInt(itemStrSplit[2]); stack.setDurability(durability); items.add(stack); } else { - items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), - Integer.parseInt(itemStrSplit[1]))); + items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]))); } } } @@ -321,21 +295,29 @@ public class ZoneVolumeMapper { BufferedWriter signsWriter = null; BufferedWriter invsWriter = null; try { - (new File(war.getDataFolder().getPath() +"/dat/warzone-"+zoneName)).mkdir(); + (new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir(); String path = war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName(); cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners"))); blocksOutput = new FileOutputStream(new File(path + ".blocks")); signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs"))); invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs"))); - cornersWriter.write("corner1"); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getX())); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getY())); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerOne().getZ())); cornersWriter.newLine(); - cornersWriter.write("corner2"); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getX())); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getY())); cornersWriter.newLine(); - cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ())); cornersWriter.newLine(); + cornersWriter.write("corner1"); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerOne().getX())); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerOne().getY())); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerOne().getZ())); + cornersWriter.newLine(); + cornersWriter.write("corner2"); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerTwo().getX())); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerTwo().getY())); + cornersWriter.newLine(); + cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ())); + cornersWriter.newLine(); int x = 0; int y = 0; @@ -346,7 +328,7 @@ public class ZoneVolumeMapper { BlockState state; x = volume.getMinX(); - for (int i = 0; i < volume.getSizeX(); i++){ + for (int i = 0; i < volume.getSizeX(); i++) { y = volume.getMinY(); for (int j = 0; j < volume.getSizeY(); j++) { z = volume.getMinZ(); @@ -357,13 +339,13 @@ public class ZoneVolumeMapper { data = block.getData(); state = block.getState(); - blocksOutput.write((byte)typeId); + blocksOutput.write((byte) typeId); blocksOutput.write(data); if (state instanceof Sign) { // Signs String extra = ""; - Sign sign = (Sign)state; + Sign sign = (Sign) state; if (sign.getLines() != null) { for (String line : sign.getLines()) { extra += line + ";;"; @@ -373,11 +355,11 @@ public class ZoneVolumeMapper { } } else if (state instanceof Chest) { // Chests - Chest chest = (Chest)state; + Chest chest = (Chest) state; Inventory inv = chest.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -387,11 +369,9 @@ public class ZoneVolumeMapper { if (items != null) { for (ItemStack item : items) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -401,11 +381,11 @@ public class ZoneVolumeMapper { } } else if (state instanceof Dispenser) { // Dispensers - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; Inventory inv = dispenser.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -415,11 +395,9 @@ public class ZoneVolumeMapper { if (items != null) { for (ItemStack item : items) { if (item != null) { - extra += item.getTypeId() + ";" - + item.getAmount() + ";" - + item.getDurability(); + extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability(); if (item.getData() != null) { - extra += ";" + item.getData().getData() ; + extra += ";" + item.getData().getData(); } extra += ";;"; } @@ -429,11 +407,8 @@ public class ZoneVolumeMapper { } } noOfSavedBlocks++; - } - catch (Exception e) { - war.logWarn("Unexpected error while saving a block to " + - " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks - + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage()); + } catch (Exception e) { + war.logWarn("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } finally { z++; @@ -444,31 +419,27 @@ public class ZoneVolumeMapper { x++; } } catch (IOException e) { - war.logWarn("Failed to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } catch (Exception e) { - war.logWarn("Unexpected error caused failure to write volume file " + zoneName + - " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); - } - finally { + } finally { try { if (cornersWriter != null) { - cornersWriter.close(); + cornersWriter.close(); } if (blocksOutput != null) { - blocksOutput.close(); + blocksOutput.close(); } if (signsWriter != null) { - signsWriter.close(); + signsWriter.close(); } if (invsWriter != null) { - invsWriter.close(); + invsWriter.close(); } } catch (IOException e) { - war.logWarn("Failed to close volume file " + volume.getName() + - " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); + war.logWarn("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } } @@ -490,7 +461,7 @@ public class ZoneVolumeMapper { } private static void deleteFile(String path, War war) { - File volFile= new File(path); + File volFile = new File(path); if (volFile.exists()) { boolean deletedData = volFile.delete(); if (!deletedData) { @@ -499,5 +470,4 @@ public class ZoneVolumeMapper { } } - } diff --git a/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java b/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java index b6db7ea..1930c9e 100644 --- a/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java +++ b/war/src/main/java/com/tommytony/war/utils/ChatFixUtil.java @@ -5,62 +5,32 @@ import java.util.*; import org.bukkit.entity.Player; /** - * The purpose of this tool is twofold: - * 1: Avoid client crashes due to bad color formating. - * 2: Make color continue on word wrapping - * - * In minecraft the degree sign is used as a prefix to another char to create a color. - * For example the code for white is "\u00A7f". - * The "\u00A7" is the unicode notation for the degree sign and the "f" means white. - * - * When does minecraft wrap the text? After how many chars? - * Answer: - * Because the font isn't monospace this differs depending on what you write. - * However we can fit 53 "M" without wrapping and the 54th char would then wrap (be at the beginning of the next line instead) - * As there is no broader char than "M" we can know for sure the minimum line length is 53. - * Note that this means the number of DISPLAYED chars per row is 53. - * A degree sign and the char after will NOT count, as they will not be displayed as chars. - * + * The purpose of this tool is twofold: 1: Avoid client crashes due to bad color formating. 2: Make color continue on word wrapping + * + * In minecraft the degree sign is used as a prefix to another char to create a color. For example the code for white is "\u00A7f". The "\u00A7" is the unicode notation for the degree sign and the "f" means white. + * + * When does minecraft wrap the text? After how many chars? Answer: Because the font isn't monospace this differs depending on what you write. However we can fit 53 "M" without wrapping and the 54th char would then wrap (be at the beginning of the next line instead) As there is no broader char than "M" we can know for sure the minimum line length is 53. Note that this means the number of DISPLAYED chars per row is 53. A degree sign and the char after will NOT count, as they will not be displayed as chars. + * * Good to know: Numbers have the same font width as an M. - * - * When does the client crash? - * Answer: - * When a row ends with a degree char and optionally another sign after. - * Another way to say the same: When a line ends with either a broken or valid color notation. - * AND - * The client will ALWAYS crash if the sign after the last displayed char in a row is a degree char. - * A goofy way to explatin it: - * For a line with only "M" and numbers, the fiftyfourth "displayed char" musn't be a degree sign. - * - * WARNING: - * Above is a hypothesis I have created based on what my experiments have shown. - * I am fairly sure it is correct but please help me test it further. + * + * When does the client crash? Answer: When a row ends with a degree char and optionally another sign after. Another way to say the same: When a line ends with either a broken or valid color notation. AND The client will ALWAYS crash if the sign after the last displayed char in a row is a degree char. A goofy way to explatin it: For a line with only "M" and numbers, the fiftyfourth "displayed char" musn't be a degree sign. + * + * WARNING: Above is a hypothesis I have created based on what my experiments have shown. I am fairly sure it is correct but please help me test it further. */ public class ChatFixUtil { public final static char deg = '\u00A7'; public final static int lineLength = 53; /** - * This method wraps the msg for you at row lengths of 53, - * avoids client crash scenarios and makes the previous color continue on - * the next line. - * - * The upsides with filtering your messages through this method are: - * - No client crashes. - * - Line wrapping with preserved color. - * - * The downsides are: - * - The width of the chat window will not be used to it's fullest. - * For example you can fit more that 53 commas (,) in a chatwindow row - * but the line would break after 53 displayed chars. - * - * Suggested usage: - * NO NEED TO USE the fix method for static help pages in your plugin. - * As the text is static you can make sure there is no client crash yourself - * and be able to use the full line length. - * - * DO USE in cases like where you output colored messages with playernames in your - * plugin. As the player names have different length there is potential for client crash. + * This method wraps the msg for you at row lengths of 53, avoids client crash scenarios and makes the previous color continue on the next line. + * + * The upsides with filtering your messages through this method are: - No client crashes. - Line wrapping with preserved color. + * + * The downsides are: - The width of the chat window will not be used to it's fullest. For example you can fit more that 53 commas (,) in a chatwindow row but the line would break after 53 displayed chars. + * + * Suggested usage: NO NEED TO USE the fix method for static help pages in your plugin. As the text is static you can make sure there is no client crash yourself and be able to use the full line length. + * + * DO USE in cases like where you output colored messages with playernames in your plugin. As the player names have different length there is potential for client crash. */ public static ArrayList fix(String msg) { // Make sure the end of msg is good @@ -78,14 +48,14 @@ public class ChatFixUtil { displen = 0; row = ""; if (latestColor != null) { - row += ChatFixUtil.deg+latestColor; + row += ChatFixUtil.deg + latestColor; } } char c = msg.charAt(i); if (c == ChatFixUtil.deg) { - latestColor = String.valueOf(msg.charAt(i+1)); - row += ChatFixUtil.deg+latestColor; + latestColor = String.valueOf(msg.charAt(i + 1)); + row += ChatFixUtil.deg + latestColor; i++; } else { displen += 1; @@ -104,18 +74,16 @@ public class ChatFixUtil { return ret; } - /** - * Removes the ending chars as long as they are deg or deg+'anychar' or a space - * As I see it we would never want those chars at the end of a msg. + * Removes the ending chars as long as they are deg or deg+'anychar' or a space As I see it we would never want those chars at the end of a msg. */ - protected static String cleanMsgEnding (String msg) { + protected static String cleanMsgEnding(String msg) { while (msg.length() > 0) { if (msg.endsWith(String.valueOf(ChatFixUtil.deg)) || msg.endsWith(" ")) { - msg = msg.substring(0, msg.length()-1); + msg = msg.substring(0, msg.length() - 1); } else if (msg.length() >= 2 && msg.charAt(msg.length() - 2) == ChatFixUtil.deg) { - msg = msg.substring(0, msg.length()-2); + msg = msg.substring(0, msg.length() - 2); } else { break; } @@ -124,16 +92,14 @@ public class ChatFixUtil { } /** - * This test util assumes line break after 53 displayed chars. - * The fix method above breaks like that so this method should - * be a valid way to test if a message row would crash a client. + * This test util assumes line break after 53 displayed chars. The fix method above breaks like that so this method should be a valid way to test if a message row would crash a client. */ public static String thisMsgWouldCrashClient(String str) { // There would always be crash if we end with deg or deg+'anychar' if (str.length() >= 1 && str.charAt(str.length() - 1) == ChatFixUtil.deg) { - return "Crash: The str ends with deg."; + return "Crash: The str ends with deg."; } else if (str.length() >= 2 && str.charAt(str.length() - 2) == ChatFixUtil.deg) { - return "Crash: The str ends with deg+'anychar'."; + return "Crash: The str ends with deg+'anychar'."; } int displayedChars = 0; @@ -141,7 +107,7 @@ public class ChatFixUtil { for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == ChatFixUtil.deg && displayedChars == ChatFixUtil.lineLength) { - return "Crash: Deg as fiftyforth \"displayed\" char"; + return "Crash: Deg as fiftyforth \"displayed\" char"; } else if (c == ChatFixUtil.deg) { i++; // this and next: they are not displayed... skip them... } else { @@ -151,12 +117,12 @@ public class ChatFixUtil { return "all ok"; } - //----------------------------------------------// + // ----------------------------------------------// // Methods for effectively sending messages - //----------------------------------------------// - //----------------------------------------------// + // ----------------------------------------------// + // ----------------------------------------------// // One player - //----------------------------------------------// + // ----------------------------------------------// public static void sendMessage(Player player, String message, boolean fix) { if (fix) { List messages = ChatFixUtil.fix(message); @@ -167,6 +133,7 @@ public class ChatFixUtil { } } } + public static void sendMessage(Player player, List messages, boolean fix) { if (fix) { messages = ChatFixUtil.fix(messages); @@ -175,15 +142,18 @@ public class ChatFixUtil { ChatFixUtil.sendMessage(player, message, false); } } + public static void sendMessage(Player player, String message) { ChatFixUtil.sendMessage(player, message, true); } + public static void sendMessage(Player player, List messages) { ChatFixUtil.sendMessage(player, messages, true); } - //----------------------------------------------// + + // ----------------------------------------------// // Many Players - //----------------------------------------------// + // ----------------------------------------------// public static void sendMessage(Collection players, String message, boolean fix) { if (fix) { List messages = ChatFixUtil.fix(message); @@ -194,6 +164,7 @@ public class ChatFixUtil { } } } + public static void sendMessage(Collection players, List messages, boolean fix) { if (fix) { messages = ChatFixUtil.fix(messages); @@ -203,9 +174,11 @@ public class ChatFixUtil { ChatFixUtil.sendMessage(players, message, false); } } + public static void sendMessage(Collection players, String message) { ChatFixUtil.sendMessage(players, message, true); } + public static void sendMessage(Collection players, List messages) { ChatFixUtil.sendMessage(players, messages, true); } diff --git a/war/src/main/java/com/tommytony/war/utils/InventoryStash.java b/war/src/main/java/com/tommytony/war/utils/InventoryStash.java index 07be978..2d78429 100644 --- a/war/src/main/java/com/tommytony/war/utils/InventoryStash.java +++ b/war/src/main/java/com/tommytony/war/utils/InventoryStash.java @@ -63,5 +63,4 @@ public class InventoryStash { return this.feet; } - } diff --git a/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java b/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java index 442f850..6e55f07 100644 --- a/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java +++ b/war/src/main/java/com/tommytony/war/volumes/BlockInfo.java @@ -5,9 +5,9 @@ import org.bukkit.World; import org.bukkit.block.Block; /** - * + * * @author tommytony - * + * */ public class BlockInfo { private int x; @@ -15,14 +15,14 @@ public class BlockInfo { private int z; private int type; private byte data; - //private String[] signLines; + + // private String[] signLines; public static Block getBlock(World world, BlockInfo info) { return world.getBlockAt(info.getX(), info.getY(), info.getZ()); } - public BlockInfo(int x, int y, int z, int type, byte data) - { + public BlockInfo(int x, int y, int z, int type, byte data) { this.x = x; this.y = y; this.z = z; @@ -36,29 +36,29 @@ public class BlockInfo { this.z = block.getZ(); this.type = block.getTypeId(); this.data = block.getData(); -// if (is(Material.SIGN) || is(Material.SIGN_POST)) { -// Sign sign = (Sign)block.getState(); -// this.signLines = sign.getLines(); -// } + // if (is(Material.SIGN) || is(Material.SIGN_POST)) { + // Sign sign = (Sign)block.getState(); + // this.signLines = sign.getLines(); + // } } -// public BlockInfo(BlockState blockState) { -// this.x = blockState.getX(); -// this.y = blockState.getY(); -// this.z = blockState.getZ(); -// this.type = blockState.getTypeId(); -// this.data = blockState.getData().getData(); -//// if (is(Material.SIGN) || is(Material.SIGN_POST)) { -//// Sign sign = (Sign)blockState; -//// this.signLines = sign.getLines(); -//// } -// } + // public BlockInfo(BlockState blockState) { + // this.x = blockState.getX(); + // this.y = blockState.getY(); + // this.z = blockState.getZ(); + // this.type = blockState.getTypeId(); + // this.data = blockState.getData().getData(); + // // if (is(Material.SIGN) || is(Material.SIGN_POST)) { + // // Sign sign = (Sign)blockState; + // // this.signLines = sign.getLines(); + // // } + // } -// public BlockInfo(int typeID, byte data, String[] lines) { -// type = typeID; -// this.data = data; -// //signLines = lines; -// } + // public BlockInfo(int typeID, byte data, String[] lines) { + // type = typeID; + // this.data = data; + // //signLines = lines; + // } public int getX() { return this.x; @@ -101,10 +101,10 @@ public class BlockInfo { return this.getType() == material; } -// public String[] getSignLines() { -// if (is(Material.SIGN) || is(Material.SIGN_POST)){ -// return new String[4] {"", ""}; -// } -// return null; -// } + // public String[] getSignLines() { + // if (is(Material.SIGN) || is(Material.SIGN_POST)){ + // return new String[4] {"", ""}; + // } + // return null; + // } } 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 c146a61..322c41e 100644 --- a/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/CenteredVolume.java @@ -7,11 +7,11 @@ import org.bukkit.block.Block; import bukkit.tommytony.war.War; /** - * + * * @author tommytony - * - * Broken, don't use. - * + * + * Broken, don't use. + * */ @Deprecated public class CenteredVolume extends Volume { @@ -28,10 +28,7 @@ public class CenteredVolume extends Volume { } public void changeCenter(Location newCenter) { - this.changeCenter(this.world.getBlockAt(newCenter.getBlockX(), - newCenter.getBlockY(), - newCenter.getBlockZ()), - this.sideSize); + this.changeCenter(this.world.getBlockAt(newCenter.getBlockX(), newCenter.getBlockY(), newCenter.getBlockZ()), this.sideSize); } public void changeCenter(Block newCenter, int sideSize) { @@ -54,7 +51,7 @@ public class CenteredVolume extends Volume { Block cornerOne = this.world.getBlockAt(x, y, z); this.setCornerOne(cornerOne); - if (this.sideSize % 2 == 0) { // not a real center, bottom half is larger by 1 + if (this.sideSize % 2 == 0) { // not a real center, bottom half is larger by 1 int bottomHalfOfSide = this.sideSize - topHalfOfSide; x = this.center.getX() - bottomHalfOfSide; y = this.center.getY() - bottomHalfOfSide; diff --git a/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java b/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java index f1bc1c7..a700183 100644 --- a/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java +++ b/war/src/main/java/com/tommytony/war/volumes/NotNorthwestException.java @@ -4,5 +4,4 @@ public class NotNorthwestException extends Exception { private static final long serialVersionUID = -5736463256274556866L; - } diff --git a/war/src/main/java/com/tommytony/war/volumes/TooBigException.java b/war/src/main/java/com/tommytony/war/volumes/TooBigException.java index 6f0201e..5a1210c 100644 --- a/war/src/main/java/com/tommytony/war/volumes/TooBigException.java +++ b/war/src/main/java/com/tommytony/war/volumes/TooBigException.java @@ -7,5 +7,4 @@ public class TooBigException extends Exception { */ private static final long serialVersionUID = 61793179891881015L; - } diff --git a/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java b/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java index caa5e5e..4014f9b 100644 --- a/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java +++ b/war/src/main/java/com/tommytony/war/volumes/TooSmallException.java @@ -7,5 +7,4 @@ public class TooSmallException extends Exception { */ private static final long serialVersionUID = -1641366536434076088L; - } 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 46fc857..c030b8b 100644 --- a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java @@ -8,12 +8,12 @@ import org.bukkit.block.BlockFace; import bukkit.tommytony.war.War; /** - * + * * @author tommytony - * + * */ @Deprecated -public class VerticalVolume extends Volume{ +public class VerticalVolume extends Volume { public VerticalVolume(String name, War war, World world) { super(name, war, world); @@ -21,59 +21,47 @@ public class VerticalVolume extends Volume{ } @Override - public void setCornerOne(Block block){ + public void setCornerOne(Block block) { // corner one defaults to topmost corner Block topBlock = this.getWorld().getBlockAt(block.getX(), 127, block.getZ()); super.setCornerOne(topBlock); } @Override - public void setCornerTwo(Block block){ + public void setCornerTwo(Block block) { // corner two defaults to bottom most corner Block bottomBlock = this.getWorld().getBlockAt(block.getX(), 0, block.getZ()); super.setCornerTwo(bottomBlock); } - public boolean isWallBlock(Block block){ + public boolean isWallBlock(Block block) { return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block); } public boolean isEastWallBlock(Block block) { - if (this.getMinZ() == block.getZ() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX()) - { - return true; // east wall + if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) { + return true; // east wall } return false; } public boolean isSouthWallBlock(Block block) { - if (this.getMaxX() == block.getX() - && block.getZ() <= this.getMaxZ() - && block.getZ() >= this.getMinZ()) - { - return true; // south wall + if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) { + return true; // south wall } return false; } public boolean isNorthWallBlock(Block block) { - if (this.getMinX() == block.getX() - && block.getZ() <= this.getMaxZ() - && block.getZ() >= this.getMinZ()) - { - return true; // north wall + if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) { + return true; // north wall } return false; } public boolean isWestWallBlock(Block block) { - if (this.getMaxZ() == block.getZ() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX()) - { - return true; // west wall + if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) { + return true; // west wall } return false; } @@ -101,7 +89,7 @@ public class VerticalVolume extends Volume{ } } else if (wall == BlockFace.WEST) { int z = this.getMaxZ(); - int k = this.getSizeZ()-1; + int k = this.getSizeZ() - 1; int y = this.getMinY(); for (int j = 0; j < this.getSizeY(); j++) { int x = this.getMinX(); @@ -135,7 +123,7 @@ public class VerticalVolume extends Volume{ } } else if (wall == BlockFace.SOUTH) { int x = this.getMaxX(); - int i = this.getSizeX()-1; + int i = this.getSizeX() - 1; int y = this.getMinY(); for (int j = 0; j < this.getSizeY(); j++) { int z = this.getMinZ(); @@ -159,25 +147,20 @@ public class VerticalVolume extends Volume{ } private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) { - if (currentBlock.getTypeId() != oldBlockType || - (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || - (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && - (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) - ) - ) { - currentBlock.setTypeId(oldBlockType); - currentBlock.setData(oldBlockData); -// if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) { -// BlockState state = currentBlock.getState(); -// Sign currentSign = (Sign) state; -// currentSign.setLine(0, oldBlockInfo.getSignLines()[0]); -// currentSign.setLine(1, oldBlockInfo.getSignLines()[0]); -// currentSign.setLine(2, oldBlockInfo.getSignLines()[0]); -// currentSign.setLine(3, oldBlockInfo.getSignLines()[0]); -// state.update(); -// } - return true; - } + if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()))) { + currentBlock.setTypeId(oldBlockType); + currentBlock.setData(oldBlockData); + // if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) { + // BlockState state = currentBlock.getState(); + // Sign currentSign = (Sign) state; + // currentSign.setLine(0, oldBlockInfo.getSignLines()[0]); + // currentSign.setLine(1, oldBlockInfo.getSignLines()[0]); + // currentSign.setLine(2, oldBlockInfo.getSignLines()[0]); + // currentSign.setLine(3, oldBlockInfo.getSignLines()[0]); + // state.update(); + // } + return true; + } return false; } 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 70d11b1..d2e5a15 100644 --- a/war/src/main/java/com/tommytony/war/volumes/Volume.java +++ b/war/src/main/java/com/tommytony/war/volumes/Volume.java @@ -21,14 +21,14 @@ import bukkit.tommytony.war.War; import com.tommytony.war.jobs.BlockResetJob; /** - * + * * @author tommytony - * + * */ public class Volume { private final String name; private final World world; - //private final Warzone warzone; + // private final Warzone warzone; private BlockInfo cornerOne; private BlockInfo cornerTwo; private int[][][] blockTypes = null; @@ -60,9 +60,9 @@ public class Volume { } public int saveBlocks() { -// BlockSaveJob job = new BlockSaveJob(this); -// war.getServer().getScheduler().scheduleSyncDelayedTask(war, job); -// return 0; + // BlockSaveJob job = new BlockSaveJob(this); + // war.getServer().getScheduler().scheduleSyncDelayedTask(war, job); + // return 0; int noOfSavedBlocks = 0; int x = 0; int y = 0; @@ -74,11 +74,11 @@ public class Volume { this.getSignLines().clear(); this.getInvBlockContents().clear(); x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++){ + for (int i = 0; i < this.getSizeX(); i++) { y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++){ + for (int j = 0; j < this.getSizeY(); j++) { z = this.getMinZ(); - for (int k = 0;k < this.getSizeZ(); k++) { + for (int k = 0; k < this.getSizeZ(); k++) { try { Block block = this.getWorld().getBlockAt(x, y, z); this.getBlockTypes()[i][j][k] = block.getTypeId(); @@ -86,18 +86,18 @@ public class Volume { BlockState state = block.getState(); if (state instanceof Sign) { // Signs - Sign sign = (Sign)state; + Sign sign = (Sign) state; if (sign.getLines() != null) { this.getSignLines().put("sign-" + i + "-" + j + "-" + k, sign.getLines()); } } else if (state instanceof Chest) { // Chests - Chest chest = (Chest)state; + Chest chest = (Chest) state; Inventory inv = chest.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -106,11 +106,11 @@ public class Volume { this.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items); } else if (state instanceof Dispenser) { // Dispensers - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; Inventory inv = dispenser.getInventory(); int size = inv.getSize(); List items = new ArrayList(); - for (int invIndex = 0; invIndex < size; invIndex++){ + for (int invIndex = 0; invIndex < size; invIndex++) { ItemStack item = inv.getItem(invIndex); if (item != null && item.getType().getId() != Material.AIR.getId()) { items.add(item); @@ -121,8 +121,7 @@ public class Volume { noOfSavedBlocks++; } catch (Exception e) { - this.getWar().getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks - + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage()); + this.getWar().getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage()); e.printStackTrace(); } finally { z++; @@ -134,8 +133,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks - + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " "+ e.getMessage()); + this.getWar().getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); e.printStackTrace(); } return noOfSavedBlocks; @@ -154,31 +152,23 @@ public class Volume { try { if (this.hasTwoCorners() && this.isSaved()) { x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++){ + for (int i = 0; i < this.getSizeX(); i++) { y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++){ + for (int j = 0; j < this.getSizeY(); j++) { z = this.getMinZ(); - for (int k = 0;k < this.getSizeZ(); k++) { + for (int k = 0; k < this.getSizeZ(); k++) { try { oldBlockType = this.getBlockTypes()[i][j][k]; byte oldBlockData = this.getBlockDatas()[i][j][k]; Block currentBlock = this.getWorld().getBlockAt(x, y, z); currentBlockId = currentBlock.getTypeId(); - if (currentBlockId != oldBlockType || - (currentBlockId == oldBlockType && currentBlock.getData() != oldBlockData ) || - (currentBlockId == oldBlockType && currentBlock.getData() == oldBlockData && - (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId() - || oldBlockType == Material.CHEST.getId() || oldBlockType == Material.DISPENSER.getId()) - ) - ) { - if (oldBlockType == Material.WALL_SIGN.getId() - || oldBlockType == Material.SIGN_POST.getId()) { + if (currentBlockId != oldBlockType || (currentBlockId == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlockId == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId() || oldBlockType == Material.CHEST.getId() || oldBlockType == Material.DISPENSER.getId()))) { + if (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) { // Signs - if (oldBlockType == Material.SIGN_POST.getId() && ((oldBlockData & 0x04) == 0x04) - && i+1 != this.getSizeX()) { + if (oldBlockType == Material.SIGN_POST.getId() && ((oldBlockData & 0x04) == 0x04) && i + 1 != this.getSizeX()) { Block southBlock = currentBlock.getFace(BlockFace.SOUTH); - int oldSouthBlockType = this.getBlockTypes()[i+1][j][k]; - byte oldSouthBlockData = this.getBlockDatas()[i+1][j][k]; + int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k]; + byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k]; if (southBlock.getTypeId() != oldSouthBlockType) { southBlock.setTypeId(oldSouthBlockType); southBlock.setData(oldSouthBlockData); @@ -188,20 +178,20 @@ public class Volume { BlockState state = currentBlock.getState(); state.setData(new org.bukkit.material.Sign(oldBlockType, oldBlockData)); if (state instanceof Sign) { - Sign sign = (Sign)state; + Sign sign = (Sign) state; String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k); if (lines != null && sign.getLines() != null) { - if (lines.length>0) { - sign.setLine(0, lines[0]); + if (lines.length > 0) { + sign.setLine(0, lines[0]); } - if (lines.length>1) { - sign.setLine(1, lines[1]); + if (lines.length > 1) { + sign.setLine(1, lines[1]); } - if (lines.length>2) { - sign.setLine(2, lines[2]); + if (lines.length > 2) { + sign.setLine(2, lines[2]); } - if (lines.length>3) { - sign.setLine(3, lines[3]); + if (lines.length > 3) { + sign.setLine(3, lines[3]); } sign.update(true); } @@ -212,7 +202,7 @@ public class Volume { currentBlock.setData(oldBlockData); BlockState state = currentBlock.getState(); if (state instanceof Chest) { - Chest chest = (Chest)state; + Chest chest = (Chest) state; List contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k); if (contents != null) { int ii = 0; @@ -232,7 +222,7 @@ public class Volume { currentBlock.setData(oldBlockData); BlockState state = currentBlock.getState(); if (state instanceof Dispenser) { - Dispenser dispenser = (Dispenser)state; + Dispenser dispenser = (Dispenser) state; List contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k); if (contents != null) { int ii = 0; @@ -246,30 +236,23 @@ public class Volume { dispenser.update(true); } } - } else if (oldBlockType == Material.WOODEN_DOOR.getId() || oldBlockType == Material.IRON_DOOR_BLOCK.getId()){ + } else if (oldBlockType == Material.WOODEN_DOOR.getId() || oldBlockType == Material.IRON_DOOR_BLOCK.getId()) { // Door blocks // Check if is bottom door block - if (j+1 < this.getSizeY() && this.getBlockTypes()[i][j+1][k] == oldBlockType) { + if (j + 1 < this.getSizeY() && this.getBlockTypes()[i][j + 1][k] == oldBlockType) { // set both door blocks right away currentBlock.setType(Material.getMaterial(oldBlockType)); currentBlock.setData(oldBlockData); - Block blockAbove = this.getWorld().getBlockAt(x, y+1, z); + Block blockAbove = this.getWorld().getBlockAt(x, y + 1, z); blockAbove.setType(Material.getMaterial(oldBlockType)); - blockAbove.setData(this.getBlockDatas()[i][j+1][k]); + blockAbove.setData(this.getBlockDatas()[i][j + 1][k]); } - } else if (((oldBlockType == Material.TORCH.getId() && ((oldBlockData & 0x02) == 0x02)) - || (oldBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((oldBlockData & 0x02) == 0x02)) - || (oldBlockType == Material.REDSTONE_TORCH_ON.getId() && ((oldBlockData & 0x02) == 0x02)) - || (oldBlockType == Material.LEVER.getId() && ((oldBlockData & 0x02) == 0x02)) - || (oldBlockType == Material.STONE_BUTTON.getId() && ((oldBlockData & 0x02) == 0x02)) - || (oldBlockType == Material.LADDER.getId() && ((oldBlockData & 0x04) == 0x04)) - || (oldBlockType == Material.RAILS.getId() && ((oldBlockData & 0x02) == 0x02))) - && i+1 != this.getSizeX()){ + } else if (((oldBlockType == Material.TORCH.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_ON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LEVER.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.STONE_BUTTON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LADDER.getId() && ((oldBlockData & 0x04) == 0x04)) || (oldBlockType == Material.RAILS.getId() && ((oldBlockData & 0x02) == 0x02))) && i + 1 != this.getSizeX()) { // Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol Block southBlock = currentBlock.getFace(BlockFace.SOUTH); - int oldSouthBlockType = this.getBlockTypes()[i+1][j][k]; - byte oldSouthBlockData = this.getBlockDatas()[i+1][j][k]; + int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k]; + byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k]; if (southBlock.getTypeId() != oldSouthBlockType) { southBlock.setTypeId(oldSouthBlockType); southBlock.setData(oldSouthBlockData); @@ -286,9 +269,7 @@ public class Volume { } visitedBlocks++; } catch (Exception e) { - this.getWar().getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks - + ". Blocks reset: "+ noOfResetBlocks + - ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); + this.getWar().getLogger().warning("Failed to reset block in volume " + this.getName() + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage()); e.printStackTrace(); } finally { z++; @@ -300,9 +281,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().logWarn("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks - + ". Blocks reset: "+ noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z - + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage()); e.printStackTrace(); } return noOfResetBlocks; @@ -317,7 +296,6 @@ public class Volume { this.blockDatas = data; } - public void setCornerTwo(Block block) { this.cornerTwo = new BlockInfo(block); } @@ -328,21 +306,21 @@ public class Volume { public BlockInfo getMinXBlock() { if (this.cornerOne.getX() < this.cornerTwo.getX()) { - return this.cornerOne; + return this.cornerOne; } return this.cornerTwo; } public BlockInfo getMinYBlock() { if (this.cornerOne.getY() < this.cornerTwo.getY()) { - return this.cornerOne; + return this.cornerOne; } return this.cornerTwo; } public BlockInfo getMinZBlock() { if (this.cornerOne.getZ() < this.cornerTwo.getZ()) { - return this.cornerOne; + return this.cornerOne; } return this.cornerTwo; } @@ -361,21 +339,21 @@ public class Volume { public BlockInfo getMaxXBlock() { if (this.cornerOne.getX() < this.cornerTwo.getX()) { - return this.cornerTwo; + return this.cornerTwo; } return this.cornerOne; } public BlockInfo getMaxYBlock() { if (this.cornerOne.getY() < this.cornerTwo.getY()) { - return this.cornerTwo; + return this.cornerTwo; } return this.cornerOne; } public BlockInfo getMaxZBlock() { if (this.cornerOne.getZ() < this.cornerTwo.getZ()) { - return this.cornerTwo; + return this.cornerTwo; } return this.cornerOne; } @@ -424,22 +402,14 @@ public class Volume { int x = location.getBlockX(); int y = location.getBlockY(); int z = location.getBlockZ(); - return this.hasTwoCorners() && - location.getWorld().getName().equals(this.world.getName()) && - x <= this.getMaxX() && x >= this.getMinX() && - y <= this.getMaxY() && y >= this.getMinY() && - z <= this.getMaxZ() && z >= this.getMinZ(); + return this.hasTwoCorners() && location.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ(); } public boolean contains(Block block) { int x = block.getX(); int y = block.getY(); int z = block.getZ(); - return this.hasTwoCorners() && - block.getWorld().getName().equals(this.world.getName()) && - x <= this.getMaxX() && x >= this.getMinX() && - y <= this.getMaxY() && y >= this.getMinY() && - z <= this.getMaxZ() && z >= this.getMinZ(); + return this.hasTwoCorners() && block.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ(); } public void setBlockTypes(int[][][] blockTypes) { @@ -458,11 +428,11 @@ public class Volume { try { if (this.hasTwoCorners() && this.isSaved()) { int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++){ + for (int i = 0; i < this.getSizeX(); i++) { int y = this.getMaxY(); - for (int j = this.getSizeY(); j > 0; j--){ + for (int j = this.getSizeY(); j > 0; j--) { int z = this.getMinZ(); - for (int k = 0;k < this.getSizeZ(); k++) { + for (int k = 0; k < this.getSizeZ(); k++) { Block currentBlock = this.getWorld().getBlockAt(x, y, z); currentBlock.setType(material); z++; @@ -481,17 +451,12 @@ public class Volume { try { if (this.hasTwoCorners() && this.isSaved()) { int x = this.getMinX(); - for (int i = 0; i < this.getSizeX(); i++){ + for (int i = 0; i < this.getSizeX(); i++) { int y = this.getMinY(); - for (int j = 0; j < this.getSizeY(); j++){ + for (int j = 0; j < this.getSizeY(); j++) { int z = this.getMinZ(); - for (int k = 0;k < this.getSizeZ(); k++) { - if ((face == BlockFace.DOWN && y == this.getMinY()) - || (face == BlockFace.UP && y == this.getMaxY()) - || (face == BlockFace.NORTH && x == this.getMinX()) - || (face == BlockFace.EAST && z == this.getMinZ()) - || (face == BlockFace.SOUTH && x == this.getMaxX()) - || (face == BlockFace.WEST && z == this.getMaxZ())) { + for (int k = 0; k < this.getSizeZ(); k++) { + if ((face == BlockFace.DOWN && y == this.getMinY()) || (face == BlockFace.UP && y == this.getMaxY()) || (face == BlockFace.NORTH && x == this.getMinX()) || (face == BlockFace.EAST && z == this.getMinZ()) || (face == BlockFace.SOUTH && x == this.getMaxX()) || (face == BlockFace.WEST && z == this.getMaxZ())) { Block currentBlock = this.getWorld().getBlockAt(x, y, z); currentBlock.setType(material); } @@ -514,20 +479,20 @@ public class Volume { Block currentBlock = null; if (this.hasTwoCorners() && this.isSaved()) { x = this.getMinX(); - for (i = 0; i < this.getSizeX(); i++){ + for (i = 0; i < this.getSizeX(); i++) { y = this.getMaxY(); - for (j = this.getSizeY(); j > 0; j--){ + for (j = this.getSizeY(); j > 0; j--) { z = this.getMinZ(); - for (k = 0;k < this.getSizeZ(); k++) { + for (k = 0; k < this.getSizeZ(); k++) { currentBlock = this.getWorld().getBlockAt(x, y, z); for (Material oldType : oldTypes) { if (currentBlock.getType().getId() == oldType.getId()) { currentBlock.setType(newType); -// BlockState state = currentBlock.getState(); -// if (state != null) { -// state.setType(newType); -// state.update(true); -// } + // BlockState state = currentBlock.getState(); + // if (state != null) { + // state.setType(newType); + // state.update(true); + // } } } z++; diff --git a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java b/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java index ee4ef7f..c41e29d 100644 --- a/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/ZoneVolume.java @@ -11,9 +11,9 @@ import com.tommytony.war.Warzone; import com.tommytony.war.mappers.ZoneVolumeMapper; /** - * + * * @author tommytony - * + * */ public class ZoneVolume extends Volume { @@ -26,7 +26,7 @@ public class ZoneVolume extends Volume { } @Override - public int saveBlocks() { + public int saveBlocks() { // Save blocks directly to disk (i.e. don't put everything in memory) int saved = ZoneVolumeMapper.save(this, this.zone.getName(), this.getWar()); this.getWar().logInfo("Saved " + saved + " blocks in warzone " + this.zone.getName() + "."); @@ -45,7 +45,7 @@ public class ZoneVolume extends Volume { } @Override - public int resetBlocks() { + public int resetBlocks() { // Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks) int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWar(), this.getWorld(), false); this.getWar().logInfo("Reset " + reset + " blocks in warzone " + this.zone.getName() + "."); @@ -68,30 +68,29 @@ public class ZoneVolume extends Volume { BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData()); BlockInfo oldCornerOne = this.getCornerOne(); BlockInfo oldCornerTwo = this.getCornerTwo(); - if (this.getCornerOne() == null) - { + if (this.getCornerOne() == null) { if (this.getCornerTwo() == null) { // northwest defaults to corner 1 super.setCornerOne(topBlock); } else if (this.getCornerTwo().getX() <= block.getX() || this.getCornerTwo().getZ() >= block.getZ()) { - throw new NotNorthwestException(); + throw new NotNorthwestException(); } else { // corner 2 already set, but we're sure we're located at the northwest of it super.setCornerOne(topBlock); } - } else if (this.getCornerTwo() == null){ + } else if (this.getCornerTwo() == null) { // corner 1 already exists, set northwest as corner 2 (only if it's at the northwest of corner 1) if (this.getCornerOne().getX() <= block.getX() || this.getCornerOne().getZ() >= block.getZ()) { - throw new NotNorthwestException(); + throw new NotNorthwestException(); } super.setCornerTwo(topBlock); } else { // both corners already set: we are resizing (only if the new block is northwest relative to the southeasternmost block) if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) { - throw new NotNorthwestException(); + throw new NotNorthwestException(); } BlockInfo minXBlock = this.getMinXBlock(); // north means min X - minXBlock.setX(block.getX()); // mutating, argh! + minXBlock.setX(block.getX()); // mutating, argh! BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z maxZBlock.setZ(block.getZ()); } @@ -108,17 +107,17 @@ public class ZoneVolume extends Volume { public int getNorthwestX() { if (!this.hasTwoCorners()) { - return 0; + return 0; } else { - return this.getMinX(); + return this.getMinX(); } } public int getNorthwestZ() { if (!this.hasTwoCorners()) { - return 0; + return 0; } else { - return this.getMaxZ(); + return this.getMaxZ(); } } @@ -127,30 +126,29 @@ public class ZoneVolume extends Volume { BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData()); BlockInfo oldCornerOne = this.getCornerOne(); BlockInfo oldCornerTwo = this.getCornerTwo(); - if (this.getCornerTwo() == null) - { + if (this.getCornerTwo() == null) { if (this.getCornerOne() == null) { // southeast defaults to corner 2 super.setCornerTwo(bottomBlock); } else if (this.getCornerOne().getX() >= block.getX() || this.getCornerOne().getZ() <= block.getZ()) { - throw new NotSoutheastException(); + throw new NotSoutheastException(); } else { // corner 1 already set, but we're sure we're located at the southeast of it super.setCornerTwo(bottomBlock); } - } else if (this.getCornerOne() == null){ + } else if (this.getCornerOne() == null) { // corner 2 already exists, set northwest as corner 1 (only if it's at the southeast of corner 2) if (this.getCornerTwo().getX() >= block.getX() || this.getCornerTwo().getZ() <= block.getZ()) { - throw new NotSoutheastException(); + throw new NotSoutheastException(); } super.setCornerOne(bottomBlock); } else { // both corners already set: we are resizing (only if the new block is southeast relative to the northwesternmost block) if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) { - throw new NotSoutheastException(); + throw new NotSoutheastException(); } BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X - maxXBlock.setX(block.getX()); // mutating, argh! + maxXBlock.setX(block.getX()); // mutating, argh! BlockInfo minZBlock = this.getMinZBlock(); // east means min Z minZBlock.setZ(block.getZ()); } @@ -168,25 +166,25 @@ public class ZoneVolume extends Volume { public int getSoutheastX() { if (!this.hasTwoCorners()) { - return 0; + return 0; } else { - return this.getMaxX(); + return this.getMaxX(); } } public int getSoutheastZ() { if (!this.hasTwoCorners()) { - return 0; + return 0; } else { - return this.getMinZ(); + return this.getMinZ(); } } public int getCenterY() { if (!this.hasTwoCorners()) { - return 0; + return 0; } else { - return this.getMinY() + (this.getMaxY() - this.getMinY())/2; + return this.getMinY() + (this.getMaxY() - this.getMinY()) / 2; } } @@ -215,19 +213,15 @@ public class ZoneVolume extends Volume { } public boolean tooSmall() { - if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() < 10) - || (this.getMaxY() - this.getMinY() < 10) - || (this.getMaxZ() - this.getMinZ() < 10))) { - return true; + if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() < 10) || (this.getMaxY() - this.getMinY() < 10) || (this.getMaxZ() - this.getMinZ() < 10))) { + return true; } return false; } public boolean tooBig() { - if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() > 750) - || (this.getMaxY() - this.getMinY() > 750) - || (this.getMaxZ() - this.getMinZ() > 750))) { - return true; + if (this.hasTwoCorners() && ((this.getMaxX() - this.getMinX() > 750) || (this.getMaxY() - this.getMinY() > 750) || (this.getMaxZ() - this.getMinZ() > 750))) { + return true; } return false; } @@ -236,24 +230,21 @@ public class ZoneVolume extends Volume { // check team spawns & flags for (Team team : this.zone.getTeams()) { if (team.getTeamSpawn() != null) { - if (!this.isInside(team.getSpawnVolume().getCornerOne()) - || !this.isInside(team.getSpawnVolume().getCornerTwo())) { - return true; + if (!this.isInside(team.getSpawnVolume().getCornerOne()) || !this.isInside(team.getSpawnVolume().getCornerTwo())) { + return true; } } if (team.getTeamFlag() != null) { - if (!this.isInside(team.getFlagVolume().getCornerOne()) - || !this.isInside(team.getFlagVolume().getCornerTwo())) { - return true; + if (!this.isInside(team.getFlagVolume().getCornerOne()) || !this.isInside(team.getFlagVolume().getCornerTwo())) { + return true; } } } // check monuments for (Monument monument : this.zone.getMonuments()) { if (monument.getVolume() != null) { - if (!this.isInside(monument.getVolume().getCornerOne()) - || !this.isInside(monument.getVolume().getCornerTwo())) { - return true; + if (!this.isInside(monument.getVolume().getCornerOne()) || !this.isInside(monument.getVolume().getCornerTwo())) { + return true; } } } @@ -261,222 +252,63 @@ public class ZoneVolume extends Volume { } private boolean isInside(BlockInfo info) { - if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && - info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && - info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) { - return true; + if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) { + return true; } return false; } - public boolean isWallBlock(Block block){ - return this.isEastWallBlock(block) || this.isNorthWallBlock(block) - || this.isSouthWallBlock(block) || this.isWestWallBlock(block) - || this.isUpWallBlock(block) || this.isDownWallBlock(block); + public boolean isWallBlock(Block block) { + return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block) || this.isUpWallBlock(block) || this.isDownWallBlock(block); } public boolean isEastWallBlock(Block block) { - if (this.getMinZ() == block.getZ() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX() - && block.getY() >= this.getMinY() - && block.getY() <= this.getMaxY()) - { - return true; // east wall + if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { + return true; // east wall } return false; } public boolean isSouthWallBlock(Block block) { - if (this.getMaxX() == block.getX() - && block.getZ() <= this.getMaxZ() - && block.getZ() >= this.getMinZ() - && block.getY() >= this.getMinY() - && block.getY() <= this.getMaxY()) - { - return true; // south wall + if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { + return true; // south wall } return false; } public boolean isNorthWallBlock(Block block) { - if (this.getMinX() == block.getX() - && block.getZ() <= this.getMaxZ() - && block.getZ() >= this.getMinZ() - && block.getY() >= this.getMinY() - && block.getY() <= this.getMaxY()) - { - return true; // north wall + if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { + return true; // north wall } return false; } public boolean isWestWallBlock(Block block) { - if (this.getMaxZ() == block.getZ() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX() - && block.getY() >= this.getMinY() - && block.getY() <= this.getMaxY()) - { - return true; // west wall + if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getY() >= this.getMinY() && block.getY() <= this.getMaxY()) { + return true; // west wall } return false; } public boolean isUpWallBlock(Block block) { - if (this.getMaxY() == block.getY() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX() - && block.getZ() >= this.getMinZ() - && block.getZ() <= this.getMaxZ()) - { - return true; // top wall + if (this.getMaxY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) { + return true; // top wall } return false; } public boolean isDownWallBlock(Block block) { - if (this.getMinY() == block.getY() - && block.getX() <= this.getMaxX() - && block.getX() >= this.getMinX() - && block.getZ() >= this.getMinZ() - && block.getZ() <= this.getMaxZ()) - { - return true; // bottom wall + if (this.getMinY() == block.getY() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX() && block.getZ() >= this.getMinZ() && block.getZ() <= this.getMaxZ()) { + return true; // bottom wall } return false; } - /*public int resetWallBlocks(BlockFace wall) { - int noOfResetBlocks = 0; - try { - if (hasTwoCorners() && getBlockTypes() != null) { - if (wall == BlockFace.EAST) { - int z = getMinZ(); - int k = 0; - int y = getMinY(); - for (int j = 0; j < getSizeY(); j++) { - int x = getMinX(); - for (int i = 0; i < getSizeX(); i++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - x++; - } - y++; - } - } else if (wall == BlockFace.WEST) { - int z = getMaxZ(); - int k = getSizeZ()-1; - int y = getMinY(); - for (int j = 0; j < getSizeY(); j++) { - int x = getMinX(); - for (int i = 0; i < getSizeX(); i++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - x++; - } - y++; - } - } else if (wall == BlockFace.NORTH) { - int x = getMinX(); - int i = 0; - int y = getMinY(); - for (int j = 0; j < getSizeY(); j++) { - int z = getMinZ(); - for (int k = 0; k < getSizeZ(); k++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - y++; - } - } else if (wall == BlockFace.SOUTH) { - int x = getMaxX(); - int i = getSizeX()-1; - int y = getMinY(); - for (int j = 0; j < getSizeY(); j++) { - int z = getMinZ(); - for (int k = 0; k < getSizeZ(); k++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - y++; - } - } else if (wall == BlockFace.UP) { - int x = getMinX(); - int y = getMaxY(); - int j = getSizeY()-1; - for (int i = 0;i < getSizeX(); i++) { - int z = getMinZ(); - for (int k = 0; k < getSizeZ(); k++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - x++; - } - } else if (wall == BlockFace.DOWN) { - int x = getMinX(); - int y = getMinY(); - int j = 0; - for (int i = 0;i < getSizeX(); i++) { - int z = getMinZ(); - for (int k = 0; k < getSizeZ(); k++) { - int oldBlockType = getBlockTypes()[i][j][k]; - byte oldBlockData = getBlockDatas()[i][j][k]; - Block currentBlock = getWorld().getBlockAt(x, y, z); - if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { - noOfResetBlocks++; - } - z++; - } - x++; - } - } - } - } catch (Exception e) { - this.getWar().logWarn("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage()); - } - return noOfResetBlocks; - } - - - private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) { - if (currentBlock.getTypeId() != oldBlockType || - (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || - (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && - (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) - ) - ) { - currentBlock.setTypeId(oldBlockType); - currentBlock.setData(oldBlockData); - // TODO: reset wall signs, chests and dispensers properly like in resetBlocks - return true; - } - return false; - } - */ - + /* + * public int resetWallBlocks(BlockFace wall) { int noOfResetBlocks = 0; try { if (hasTwoCorners() && getBlockTypes() != null) { if (wall == BlockFace.EAST) { int z = getMinZ(); int k = 0; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int x = getMinX(); for (int i = 0; i < getSizeX(); i++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } x++; } y++; } } else if (wall == BlockFace.WEST) { int z = getMaxZ(); int k = getSizeZ()-1; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int x = getMinX(); for (int i = 0; i < getSizeX(); i++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } x++; } y++; } } else if (wall == BlockFace.NORTH) { int x = getMinX(); int i = 0; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } y++; } } else if (wall == BlockFace.SOUTH) { int x = getMaxX(); int i = getSizeX()-1; int y = getMinY(); for (int j = 0; j < getSizeY(); j++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } y++; } } else if (wall == BlockFace.UP) { int x = getMinX(); int y = getMaxY(); int j = getSizeY()-1; for (int i = 0;i < getSizeX(); i++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } x++; } } else if (wall == BlockFace.DOWN) { int x = getMinX(); int y = getMinY(); int j = 0; for (int i = 0;i < getSizeX(); i++) { int z = getMinZ(); for (int k = 0; k < getSizeZ(); k++) { int oldBlockType = getBlockTypes()[i][j][k]; byte oldBlockData = getBlockDatas()[i][j][k]; Block currentBlock = getWorld().getBlockAt(x, y, z); if (resetBlock(oldBlockType, oldBlockData, currentBlock)) { noOfResetBlocks++; } z++; } x++; } } } } catch (Exception e) { this.getWar().logWarn("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage()); } return noOfResetBlocks; } + * + * + * private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) { if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) ) ) { currentBlock.setTypeId(oldBlockType); currentBlock.setData(oldBlockData); // TODO: reset wall signs, chests and dispensers properly like in resetBlocks return true; } return false; } + */ }