From 3b7f308fba7d83a6ed18d0efb4c2482fabb4e47c Mon Sep 17 00:00:00 2001 From: taoneill Date: Thu, 10 Feb 2011 01:32:40 -0500 Subject: [PATCH] Closes 36. Team members that sneak out of the warzone are killed (should prevent people from warping out with their zone goodies as well). Huge refactor of how I send messages to players to accomodate the chat color fix for client crashes. Woot. --- .../main/java/bukkit/tommytony/war/War.java | 248 +++++++++--------- .../tommytony/war/WarBlockListener.java | 30 +-- .../tommytony/war/WarEntityListener.java | 42 +-- .../tommytony/war/WarPlayerListener.java | 80 +++--- .../java/com/tommytony/war/ChatFixUtil.java | 230 ++++++++++++++++ war/src/main/java/com/tommytony/war/Team.java | 2 +- .../main/java/com/tommytony/war/Warzone.java | 14 +- .../java/com/tommytony/war/ZoneLobby.java | 2 +- .../tommytony/war/mappers/VolumeMapper.java | 10 +- .../com/tommytony/war/mappers/WarMapper.java | 8 +- .../tommytony/war/mappers/WarzoneMapper.java | 6 +- .../tommytony/war/volumes/VerticalVolume.java | 2 +- .../com/tommytony/war/volumes/Volume.java | 8 +- 13 files changed, 463 insertions(+), 219 deletions(-) create mode 100644 war/src/main/java/com/tommytony/war/ChatFixUtil.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index e2a4939..c680017 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -29,6 +29,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.nijikokun.bukkit.Permissions.Permissions; +import com.tommytony.war.ChatFixUtil; import com.tommytony.war.Monument; import com.tommytony.war.Team; import com.tommytony.war.TeamChatColors; @@ -83,7 +84,7 @@ public class War extends JavaPlugin { public void onDisable() { for(Warzone warzone : warzones) { - this.info("Clearing zone " + warzone.getName() + "..."); + this.logInfo("Clearing zone " + warzone.getName() + "..."); for(Team team : warzone.getTeams()) { for(Player player : team.getPlayers()) { warzone.handlePlayerLeave(player, warzone.getTeleport()); @@ -97,7 +98,7 @@ public class War extends JavaPlugin { if(warHub != null) { warHub.getVolume().resetBlocks(); } - this.info("Done. War v" + desc.getVersion() + " is off."); + this.logInfo("Done. War v" + desc.getVersion() + " is off."); } public void onEnable() { @@ -132,7 +133,7 @@ public class War extends JavaPlugin { this.defaultAutoAssignOnly = false; this.getDefaultReward().put(0, new ItemStack(Material.CAKE, 1)); WarMapper.load(this); - this.info("Done. War v"+ desc.getVersion() + " is on."); + this.logInfo("Done. War v"+ desc.getVersion() + " is on."); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { @@ -141,8 +142,8 @@ 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 = this.str("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 > 1) { command = args[1]; arguments = new String[args.length - 1]; @@ -150,10 +151,10 @@ public class War extends JavaPlugin { arguments[i-1] = args[i]; } if(arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) { - player.sendMessage(helpMessage); + this.msg(player, helpMessage); } } else if (command.equals("war") || command.equals("War")) { - player.sendMessage(helpMessage); + this.msg(player, helpMessage); } else { arguments = args; } @@ -224,7 +225,7 @@ public class War extends JavaPlugin { || command.equals("setwarhub") || command.equals("deletewarhub") || command.equals("setwarconfig")) { - player.sendMessage(this.bad("You can't do this if you are not a warzone maker.")); + this.badMsg(player, "You can't do this if you are not a warzone maker."); } else if (command.equals("zonemaker")) { performZonemakerAsPlayer(player); } @@ -241,34 +242,34 @@ public class War extends JavaPlugin { } if(wasImpersonating) { getZoneMakersImpersonatingPlayers().remove(player.getName()); - player.sendMessage(str("You are back as a zone maker.")); + msg(player, "You are back as a zone maker."); } WarMapper.save(this); } public void performZonemakerAsZonemaker(Player player, String[] arguments) { if(arguments.length > 2) { - player.sendMessage(this.bad("Usage: /zonemaker , /zonemaker" + + 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.")); + "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 if(zoneMakerNames.contains(arguments[0])) { // kick zoneMakerNames.remove(arguments[0]); - player.sendMessage(str(arguments[0] + " is not a zone maker anymore.")); + msg(player, arguments[0] + " is not a zone maker anymore."); Player kickedMaker = getServer().getPlayer(arguments[0]); if(kickedMaker != null) { - kickedMaker.sendMessage(str(player.getName() + " took away your warzone maker priviledges.")); + msg(kickedMaker, player.getName() + " took away your warzone maker priviledges."); } } else { // add zoneMakerNames.add(arguments[0]); - player.sendMessage(str(arguments[0] + " is now a zone maker.")); + msg(player, arguments[0] + " is now a zone maker."); Player newMaker = getServer().getPlayer(arguments[0]); if(newMaker != null) { - newMaker.sendMessage(str(player.getName() + " made you warzone maker.")); + msg(newMaker, player.getName() + " made you warzone maker."); } } } else { @@ -276,7 +277,7 @@ public class War extends JavaPlugin { if(isZoneMaker(player)) { getZoneMakersImpersonatingPlayers().add(player.getName()); } - player.sendMessage(str("You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode.")); + msg(player, "You are now impersonating a regular player. Type /zonemaker again to toggle back to war maker mode."); } WarMapper.save(this); @@ -285,14 +286,14 @@ public class War extends JavaPlugin { public void performSetWarConfig(Player player, String[] arguments) { if(arguments.length == 0) { - player.sendMessage(this.bad("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. Must be in warzone.")); + 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. Must be in warzone."); } else { if(updateFromNamedParams(arguments)) { WarMapper.save(this); - player.sendMessage(this.str("War config saved.")); + this.msg(player, "War config saved."); } else { - player.sendMessage(this.bad("Failed to read named parameters.")); + this.badMsg(player, "Failed to read named parameters."); } } } @@ -308,9 +309,9 @@ public class War extends JavaPlugin { zone.getLobby().initialize(); } - player.sendMessage(this.str("War hub removed.")); + this.msg(player, "War hub removed."); } else { - player.sendMessage(this.bad("No War hub to delete.")); + this.badMsg(player, "No War hub to delete."); } WarMapper.save(this); } @@ -322,7 +323,7 @@ public class War extends JavaPlugin { warHub.getVolume().resetBlocks(); warHub.setLocation(player.getLocation()); warHub.initialize(); - player.sendMessage(str("War hub moved.")); + msg(player, "War hub moved."); } else { warHub = new WarHub(this, player.getLocation()); warHub.initialize(); @@ -330,20 +331,20 @@ public class War extends JavaPlugin { zone.getLobby().getVolume().resetBlocks(); zone.getLobby().initialize(); } - player.sendMessage(str("War hub created.")); + msg(player, "War hub created."); } WarMapper.save(this); } else { - player.sendMessage(bad("No warzones yet.")); + badMsg(player, "No warzones yet."); } } public void performDeleteMonument(Player player, String[] arguments) { if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation()))) { - player.sendMessage(this.bad("Usage: /deletemonument ." + + this.badMsg(player, "Usage: /deletemonument ." + " Deletes the monument. " + - "Must be in a warzone or lobby (try /warzones and /warzone). ")); + "Must be in a warzone or lobby (try /warzones and /warzone). "); } else { String name = arguments[0]; Warzone warzone = this.warzone(player.getLocation()); @@ -358,9 +359,9 @@ public class War extends JavaPlugin { monument.getVolume().resetBlocks(); warzone.getMonuments().remove(monument); WarzoneMapper.save(this, warzone, false); - player.sendMessage(this.str("Monument " + name + " removed.")); + this.msg(player, "Monument " + name + " removed."); } else { - player.sendMessage(this.bad("No such monument.")); + this.badMsg(player, "No such monument."); } } } @@ -369,7 +370,7 @@ public class War extends JavaPlugin { 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()))) { - player.sendMessage(this.bad("Usage: /setmonument . Creates or moves a monument. Monument can't have same name as zone. Must be in warzone.")); + 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()); String monumentName = arguments[0]; @@ -378,12 +379,12 @@ public class War extends JavaPlugin { Monument monument = warzone.getMonument(monumentName); monument.getVolume().resetBlocks(); monument.setLocation(player.getLocation()); - player.sendMessage(this.str("Monument " + monument.getName() + " was moved.")); + this.msg(player, "Monument " + monument.getName() + " was moved."); } else { // create a new monument Monument monument = new Monument(arguments[0], this, warzone, player.getLocation()); warzone.getMonuments().add(monument); - player.sendMessage(this.str("Monument " + monument.getName() + " created.")); + this.msg(player, "Monument " + monument.getName() + " created."); } WarzoneMapper.save(this, warzone, false); } @@ -392,9 +393,9 @@ public class War extends JavaPlugin { public void performDeleteTeam(Player player, String[] arguments) { if(arguments.length < 1 || (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation()))) { - player.sendMessage(this.bad("Usage: /deleteteam ." + + this.badMsg(player, "Usage: /deleteteam ." + " Deletes the team and its spawn. " + - "Must be in a warzone or lobby (try /zones and /zone). ")); + "Must be in a warzone or lobby (try /zones and /zone). "); } else { String name = TeamMaterials.teamMaterialToString(TeamMaterials.teamMaterialFromString(arguments[0])); Warzone warzone = this.warzone(player.getLocation()); @@ -422,9 +423,9 @@ public class War extends JavaPlugin { warzone.getLobby().initialize(); } WarzoneMapper.save(this, warzone, false); - player.sendMessage(this.str("Team " + name + " removed.")); + this.msg(player, "Team " + name + " removed."); } else { - player.sendMessage(this.bad("No such team.")); + this.badMsg(player, "No such team."); } } } @@ -432,9 +433,9 @@ public class War extends JavaPlugin { public void performSetTeamFlag(Player player, String[] arguments) { if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { - player.sendMessage(this.bad("Usage: /setteamflag . " + + this.badMsg(player, "Usage: /setteamflag . " + "Sets the team flag post to the current location. " + - "Must be in a warzone (try /zones and /zone). ")); + "Must be in a warzone (try /zones and /zone). "); } else { Material teamMaterial = TeamMaterials.teamMaterialFromString(arguments[0]); String name = TeamMaterials.teamMaterialToString(teamMaterial); @@ -442,14 +443,14 @@ public class War extends JavaPlugin { Team team = warzone.getTeamByMaterial(teamMaterial); if(team == null) { // no such team yet - player.sendMessage(this.bad("Place the team spawn first.")); + this.badMsg(player, "Place the team spawn first."); } else if (team.getFlagVolume() == null){ // new team flag team.setTeamFlag(player.getLocation()); Location playerLoc = player.getLocation(); player.teleportTo(new Location(playerLoc.getWorld(), playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ())); - player.sendMessage(this.str("Team " + name + " flag added here.")); + this.msg(player, "Team " + name + " flag added here."); WarzoneMapper.save(this, warzone, false); } else { // relocate flag @@ -458,7 +459,7 @@ public class War extends JavaPlugin { Location playerLoc = player.getLocation(); player.teleportTo(new Location(playerLoc.getWorld(), playerLoc.getBlockX()+1, playerLoc.getBlockY(), playerLoc.getBlockZ()+1)); - player.sendMessage(this.str("Team " + name + " flag moved.")); + this.msg(player, "Team " + name + " flag moved."); WarzoneMapper.save(this, warzone, false); } } @@ -467,9 +468,9 @@ public class War extends JavaPlugin { public void performSetTeam(Player player, String[] arguments) { if(arguments.length < 1 || !this.inAnyWarzone(player.getLocation()) || (arguments.length > 0 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { - player.sendMessage(this.bad("Usage: /setteam . " + + this.badMsg(player, "Usage: /setteam . " + "Sets the team spawn to the current location. " + - "Must be in a warzone (try /zones and /zone). ")); + "Must be in a warzone (try /zones and /zone). "); } else { Material teamMaterial = TeamMaterials.teamMaterialFromString(arguments[0]); String name = TeamMaterials.teamMaterialToString(teamMaterial); @@ -478,7 +479,7 @@ public class War extends JavaPlugin { if(existingTeam != null) { // relocate existingTeam.setTeamSpawn(player.getLocation()); - player.sendMessage(this.str("Team " + existingTeam.getName() + " spawn relocated.")); + this.msg(player, "Team " + existingTeam.getName() + " spawn relocated."); } else { // new team Team newTeam = new Team(name, teamMaterial, player.getLocation(), this, warzone); @@ -491,7 +492,7 @@ public class War extends JavaPlugin { warzone.getLobby().initialize(); } newTeam.setTeamSpawn(player.getLocation()); - player.sendMessage(this.str("Team " + name + " created with spawn here.")); + this.msg(player, "Team " + name + " created with spawn here."); } WarzoneMapper.save(this, warzone, false); @@ -500,9 +501,9 @@ public class War extends JavaPlugin { public void performDeleteZone(Player player) { if(!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - player.sendMessage(this.bad("Usage: /deletezone. " + + this.badMsg(player, "Usage: /deletezone. " + "Deletes the warzone. " + - "Must be in the warzone (try /zones and /zone). ")); + "Must be in the warzone (try /zones and /zone). "); } else { Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); @@ -529,13 +530,13 @@ public class War extends JavaPlugin { warHub.getVolume().resetBlocks(); warHub.initialize(); } - player.sendMessage(this.str("Warzone " + warzone.getName() + " removed.")); + this.msg(player, "Warzone " + warzone.getName() + " removed."); } } public void performResetZone(Player player, String[] arguments) { if(!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - player.sendMessage(this.bad("Usage: /resetzone . Reloads the zone (from disk if the hard option is specified). Must be in warzone or lobby.")); + this.badMsg(player, "Usage: /resetzone . Reloads the zone (from disk if the hard option is specified). Must be in warzone or lobby."); } else { Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); @@ -547,18 +548,18 @@ public class War extends JavaPlugin { int resetBlocks = 0; warzone.clearFlagThieves(); for(Team team: warzone.getTeams()) { - team.teamcast(this.str("The war has ended. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams...")); + team.teamcast("The war has ended. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams..."); for(Player p : team.getPlayers()) { warzone.restorePlayerInventory(p); p.teleportTo(warzone.getTeleport()); - player.sendMessage(this.str("You have left the warzone. Your inventory has (hopefully) been restored.")); + this.msg(player, "You have left the warzone. Your inventory has (hopefully) been restored."); } team.setPoints(0); team.getPlayers().clear(); } Warzone resetWarzone = null; - player.sendMessage(this.str("Reloading warzone " + warzone.getName() + ".")); + this.msg(player, "Reloading warzone " + warzone.getName() + "."); if(arguments.length == 1 && (arguments[0].equals("hard") || arguments[0].equals("h"))) { // reset from disk this.getWarzones().remove(warzone); @@ -578,16 +579,16 @@ public class War extends JavaPlugin { } - player.sendMessage(this.str("Warzone and teams reset. " + resetBlocks + " blocks reset.")); - info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); + this.msg(player, "Warzone and teams reset. " + resetBlocks + " blocks reset."); + logInfo(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); } } public void performSetZoneConfig(Player player, String[] arguments) { if((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || arguments.length == 0) { - player.sendMessage(this.bad("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.")); + 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()); @@ -597,24 +598,24 @@ public class War extends JavaPlugin { lobby = warzone.getLobby(); } if(updateZoneFromNamedParams(warzone, arguments)) { - player.sendMessage(this.str("Saving config and resetting warzone " + warzone.getName() + ".")); + this.msg(player, "Saving config and resetting warzone " + warzone.getName() + "."); WarzoneMapper.save(this, warzone, false); warzone.getVolume().resetBlocks(); if(lobby != null) { lobby.getVolume().resetBlocks(); } warzone.initializeZone(); // bring back team spawns etc - player.sendMessage(this.str("Warzone config saved. Zone reset.")); + this.msg(player, "Warzone config saved. Zone reset."); } else { - player.sendMessage(this.bad("Failed to read named parameters.")); + this.badMsg(player, "Failed to read named parameters."); } } } public void performSaveZone(Player player, String[] arguments) { if(!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - player.sendMessage(this.bad("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()); @@ -623,7 +624,7 @@ public class War extends JavaPlugin { } else { lobby = warzone.getLobby(); } - player.sendMessage(this.str("Saving warzone " + warzone.getName() + ".")); + this.msg(player, "Saving warzone " + warzone.getName() + "."); int savedBlocks = warzone.saveState(true); updateZoneFromNamedParams(warzone, arguments); WarzoneMapper.save(this, warzone, true); @@ -633,7 +634,7 @@ public class War extends JavaPlugin { } warzone.initializeZone(); // bring back team spawns etc - player.sendMessage(this.str("Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks.")); + this.msg(player, "Warzone " + warzone.getName() + " initial state changed. Saved " + savedBlocks + " blocks."); } } @@ -645,9 +646,9 @@ public class War extends JavaPlugin { && !arguments[0].equals("east") && !arguments[0].equals("e") && !arguments[0].equals("south") && !arguments[0].equals("s") && !arguments[0].equals("west") && !arguments[0].equals("w"))) { - player.sendMessage(this.bad("Usage: /setzonelobby . Must be in warzone." + + this.badMsg(player, "Usage: /setzonelobby . Must be in warzone." + "Defines on which side the zone lobby lies. " + - "Removes any previously set lobby.")); + "Removes any previously set lobby."); } else { Warzone warzone = this.warzone(player.getLocation()); ZoneLobby lobby = this.lobby(player.getLocation()); @@ -676,7 +677,7 @@ public class War extends JavaPlugin { lobby.getVolume().resetBlocks(); lobby.changeWall(wall); lobby.initialize(); - player.sendMessage(this.str("Warzone lobby moved to " + wallStr + " side of zone.")); + this.msg(player, "Warzone lobby moved to " + wallStr + " side of zone."); } else { // new lobby lobby = new ZoneLobby(this, warzone, wall); @@ -686,7 +687,7 @@ public class War extends JavaPlugin { warHub.getVolume().resetBlocks(); warHub.initialize(); } - player.sendMessage(this.str("Warzone lobby created on " + wallStr + "side of zone.")); + this.msg(player, "Warzone lobby created on " + wallStr + "side of zone."); } WarzoneMapper.save(this, warzone, false); } @@ -696,9 +697,9 @@ public class War extends JavaPlugin { if(arguments.length < 2 || arguments.length > 2 || (arguments.length == 2 && (!arguments[1].equals("southeast") && !arguments[1].equals("northwest") && !arguments[1].equals("se") && !arguments[1].equals("nw")))) { - player.sendMessage(this.bad("Usage: /setzone <'southeast'/'northwest'/'se'/'nw'>. " + + this.badMsg(player, "Usage: /setzone <'southeast'/'northwest'/'se'/'nw'>. " + "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 zone if the outline is correct.")); + "Saves the zone blocks if the zone if the outline is correct."); } else { Warzone warzone = this.findWarzone(arguments[0]); if(warzone == null) { @@ -708,12 +709,12 @@ public class War extends JavaPlugin { WarMapper.save(this); if(arguments[1].equals("northwest") || arguments[1].equals("nw")) { warzone.setNorthwest(player.getLocation()); - player.sendMessage(this.str("Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" - + (int)warzone.getNorthwest().getBlockX() + " z:" + (int)warzone.getNorthwest().getBlockZ() + ".")); + this.msg(player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + + (int)warzone.getNorthwest().getBlockX() + " z:" + (int)warzone.getNorthwest().getBlockZ() + "."); } else { warzone.setSoutheast(player.getLocation()); - player.sendMessage(this.str("Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" - + (int)warzone.getSoutheast().getBlockX() + " z:" + (int)warzone.getSoutheast().getBlockZ() + ".")); + this.msg(player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + + (int)warzone.getSoutheast().getBlockX() + " z:" + (int)warzone.getSoutheast().getBlockZ() + "."); } WarzoneMapper.save(this, warzone, false); } else { @@ -722,14 +723,14 @@ public class War extends JavaPlugin { if(warzone.getSoutheast() != null && (player.getLocation().getBlockX() >= warzone.getSoutheast().getBlockX() || player.getLocation().getBlockZ() <= warzone.getSoutheast().getBlockZ())) { - player.sendMessage(this.bad("You must place that corner northwest relative to the existing southeast corner!")); + this.badMsg(player, "You must place that corner northwest relative to the existing southeast corner!"); } else if (warzone.getSoutheast() == null){ // just moving the single nw corner we've placed so far warzone.setNorthwest(player.getLocation()); }else { String msgString = ""; if(warzone.getVolume().isSaved()) { - player.sendMessage(str("Resetting " + warzone.getName() + " blocks.")); + msg(player, "Resetting " + warzone.getName() + " blocks."); if(warzone.getLobby() != null) { warzone.getLobby().getVolume().resetBlocks(); } @@ -739,28 +740,28 @@ public class War extends JavaPlugin { } warzone.setNorthwest(player.getLocation()); if(warzone.tooSmall()) { - player.sendMessage(bad("Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.")); + badMsg(player, "Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20."); } else if (warzone.tooBig()) { - player.sendMessage(bad("Warzone " + warzone.getName() + " is too Big. Max north-south size: 500. Max east-west size: 500.")); + badMsg(player, "Warzone " + warzone.getName() + " is too Big. Max north-south size: 500. Max east-west size: 500."); } else { msgString += "New zone outline ok. Northwesternmost point of zone " + warzone.getName() + " set to x:" + (int)warzone.getNorthwest().getBlockX() + " z:" + (int)warzone.getNorthwest().getBlockZ()+ ". Saving new warzone blocks..."; - player.sendMessage(str(msgString)); + msg(player, msgString); } } } else if(arguments[1].equals("southeast") || arguments[1].equals("se")) { if(warzone.getNorthwest() != null && (player.getLocation().getBlockX() <= warzone.getNorthwest().getBlockX() || player.getLocation().getBlockZ() >= warzone.getNorthwest().getBlockZ())) { - player.sendMessage(this.bad("You must place that corner southeast relative to the existing northwest corner! ")); + this.badMsg(player, "You must place that corner southeast relative to the existing northwest corner! "); } else if (warzone.getNorthwest() == null){ // just moving the single se corner we've placed so far warzone.setSoutheast(player.getLocation()); } else { String msgString = ""; if(warzone.getVolume().isSaved()) { - player.sendMessage(str("Resetting zone " + warzone.getName() + " blocks.")); + msg(player, "Resetting zone " + warzone.getName() + " blocks."); if(warzone.getLobby() != null) { warzone.getLobby().getVolume().resetBlocks(); } @@ -770,23 +771,23 @@ public class War extends JavaPlugin { } warzone.setSoutheast(player.getLocation()); if(warzone.tooSmall()) { - player.sendMessage(bad("Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20.")); + badMsg(player, "Warzone " + warzone.getName() + " is too small. Min north-south size: 20. Min east-west size: 20."); } else if (warzone.tooBig()) { - player.sendMessage(bad("Warzone " + warzone.getName() + " is too Big. Max north-south size: 500. Max east-west size: 500.")); + badMsg(player, "Warzone " + warzone.getName() + " is too Big. Max north-south size: 500. Max east-west size: 500."); } else { msgString += "New zone outline ok. Southeasternmost point of zone " + warzone.getName() + " set to x:" + (int)warzone.getSoutheast().getBlockX() + " z:" + (int)warzone.getSoutheast().getBlockZ()+ ". Saving new warzone blocks..."; - player.sendMessage(str(msgString)); + msg(player, msgString); } } } } if(warzone.getNorthwest() == null) { - player.sendMessage(str("Still missing northwesternmost point.")); + msg(player, "Still missing northwesternmost point."); } if(warzone.getSoutheast() == null) { - player.sendMessage(str("Still missing southeasternmost point.")); + msg(player, "Still missing southeasternmost point."); } if(warzone.getNorthwest() != null && warzone.getSoutheast() != null) { if(warzone.ready()) { @@ -800,14 +801,14 @@ public class War extends JavaPlugin { warHub.getVolume().resetBlocks(); warHub.initialize(); } - player.sendMessage(this.str("Default lobby created on south side of zone. Use /setzonelobby to change which zone wall it is attached to.")); + this.msg(player, "Default lobby created on south side of zone. Use /setzonelobby to change which zone wall it is attached to."); } else { // gotta move the lobby warzone.getLobby().changeWall(warzone.getLobby().getWall()); } warzone.initializeZone(); WarzoneMapper.save(this, warzone, true); - player.sendMessage(this.str("Warzone saved. Use /setteam, /setmonument and /savezone to configure the zone.")); + this.msg(player, "Warzone saved. Use /setteam, /setmonument and /savezone to configure the zone."); } } } @@ -815,25 +816,25 @@ public class War extends JavaPlugin { public void performNextBattle(Player player) { if(!this.inAnyWarzone(player.getLocation())) { - player.sendMessage(this.bad("Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone.")); + this.badMsg(player, "Usage: /nextbattle. Resets the zone blocks and all teams' life pools. Must be in warzone."); } else { Warzone warzone = this.warzone(player.getLocation()); warzone.clearFlagThieves(); for(Team team: warzone.getTeams()) { - team.teamcast(this.str("The battle was interrupted. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools...")); + team.teamcast("The battle was interrupted. " + playerListener.getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools..."); } int resetBlocks = warzone.getVolume().resetBlocks(); warzone.initializeZone(); - player.sendMessage(this.str("Warzone reset. " + resetBlocks + " blocks reset.")); - info(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); + this.msg(player, "Warzone reset. " + resetBlocks + " blocks reset."); + logInfo(resetBlocks + " blocks reset in warzone " + warzone.getName() + "."); } } public void performWarhub(Player player) { if(this.getWarHub() == null) { - player.sendMessage(this.bad("No warhub on this War server. Try /zones and /zone.")); + this.badMsg(player, "No warhub on this War server. Try /zones and /zone."); } else if(!canWarp(player)) { - player.sendMessage(this.bad("Can't warp to warhub. You need the 'war.warp' permission.")); + this.badMsg(player, "Can't warp to warhub. You need the 'war.warp' permission."); } else { Team playerTeam = this.getPlayerTeam(player.getName()); Warzone playerWarzone = getPlayerTeamWarzone(player.getName()); @@ -847,8 +848,8 @@ public class War extends JavaPlugin { public void performTeam(Player player, String[] arguments) { Team playerTeam = this.getPlayerTeam(player.getName()); if(!this.inAnyWarzone(player.getLocation()) && playerTeam != null) { - player.sendMessage(this.bad("Usage: /team . " + - "Sends a message only to your teammates.")); + this.badMsg(player, "Usage: /team . " + + "Sends a message only to your teammates."); } else { ChatColor color = null; if(playerTeam.getMaterial() == TeamMaterials.TEAMDIAMOND) { @@ -863,14 +864,14 @@ public class War extends JavaPlugin { String part = arguments[j]; teamMessage += part + " "; } - playerTeam.teamcast(this.str(teamMessage)); + playerTeam.teamcast(teamMessage); } } public void performLeave(Player player) { if(!this.inAnyWarzone(player.getLocation()) || this.getPlayerTeam(player.getName()) == null) { - player.sendMessage(this.bad("Usage: /leave. " + - "Must be in a team already.")); + this.badMsg(player, "Usage: /leave. " + + "Must be in a team already."); } else { Warzone zone = getPlayerTeamWarzone(player.getName()); zone.handlePlayerLeave(player, zone.getTeleport()); @@ -880,17 +881,17 @@ 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 && TeamMaterials.teamMaterialFromString(arguments[0]) == null)) { - player.sendMessage(this.bad("Usage: /join ." + + 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.")); + " 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())){ - warn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); + logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); } if(zone.isFlagThief(player.getName())) { Team victim = zone.getVictimTeamForThief(player.getName()); @@ -898,7 +899,7 @@ public class War extends JavaPlugin { victim.initializeTeamFlag(); zone.removeThief(player.getName()); for(Team t : zone.getTeams()) { - t.teamcast(this.str("Team " + victim.getName() + " flag was returned.")); + t.teamcast("Team " + victim.getName() + " flag was returned."); } } previousTeam.resetSign(); @@ -919,7 +920,7 @@ public class War extends JavaPlugin { if(team.getName().equals(name)) { if(!warzone.hasPlayerInventory(player.getName())) { warzone.keepPlayerInventory(player); - player.sendMessage(this.str("Your inventory is is storage until you /leave.")); + this.msg(player, "Your inventory is is storage until you /leave."); } if(team.getPlayers().size() < warzone.getTeamCap()) { team.addPlayer(player); @@ -930,35 +931,35 @@ public class War extends JavaPlugin { } foundTeam = true; } else { - player.sendMessage(this.bad("Team " + name + " is full.")); + this.badMsg(player, "Team " + name + " is full."); foundTeam = true; } } } if(foundTeam) { for(Team team : teams){ - team.teamcast(this.str("" + player.getName() + " joined " + name)); + team.teamcast("" + player.getName() + " joined " + name); } } else { - player.sendMessage(this.bad("No such team. Try /teams.")); + this.badMsg(player, "No such team. Try /teams."); } } } public void performTeams(Player player) { if(!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - player.sendMessage(this.bad("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 { - player.sendMessage(this.str("" + playerListener.getAllTeamsMsg(player))); + this.msg(player, "" + playerListener.getAllTeamsMsg(player)); } } public void performZone(Player player, String[] arguments) { if(arguments.length < 1) { - player.sendMessage(this.bad("Usage: /zone .")); + this.badMsg(player, "Usage: /zone ."); } else if(!canWarp(player)) { - player.sendMessage(this.bad("Can't warp to zone. You need the 'war.warp' permission.")); + this.badMsg(player, "Can't warp to zone. You need the 'war.warp' permission."); } else { boolean warped = false; for(Warzone warzone : this.getWarzones()) { @@ -974,7 +975,7 @@ public class War extends JavaPlugin { } } if(!warped) { - player.sendMessage(this.bad("No such warzone.")); + this.badMsg(player, "No such warzone."); } } } @@ -994,8 +995,8 @@ public class War extends JavaPlugin { } warzonesMessage += playerTotal + " players) "; } - player.sendMessage(this.str(warzonesMessage + " Use /zone to " + - "teleport to a warzone. ")); + this.msg(player, warzonesMessage + " Use /zone to " + + "teleport to a warzone. "); } private boolean updateZoneFromNamedParams(Warzone warzone, String[] arguments) { @@ -1166,19 +1167,18 @@ public class War extends JavaPlugin { return warzones; } - public String str(String str) { + public void msg(Player player, String str) { String out = ChatColor.GRAY + "[War] " + ChatColor.WHITE + colorTeams(str, ChatColor.WHITE) + " "; - return out; + ChatFixUtil.sendMessage(player, out); } - public String bad(String str) { + public void badMsg(Player player, String str) { String out = ChatColor.GRAY + "[War] " + ChatColor.RED + colorTeams(str, ChatColor.RED) + " "; - return out; + ChatFixUtil.sendMessage(player, out); } private String colorTeams(String str, ChatColor msgColor) { - String out = str.replaceAll(" ", msgColor + " "); - out = out.replaceAll("iron", TeamChatColors.TEAMIRON + "iron" + msgColor); + String out = str.replaceAll("iron", TeamChatColors.TEAMIRON + "iron" + msgColor); out = out.replaceAll("Iron", TeamChatColors.TEAMIRON + "Iron" + msgColor); out = out.replaceAll("gold", TeamChatColors.TEAMGOLD + "gold" + msgColor); out = out.replaceAll("Gold", TeamChatColors.TEAMGOLD + "Gold" + msgColor); @@ -1187,12 +1187,12 @@ public class War extends JavaPlugin { return out; } - public void info(String str) { + public void logInfo(String str) { this.getLogger().log(Level.INFO, "[War] " + str); } - public void warn(String str) { - this.getLogger().log(Level.INFO, "[War] " + str); + public void logWarn(String str) { + this.getLogger().log(Level.WARNING, "[War] " + str); } public Warzone findWarzone(String warzoneName) { @@ -1374,7 +1374,7 @@ public class War extends JavaPlugin { if(test != null) { this.Permissions = (Permissions)test; } else { - info("Permissions system not enabled. Defaulting to regular War config."); + logInfo("Permissions system not enabled. Defaulting to regular War config."); } } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java index 4beb4a3..bad79ea 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java @@ -43,33 +43,33 @@ public class WarBlockListener extends BlockListener { monument.capture(team); List teams = zone.getTeams(); for(Team t : teams) { - t.teamcast(war.str("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".")); + t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + "."); } return; // important otherwise cancelled down a few line by isImportantblock } else { - player.sendMessage(war.bad("You can't capture a monument without a block of your team's material. Get one from your team spawn.")); + war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn."); event.setCancelled(true); return; } } if(zone != null && zone.isImportantBlock(block)){ - player.sendMessage(war.bad("Can't build here.")); + war.badMsg(player, "Can't build here."); event.setCancelled(true); return; } // protect warzone lobbies for(Warzone wz: war.getWarzones()) { if(wz.getLobby() != null && wz.getLobby().getVolume().contains(block)) { - player.sendMessage(war.bad("Can't build here.")); + war.badMsg(player, "Can't build here."); event.setCancelled(true); return; } } // protect the hub if(war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) { - player.sendMessage(war.bad("Can't build here.")); + war.badMsg(player, "Can't build here."); event.setCancelled(true); return; } @@ -86,7 +86,7 @@ public class WarBlockListener extends BlockListener { if(warzone != null && war.getPlayerTeam(player.getName()) == null && !isZoneMaker) { // can't actually destroy blocks in a warzone if not part of a team - player.sendMessage(war.bad("Can't destroy part of a warzone if you're not in a team.")); + 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 @@ -96,7 +96,7 @@ public class WarBlockListener extends BlockListener { List teams = warzone.getTeams(); for(Team t : teams) { - t.teamcast(war.str("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName())); + t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName()); } monument.uncapture(); } @@ -104,7 +104,7 @@ public class WarBlockListener extends BlockListener { }else if(warzone != null && warzone.isImportantBlock(block)) { if(team != null && team.getSpawnVolume().contains(block)) { if(player.getInventory().contains(team.getMaterial())) { - player.sendMessage(war.bad("You already have a " + team.getName() + " block.")); + war.badMsg(player, "You already have a " + team.getName() + " block."); event.setCancelled(true); return; } @@ -112,7 +112,7 @@ public class WarBlockListener extends BlockListener { } else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) { if(warzone.isFlagThief(player.getName())) { // detect audacious thieves - player.sendMessage(war.bad("You can only steal one flag at a time!")); + war.badMsg(player, "You can only steal one flag at a time!"); } else { // player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air Team lostFlagTeam = warzone.getTeamForFlagBlock(block); @@ -122,17 +122,17 @@ public class WarBlockListener extends BlockListener { block.setType(Material.AIR); for(Team t : warzone.getTeams()) { - t.teamcast(war.str(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag.")); + t.teamcast(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag."); if(t.getName().equals(lostFlagTeam.getName())){ - t.teamcast(war.str("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag.")); + t.teamcast("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag."); } } - player.sendMessage(war.str("You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!")); + war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!"); } event.setCancelled(true); return; } else if (!warzone.isMonumentCenterBlock(block)){ - player.sendMessage(war.bad("Can't destroy this.")); + war.badMsg(player, "Can't destroy this."); event.setCancelled(true); return; } @@ -143,7 +143,7 @@ public class WarBlockListener extends BlockListener { for(Warzone zone: war.getWarzones()) { if(zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) { - player.sendMessage(war.bad("Can't destroy this.")); + war.badMsg(player, "Can't destroy this."); event.setCancelled(true); return; } @@ -152,7 +152,7 @@ public class WarBlockListener extends BlockListener { // protect the hub if(war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) { - player.sendMessage(war.bad("Can't destroy this.")); + war.badMsg(player, "Can't destroy this."); event.setCancelled(true); return; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 65f3e7b..294a318 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -117,11 +117,11 @@ public class WarEntityListener extends EntityListener { // //} // } if(defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn - a.sendMessage(war.bad("Can't attack a player that's inside his team's spawn.")); + war.badMsg(a, "Can't attack a player that's inside his team's spawn."); event.setCancelled(true); } else if(attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) { // only let a player inside spawn attack an enemy player if that player enters the spawn - a.sendMessage(war.bad("Can't attack a player from inside your spawn.")); + war.badMsg(a, "Can't attack a player from inside your spawn."); event.setCancelled(true); } //} @@ -131,28 +131,28 @@ public class WarEntityListener extends EntityListener { && attacker.getEntityId() != defender.getEntityId()) { // same team, but not same person if(attackerWarzone.getFriendlyFire()) { - a.sendMessage(war.bad("Friendly fire is on! Please, don't hurt your teammates.")); // if ff is on, let the attack go through + war.badMsg(a, "Friendly fire is on! Please, don't hurt your teammates."); // if ff is on, let the attack go through } else { - a.sendMessage(war.bad("Your attack missed! Your target is on your team.")); + war.badMsg(a, "Your attack missed! Your target is on your team."); event.setCancelled(true); // ff is off } } else if (attackerTeam == null && defenderTeam == null && !war.isPvpInZonesOnly()){ // let normal PVP through is its not turned off } else if (attackerTeam == null && defenderTeam == null && war.isPvpInZonesOnly()) { - a.sendMessage(war.bad("Your attack missed! Global PVP is turned off. You can only attack other players in warzones. Try /warhub, /zones and /zone.")); + war.badMsg(a, "Your attack missed! Global PVP is turned off. You can only attack other players in warzones. Try /warhub, /zones and /zone."); event.setCancelled(true); // global pvp is off } else { - a.sendMessage(war.bad("Your attack missed!")); + war.badMsg(a, "Your attack missed!"); if(attackerTeam == null) { - a.sendMessage(war.bad(" You must join a team " + + war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + - "in the other teams in that warzone.")); + "in the other teams in that warzone."); } else if (defenderTeam == null) { - a.sendMessage(war.bad("Your target is not in a team.")); + war.badMsg(a, "Your target is not in a team."); } else if (attackerTeam == defenderTeam) { - a.sendMessage(war.bad("Your target is on your team.")); + war.badMsg(a, "Your target is on your team."); } else if (attackerWarzone != defenderWarzone) { - a.sendMessage(war.bad("Your target is playing in another warzone.")); + war.badMsg(a, "Your target is playing in another warzone."); } event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team } @@ -173,17 +173,17 @@ public class WarEntityListener extends EntityListener { for(Block block : explodedBlocks) { if(war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) { event.setCancelled(true); - war.info("Explosion prevented at warhub."); + war.logInfo("Explosion prevented at warhub."); return; } for(Warzone zone : war.getWarzones()) { if(zone.isImportantBlock(block)) { event.setCancelled(true); - war.info("Explosion prevented in zone " + zone.getName() + "."); + war.logInfo("Explosion prevented in zone " + zone.getName() + "."); return; } else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) { event.setCancelled(true); - war.info("Explosion prevented at zone " + zone.getName() + " lobby."); + war.logInfo("Explosion prevented at zone " + zone.getName() + " lobby."); return; } } @@ -192,7 +192,7 @@ public class WarEntityListener extends EntityListener { private void handleDeath(Player player, Warzone playerWarzone, Team playerTeam) { // teleport to team spawn upon death - player.sendMessage(war.str("You died.")); + war.msg(player, "You died."); boolean newBattle = false; boolean scoreCapReached = false; //synchronized(playerWarzone) { @@ -202,8 +202,8 @@ public class WarEntityListener extends EntityListener { List teams = playerWarzone.getTeams(); String scorers = ""; for(Team t : teams) { - t.teamcast(war.str("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.getName().equals(playerTeam.getName())) { // all other teams get a point @@ -214,7 +214,7 @@ public class WarEntityListener extends EntityListener { } if(!scorers.equals("")){ for(Team t : teams) { - t.teamcast(war.str(scorers)); + t.teamcast(scorers); } } // detect score cap @@ -239,7 +239,7 @@ public class WarEntityListener extends EntityListener { } else { // A new battle starts. Reset the zone but not the teams. for(Team t : teams) { - t.teamcast(war.str("A new battle begins. Warzone reset.")); + t.teamcast("A new battle begins. Warzone reset."); } playerWarzone.getVolume().resetBlocks(); playerWarzone.initializeZone(); @@ -254,13 +254,13 @@ public class WarEntityListener extends EntityListener { victim.initializeTeamFlag(); playerWarzone.removeThief(player.getName()); for(Team t : playerWarzone.getTeams()) { - t.teamcast(war.str(player.getName() + " died and dropped team " + victim.getName() + "'s flag.")); + t.teamcast(player.getName() + " died and dropped team " + victim.getName() + "'s flag."); } } playerTeam.setRemainingLives(remaining - 1); if(remaining - 1 == 0) { for(Team t : playerWarzone.getTeams()) { - t.teamcast(war.str("Team " + t.getName() + "'s life pool is empty. One more death and they lose the battle!")); + t.teamcast("Team " + t.getName() + "'s life pool is empty. One more death and they lose the battle!"); } } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index 01cc20b..d2bab72 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Random; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; @@ -70,7 +71,7 @@ public class WarPlayerListener extends PlayerListener { } } - player.sendMessage(war.str("You were disconnected. Here's your inventory from last time.")); + war.msg(player, "You were disconnected. Here's your inventory from last time."); } } @@ -142,7 +143,7 @@ public class WarPlayerListener extends PlayerListener { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.bad("All teams are full.")); + war.badMsg(player, "All teams are full."); } return; } @@ -159,18 +160,18 @@ public class WarPlayerListener extends PlayerListener { war.getWarHub().resetZoneSign(zone); } zone.keepPlayerInventory(player); - player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + war.msg(player, "Your inventory is is storage until you /leave."); zone.respawnPlayer(event, diamondTeam, player); //zone.respawnPlayer(diamondTeam, player); //event.setCancelled(true); for(Team team : zone.getTeams()){ - team.teamcast(war.str("" + player.getName() + " joined team diamond.")); + team.teamcast("" + player.getName() + " joined team diamond."); } } else { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.bad("Team diamond is full.")); + war.badMsg(player, "Team diamond is full."); } return; } @@ -187,18 +188,18 @@ public class WarPlayerListener extends PlayerListener { war.getWarHub().resetZoneSign(zone); } zone.keepPlayerInventory(player); - player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + war.msg(player, "Your inventory is is storage until you /leave."); zone.respawnPlayer(event, ironTeam, player); // zone.respawnPlayer(ironTeam, player); // event.setCancelled(true); for(Team team : zone.getTeams()){ - team.teamcast(war.str("" + player.getName() + " joined team iron.")); + team.teamcast("" + player.getName() + " joined team iron."); } } else { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.bad("Team iron is full.")); + war.badMsg(player, "Team iron is full."); } return; } @@ -215,18 +216,18 @@ public class WarPlayerListener extends PlayerListener { war.getWarHub().resetZoneSign(zone); } zone.keepPlayerInventory(player); - player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + war.msg(player, "Your inventory is is storage until you /leave."); zone.respawnPlayer(event, goldTeam, player); //zone.respawnPlayer(goldTeam, player); //event.setCancelled(true); for(Team team : zone.getTeams()){ - team.teamcast(war.str("" + player.getName() + " joined team gold.")); + team.teamcast("" + player.getName() + " joined team gold."); } } else { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.bad("Team gold is full.")); + war.badMsg(player, "Team gold is full."); } return; } @@ -237,7 +238,7 @@ public class WarPlayerListener extends PlayerListener { event.setFrom(war.getWarHub().getLocation()); player.teleportTo(war.getWarHub().getLocation()); event.setCancelled(true); - player.sendMessage(war.str("Welcome to the War hub.")); + war.msg(player, "Welcome to the War hub."); return; } } else if ((isAutoAssignGate || isDiamondGate || isGoldGate || isIronGate) && @@ -245,7 +246,7 @@ public class WarPlayerListener extends PlayerListener { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.bad("You don't have permission to play War. Ask a mod for the 'war.player' permission, please.")); + war.badMsg(player, "You don't have permission to play War. Ask a mod for the 'war.player' permission, please."); return; } @@ -260,7 +261,7 @@ public class WarPlayerListener extends PlayerListener { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - player.sendMessage(war.str("Welcome to warzone " + zone.getName() + ".")); + war.msg(player, "Welcome to warzone " + zone.getName() + "."); return; } } @@ -282,14 +283,15 @@ public class WarPlayerListener extends PlayerListener { Team team = war.getPlayerTeam(player.getName()); // Player belongs to a warzone team but is outside: he snuck out or is at spawn and died -// if(locZone == null && team != null) { -// handleDeath(event, player, playerWarzone, team); -// event.setFrom(team.getTeamSpawn()); -// //playerWarzone.respawnPlayer(team, player); -// player.teleportTo(team.getTeamSpawn()); -// event.setCancelled(true); -// return; -// } + if(locZone == null && team != null) { + handleDeath(event, player, playerWarzone, team); + war.badMsg(player, "You can't sneak out of a zone while in a team. Use /leave or walk out the lobby to exit the zone, please."); + event.setFrom(team.getTeamSpawn()); + //playerWarzone.respawnPlayer(team, player); + player.teleportTo(team.getTeamSpawn()); + event.setCancelled(true); + return; + } // Monuments if(team != null @@ -301,7 +303,7 @@ public class WarPlayerListener extends PlayerListener { int newHp = currentHp + 5; if(newHp > 20) newHp = 20; player.setHealth(newHp); - player.sendMessage(war.str("Your dance pleases the monument's voodoo. You gain health!")); + war.msg(player, "Your dance pleases the monument's voodoo. You gain health!"); return; } @@ -310,7 +312,7 @@ public class WarPlayerListener extends PlayerListener { && (team.getSpawnVolume().contains(player.getLocation()) || (team.getFlagVolume() != null && team.getFlagVolume().contains(player.getLocation())))) { if(playerWarzone.isTeamFlagStolen(team)) { - player.sendMessage(war.bad("You can't capture the enemy flag until your team flag is returned.")); + war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned."); } else { synchronized(playerWarzone) { // flags can be captured at own spawn or own flag pole @@ -329,8 +331,8 @@ public class WarPlayerListener extends PlayerListener { victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it victim.initializeTeamFlag(); for(Team t : playerWarzone.getTeams()) { - t.teamcast(war.str(player.getName() + " captured team " + victim.getName() - + "'s flag. Team " + team.getName() + " scores one point." )); + t.teamcast(player.getName() + " captured team " + victim.getName() + + "'s flag. Team " + team.getName() + " scores one point." ); } playerWarzone.respawnPlayer(event, team, player); team.resetSign(); @@ -347,7 +349,7 @@ public class WarPlayerListener extends PlayerListener { event.setFrom(zone.getTeleport()); player.teleportTo(zone.getTeleport()); event.setCancelled(true); - //player.sendMessage(war.str("You can't be inside a warzone without a team.")); + //war.str("You can't be inside a warzone without a team.")); } } @@ -357,7 +359,7 @@ public class WarPlayerListener extends PlayerListener { Team previousTeam = war.getPlayerTeam(player.getName()); if(previousTeam != null) { if(!previousTeam.removePlayer(player.getName())){ - war.warn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); + war.logWarn("Could not remove player " + player.getName() + " from team " + previousTeam.getName()); } } } @@ -386,7 +388,7 @@ public class WarPlayerListener extends PlayerListener { private void handleDeath(PlayerMoveEvent event, Player player, Warzone playerWarzone, Team playerTeam) { // teleport to team spawn upon death - player.sendMessage(war.str("You died.")); + war.msg(player, "You died."); boolean newBattle = false; boolean scoreCapReached = false; //synchronized(playerWarzone) { @@ -394,14 +396,21 @@ public class WarPlayerListener extends PlayerListener { int remaining = playerTeam.getRemainingLifes(); if(remaining == 0) { // your death caused your team to lose List teams = playerWarzone.getTeams(); + String scorers = ""; for(Team t : teams) { - t.teamcast(war.str("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.getName().equals(playerTeam.getName())) { // all other teams get a point t.addPoint(); t.resetSign(); + scorers += "Team " + t.getName() + " scores one point. "; + } + } + if(!scorers.equals("")){ + for(Team t : teams) { + t.teamcast(scorers); } } // detect score cap @@ -428,7 +437,7 @@ public class WarPlayerListener extends PlayerListener { } else { // A new battle starts. Reset the zone but not the teams. for(Team t : teams) { - t.teamcast(war.str("A new battle begins. The warzone is being reset...")); + t.teamcast("A new battle begins. The warzone is being reset..."); } playerWarzone.getVolume().resetBlocks(); playerWarzone.initializeZone(event); @@ -443,10 +452,15 @@ public class WarPlayerListener extends PlayerListener { victim.initializeTeamFlag(); playerWarzone.removeThief(player.getName()); for(Team t : playerWarzone.getTeams()) { - t.teamcast(war.str(player.getName() + " died and dropped team " + victim.getName() + "'s flag.")); + t.teamcast(player.getName() + " died and dropped team " + victim.getName() + "'s flag."); } } playerTeam.setRemainingLives(remaining - 1); + if(remaining - 1 == 0) { + for(Team t : playerWarzone.getTeams()) { + t.teamcast("Team " + t.getName() + "'s life pool is empty. One more death and they lose the battle!"); + } + } } //} //} diff --git a/war/src/main/java/com/tommytony/war/ChatFixUtil.java b/war/src/main/java/com/tommytony/war/ChatFixUtil.java new file mode 100644 index 0000000..66ecca1 --- /dev/null +++ b/war/src/main/java/com/tommytony/war/ChatFixUtil.java @@ -0,0 +1,230 @@ +package com.tommytony.war; + +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. + * + * 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. + */ +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. + */ + public static ArrayList fix(String msg) { + // Make sure the end of msg is good + msg = cleanMsgEnding(msg); + + ArrayList ret = new ArrayList(); + int displen = 0; // The number of displayed chars in row so far. + String row = ""; + String latestColor = null; + + for (int i = 0; i < msg.length(); i++) { + if (displen == lineLength) { + // it is time to start on the next row! + ret.add(row); + displen = 0; + row = ""; + if (latestColor != null) { + row += deg+latestColor; + } + } + char c = msg.charAt(i); + + if (c == deg) { + latestColor = String.valueOf(msg.charAt(i+1)); + row += deg+latestColor; + i++; + } else { + displen += 1; + row += c; + } + } + ret.add(row); + return ret; + } + + public static ArrayList fix(List messages) { + ArrayList ret = new ArrayList(); + for(String message : messages) { + ret.addAll(fix(message)); + } + 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. + */ + protected static String cleanMsgEnding (String msg) { + + while (msg.length() > 0) { + if (msg.endsWith(String.valueOf(deg)) || msg.endsWith(" ")) { + msg = msg.substring(0, msg.length()-1); + } else if (msg.length() >= 2 && msg.charAt(msg.length() - 2) == deg) { + msg = msg.substring(0, msg.length()-2); + } else { + break; + } + } + return msg; + } + + /** + * 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) == deg) { + return "Crash: The str ends with deg."; + } else if (str.length() >= 2 && str.charAt(str.length() - 2) == deg) { + return "Crash: The str ends with deg+'anychar'."; + } + + int displayedChars = 0; + + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (c == deg && displayedChars == lineLength) { + return "Crash: Deg as fiftyforth \"displayed\" char"; + } else if (c == deg) { + i++; // this and next: they are not displayed... skip them... + } else { + displayedChars += 1; + } + } + 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); + sendMessage(player, messages, false); + } else { + if (player != null) { + player.sendMessage(message); + } + } + } + public static void sendMessage(Player player, List messages, boolean fix) { + if (fix) { + messages = ChatFixUtil.fix(messages); + } + for (String message : messages) { + sendMessage(player, message, false); + } + } + public static void sendMessage(Player player, String message) { + sendMessage(player, message, true); + } + public static void sendMessage(Player player, List messages) { + sendMessage(player, messages, true); + } + //----------------------------------------------// + // Many Players + //----------------------------------------------// + public static void sendMessage(Collection players, String message, boolean fix) { + if (fix) { + List messages = ChatFixUtil.fix(message); + sendMessage(players, messages, false); + } else { + for (Player player : players) { + sendMessage(player, message, false); + } + } + } + public static void sendMessage(Collection players, List messages, boolean fix) { + if (fix) { + messages = ChatFixUtil.fix(messages); + } + + for (String message : messages) { + sendMessage(players, message, false); + } + } + public static void sendMessage(Collection players, String message) { + sendMessage(players, message, true); + } + public static void sendMessage(Collection players, List messages) { + sendMessage(players, messages, true); + } +} + + + + + + + + + + + + + + + + + + diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index c751eed..34280c4 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -319,7 +319,7 @@ public class Team { public void teamcast(String message) { for(Player player : players) { - player.sendMessage(message); + war.msg(player, message); } } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 0d7acd8..4d95073 100644 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -797,10 +797,10 @@ public class Warzone { if(!hasPlayerInventory(player.getName())) { keepPlayerInventory(player); } - player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + war.msg(player, "Your inventory is is storage until you /leave."); respawnPlayer(event, lowestNoOfPlayers, player); for(Team team : teams){ - team.teamcast(war.str("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + ".")); + team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); } } } @@ -819,10 +819,10 @@ public class Warzone { if(!hasPlayerInventory(player.getName())) { keepPlayerInventory(player); } - player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + war.msg(player, "Your inventory is is storage until you /leave."); respawnPlayer(lowestNoOfPlayers, player); for(Team team : teams){ - team.teamcast(war.str("" + player.getName() + " joined team " + team.getName() + ".")); + team.teamcast("" + player.getName() + " joined team " + team.getName() + "."); } } } @@ -872,7 +872,7 @@ public class Warzone { victim.initializeTeamFlag(); zone.removeThief(player.getName()); for(Team t : zone.getTeams()) { - t.teamcast(war.str("Team " + victim.getName() + " flag was returned.")); + t.teamcast("Team " + victim.getName() + " flag was returned."); } } if(zone.getLobby() != null) { @@ -882,7 +882,7 @@ public class Warzone { zone.restorePlayerInventory(player); } player.teleportTo(destination); - player.sendMessage(war.str("Left the zone. Your inventory has (hopefully) been restored.")); + war.msg(player, "Left the zone. Your inventory has (hopefully) been restored."); if(war.getWarHub() != null) { war.getWarHub().resetZoneSign(zone); } @@ -945,7 +945,7 @@ public class Warzone { winnersStr += ". Your inventory has (hopefully) been reset. The warzone is being reset... Please choose a new team."; // Score cap reached. Reset everything. for(Team t : this.getTeams()) { - t.teamcast(war.str(winnersStr)); + t.teamcast(winnersStr); for(Player tp : t.getPlayers()) { if(!tp.getName().equals(player.getName())) { if(this.hasPlayerInventory(tp.getName())){ diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index f32f803..47c108c 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -222,7 +222,7 @@ public class ZoneLobby { lobbyMiddleWallBlock.getFace(BlockFace.DOWN).getFace(BlockFace.SOUTH, lobbyHalfSide - 1).getFace(wall, 9).setType(Material.GLOWSTONE); } } else { - war.warn("Failed to initalize zone lobby for zone " + warzone.getName()); + war.logWarn("Failed to initalize zone lobby for zone " + warzone.getName()); } } 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 e4812f2..d6956c5 100644 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -138,7 +138,7 @@ public class VolumeMapper { } } } catch (IOException e) { - war.warn("Failed to read volume file " + volume.getName() + + war.logWarn("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } finally { @@ -146,7 +146,7 @@ public class VolumeMapper { try { in.close(); } catch (IOException e) { - war.warn("Failed to close file reader for volume " + volume.getName() + + war.logWarn("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } @@ -213,7 +213,7 @@ public class VolumeMapper { } } } catch (IOException e) { - war.warn("Failed to write volume file " + zoneName + + war.logWarn("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } @@ -222,7 +222,7 @@ public class VolumeMapper { try { out.close(); } catch (IOException e) { - war.warn("Failed to close file writer for volume " + volume.getName() + + war.logWarn("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage()); e.printStackTrace(); } @@ -234,7 +234,7 @@ public class VolumeMapper { File volFile= new File("War/dat/volume-" + volume.getName()); boolean deletedData = volFile.delete(); if(!deletedData) { - war.warn("Failed to delete file " + volFile.getName()); + 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 2d3a104..ddf4725 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -29,7 +29,7 @@ public class WarMapper { try { warConfig.load(); } catch (IOException e) { - war.warn("Failed to load war.txt file."); + war.logWarn("Failed to load war.txt file."); e.printStackTrace(); } @@ -38,11 +38,11 @@ public class WarMapper { if(!warConfig.containsKey("warzones")) { newWar = true; WarMapper.save(war); - war.info("war.txt settings file created."); + war.logInfo("war.txt settings file created."); try { warConfig.load(); } catch (IOException e) { - war.warn("Failed to reload war.txt file after creating it."); + war.logWarn("Failed to reload war.txt file after creating it."); e.printStackTrace(); } } @@ -53,7 +53,7 @@ public class WarMapper { war.getWarzones().clear(); for(String warzoneName : warzoneSplit) { if(warzoneName != null && !warzoneName.equals("")){ - war.info("Restoring zone " + warzoneName + "..."); + war.logInfo("Restoring zone " + warzoneName + "..."); Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists war.getWarzones().add(zone); zone.getVolume().resetBlocks(); 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 df523ef..2c44a05 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -455,17 +455,17 @@ public class WarzoneMapper { for(File file : files) { boolean deletedData = file.delete(); if(!deletedData) { - war.warn("Failed to delete file " + file.getName()); + war.logWarn("Failed to delete file " + file.getName()); } } boolean deletedData = zoneFolder.delete(); if(!deletedData) { - war.warn("Failed to delete folder " + zoneFolder.getName()); + war.logWarn("Failed to delete folder " + zoneFolder.getName()); } File zoneFile = new File(war.getDataFolder().getPath() + "/warzone-" + name + ".txt"); deletedData = zoneFile.delete(); if(!deletedData) { - war.warn("Failed to delete file " + zoneFile.getName()); + war.logWarn("Failed to delete file " + zoneFile.getName()); } } 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 cbb81c5..5652a3f 100644 --- a/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java +++ b/war/src/main/java/com/tommytony/war/volumes/VerticalVolume.java @@ -150,7 +150,7 @@ public class VerticalVolume extends Volume{ } } } catch (Exception e) { - this.getWar().warn("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to reset wall " + wall + " in volume " + getName() + ". " + e.getClass().toString() + " " + e.getMessage()); } return noOfResetBlocks; } 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 a5abc8a..019261c 100644 --- a/war/src/main/java/com/tommytony/war/volumes/Volume.java +++ b/war/src/main/java/com/tommytony/war/volumes/Volume.java @@ -213,7 +213,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().warn("Failed to reset volume " + getName() + " blocks. " + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to reset volume " + getName() + " blocks. " + e.getClass().toString() + " " + e.getMessage()); } return noOfResetBlocks; } @@ -363,7 +363,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().warn("Failed to set block to " + material + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to set block to " + material + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); } } @@ -393,7 +393,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().warn("Failed to set block to " + material + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to set block to " + material + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); } } @@ -425,7 +425,7 @@ public class Volume { } } } catch (Exception e) { - this.getWar().warn("Failed to switch block to " + newType + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); + this.getWar().logWarn("Failed to switch block to " + newType + "in volume " + name + "." + e.getClass().toString() + " " + e.getMessage()); } }