mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 10:45:22 +01:00
WIP trying out moving flags into flag manager.
This commit is contained in:
parent
812594783e
commit
ffbf938a32
@ -6,18 +6,17 @@ import org.bukkit.event.Listener;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.lists.Flaggs;
|
||||
|
||||
public class Flag {
|
||||
public class Flag implements Comparable<Flag> {
|
||||
|
||||
private String id;
|
||||
private PanelItem icon;
|
||||
private Listener listener;
|
||||
private final Flaggs id;
|
||||
private final PanelItem icon;
|
||||
private final Listener listener;
|
||||
private boolean defaultSetting;
|
||||
|
||||
public Flag() {}
|
||||
|
||||
public Flag(BSkyBlock plugin, String id, PanelItem icon, Listener listener, boolean defaultSetting) {
|
||||
this.id = id;
|
||||
public Flag(BSkyBlock plugin, Flaggs id2, PanelItem icon, Listener listener, boolean defaultSetting) {
|
||||
this.id = id2;
|
||||
this.icon = icon;
|
||||
this.listener = listener;
|
||||
//System.out.println("DEBUG: " + plugin);
|
||||
@ -25,7 +24,7 @@ public class Flag {
|
||||
plugin.getFlagsManager().registerFlag(this);
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
public Flaggs getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -44,4 +43,9 @@ public class Flag {
|
||||
public void setDefaultSetting(boolean defaultSetting) {
|
||||
this.defaultSetting = defaultSetting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Flag o) {
|
||||
return id.compareTo(o.getID());
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,17 @@ import org.bukkit.inventory.ItemStack;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
import us.tastybento.bskyblock.lists.Flaggs;
|
||||
|
||||
public class FlagBuilder {
|
||||
|
||||
private String id = "";
|
||||
private Flaggs id;
|
||||
private PanelItem icon;
|
||||
private Listener listener;
|
||||
private boolean defaultSetting;
|
||||
|
||||
public FlagBuilder id(String id) {
|
||||
this.id = id;
|
||||
public FlagBuilder id(Flaggs flag) {
|
||||
this.id = flag;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class FlagSerializer implements AdapterInterface<HashMap<Flag, Integer>,
|
||||
return result;
|
||||
HashMap<Flag, Integer> flags = (HashMap<Flag, Integer>)object;
|
||||
for (Entry<Flag, Integer> en: flags.entrySet()) {
|
||||
result.put(en.getKey().getID(), en.getValue());
|
||||
result.put(en.getKey().getID().name(), en.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.lists.Flaggs;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -32,7 +33,7 @@ public class BlockInteractionListener extends AbstractFlagListener {
|
||||
}
|
||||
switch (e.getClickedBlock().getType()) {
|
||||
case ANVIL:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ANVIL);
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), plugin.getFlagsManager().getFlagByID(Flaggs.ANVIL));
|
||||
break;
|
||||
case BEACON:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BEACON);
|
||||
|
51
src/main/java/us/tastybento/bskyblock/lists/Flaggs.java
Normal file
51
src/main/java/us/tastybento/bskyblock/lists/Flaggs.java
Normal file
@ -0,0 +1,51 @@
|
||||
package us.tastybento.bskyblock.lists;
|
||||
|
||||
|
||||
public enum Flaggs {
|
||||
ANVIL,
|
||||
ARMOR_STAND,
|
||||
BEACON,
|
||||
BED,
|
||||
BREAK_BLOCKS,
|
||||
BREEDING,
|
||||
BREWING,
|
||||
BUCKET,
|
||||
CHEST,
|
||||
CHORUS_FRUIT,
|
||||
COLLECT_LAVA,
|
||||
COLLECT_WATER,
|
||||
CRAFTING,
|
||||
CROP_TRAMPLE,
|
||||
DOOR,
|
||||
EGGS,
|
||||
ENCHANTING,
|
||||
ENDER_PEARL,
|
||||
ENTER_EXIT_MESSAGES,
|
||||
FIRE,
|
||||
FIRE_EXTINGUISH,
|
||||
FIRE_SPREAD,
|
||||
FURNACE,
|
||||
GATE,
|
||||
HURT_MOBS,
|
||||
HURT_MONSTERS,
|
||||
ITEM_DROP,
|
||||
ITEM_PICKUP,
|
||||
LEASH,
|
||||
LEVER_BUTTON,
|
||||
MILKING,
|
||||
MOB_SPAWN,
|
||||
MONSTER_SPAWN,
|
||||
MOUNT_INVENTORY,
|
||||
MUSIC,
|
||||
PLACE_BLOCKS,
|
||||
PORTAL,
|
||||
PRESSURE_PLATE,
|
||||
PVP_END,
|
||||
PVP_NETHER,
|
||||
PVP_OVERWORLD,
|
||||
REDSTONE,
|
||||
RIDING,
|
||||
SHEARING,
|
||||
SPAWN_EGGS,
|
||||
TRADING
|
||||
}
|
@ -3,7 +3,6 @@ package us.tastybento.bskyblock.lists;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
import us.tastybento.bskyblock.api.flags.FlagBuilder;
|
||||
import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
|
||||
@ -28,53 +27,8 @@ import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
|
||||
public class Flags {
|
||||
public static Flag ANVIL;
|
||||
public static Flag ARMOR_STAND;
|
||||
public static Flag BEACON;
|
||||
public static Flag BED;
|
||||
public static Flag BREAK_BLOCKS;
|
||||
public static Flag BREEDING;
|
||||
public static Flag BREWING;
|
||||
public static Flag BUCKET;
|
||||
public static Flag CHEST;
|
||||
public static Flag CHORUS_FRUIT;
|
||||
public static Flag COLLECT_LAVA;
|
||||
public static Flag COLLECT_WATER;
|
||||
public static Flag CRAFTING;
|
||||
public static Flag CROP_TRAMPLE;
|
||||
public static Flag DOOR;
|
||||
public static Flag EGGS;
|
||||
public static Flag ENCHANTING;
|
||||
public static Flag ENDER_PEARL;
|
||||
public static Flag ENTER_EXIT_MESSAGES;
|
||||
public static Flag FIRE;
|
||||
public static Flag FIRE_EXTINGUISH;
|
||||
public static Flag FIRE_SPREAD;
|
||||
public static Flag FURNACE;
|
||||
public static Flag GATE;
|
||||
public static Flag HURT_MOBS;
|
||||
public static Flag HURT_MONSTERS;
|
||||
public static Flag ITEM_DROP;
|
||||
public static Flag ITEM_PICKUP;
|
||||
public static Flag LEASH;
|
||||
public static Flag LEVER_BUTTON;
|
||||
public static Flag MILKING;
|
||||
public static Flag MOB_SPAWN;
|
||||
public static Flag MONSTER_SPAWN;
|
||||
public static Flag MOUNT_INVENTORY;
|
||||
public static Flag MUSIC;
|
||||
public static Flag PLACE_BLOCKS;
|
||||
public static Flag PORTAL;
|
||||
public static Flag PRESSURE_PLATE;
|
||||
public static Flag PVP_END;
|
||||
public static Flag PVP_NETHER;
|
||||
public static Flag PVP_OVERWORLD;
|
||||
public static Flag REDSTONE;
|
||||
public static Flag RIDING;
|
||||
public static Flag SHEARING;
|
||||
public static Flag SPAWN_EGGS;
|
||||
public static Flag TRADING;
|
||||
|
||||
private BSkyBlock p;
|
||||
|
||||
@ -82,49 +36,49 @@ public class Flags {
|
||||
p = plugin;
|
||||
|
||||
// Break and place blocks
|
||||
BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener(p)).build(p);
|
||||
PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.BREAK_BLOCKS).icon(Material.STONE).listener(new BreakBlocksListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PLACE_BLOCKS).icon(Material.DIRT).listener(new PlaceBlocksListener(p)).build(p);
|
||||
|
||||
// Block interactions - all use BlockInteractionListener()
|
||||
ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener(p)).build(p);
|
||||
BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build(p);
|
||||
BED = new FlagBuilder().id("BED").icon(Material.BED).build(p);
|
||||
BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build(p);
|
||||
CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build(p);
|
||||
DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOODEN_DOOR).build(p);
|
||||
CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build(p);
|
||||
ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build(p);
|
||||
FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build(p);
|
||||
GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build(p);
|
||||
MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build(p);
|
||||
LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build(p);
|
||||
REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build(p);
|
||||
SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build(p);
|
||||
new FlagBuilder().id(Flaggs.ANVIL).icon(Material.ANVIL).listener(new BlockInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.BEACON).icon(Material.BEACON).build(p);
|
||||
new FlagBuilder().id(Flaggs.BED).icon(Material.BED).build(p);
|
||||
new FlagBuilder().id(Flaggs.BREWING).icon(Material.BREWING_STAND_ITEM).build(p);
|
||||
new FlagBuilder().id(Flaggs.CHEST).icon(Material.CHEST).build(p);
|
||||
new FlagBuilder().id(Flaggs.DOOR).allowedByDefault(true).icon(Material.WOODEN_DOOR).build(p);
|
||||
new FlagBuilder().id(Flaggs.CRAFTING).allowedByDefault(true).icon(Material.WORKBENCH).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENCHANTING).allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build(p);
|
||||
new FlagBuilder().id(Flaggs.FURNACE).icon(Material.FURNACE).build(p);
|
||||
new FlagBuilder().id(Flaggs.GATE).allowedByDefault(true).icon(Material.FENCE_GATE).build(p);
|
||||
new FlagBuilder().id(Flaggs.MUSIC).icon(Material.JUKEBOX).build(p);
|
||||
new FlagBuilder().id(Flaggs.LEVER_BUTTON).icon(Material.LEVER).build(p);
|
||||
new FlagBuilder().id(Flaggs.REDSTONE).icon(Material.REDSTONE).build(p);
|
||||
new FlagBuilder().id(Flaggs.SPAWN_EGGS).icon(Material.MONSTER_EGG).build(p);
|
||||
|
||||
// Entity interactions
|
||||
ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener(p)).build(p);
|
||||
RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build(p);
|
||||
TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build(p);
|
||||
new FlagBuilder().id(Flaggs.ARMOR_STAND).icon(Material.ARMOR_STAND).listener(new EntityInteractListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.RIDING).icon(Material.GOLD_BARDING).build(p);
|
||||
new FlagBuilder().id(Flaggs.TRADING).allowedByDefault(true).icon(Material.EMERALD).build(p);
|
||||
|
||||
// Breeding
|
||||
BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.BREEDING).icon(Material.CARROT).listener(new BreedingListener(p)).build(p);
|
||||
|
||||
// Buckets. All bucket use is covered by one listener
|
||||
BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener(p)).build(p);
|
||||
COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build(p);
|
||||
COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build(p);
|
||||
MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flaggs.BUCKET).icon(Material.BUCKET).listener(new BucketListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.COLLECT_LAVA).icon(Material.LAVA_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flaggs.COLLECT_WATER).icon(Material.WATER_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flaggs.MILKING).icon(Material.MILK_BUCKET).build(p);
|
||||
|
||||
// Chorus Fruit and Enderpearls
|
||||
CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(p)).build(p);
|
||||
ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build(p);
|
||||
new FlagBuilder().id(Flaggs.CHORUS_FRUIT).icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENDER_PEARL).icon(Material.ENDER_PEARL).build(p);
|
||||
|
||||
// Physical interactions
|
||||
CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener(p)).build(p);
|
||||
PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build(p);
|
||||
new FlagBuilder().id(Flaggs.CROP_TRAMPLE).icon(Material.WHEAT).listener(new PhysicalInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PRESSURE_PLATE).icon(Material.GOLD_PLATE).build(p);
|
||||
|
||||
// Egg throwing
|
||||
EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.EGGS).icon(Material.EGG).listener(new EggListener(p)).build(p);
|
||||
|
||||
/*
|
||||
* Fire
|
||||
@ -136,41 +90,39 @@ public class Flags {
|
||||
* I'll take you to burn
|
||||
* - The Crazy World of Arthur Brown
|
||||
*/
|
||||
FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener(p)).build(p);
|
||||
FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build(p);
|
||||
FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build(p);
|
||||
new FlagBuilder().id(Flaggs.FIRE).icon(Material.FLINT_AND_STEEL).listener(new FireListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.FIRE_EXTINGUISH).icon(Material.POTION).build(p);
|
||||
new FlagBuilder().id(Flaggs.FIRE_SPREAD).icon(Material.FIREWORK_CHARGE).build(p);
|
||||
|
||||
// Inventories
|
||||
MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.MOUNT_INVENTORY).icon(Material.IRON_BARDING).listener(new InventoryListener(p)).build(p);
|
||||
|
||||
// Hurting things
|
||||
HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener(p)).build(p);
|
||||
HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build(p);
|
||||
new FlagBuilder().id(Flaggs.HURT_MOBS).icon(Material.STONE_SWORD).listener(new HurtingListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.HURT_MONSTERS).icon(Material.WOOD_SWORD).build(p);
|
||||
|
||||
// Leashes
|
||||
LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.LEASH).icon(Material.LEASH).listener(new LeashListener(p)).build(p);
|
||||
|
||||
// Portal use protection
|
||||
PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener(p)).build(p);
|
||||
|
||||
// PVP
|
||||
PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).listener(new PVPListener(p)).build(p);
|
||||
PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).build(p);
|
||||
PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).build(p);
|
||||
new FlagBuilder().id(Flaggs.PORTAL).icon(Material.OBSIDIAN).listener(new PortalListener(p)).build(p);
|
||||
|
||||
// Shearing
|
||||
SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.SHEARING).icon(Material.SHEARS).listener(new ShearingListener(p)).build(p);
|
||||
|
||||
// Item pickup or drop
|
||||
ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(p)).build(p);
|
||||
ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build(p);
|
||||
new FlagBuilder().id(Flaggs.ITEM_DROP).icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.ITEM_PICKUP).icon(Material.DIRT).build(p);
|
||||
|
||||
/*
|
||||
* Non-protection flags
|
||||
*/
|
||||
|
||||
ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).build(p);
|
||||
MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).build(p);
|
||||
MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).build(p);
|
||||
// PVP
|
||||
new FlagBuilder().id(Flaggs.PVP_OVERWORLD).icon(Material.ARROW).listener(new PVPListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PVP_NETHER).icon(Material.IRON_AXE).build(p);
|
||||
new FlagBuilder().id(Flaggs.PVP_END).icon(Material.END_CRYSTAL).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENTER_EXIT_MESSAGES).icon(Material.DIRT).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flaggs.MOB_SPAWN).icon(Material.APPLE).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flaggs.MONSTER_SPAWN).icon(Material.MOB_SPAWNER).allowedByDefault(true).build(p);
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +1,172 @@
|
||||
package us.tastybento.bskyblock.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
import us.tastybento.bskyblock.api.flags.FlagBuilder;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.BreedingListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.BucketListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.EggListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.EntityInteractListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.FireListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.HurtingListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.InventoryListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.ItemDropPickUpListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.LeashListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.PVPListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.PortalListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||
import us.tastybento.bskyblock.lists.Flaggs;
|
||||
|
||||
public class FlagsManager {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private BSkyBlock p;
|
||||
|
||||
public FlagsManager(BSkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
this.p = plugin;
|
||||
|
||||
// Register flags
|
||||
registerFlags();
|
||||
}
|
||||
|
||||
private List<Flag> flags = new ArrayList<>();
|
||||
private HashMap<Flaggs, Flag> flags = new HashMap<>();
|
||||
|
||||
public void registerFlag(Flag flag) {
|
||||
//TODO all the security checks
|
||||
//plugin.getLogger().info("DEBUG: registering flag " + flag.getID());
|
||||
flags.add(flag);
|
||||
flags.put(flag.getID(), flag);
|
||||
// If there is a listener, register it into Bukkit.
|
||||
flag.getListener().ifPresent(l -> plugin.getServer().getPluginManager().registerEvents(l, plugin));
|
||||
flag.getListener().ifPresent(l -> p.getServer().getPluginManager().registerEvents(l, p));
|
||||
}
|
||||
|
||||
public List<Flag> getFlags() {
|
||||
public HashMap<Flaggs, Flag> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public Flag getFlagByID(String id) {
|
||||
for (Flag flag : flags) {
|
||||
if (flag.getID().equals(id.toUpperCase())) return flag;
|
||||
}
|
||||
return null;
|
||||
public Flag getFlagByID(Flaggs id) {
|
||||
return flags.get(id);
|
||||
}
|
||||
|
||||
public Flag getFlagByIcon(PanelItem item) {
|
||||
for (Flag flag : flags) {
|
||||
for (Flag flag : flags.values()) {
|
||||
if (flag.getIcon().equals(item)) return flag;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void registerFlags() {
|
||||
|
||||
// Break and place blocks
|
||||
new FlagBuilder().id(Flaggs.BREAK_BLOCKS).icon(Material.STONE).listener(new BreakBlocksListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PLACE_BLOCKS).icon(Material.DIRT).listener(new PlaceBlocksListener(p)).build(p);
|
||||
|
||||
// Block interactions - all use BlockInteractionListener()
|
||||
new FlagBuilder().id(Flaggs.ANVIL).icon(Material.ANVIL).listener(new BlockInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.BEACON).icon(Material.BEACON).build(p);
|
||||
new FlagBuilder().id(Flaggs.BED).icon(Material.BED).build(p);
|
||||
new FlagBuilder().id(Flaggs.BREWING).icon(Material.BREWING_STAND_ITEM).build(p);
|
||||
new FlagBuilder().id(Flaggs.CHEST).icon(Material.CHEST).build(p);
|
||||
new FlagBuilder().id(Flaggs.DOOR).allowedByDefault(true).icon(Material.WOODEN_DOOR).build(p);
|
||||
new FlagBuilder().id(Flaggs.CRAFTING).allowedByDefault(true).icon(Material.WORKBENCH).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENCHANTING).allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build(p);
|
||||
new FlagBuilder().id(Flaggs.FURNACE).icon(Material.FURNACE).build(p);
|
||||
new FlagBuilder().id(Flaggs.GATE).allowedByDefault(true).icon(Material.FENCE_GATE).build(p);
|
||||
new FlagBuilder().id(Flaggs.MUSIC).icon(Material.JUKEBOX).build(p);
|
||||
new FlagBuilder().id(Flaggs.LEVER_BUTTON).icon(Material.LEVER).build(p);
|
||||
new FlagBuilder().id(Flaggs.REDSTONE).icon(Material.REDSTONE).build(p);
|
||||
new FlagBuilder().id(Flaggs.SPAWN_EGGS).icon(Material.MONSTER_EGG).build(p);
|
||||
|
||||
// Entity interactions
|
||||
new FlagBuilder().id(Flaggs.ARMOR_STAND).icon(Material.ARMOR_STAND).listener(new EntityInteractListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.RIDING).icon(Material.GOLD_BARDING).build(p);
|
||||
new FlagBuilder().id(Flaggs.TRADING).allowedByDefault(true).icon(Material.EMERALD).build(p);
|
||||
|
||||
// Breeding
|
||||
new FlagBuilder().id(Flaggs.BREEDING).icon(Material.CARROT).listener(new BreedingListener(p)).build(p);
|
||||
|
||||
// Buckets. All bucket use is covered by one listener
|
||||
new FlagBuilder().id(Flaggs.BUCKET).icon(Material.BUCKET).listener(new BucketListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.COLLECT_LAVA).icon(Material.LAVA_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flaggs.COLLECT_WATER).icon(Material.WATER_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flaggs.MILKING).icon(Material.MILK_BUCKET).build(p);
|
||||
|
||||
// Chorus Fruit and Enderpearls
|
||||
new FlagBuilder().id(Flaggs.CHORUS_FRUIT).icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENDER_PEARL).icon(Material.ENDER_PEARL).build(p);
|
||||
|
||||
// Physical interactions
|
||||
new FlagBuilder().id(Flaggs.CROP_TRAMPLE).icon(Material.WHEAT).listener(new PhysicalInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PRESSURE_PLATE).icon(Material.GOLD_PLATE).build(p);
|
||||
|
||||
// Egg throwing
|
||||
new FlagBuilder().id(Flaggs.EGGS).icon(Material.EGG).listener(new EggListener(p)).build(p);
|
||||
|
||||
/*
|
||||
* Fire
|
||||
* I'll take you to burn.
|
||||
* Fire
|
||||
* I'll take you to learn.
|
||||
* You gonna burn, burn, burn
|
||||
* Fire
|
||||
* I'll take you to burn
|
||||
* - The Crazy World of Arthur Brown
|
||||
*/
|
||||
new FlagBuilder().id(Flaggs.FIRE).icon(Material.FLINT_AND_STEEL).listener(new FireListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.FIRE_EXTINGUISH).icon(Material.POTION).build(p);
|
||||
new FlagBuilder().id(Flaggs.FIRE_SPREAD).icon(Material.FIREWORK_CHARGE).build(p);
|
||||
|
||||
// Inventories
|
||||
new FlagBuilder().id(Flaggs.MOUNT_INVENTORY).icon(Material.IRON_BARDING).listener(new InventoryListener(p)).build(p);
|
||||
|
||||
// Hurting things
|
||||
new FlagBuilder().id(Flaggs.HURT_MOBS).icon(Material.STONE_SWORD).listener(new HurtingListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.HURT_MONSTERS).icon(Material.WOOD_SWORD).build(p);
|
||||
|
||||
// Leashes
|
||||
new FlagBuilder().id(Flaggs.LEASH).icon(Material.LEASH).listener(new LeashListener(p)).build(p);
|
||||
|
||||
// Portal use protection
|
||||
new FlagBuilder().id(Flaggs.PORTAL).icon(Material.OBSIDIAN).listener(new PortalListener(p)).build(p);
|
||||
|
||||
// Shearing
|
||||
new FlagBuilder().id(Flaggs.SHEARING).icon(Material.SHEARS).listener(new ShearingListener(p)).build(p);
|
||||
|
||||
// Item pickup or drop
|
||||
new FlagBuilder().id(Flaggs.ITEM_DROP).icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.ITEM_PICKUP).icon(Material.DIRT).build(p);
|
||||
|
||||
/*
|
||||
* Non-protection flags
|
||||
*/
|
||||
// PVP
|
||||
new FlagBuilder().id(Flaggs.PVP_OVERWORLD).icon(Material.ARROW).listener(new PVPListener(p)).build(p);
|
||||
new FlagBuilder().id(Flaggs.PVP_NETHER).icon(Material.IRON_AXE).build(p);
|
||||
new FlagBuilder().id(Flaggs.PVP_END).icon(Material.END_CRYSTAL).build(p);
|
||||
new FlagBuilder().id(Flaggs.ENTER_EXIT_MESSAGES).icon(Material.DIRT).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flaggs.MOB_SPAWN).icon(Material.APPLE).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flaggs.MONSTER_SPAWN).icon(Material.MOB_SPAWNER).allowedByDefault(true).build(p);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get flag by string
|
||||
* @param key - string name same as the enum
|
||||
* @return Flag or null if not known
|
||||
*/
|
||||
public Flag getFlagByID(String key) {
|
||||
for (Flaggs flag: Flaggs.values()) {
|
||||
if (flag.name().equalsIgnoreCase(key)) return this.getFlagByID(flag);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user