From e1b895a966e461402a178315162fcb3ae12d3d9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 13 Aug 2011 19:58:54 +0200 Subject: [PATCH] We don't have to invent the wheel twice --- .../main/java/bukkit/tommytony/war/War.java | 99 +++++++++---------- 1 file changed, 45 insertions(+), 54 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 09a1086..a8adde0 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -111,10 +111,10 @@ public class War extends JavaPlugin { if(!loadedOnce) { loadedOnce = true; // This prevented multiple hookups of the same listener - + // Register hooks PluginManager pm = this.getServer().getPluginManager(); - + pm.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this); @@ -123,17 +123,17 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this.playerListener, Priority.Normal, this); pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Priority.Normal, this); 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_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); pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this); - + pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this); } - + // Load files from disk or create them (using these defaults) this.getDefaultLoadout().put(0, new ItemStack(Material.STONE_SWORD, 1, (byte) 8)); this.getDefaultLoadout().put(1, new ItemStack(Material.BOW, 1, (byte) 8)); @@ -141,7 +141,7 @@ public class War extends JavaPlugin { this.getDefaultLoadout().put(3, new ItemStack(Material.IRON_PICKAXE, 1, (byte) 8)); this.getDefaultLoadout().put(4, new ItemStack(Material.STONE_SPADE, 1, (byte) 8)); this.getDefaultReward().put( 0, new ItemStack(Material.CAKE, 1)); - + WarMapper.load(); this.log("War v" + this.desc.getVersion() + " is on.", Level.INFO); } @@ -154,7 +154,7 @@ public class War extends JavaPlugin { warzone.unload(); } this.warzones.clear(); - + PluginManager pm = this.getServer().getPluginManager(); if (this.warHub != null) { @@ -280,7 +280,7 @@ public class War extends JavaPlugin { String onOff = namedParams.get("nocreatures"); warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true")); } - + if (namedParams.containsKey("resetonempty")) { String onOff = namedParams.get("resetonempty"); warzone.setResetOnEmpty(onOff.equals("on") || onOff.equals("true")); @@ -374,7 +374,7 @@ public class War extends JavaPlugin { String onOff = namedParams.get("nocreatures"); this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true")); } - + if (namedParams.containsKey("resetonempty")) { String onOff = namedParams.get("resetonempty"); this.setDefaultResetOnEmpty(onOff.equals("on") || onOff.equals("true")); @@ -405,53 +405,44 @@ public class War extends JavaPlugin { return false; } } - + public String printConfig(Warzone zone) { - return "Warzone " + zone.getName() + " config - " - + "lifepool:" + zone.getLifePool() + " " - + "teamsize:" + zone.getTeamCap() + " " - + "maxscore:" + zone.getScoreCap() + " " - + "ff:" + onOffStr(zone.getFriendlyFire()) - + "autoassign:" + onOffStr(zone.getAutoAssignOnly()) - + "blockheads:" + onOffStr(zone.isBlockHeads()) - + "spawnstyle:" + zone.getSpawnStyle() + " " - + "monumentheal:" + zone.getMonumentHeal() + " " - + "unbreakable:" + onOffStr(zone.isUnbreakableZoneBlocks()) - + "disabled:" + onOffStr(zone.isDisabled()) - + "nocreatures:" + onOffStr(zone.isNoCreatures()) - + "resetonempty:" + onOffStr(zone.isResetOnEmpty()) - + "resetonload:" + onOffStr(zone.isResetOnLoad()) - + "resetonunload:" + onOffStr(zone.isResetOnUnload()); + return "Warzone " + zone.getName() + " config -" + + " lifepool:" + zone.getLifePool() + + " teamsize:" + zone.getTeamCap() + + " maxscore:" + zone.getScoreCap() + + " ff:" + String.valueOf(zone.getFriendlyFire()) + + " autoassign:" + String.valueOf(zone.getAutoAssignOnly()) + + " blockheads:" + String.valueOf(zone.isBlockHeads()) + + " spawnstyle:" + zone.getSpawnStyle() + + " monumentheal:" + zone.getMonumentHeal() + + " unbreakable:" + String.valueOf(zone.isUnbreakableZoneBlocks()) + + " disabled:" + String.valueOf(zone.isDisabled()) + + " nocreatures:" + String.valueOf(zone.isNoCreatures()) + + " resetonempty:" + String.valueOf(zone.isResetOnEmpty()) + + " resetonload:" + String.valueOf(zone.isResetOnLoad()) + + " resetonunload:" + String.valueOf(zone.isResetOnUnload()); } - + public String printConfig() { - return "War config - " - + "pvpinzonesonly:" + onOffStr(War.war.isPvpInZonesOnly()) - + "disablepvpmessage:" + onOffStr(War.war.isDisablePvpMessage()) - + "buildinzonesonly:" + onOffStr(War.war.isBuildInZonesOnly()) - + "- Warzone defaults - " - + "lifepool:" + War.war.getDefaultLifepool() + " " - + "teamsize:" + War.war.getDefaultTeamCap() + " " - + "maxscore:" + War.war.getDefaultScoreCap() + " " - + "ff:" + onOffStr(War.war.isDefaultFriendlyFire()) - + "autoassign:" + onOffStr(War.war.isDefaultAutoAssignOnly()) - + "blockheads:" + onOffStr(War.war.isDefaultBlockHeads()) - + "spawnstyle:" + War.war.getDefaultSpawnStyle() + " " - + "monumentheal:" + War.war.getDefaultMonumentHeal() + " " - + "unbreakable:" + onOffStr(War.war.isDefaultUnbreakableZoneBlocks()) - + "nocreatures:" + onOffStr(War.war.isDefaultNoCreatures()) - + "resetonempty:" + onOffStr(War.war.isDefaultResetOnEmpty()) - + "resetonload:" + onOffStr(War.war.isDefaultResetOnLoad()) - + "resetonunload:" + onOffStr(War.war.isDefaultResetOnUnload()); - } - - private String onOffStr(boolean makeThisAString) { - if(makeThisAString) { - return "on "; - } else { - return "off "; - } - + return "War config -" + + " pvpinzonesonly:" + String.valueOf(War.war.isPvpInZonesOnly()) + + " disablepvpmessage:" + String.valueOf(War.war.isDisablePvpMessage()) + + " buildinzonesonly:" + String.valueOf(War.war.isBuildInZonesOnly()) + + " - Warzone defaults -" + + " lifepool:" + War.war.getDefaultLifepool() + + " teamsize:" + War.war.getDefaultTeamCap() + + " maxscore:" + War.war.getDefaultScoreCap() + + " ff:" + String.valueOf(War.war.isDefaultFriendlyFire()) + + " autoassign:" + String.valueOf(War.war.isDefaultAutoAssignOnly()) + + " blockheads:" + String.valueOf(War.war.isDefaultBlockHeads()) + + " spawnstyle:" + War.war.getDefaultSpawnStyle() + + " monumentheal:" + War.war.getDefaultMonumentHeal() + + " unbreakable:" + String.valueOf(War.war.isDefaultUnbreakableZoneBlocks()) + + " nocreatures:" + String.valueOf(War.war.isDefaultNoCreatures()) + + " resetonempty:" + String.valueOf(War.war.isDefaultResetOnEmpty()) + + " resetonload:" + String.valueOf(War.war.isDefaultResetOnLoad()) + + " resetonunload:" + String.valueOf(War.war.isDefaultResetOnUnload()); } private void setZoneRallyPoint(String warzoneName, Player player) { @@ -512,7 +503,7 @@ public class War extends JavaPlugin { } /** - * Colors the teams and examples in messages + * Colors the teams and examples in messages * * @param String str message-string * @param String msgColor current message-color