mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-30 20:11:32 +01:00
Added Setting type to flags.
Flags can be Protection type or Setting Type. Still needs testing for PVP.
This commit is contained in:
parent
645b4eb610
commit
be5404e9c2
@ -4,24 +4,27 @@ import java.util.Optional;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
public class Flag implements Comparable<Flag> {
|
||||
|
||||
public enum FlagType {
|
||||
PROTECTION,
|
||||
SETTING
|
||||
}
|
||||
|
||||
private final Flags id;
|
||||
private final PanelItem icon;
|
||||
private final Listener listener;
|
||||
private final FlagType type;
|
||||
private boolean defaultSetting;
|
||||
|
||||
public Flag(BSkyBlock plugin, Flags id2, PanelItem icon, Listener listener, boolean defaultSetting) {
|
||||
public Flag(Flags id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
|
||||
this.id = id2;
|
||||
this.icon = icon;
|
||||
this.listener = listener;
|
||||
//System.out.println("DEBUG: " + plugin);
|
||||
//System.out.println("DEBUG: " + plugin.getFlagsManager());
|
||||
plugin.getFlagsManager().registerFlag(this);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Flags getID() {
|
||||
@ -36,7 +39,7 @@ public class Flag implements Comparable<Flag> {
|
||||
return Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
public boolean isAllowed() {
|
||||
public boolean isDefaultSetting() {
|
||||
return defaultSetting;
|
||||
}
|
||||
|
||||
@ -44,6 +47,13 @@ public class Flag implements Comparable<Flag> {
|
||||
this.defaultSetting = defaultSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public FlagType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Flag o) {
|
||||
return id.compareTo(o.getID());
|
||||
|
@ -4,7 +4,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
@ -15,6 +15,7 @@ public class FlagBuilder {
|
||||
private PanelItem icon;
|
||||
private Listener listener;
|
||||
private boolean defaultSetting;
|
||||
private FlagType type = FlagType.PROTECTION;
|
||||
|
||||
public FlagBuilder id(Flags flag) {
|
||||
this.id = flag;
|
||||
@ -39,8 +40,8 @@ public class FlagBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Flag build(BSkyBlock plugin) {
|
||||
return new Flag(plugin, id, icon, listener, defaultSetting);
|
||||
public Flag build() {
|
||||
return new Flag(id, icon, listener, defaultSetting, type);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,4 +53,14 @@ public class FlagBuilder {
|
||||
this.defaultSetting = setting;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of this flag
|
||||
* @param type {@link FlagType}
|
||||
* @return FlagBuilder
|
||||
*/
|
||||
public FlagBuilder type(FlagType type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import org.bukkit.event.Listener;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
@ -140,6 +141,21 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
* @return true if the check is okay, false if it was disallowed
|
||||
*/
|
||||
public boolean checkIsland(Event e, Location loc, Flags flag, boolean silent) {
|
||||
// If this is not an Island World, skip
|
||||
if (!inWorld(loc)) return true;
|
||||
|
||||
// Get the island and if present
|
||||
Optional<Island> island = plugin.getIslands().getIslandAt(loc);
|
||||
|
||||
// Handle Settings Flag
|
||||
id(flag);
|
||||
id(flag).getType();
|
||||
if (id(flag).getType().equals(FlagType.SETTING)) {
|
||||
// If the island exists, return the setting, otherwise return the default setting for this flag
|
||||
return island.map(x -> x.isAllowed(flag)).orElse(isDefaultAllowed(flag));
|
||||
}
|
||||
|
||||
// Protection flag
|
||||
|
||||
// If the user is not set already, try to get it from the event
|
||||
if (user == null) {
|
||||
@ -151,12 +167,8 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// If this is not an Island World, skip
|
||||
if (!inWorld(user)) return true;
|
||||
|
||||
// Get the island and if present, check the flag, react if required and return
|
||||
Optional<Island> island = plugin.getIslands().getIslandAt(loc);
|
||||
|
||||
|
||||
|
||||
if (island.isPresent()) {
|
||||
if (!island.get().isAllowed(user, flag)) {
|
||||
noGo(e, silent);
|
||||
@ -170,7 +182,7 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
}
|
||||
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
if (!isAllowed(flag)) {
|
||||
if (!isDefaultAllowed(flag)) {
|
||||
noGo(e, silent);
|
||||
user = null;
|
||||
return false;
|
||||
@ -188,8 +200,13 @@ public abstract class AbstractFlagListener implements Listener {
|
||||
protected Flag id(Flags flag) {
|
||||
return plugin.getFlagsManager().getFlagByID(flag);
|
||||
}
|
||||
|
||||
protected boolean isAllowed(Flags flag) {
|
||||
return plugin.getFlagsManager().isAllowed(flag);
|
||||
|
||||
/**
|
||||
* Return the default setting for this flag
|
||||
* @param flag
|
||||
* @return
|
||||
*/
|
||||
protected boolean isDefaultAllowed(Flags flag) {
|
||||
return plugin.getFlagsManager().isDefaultAllowed(flag);
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
|
||||
});
|
||||
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
if (!isAllowed(Flags.BREAK_BLOCKS)) {
|
||||
if (!isDefaultAllowed(Flags.BREAK_BLOCKS)) {
|
||||
e.setCancelled(true);
|
||||
user.sendMessage("protection.protected");
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class FireListener extends AbstractFlagListener {
|
||||
if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
});
|
||||
// If not on an island, check the default setting
|
||||
if (!island.isPresent() && !isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
if (!island.isPresent() && !isDefaultAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +69,7 @@ public class FireListener extends AbstractFlagListener {
|
||||
if (!x.isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
});
|
||||
// If not on an island, check the default setting
|
||||
if (!island.isPresent() && !isAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
if (!island.isPresent() && !isDefaultAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ public class FireListener extends AbstractFlagListener {
|
||||
if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
});
|
||||
// If not on an island, check the default setting
|
||||
if (!island.isPresent() && !isAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
if (!island.isPresent() && !isDefaultAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ public class FireListener extends AbstractFlagListener {
|
||||
if (!x.isAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
});
|
||||
// If not on an island, check the default setting
|
||||
if (!island.isPresent() && !isAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
if (!island.isPresent() && !isDefaultAllowed(Flags.FIRE)) e.setCancelled(true);
|
||||
|
||||
// If either of these canceled the event, return
|
||||
if (e.isCancelled()) return;
|
||||
|
@ -65,13 +65,13 @@ public class MobSpawnListener extends AbstractFlagListener {
|
||||
} else {
|
||||
// Outside of the island
|
||||
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
|
||||
if (!isAllowed(Flags.MOB_SPAWN)) {
|
||||
if (!isDefaultAllowed(Flags.MOB_SPAWN)) {
|
||||
// Mobs not allowed to spawn
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else if (e.getEntity() instanceof Animals) {
|
||||
if (!isAllowed(Flags.MONSTER_SPAWN)) {
|
||||
if (!isDefaultAllowed(Flags.MONSTER_SPAWN)) {
|
||||
// Mobs not allowed to spawn
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
|
@ -2,10 +2,12 @@ package us.tastybento.bskyblock.managers;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.flags.Flag;
|
||||
import us.tastybento.bskyblock.api.flags.Flag.FlagType;
|
||||
import us.tastybento.bskyblock.api.flags.FlagBuilder;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.listeners.flags.BlockInteractionListener;
|
||||
@ -29,23 +31,22 @@ import us.tastybento.bskyblock.lists.Flags;
|
||||
|
||||
public class FlagsManager {
|
||||
|
||||
private BSkyBlock p;
|
||||
private BSkyBlock plugin;
|
||||
private HashMap<Flags, Flag> flags = new HashMap<>();
|
||||
|
||||
|
||||
public FlagsManager(BSkyBlock plugin) {
|
||||
this.p = plugin;
|
||||
this.plugin = plugin;
|
||||
|
||||
// Register flags
|
||||
registerFlags();
|
||||
}
|
||||
|
||||
private HashMap<Flags, Flag> flags = new HashMap<>();
|
||||
|
||||
public void registerFlag(Flag flag) {
|
||||
//TODO all the security checks
|
||||
//plugin.getLogger().info("DEBUG: registering flag " + flag.getID());
|
||||
//Bukkit.getLogger().info("DEBUG: registering flag " + flag.getID());
|
||||
flags.put(flag.getID(), flag);
|
||||
// If there is a listener, register it into Bukkit.
|
||||
flag.getListener().ifPresent(l -> p.getServer().getPluginManager().registerEvents(l, p));
|
||||
flag.getListener().ifPresent(l -> Bukkit.getServer().getPluginManager().registerEvents(l, plugin));
|
||||
}
|
||||
|
||||
public HashMap<Flags, Flag> getFlags() {
|
||||
@ -53,6 +54,7 @@ public class FlagsManager {
|
||||
}
|
||||
|
||||
public Flag getFlagByID(Flags id) {
|
||||
//Bukkit.getLogger().info("DEBUG: requesting " + id + " flags size = " + flags.size());
|
||||
return flags.get(id);
|
||||
}
|
||||
|
||||
@ -66,49 +68,49 @@ public class FlagsManager {
|
||||
private void registerFlags() {
|
||||
|
||||
// Break and place blocks
|
||||
new FlagBuilder().id(Flags.BREAK_BLOCKS).icon(Material.STONE).listener(new BreakBlocksListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.PLACE_BLOCKS).icon(Material.DIRT).listener(new PlaceBlocksListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.BREAK_BLOCKS).icon(Material.STONE).listener(new BreakBlocksListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.PLACE_BLOCKS).icon(Material.DIRT).listener(new PlaceBlocksListener(plugin)).build());
|
||||
|
||||
// Block interactions - all use BlockInteractionListener()
|
||||
new FlagBuilder().id(Flags.ANVIL).icon(Material.ANVIL).listener(new BlockInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.BEACON).icon(Material.BEACON).build(p);
|
||||
new FlagBuilder().id(Flags.BED).icon(Material.BED).build(p);
|
||||
new FlagBuilder().id(Flags.BREWING).icon(Material.BREWING_STAND_ITEM).build(p);
|
||||
new FlagBuilder().id(Flags.CHEST).icon(Material.CHEST).build(p);
|
||||
new FlagBuilder().id(Flags.DOOR).allowedByDefault(true).icon(Material.WOODEN_DOOR).build(p);
|
||||
new FlagBuilder().id(Flags.CRAFTING).allowedByDefault(true).icon(Material.WORKBENCH).build(p);
|
||||
new FlagBuilder().id(Flags.ENCHANTING).allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build(p);
|
||||
new FlagBuilder().id(Flags.FURNACE).icon(Material.FURNACE).build(p);
|
||||
new FlagBuilder().id(Flags.GATE).allowedByDefault(true).icon(Material.FENCE_GATE).build(p);
|
||||
new FlagBuilder().id(Flags.MUSIC).icon(Material.JUKEBOX).build(p);
|
||||
new FlagBuilder().id(Flags.LEVER_BUTTON).icon(Material.LEVER).build(p);
|
||||
new FlagBuilder().id(Flags.REDSTONE).icon(Material.REDSTONE).build(p);
|
||||
new FlagBuilder().id(Flags.SPAWN_EGGS).icon(Material.MONSTER_EGG).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.ANVIL).icon(Material.ANVIL).listener(new BlockInteractionListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.BEACON).icon(Material.BEACON).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.BED).icon(Material.BED).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.BREWING).icon(Material.BREWING_STAND_ITEM).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.CHEST).icon(Material.CHEST).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.DOOR).allowedByDefault(true).icon(Material.WOODEN_DOOR).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.CRAFTING).allowedByDefault(true).icon(Material.WORKBENCH).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.ENCHANTING).allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.FURNACE).icon(Material.FURNACE).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.GATE).allowedByDefault(true).icon(Material.FENCE_GATE).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.MUSIC).icon(Material.JUKEBOX).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.LEVER_BUTTON).icon(Material.LEVER).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.REDSTONE).icon(Material.REDSTONE).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.SPAWN_EGGS).icon(Material.MONSTER_EGG).build());
|
||||
|
||||
// Entity interactions
|
||||
new FlagBuilder().id(Flags.ARMOR_STAND).icon(Material.ARMOR_STAND).listener(new EntityInteractListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.RIDING).icon(Material.GOLD_BARDING).build(p);
|
||||
new FlagBuilder().id(Flags.TRADING).allowedByDefault(true).icon(Material.EMERALD).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.ARMOR_STAND).icon(Material.ARMOR_STAND).listener(new EntityInteractListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.RIDING).icon(Material.GOLD_BARDING).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.TRADING).allowedByDefault(true).icon(Material.EMERALD).build());
|
||||
|
||||
// Breeding
|
||||
new FlagBuilder().id(Flags.BREEDING).icon(Material.CARROT).listener(new BreedingListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.BREEDING).icon(Material.CARROT).listener(new BreedingListener(plugin)).build());
|
||||
|
||||
// Buckets. All bucket use is covered by one listener
|
||||
new FlagBuilder().id(Flags.BUCKET).icon(Material.BUCKET).listener(new BucketListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.COLLECT_LAVA).icon(Material.LAVA_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flags.COLLECT_WATER).icon(Material.WATER_BUCKET).build(p);
|
||||
new FlagBuilder().id(Flags.MILKING).icon(Material.MILK_BUCKET).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.BUCKET).icon(Material.BUCKET).listener(new BucketListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.COLLECT_LAVA).icon(Material.LAVA_BUCKET).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.COLLECT_WATER).icon(Material.WATER_BUCKET).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.MILKING).icon(Material.MILK_BUCKET).build());
|
||||
|
||||
// Chorus Fruit and Enderpearls
|
||||
new FlagBuilder().id(Flags.CHORUS_FRUIT).icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.ENDER_PEARL).icon(Material.ENDER_PEARL).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.CHORUS_FRUIT).icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.ENDER_PEARL).icon(Material.ENDER_PEARL).build());
|
||||
|
||||
// Physical interactions
|
||||
new FlagBuilder().id(Flags.CROP_TRAMPLE).icon(Material.WHEAT).listener(new PhysicalInteractionListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.PRESSURE_PLATE).icon(Material.GOLD_PLATE).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.CROP_TRAMPLE).icon(Material.WHEAT).listener(new PhysicalInteractionListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.PRESSURE_PLATE).icon(Material.GOLD_PLATE).build());
|
||||
|
||||
// Egg throwing
|
||||
new FlagBuilder().id(Flags.EGGS).icon(Material.EGG).listener(new EggListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.EGGS).icon(Material.EGG).listener(new EggListener(plugin)).build());
|
||||
|
||||
/*
|
||||
* Fire
|
||||
@ -120,40 +122,41 @@ public class FlagsManager {
|
||||
* I'll take you to burn
|
||||
* - The Crazy World of Arthur Brown
|
||||
*/
|
||||
new FlagBuilder().id(Flags.FIRE).icon(Material.FLINT_AND_STEEL).listener(new FireListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.FIRE_EXTINGUISH).icon(Material.POTION).build(p);
|
||||
new FlagBuilder().id(Flags.FIRE_SPREAD).icon(Material.FIREWORK_CHARGE).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.FIRE).icon(Material.FLINT_AND_STEEL).listener(new FireListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.FIRE_EXTINGUISH).icon(Material.POTION).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.FIRE_SPREAD).icon(Material.FIREWORK_CHARGE).build());
|
||||
|
||||
// Inventories
|
||||
new FlagBuilder().id(Flags.MOUNT_INVENTORY).icon(Material.IRON_BARDING).listener(new InventoryListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.MOUNT_INVENTORY).icon(Material.IRON_BARDING).listener(new InventoryListener(plugin)).build());
|
||||
|
||||
// Hurting things
|
||||
new FlagBuilder().id(Flags.HURT_MOBS).icon(Material.STONE_SWORD).listener(new HurtingListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.HURT_MONSTERS).icon(Material.WOOD_SWORD).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.HURT_MOBS).icon(Material.STONE_SWORD).listener(new HurtingListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.HURT_MONSTERS).icon(Material.WOOD_SWORD).build());
|
||||
|
||||
// Leashes
|
||||
new FlagBuilder().id(Flags.LEASH).icon(Material.LEASH).listener(new LeashListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.LEASH).icon(Material.LEASH).listener(new LeashListener(plugin)).build());
|
||||
|
||||
// Portal use protection
|
||||
new FlagBuilder().id(Flags.PORTAL).icon(Material.OBSIDIAN).listener(new PortalListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.PORTAL).icon(Material.OBSIDIAN).listener(new PortalListener(plugin)).build());
|
||||
|
||||
// Shearing
|
||||
new FlagBuilder().id(Flags.SHEARING).icon(Material.SHEARS).listener(new ShearingListener(p)).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.SHEARING).icon(Material.SHEARS).listener(new ShearingListener(plugin)).build());
|
||||
|
||||
// Item pickup or drop
|
||||
new FlagBuilder().id(Flags.ITEM_DROP).icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.ITEM_PICKUP).icon(Material.DIRT).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.ITEM_DROP).icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.ITEM_PICKUP).icon(Material.DIRT).build());
|
||||
|
||||
/*
|
||||
* Non-protection flags
|
||||
* Settings flags (not protection flags)
|
||||
*/
|
||||
// PVP
|
||||
new FlagBuilder().id(Flags.PVP_OVERWORLD).icon(Material.ARROW).listener(new PVPListener(p)).build(p);
|
||||
new FlagBuilder().id(Flags.PVP_NETHER).icon(Material.IRON_AXE).build(p);
|
||||
new FlagBuilder().id(Flags.PVP_END).icon(Material.END_CRYSTAL).build(p);
|
||||
new FlagBuilder().id(Flags.ENTER_EXIT_MESSAGES).icon(Material.DIRT).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flags.MOB_SPAWN).icon(Material.APPLE).allowedByDefault(true).build(p);
|
||||
new FlagBuilder().id(Flags.MONSTER_SPAWN).icon(Material.MOB_SPAWNER).allowedByDefault(true).build(p);
|
||||
registerFlag(new FlagBuilder().id(Flags.PVP_OVERWORLD).icon(Material.ARROW).type(FlagType.SETTING).listener(new PVPListener(plugin)).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.PVP_NETHER).icon(Material.IRON_AXE).type(FlagType.SETTING).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.PVP_END).icon(Material.END_CRYSTAL).type(FlagType.SETTING).build());
|
||||
// Others
|
||||
registerFlag(new FlagBuilder().id(Flags.ENTER_EXIT_MESSAGES).icon(Material.DIRT).allowedByDefault(true).type(FlagType.SETTING).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.MOB_SPAWN).icon(Material.APPLE).allowedByDefault(true).type(FlagType.SETTING).build());
|
||||
registerFlag(new FlagBuilder().id(Flags.MONSTER_SPAWN).icon(Material.MOB_SPAWNER).allowedByDefault(true).type(FlagType.SETTING).build());
|
||||
|
||||
}
|
||||
|
||||
@ -169,8 +172,8 @@ public class FlagsManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAllowed(Flags flag) {
|
||||
if (flags.containsKey(flag)) return flags.get(flag).isAllowed();
|
||||
public boolean isDefaultAllowed(Flags flag) {
|
||||
if (flags.containsKey(flag)) return flags.get(flag).isDefaultSetting();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -91,6 +92,9 @@ public class TestBSkyBlock {
|
||||
Mockito.when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
Bukkit.setServer(server);
|
||||
Mockito.when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
Mockito.when(server.getPluginManager()).thenReturn(pluginManager);
|
||||
|
||||
sender = mock(CommandSender.class);
|
||||
player = mock(Player.class);
|
||||
ownerOfIsland = mock(Player.class);
|
||||
@ -123,7 +127,7 @@ public class TestBSkyBlock {
|
||||
PowerMockito.mockStatic(Flags.class);
|
||||
|
||||
plugin = Mockito.mock(BSkyBlock.class);
|
||||
flagsManager = Mockito.mock(FlagsManager.class);
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
Mockito.when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||
|
||||
block = Mockito.mock(Block.class);
|
||||
@ -159,6 +163,7 @@ public class TestBSkyBlock {
|
||||
Settings settings = mock(Settings.class);
|
||||
Mockito.when(plugin.getSettings()).thenReturn(settings);
|
||||
Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<String>());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -411,7 +416,7 @@ public class TestBSkyBlock {
|
||||
assertFalse(island.getBanned().contains(member1));
|
||||
|
||||
// Protection
|
||||
new FlagsManager(plugin);
|
||||
|
||||
// Check default settings
|
||||
// Owner should be able to do anything
|
||||
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
|
||||
@ -499,6 +504,7 @@ public class TestBSkyBlock {
|
||||
*/
|
||||
|
||||
// Now test events
|
||||
|
||||
FlagListener fl = new FlagListener(plugin);
|
||||
Bukkit.getLogger().info("SETUP: owner UUID = " + ownerOfIsland.getUniqueId());
|
||||
Bukkit.getLogger().info("SETUP: member UUID = " + player.getUniqueId());
|
||||
|
Loading…
Reference in New Issue
Block a user