From fa0a2fb90adfccbf3593c81113580d258724b14d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 23 Aug 2013 10:14:23 +0200 Subject: [PATCH] Move enum sets to mconf instead of hardcoding them. This way perhaps other server mods can add in stuff that's useful to them. --- src/com/massivecraft/factions/Const.java | 64 ------------------- .../massivecraft/factions/entity/MConf.java | 63 ++++++++++++++++++ .../listeners/FactionsListenerMain.java | 13 ++-- 3 files changed, 69 insertions(+), 71 deletions(-) diff --git a/src/com/massivecraft/factions/Const.java b/src/com/massivecraft/factions/Const.java index 66c19867..7aa48d3a 100644 --- a/src/com/massivecraft/factions/Const.java +++ b/src/com/massivecraft/factions/Const.java @@ -1,12 +1,5 @@ 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 { // MStore Collection Names @@ -27,61 +20,4 @@ public class Const public static final int MAP_WIDTH = 39; public static final char[] MAP_KEY_CHARS = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray(); - // Enumerations - - 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, - Material.TRAPPED_CHEST, - Material.HOPPER, - Material.DROPPER - ); - - 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/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index fd8a6524..40112b65 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -6,11 +6,14 @@ import java.util.Set; import java.util.TreeSet; import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventPriority; import com.massivecraft.factions.Factions; import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.mcore.store.Entity; +import com.massivecraft.mcore.util.MUtil; public class MConf extends Entity { @@ -176,5 +179,65 @@ public class MConf extends Entity public boolean logLandUnclaims = true; public boolean logMoneyTransactions = true; public boolean logPlayerCommands = true; + + // -------------------------------------------- // + // ENUMERATIONS + // -------------------------------------------- // + + public Set MATERIALS_EDIT_ON_INTERACT = MUtil.set( + Material.DIODE_BLOCK_OFF, + Material.DIODE_BLOCK_ON, + Material.NOTE_BLOCK, + Material.CAULDRON, + Material.SOIL + ); + + public Set MATERIALS_EDIT_TOOLS = MUtil.set( + Material.FIREBALL, + Material.FLINT_AND_STEEL, + Material.BUCKET, + Material.WATER_BUCKET, + Material.LAVA_BUCKET + ); + + public Set MATERIALS_DOOR = MUtil.set( + Material.WOODEN_DOOR, + Material.TRAP_DOOR, + Material.FENCE_GATE + ); + + public 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, + Material.TRAPPED_CHEST, + Material.HOPPER, + Material.DROPPER + ); + + public 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 + ); } \ No newline at end of file diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index 0fc1d31d..eac5f29d 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -51,7 +51,6 @@ import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerRespawnEvent; -import com.massivecraft.factions.Const; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; @@ -515,7 +514,7 @@ public class FactionsListenerMain implements Listener public void blockMonsters(CreatureSpawnEvent event) { // If a monster is spawning ... - if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; + if ( ! MConf.get().ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; // Check Disabled if (UConf.isDisabled(event.getLocation())) return; @@ -533,7 +532,7 @@ public class FactionsListenerMain implements Listener public void blockMonsters(EntityTargetEvent event) { // If a monster ... - if ( ! Const.ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; + if ( ! MConf.get().ENTITY_TYPES_MONSTERS.contains(event.getEntityType())) return; // ... is targeting something ... Entity target = event.getTarget(); @@ -860,7 +859,7 @@ public class FactionsListenerMain implements Listener // TODO: Possibly incorporate pain build... public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean justCheck) { - if (!Const.MATERIALS_EDIT_TOOLS.contains(material)) return true; + if (!MConf.get().MATERIALS_EDIT_TOOLS.contains(material)) return true; String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; @@ -882,9 +881,9 @@ public class FactionsListenerMain implements Listener PS ps = PS.valueOf(block); Material material = block.getType(); - if (Const.MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, ps, ! justCheck)) return false; - if (Const.MATERIALS_CONTAINER.contains(material) && ! FPerm.CONTAINER.has(me, ps, ! justCheck)) return false; - if (Const.MATERIALS_DOOR.contains(material) && ! FPerm.DOOR.has(me, ps, ! justCheck)) return false; + if (MConf.get().MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, ps, ! justCheck)) return false; + if (MConf.get().MATERIALS_CONTAINER.contains(material) && ! FPerm.CONTAINER.has(me, ps, ! justCheck)) return false; + if (MConf.get().MATERIALS_DOOR.contains(material) && ! FPerm.DOOR.has(me, ps, ! justCheck)) return false; if (material == Material.STONE_BUTTON && ! FPerm.BUTTON.has(me, ps, ! justCheck)) return false; if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false; return true;