Move enum sets to mconf instead of hardcoding them. This way perhaps other server mods can add in stuff that's useful to them.

This commit is contained in:
Olof Larsson 2013-08-23 10:14:23 +02:00
parent 844dc6c420
commit fa0a2fb90a
3 changed files with 69 additions and 71 deletions

View File

@ -1,12 +1,5 @@
package com.massivecraft.factions; 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 class Const
{ {
// MStore Collection Names // MStore Collection Names
@ -27,61 +20,4 @@ public class Const
public static final int MAP_WIDTH = 39; public static final int MAP_WIDTH = 39;
public static final char[] MAP_KEY_CHARS = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray(); public static final char[] MAP_KEY_CHARS = "\\/#?$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz".toCharArray();
// Enumerations
public static final Set<Material> 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<Material> MATERIALS_EDIT_TOOLS = MUtil.set(
Material.FIREBALL,
Material.FLINT_AND_STEEL,
Material.BUCKET,
Material.WATER_BUCKET,
Material.LAVA_BUCKET
);
public static final Set<Material> MATERIALS_DOOR = MUtil.set(
Material.WOODEN_DOOR,
Material.TRAP_DOOR,
Material.FENCE_GATE
);
public static final Set<Material> 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<EntityType> 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
);
} }

View File

@ -6,11 +6,14 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.FactionsListenerChat;
import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.store.Entity;
import com.massivecraft.mcore.util.MUtil;
public class MConf extends Entity<MConf> public class MConf extends Entity<MConf>
{ {
@ -177,4 +180,64 @@ public class MConf extends Entity<MConf>
public boolean logMoneyTransactions = true; public boolean logMoneyTransactions = true;
public boolean logPlayerCommands = true; public boolean logPlayerCommands = true;
// -------------------------------------------- //
// ENUMERATIONS
// -------------------------------------------- //
public Set<Material> MATERIALS_EDIT_ON_INTERACT = MUtil.set(
Material.DIODE_BLOCK_OFF,
Material.DIODE_BLOCK_ON,
Material.NOTE_BLOCK,
Material.CAULDRON,
Material.SOIL
);
public Set<Material> MATERIALS_EDIT_TOOLS = MUtil.set(
Material.FIREBALL,
Material.FLINT_AND_STEEL,
Material.BUCKET,
Material.WATER_BUCKET,
Material.LAVA_BUCKET
);
public Set<Material> MATERIALS_DOOR = MUtil.set(
Material.WOODEN_DOOR,
Material.TRAP_DOOR,
Material.FENCE_GATE
);
public Set<Material> 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<EntityType> 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
);
} }

View File

@ -51,7 +51,6 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
@ -515,7 +514,7 @@ public class FactionsListenerMain implements Listener
public void blockMonsters(CreatureSpawnEvent event) public void blockMonsters(CreatureSpawnEvent event)
{ {
// If a monster is spawning ... // 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 // Check Disabled
if (UConf.isDisabled(event.getLocation())) return; if (UConf.isDisabled(event.getLocation())) return;
@ -533,7 +532,7 @@ public class FactionsListenerMain implements Listener
public void blockMonsters(EntityTargetEvent event) public void blockMonsters(EntityTargetEvent event)
{ {
// If a monster ... // 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 ... // ... is targeting something ...
Entity target = event.getTarget(); Entity target = event.getTarget();
@ -860,7 +859,7 @@ public class FactionsListenerMain implements Listener
// TODO: Possibly incorporate pain build... // TODO: Possibly incorporate pain build...
public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean justCheck) 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(); String name = player.getName();
if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true;
@ -882,9 +881,9 @@ public class FactionsListenerMain implements Listener
PS ps = PS.valueOf(block); PS ps = PS.valueOf(block);
Material material = block.getType(); Material material = block.getType();
if (Const.MATERIALS_EDIT_ON_INTERACT.contains(material) && ! FPerm.BUILD.has(me, ps, ! justCheck)) return false; if (MConf.get().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 (MConf.get().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_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.STONE_BUTTON && ! FPerm.BUTTON.has(me, ps, ! justCheck)) return false;
if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false; if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false;
return true; return true;