From c4868935edd50b3a2f54e4505e86ff9988c903ed Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 10 Apr 2013 12:52:22 +0200 Subject: [PATCH] Dont confuse constants and configuration options. --- src/com/massivecraft/factions/Board.java | 6 +- src/com/massivecraft/factions/ConfServer.java | 80 +++---------------- src/com/massivecraft/factions/Const.java | 71 ++++++++++++++++ .../massivecraft/factions/MainListener.java | 2 + .../herochat/HerochatListener.java | 1 - .../listeners/FactionsChatListener.java | 4 +- .../listeners/FactionsEntityListener.java | 5 +- .../listeners/FactionsPlayerListener.java | 9 ++- 8 files changed, 99 insertions(+), 79 deletions(-) create mode 100644 src/com/massivecraft/factions/Const.java diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index f2676e73..1148d3c1 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -190,8 +190,8 @@ public class Board Faction factionLoc = getFactionAt(flocation); ret.add(Txt.titleize("("+flocation.getCoordString()+") "+factionLoc.getTag(observer))); - int halfWidth = ConfServer.mapWidth / 2; - int halfHeight = ConfServer.mapHeight / 2; + int halfWidth = Const.MAP_WIDTH / 2; + int halfHeight = Const.MAP_HEIGHT / 2; FLocation topLeft = flocation.getRelative(-halfWidth, -halfHeight); int width = halfWidth * 2 + 1; int height = halfHeight * 2 + 1; @@ -225,7 +225,7 @@ public class Board else { if (!fList.containsKey(factionHere)) - fList.put(factionHere, ConfServer.mapKeyChrs[chrIdx++]); + fList.put(factionHere, Const.MAP_KEY_CHARS[chrIdx++]); char fchar = fList.get(factionHere); row += factionHere.getColorTo(observer) + "" + fchar; } diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index e21d690e..53570fb2 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -3,7 +3,6 @@ package com.massivecraft.factions; import java.util.*; import org.bukkit.*; -import org.bukkit.entity.EntityType; import com.massivecraft.mcore.SimpleConfig; import com.massivecraft.mcore.util.MUtil; @@ -83,7 +82,6 @@ public class ConfServer extends SimpleConfig public static boolean chatParseTags = true; public static boolean chatParseTagsColored = false; public static Map chatSingleFormats = new HashMap(); - public static transient boolean chatTagHandledByAnotherPlugin = false; // Why do we need this? (Olof asks) public static String chatTagFormat = "%s"+ChatColor.WHITE; // This one is almost deprecated now right? or is it? // Herochat @@ -186,18 +184,7 @@ public class ConfServer extends SimpleConfig // for claimed areas where further faction-member ownership can be defined - public static boolean pistonProtectionThroughDenyBuild = true; - - public final transient static Set materialsEditOnInteract = EnumSet.noneOf(Material.class); - public final transient static Set materialsEditTools = EnumSet.noneOf(Material.class); - public final transient static Set materialsDoor = EnumSet.noneOf(Material.class); - public final transient static Set materialsContainer = EnumSet.noneOf(Material.class); - - //public static Set territoryProtectedMaterialsWhenOffline = EnumSet.noneOf(Material.class); - //public static Set territoryDenyUseageMaterialsWhenOffline = EnumSet.noneOf(Material.class); - - // TODO: Rename to monsterCreatureTypes - public static transient Set monsters = EnumSet.noneOf(EntityType.class); + public static boolean pistonProtectionThroughDenyBuild = true; // Spout features public static boolean spoutFactionTagsOverNames = true; // show faction tags over names over player heads @@ -211,7 +198,16 @@ public class ConfServer extends SimpleConfig public static double spoutHealthBarSolidsPerEmpty = 1d; public static String spoutHealthBarColorTag = "{c}"; public static int spoutHealthBarWidth = 30; - public static Map spoutHealthBarColorUnderQuota = new LinkedHashMap(); + + public static Map spoutHealthBarColorUnderQuota = MUtil.map( + 1.0d, "&2", + 0.8d, "&a", + 0.5d, "&e", + 0.4d, "&6", + 0.3d, "&c", + 0.2d, "&4" + ); + public static boolean spoutCapes = true; // Show faction capes public static int spoutTerritoryDisplayPosition = 1; // permanent territory display, instead of by chat; 0 = disabled, 1 = top left, 2 = top center, 3+ = top right public static float spoutTerritoryDisplaySize = 1.0f; // text scale (size) for territory display @@ -269,9 +265,7 @@ public class ConfServer extends SimpleConfig // TODO: A better solution Would be to have One wilderness faction per world. //public static Set worldsNoWildernessProtection = new LinkedHashSet(); - public static transient int mapHeight = 8; - public static transient int mapWidth = 39; - public static transient char[] mapKeyChrs = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray(); + static { @@ -290,56 +284,6 @@ public class ConfServer extends SimpleConfig chatSingleFormats.put("pl", " %s"); chatSingleFormats.put("pr", "%s "); chatSingleFormats.put("pb", " %s "); - - materialsContainer.add(Material.DISPENSER); - materialsContainer.add(Material.CHEST); - materialsContainer.add(Material.FURNACE); - materialsContainer.add(Material.BURNING_FURNACE); - materialsContainer.add(Material.JUKEBOX); - materialsContainer.add(Material.BREWING_STAND); - materialsContainer.add(Material.ENCHANTMENT_TABLE); - materialsContainer.add(Material.ANVIL); - materialsContainer.add(Material.BEACON); - - materialsEditOnInteract.add(Material.DIODE_BLOCK_OFF); - materialsEditOnInteract.add(Material.DIODE_BLOCK_ON); - materialsEditOnInteract.add(Material.NOTE_BLOCK); - materialsEditOnInteract.add(Material.CAULDRON); - materialsEditOnInteract.add(Material.SOIL); - - materialsDoor.add(Material.WOODEN_DOOR); - materialsDoor.add(Material.TRAP_DOOR); - materialsDoor.add(Material.FENCE_GATE); - - materialsEditTools.add(Material.FIREBALL); - materialsEditTools.add(Material.FLINT_AND_STEEL); - materialsEditTools.add(Material.BUCKET); - materialsEditTools.add(Material.WATER_BUCKET); - materialsEditTools.add(Material.LAVA_BUCKET); - - monsters.add(EntityType.BLAZE); - monsters.add(EntityType.CAVE_SPIDER); - monsters.add(EntityType.CREEPER); - monsters.add(EntityType.ENDERMAN); - monsters.add(EntityType.ENDER_DRAGON); - monsters.add(EntityType.GHAST); - monsters.add(EntityType.GIANT); - monsters.add(EntityType.MAGMA_CUBE); - monsters.add(EntityType.PIG_ZOMBIE); - monsters.add(EntityType.SILVERFISH); - monsters.add(EntityType.SKELETON); - monsters.add(EntityType.SLIME); - monsters.add(EntityType.SPIDER); - monsters.add(EntityType.WITCH); - monsters.add(EntityType.WITHER); - monsters.add(EntityType.ZOMBIE); - - spoutHealthBarColorUnderQuota.put(1.0d, "&2"); - spoutHealthBarColorUnderQuota.put(0.8d, "&a"); - spoutHealthBarColorUnderQuota.put(0.5d, "&e"); - spoutHealthBarColorUnderQuota.put(0.4d, "&6"); - spoutHealthBarColorUnderQuota.put(0.3d, "&c"); - spoutHealthBarColorUnderQuota.put(0.2d, "&4"); } } diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java new file mode 100644 index 00000000..cc4640ad --- /dev/null +++ b/src/com/massivecraft/factions/Const.java @@ -0,0 +1,71 @@ +package com.massivecraft.factions; + +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; + +import com.massivecraft.mcore.util.MUtil; + +public class Const +{ + public static final int MAP_HEIGHT = 8; + public static final int MAP_WIDTH = 39; + public static final char[] MAP_KEY_CHARS = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray(); + + public static final Set MATERIALS_EDIT_ON_INTERACT = MUtil.set( + Material.DIODE_BLOCK_OFF, + Material.DIODE_BLOCK_ON, + Material.NOTE_BLOCK, + Material.CAULDRON, + Material.SOIL + ); + + public static final Set MATERIALS_EDIT_TOOLS = MUtil.set( + Material.FIREBALL, + Material.FLINT_AND_STEEL, + Material.BUCKET, + Material.WATER_BUCKET, + Material.LAVA_BUCKET + ); + + public static final Set MATERIALS_DOOR = MUtil.set( + Material.WOODEN_DOOR, + Material.TRAP_DOOR, + Material.FENCE_GATE + ); + + public static final Set MATERIALS_CONTAINER = MUtil.set( + Material.DISPENSER, + Material.CHEST, + Material.FURNACE, + Material.BURNING_FURNACE, + Material.JUKEBOX, + Material.BREWING_STAND, + Material.ENCHANTMENT_TABLE, + Material.ANVIL, + Material.BEACON + ); + + //public static Set territoryProtectedMaterialsWhenOffline = EnumSet.noneOf(Material.class); + //public static Set territoryDenyUseageMaterialsWhenOffline = EnumSet.noneOf(Material.class); + + public static final Set ENTITY_TYPES_MONSTERS = MUtil.set( + EntityType.BLAZE, + EntityType.CAVE_SPIDER, + EntityType.CREEPER, + EntityType.ENDERMAN, + EntityType.ENDER_DRAGON, + EntityType.GHAST, + EntityType.GIANT, + EntityType.MAGMA_CUBE, + EntityType.PIG_ZOMBIE, + EntityType.SILVERFISH, + EntityType.SKELETON, + EntityType.SLIME, + EntityType.SPIDER, + EntityType.WITCH, + EntityType.WITHER, + EntityType.ZOMBIE + ); +} diff --git a/src/com/massivecraft/factions/MainListener.java b/src/com/massivecraft/factions/MainListener.java index 94ebe32d..f820613a 100644 --- a/src/com/massivecraft/factions/MainListener.java +++ b/src/com/massivecraft/factions/MainListener.java @@ -38,6 +38,8 @@ public class MainListener implements Listener // -------------------------------------------- // // SPOUT // -------------------------------------------- // + // TODO: These spout related methods should not be in here. + // The spout integration needs to be moved elsewhere. // Setup diff --git a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java b/src/com/massivecraft/factions/integration/herochat/HerochatListener.java index b6c302c5..d7decacc 100644 --- a/src/com/massivecraft/factions/integration/herochat/HerochatListener.java +++ b/src/com/massivecraft/factions/integration/herochat/HerochatListener.java @@ -31,7 +31,6 @@ public class HerochatListener implements Listener { // Should we even parse? if ( ! ConfServer.chatParseTags) return; - if (ConfServer.chatTagHandledByAnotherPlugin) return; Player from = event.getSender().getPlayer(); FPlayer fpfrom = FPlayerColl.i.get(from); diff --git a/src/com/massivecraft/factions/listeners/FactionsChatListener.java b/src/com/massivecraft/factions/listeners/FactionsChatListener.java index f58dfe1d..f2baf2e1 100644 --- a/src/com/massivecraft/factions/listeners/FactionsChatListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsChatListener.java @@ -79,7 +79,9 @@ public class FactionsChatListener implements Listener { // Should we even parse? if ( ! ConfServer.chatParseTags) return; - if (ConfServer.chatTagHandledByAnotherPlugin) return; + + // TODO: Replace this one with a detailed EventPriority + boolean. + //if (ConfServer.chatTagHandledByAnotherPlugin) return; Player from = event.getPlayer(); FPlayer fpfrom = FPlayerColl.i.get(from); diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index a88d7b25..a73ae868 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -40,6 +40,7 @@ import org.bukkit.potion.PotionEffectType; import com.massivecraft.factions.Board; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayer; @@ -353,7 +354,7 @@ public class FactionsEntityListener implements Listener Faction faction = Board.getFactionAt(floc); if (faction.getFlag(FFlag.MONSTERS)) return; - if ( ! ConfServer.monsters.contains(event.getEntityType())) return; + if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; event.setCancelled(true); } @@ -370,7 +371,7 @@ public class FactionsEntityListener implements Listener // We are interested in blocking targeting for certain mobs: - if ( ! ConfServer.monsters.contains(event.getEntity().getType())) return; + if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntity().getType())) return; FLocation floc = new FLocation(target.getLocation()); Faction faction = Board.getFactionAt(floc); diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 5ee08965..46e4e528 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -26,6 +26,7 @@ import org.bukkit.util.NumberConversions; import com.massivecraft.factions.Board; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPerm; @@ -202,7 +203,7 @@ public class FactionsPlayerListener implements Listener FPlayer me = FPlayerColl.i.get(name); if (me.hasAdminMode()) return true; - if (ConfServer.materialsEditTools.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; + if (Const.MATERIALS_EDIT_TOOLS.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; return true; } public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) @@ -215,9 +216,9 @@ public class FactionsPlayerListener implements Listener Location loc = block.getLocation(); Material material = block.getType(); - if (ConfServer.materialsEditOnInteract.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; - if (ConfServer.materialsContainer.contains(material) && ! FPerm.CONTAINER.has(me, loc, ! justCheck)) return false; - if (ConfServer.materialsDoor.contains(material) && ! FPerm.DOOR.has(me, loc, ! justCheck)) return false; + if (Const.MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; + if (Const.MATERIALS_CONTAINER.contains(material) && ! FPerm.CONTAINER.has(me, loc, ! justCheck)) return false; + if (Const.MATERIALS_DOOR.contains(material) && ! FPerm.DOOR.has(me, loc, ! justCheck)) return false; if (material == Material.STONE_BUTTON && ! FPerm.BUTTON.has(me, loc, ! justCheck)) return false; if (material == Material.LEVER && ! FPerm.LEVER.has(me, loc, ! justCheck)) return false; return true;