Came full circle - kept Flags as final statics

This approach simulates an enum, but one that can be extended by others
to add custom flags. I added a handy values() method that uses
reflection to provide a list of all the flags in the class.

See TestBSkyBlock.java test classes for the tests of the default flag
registration and the custom flag registration.
This commit is contained in:
Tastybento 2018-02-05 23:53:07 -08:00
parent be5404e9c2
commit ace6294e23
26 changed files with 255 additions and 387 deletions

View File

@ -5,7 +5,6 @@ import java.util.Optional;
import org.bukkit.event.Listener;
import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.lists.Flags;
public class Flag implements Comparable<Flag> {
@ -14,20 +13,20 @@ public class Flag implements Comparable<Flag> {
SETTING
}
private final Flags id;
private final String id;
private final PanelItem icon;
private final Listener listener;
private final FlagType type;
private boolean defaultSetting;
public Flag(Flags id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
public Flag(String id2, PanelItem icon, Listener listener, boolean defaultSetting, FlagType type) {
this.id = id2;
this.icon = icon;
this.listener = listener;
this.type = type;
}
public Flags getID() {
public String getID() {
return id;
}

View File

@ -7,18 +7,17 @@ import org.bukkit.inventory.ItemStack;
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;
public class FlagBuilder {
private Flags id;
private String id;
private PanelItem icon;
private Listener listener;
private boolean defaultSetting;
private FlagType type = FlagType.PROTECTION;
public FlagBuilder id(Flags flag) {
this.id = flag;
public FlagBuilder id(String string) {
this.id = string;
return this;
}
@ -63,4 +62,14 @@ public class FlagBuilder {
this.type = type;
return this;
}
/**
* Set the id of this flag to the name of this enum value
* @param flag
* @return
*/
public FlagBuilder id(Enum<?> flag) {
this.id = flag.name();
return this;
}
}

View File

@ -21,9 +21,9 @@ import us.tastybento.bskyblock.api.events.island.IslandEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Util;
@ -82,7 +82,7 @@ public class Island implements DataObject {
//// Protection flags ////
@Adapter(FlagSerializer.class)
private HashMap<Flags, Integer> flags = new HashMap<>();
private HashMap<Flag, Integer> flags = new HashMap<>();
private int levelHandicap;
private Location spawnPoint;
@ -154,14 +154,14 @@ public class Island implements DataObject {
/**
* Get the Island Guard flag ranking
* @param flag
* @param breakBlocks
* @return flag rank. Players must have at least this rank to bypass this flag
*/
public int getFlagReq(Flags flag){
if(flags.containsKey(flag)) {
return flags.get(flag);
public int getFlagReq(Flag breakBlocks){
if(flags.containsKey(breakBlocks)) {
return flags.get(breakBlocks);
} else {
flags.put(flag, RanksManager.MEMBER_RANK);
flags.put(breakBlocks, RanksManager.MEMBER_RANK);
return RanksManager.MEMBER_RANK;
}
}
@ -169,7 +169,7 @@ public class Island implements DataObject {
/**
* @return the flags
*/
public HashMap<Flags, Integer> getFlags() {
public HashMap<Flag, Integer> getFlags() {
return flags;
}
@ -414,11 +414,11 @@ public class Island implements DataObject {
/**
* Check if the flag is allowed or not
* For flags that are for the island in general and not related to rank
* @param flag
* @param breakBlocks
* @return true if allowed, false if not
*/
public boolean isAllowed(Flags flag) {
return this.getFlagReq(flag) >= 0 ? true : false;
public boolean isAllowed(Flag breakBlocks) {
return this.getFlagReq(breakBlocks) >= 0 ? true : false;
}
/**
@ -427,7 +427,7 @@ public class Island implements DataObject {
* @param flag - flag
* @return true if allowed, false if not
*/
public boolean isAllowed(User user, Flags flag) {
public boolean isAllowed(User user, Flag flag) {
//Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag));
return (this.getRank(user) >= this.getFlagReq(flag)) ? true : false;
}
@ -506,14 +506,14 @@ public class Island implements DataObject {
* @param flag
* @param value - rank value. If the flag applies to the island, a positive number = true, negative = false
*/
public void setFlag(Flags flag, int value){
public void setFlag(Flag flag, int value){
flags.put(flag, value);
}
/**
* @param flags the flags to set
*/
public void setFlags(HashMap<Flags, Integer> flags) {
public void setFlags(HashMap<Flag, Integer> flags) {
this.flags = flags;
}

View File

@ -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().name(), en.getValue());
result.put(en.getKey().getID(), en.getValue());
}
return result;
}

View File

@ -19,7 +19,6 @@ 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;
/**
* Abstract class for flag listeners. Provides common code.
@ -28,14 +27,17 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public abstract class AbstractFlagListener implements Listener {
public BSkyBlock plugin;
public BSkyBlock plugin = BSkyBlock.getInstance();
private User user = null;
public AbstractFlagListener(BSkyBlock plugin) {
super();
/**
* Used for unit testing only to set the plugin
* @param plugin
*/
public void setPlugin(BSkyBlock plugin) {
this.plugin = plugin;
}
/**
* Sets the player associated with this event.
* If the user is a fake player, they are not counted.
@ -124,11 +126,11 @@ public abstract class AbstractFlagListener implements Listener {
* Generic place blocks checker
* @param e
* @param loc
* @param redstone
* @param breakBlocks
* @return true if the check is okay, false if it was disallowed
*/
public boolean checkIsland(Event e, Location loc, Flags redstone) {
return checkIsland(e, loc, redstone, false);
public boolean checkIsland(Event e, Location loc, Flag breakBlocks) {
return checkIsland(e, loc, breakBlocks, false);
}
@ -140,7 +142,7 @@ public abstract class AbstractFlagListener implements Listener {
* @param silent - if true, no attempt is made to tell the user
* @return true if the check is okay, false if it was disallowed
*/
public boolean checkIsland(Event e, Location loc, Flags flag, boolean silent) {
public boolean checkIsland(Event e, Location loc, Flag flag, boolean silent) {
// If this is not an Island World, skip
if (!inWorld(loc)) return true;
@ -148,11 +150,9 @@ public abstract class AbstractFlagListener implements Listener {
Optional<Island> island = plugin.getIslands().getIslandAt(loc);
// Handle Settings Flag
id(flag);
id(flag).getType();
if (id(flag).getType().equals(FlagType.SETTING)) {
if (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));
return island.map(x -> x.isAllowed(flag)).orElse(flag.isDefaultSetting());
}
// Protection flag
@ -182,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 (!isDefaultAllowed(flag)) {
if (!flag.isDefaultSetting()) {
noGo(e, silent);
user = null;
return false;
@ -194,19 +194,11 @@ public abstract class AbstractFlagListener implements Listener {
/**
* Get the flag for this ID
* @param flag
* @param id
* @return Flag denoted by the id
*/
protected Flag id(Flags flag) {
return plugin.getFlagsManager().getFlagByID(flag);
protected Flag id(String id) {
return plugin.getFlagsManager().getFlagByID(id);
}
/**
* Return the default setting for this flag
* @param flag
* @return
*/
protected boolean isDefaultAllowed(Flags flag) {
return plugin.getFlagsManager().isDefaultAllowed(flag);
}
}

View File

@ -8,7 +8,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -17,10 +16,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class BlockInteractionListener extends AbstractFlagListener {
public BlockInteractionListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Handle interaction with blocks
* @param e

View File

@ -17,16 +17,11 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.util.BlockIterator;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
public class BreakBlocksListener extends AbstractFlagListener {
public BreakBlocksListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents blocks from being broken
*
@ -107,7 +102,7 @@ public class BreakBlocksListener extends AbstractFlagListener {
});
// The player is in the world, but not on an island, so general world settings apply
if (!isDefaultAllowed(Flags.BREAK_BLOCKS)) {
if (!Flags.BREAK_BLOCKS.isDefaultSetting()) {
e.setCancelled(true);
user.sendMessage("protection.protected");
}

View File

@ -14,7 +14,6 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -25,11 +24,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class BreedingListener extends AbstractFlagListener {
public BreedingListener(BSkyBlock plugin) {
super(plugin);
}
/**
* A list of items that cause breeding if a player has them in their hand and they click an animal
* This list may need to be extended with future versions of Minecraft.

View File

@ -10,7 +10,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -21,10 +20,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class BucketListener extends AbstractFlagListener {
public BucketListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents emptying of buckets
* @param e

View File

@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerEggThrowEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -17,10 +16,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class EggListener extends AbstractFlagListener {
public EggListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Handle visitor chicken egg throwing
* @param e

View File

@ -12,7 +12,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -23,10 +22,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class EntityInteractListener extends AbstractFlagListener {
public EntityInteractListener(BSkyBlock plugin) {
super(plugin);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
if (e.getRightClicked() instanceof ArmorStand) {

View File

@ -19,7 +19,6 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.BlockIterator;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags;
@ -31,10 +30,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class FireListener extends AbstractFlagListener {
public FireListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents fire spread
* @param e
@ -50,7 +45,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() && !isDefaultAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true);
}
/**
@ -69,7 +64,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() && !isDefaultAllowed(Flags.FIRE_SPREAD)) e.setCancelled(true);
if (!island.isPresent() && !Flags.FIRE_SPREAD.isDefaultSetting()) e.setCancelled(true);
}
}
@ -92,7 +87,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() && !isDefaultAllowed(Flags.FIRE)) e.setCancelled(true);
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true);
}
@ -145,7 +140,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() && !isDefaultAllowed(Flags.FIRE)) e.setCancelled(true);
if (!island.isPresent() && !Flags.FIRE.isDefaultSetting()) e.setCancelled(true);
// If either of these canceled the event, return
if (e.isCancelled()) return;

View File

@ -30,8 +30,8 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -41,10 +41,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class HurtingListener extends AbstractFlagListener {
public HurtingListener(BSkyBlock plugin) {
super(plugin);
}
private HashMap<Integer, UUID> thrownPotions = new HashMap<>();
@ -68,17 +64,17 @@ public class HurtingListener extends AbstractFlagListener {
* Finds the true attacker, even if the attack was via a projectile
* @param event
* @param damager
* @param flag
* @param hurtMobs
*/
private void respond(Event event, Entity damager, Flags flag) {
private void respond(Event event, Entity damager, Flag hurtMobs) {
// Get the attacker
if (damager instanceof Player) {
setUser(User.getInstance(damager)).checkIsland(event, damager.getLocation(), flag);
setUser(User.getInstance(damager)).checkIsland(event, damager.getLocation(), hurtMobs);
} else if (damager instanceof Projectile) {
// Find out who fired the projectile
Projectile p = (Projectile) damager;
if (p.getShooter() instanceof Player) {
if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(event, damager.getLocation(), flag)) {
if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(event, damager.getLocation(), hurtMobs)) {
damager.setFireTicks(0);
damager.remove();
}

View File

@ -16,7 +16,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
@ -27,10 +26,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class InventoryListener extends AbstractFlagListener {
public InventoryListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents visitors picking items from inventories
* @param e

View File

@ -9,7 +9,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.lists.Flags;
@ -19,10 +18,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class ItemDropPickUpListener extends AbstractFlagListener {
public ItemDropPickUpListener(BSkyBlock plugin) {
super(plugin);
}
/*
* Handle item drop by visitors
*/

View File

@ -10,7 +10,6 @@ import org.bukkit.event.entity.PlayerLeashEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -19,11 +18,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class LeashListener extends AbstractFlagListener {
public LeashListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents leashing
*

View File

@ -13,7 +13,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.lists.Flags;
@ -24,10 +23,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class MobSpawnListener extends AbstractFlagListener {
public MobSpawnListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Prevents mobs spawning naturally
*
@ -65,13 +60,13 @@ public class MobSpawnListener extends AbstractFlagListener {
} else {
// Outside of the island
if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) {
if (!isDefaultAllowed(Flags.MOB_SPAWN)) {
if (!Flags.MOB_SPAWN.isDefaultSetting()) {
// Mobs not allowed to spawn
e.setCancelled(true);
return;
}
} else if (e.getEntity() instanceof Animals) {
if (!isDefaultAllowed(Flags.MONSTER_SPAWN)) {
if (!Flags.MONSTER_SPAWN.isDefaultSetting()) {
// Mobs not allowed to spawn
e.setCancelled(true);
return;

View File

@ -20,8 +20,8 @@ import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.potion.PotionEffect;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -32,10 +32,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class PVPListener extends AbstractFlagListener {
public PVPListener(BSkyBlock plugin) {
super(plugin);
}
private HashMap<Integer, UUID> thrownPotions = new HashMap<>();
@ -48,14 +44,14 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Player) {
Flags flag = Flags.PVP_OVERWORLD;
Flag flag = Flags.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(plugin.getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
else if (e.getEntity().getWorld().equals(plugin.getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
respond(e, e.getDamager(), flag);
}
}
private void respond(Event event, Entity damager, Flags flag) {
private void respond(Event event, Entity damager, Flag flag) {
// Get the attacker
if (damager instanceof Player) {
setUser(User.getInstance(damager)).checkIsland(event, damager.getLocation(), flag);
@ -76,7 +72,7 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFishing(PlayerFishEvent e) {
if (e.getCaught() != null && e.getCaught() instanceof Player) {
Flags flag = Flags.PVP_OVERWORLD;
Flag flag = Flags.PVP_OVERWORLD;
if (e.getCaught().getWorld().equals(plugin.getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
else if (e.getCaught().getWorld().equals(plugin.getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
if (checkIsland(e, e.getCaught().getLocation(), flag)) {
@ -93,7 +89,7 @@ public class PVPListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onSplashPotionSplash(final PotionSplashEvent e) {
// Deduce the world
Flags flag = Flags.PVP_OVERWORLD;
Flag flag = Flags.PVP_OVERWORLD;
if (e.getPotion().getWorld().equals(plugin.getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
else if (e.getPotion().getWorld().equals(plugin.getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;
@ -141,7 +137,7 @@ public class PVPListener extends AbstractFlagListener {
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
// Deduce the world
Flags flag = Flags.PVP_OVERWORLD;
Flag flag = Flags.PVP_OVERWORLD;
if (e.getEntity().getWorld().equals(plugin.getIslandWorldManager().getNetherWorld())) flag = Flags.PVP_NETHER;
else if (e.getEntity().getWorld().equals(plugin.getIslandWorldManager().getEndWorld())) flag = Flags.PVP_END;

View File

@ -8,7 +8,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -17,10 +16,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class PhysicalInteractionListener extends AbstractFlagListener {
public PhysicalInteractionListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Handle physical interaction with blocks
* Crop trample, pressure plates, triggering redstone, tripwires

View File

@ -10,15 +10,10 @@ import org.bukkit.event.block.EntityBlockFormEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
public class PlaceBlocksListener extends AbstractFlagListener {
public PlaceBlocksListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Check blocks being placed in general
*

View File

@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerPortalEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -17,10 +16,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class PortalListener extends AbstractFlagListener {
public PortalListener(BSkyBlock plugin) {
super(plugin);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPortal(PlayerPortalEvent e) {
checkIsland(e, e.getFrom(), Flags.PORTAL);

View File

@ -7,7 +7,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerShearEntityEvent;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -17,10 +16,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class ShearingListener extends AbstractFlagListener {
public ShearingListener(BSkyBlock plugin) {
super(plugin);
}
// Protect sheep
@EventHandler(priority = EventPriority.LOW)
public void onShear(final PlayerShearEntityEvent e) {

View File

@ -8,7 +8,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.lists.Flags;
/**
@ -18,10 +17,6 @@ import us.tastybento.bskyblock.lists.Flags;
*/
public class TeleportationListener extends AbstractFlagListener {
public TeleportationListener(BSkyBlock plugin) {
super(plugin);
}
/**
* Ender pearl and chorus fruit teleport checks
*

View File

@ -1,51 +1,136 @@
package us.tastybento.bskyblock.lists;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum Flags {
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
import org.bukkit.Material;
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.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;
public class Flags {
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener()).build();
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener()).build();
// Block interactions - all use BlockInteractionListener()
public static final Flag ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener()).build();
public static final Flag BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build();
public static final Flag BED = new FlagBuilder().id("BED").icon(Material.BED).build();
public static final Flag BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build();
public static final Flag CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build();
public static final Flag DOOR = new FlagBuilder().id("DOOR).allowedByDefault(true").icon(Material.WOODEN_DOOR).build();
public static final Flag CRAFTING = new FlagBuilder().id("CRAFTING).allowedByDefault(true").icon(Material.WORKBENCH).build();
public static final Flag ENCHANTING = new FlagBuilder().id("ENCHANTING).allowedByDefault(true").icon(Material.ENCHANTMENT_TABLE).build();
public static final Flag FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build();
public static final Flag GATE = new FlagBuilder().id("GATE).allowedByDefault(true").icon(Material.FENCE_GATE).build();
public static final Flag MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build();
public static final Flag LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build();
public static final Flag REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build();
public static final Flag SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build();
// Entity interactions
public static final Flag ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener()).build();
public static final Flag RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build();
public static final Flag TRADING = new FlagBuilder().id("TRADING).allowedByDefault(true").icon(Material.EMERALD).build();
// Breeding
public static final Flag BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener()).build();
// Buckets. All bucket use is covered by one listener
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener()).build();
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build();
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build();
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build();
// Chorus Fruit and Enderpearls
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener()).build();
public static final Flag ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build();
// Physical interactions
public static final Flag CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener()).build();
public static final Flag PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build();
// Egg throwing
public static final Flag EGGS = new FlagBuilder().id("EGGS").icon(Material.EGG).listener(new EggListener()).build();
/*
* 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
*/
public static final Flag FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener()).build();
public static final Flag FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build();
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build();
// Inventories
public static final Flag MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener()).build();
// Hurting things
public static final Flag HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener()).build();
public static final Flag HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build();
// Leashes
public static final Flag LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener()).build();
// Portal use protection
public static final Flag PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener()).build();
// Shearing
public static final Flag SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener()).build();
// Item pickup or drop
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build();
/*
* Settings flags (not protection flags)
*/
// PVP
public static final Flag PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).type(FlagType.SETTING).listener(new PVPListener()).build();
public static final Flag PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).type(FlagType.SETTING).build();
public static final Flag PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).type(FlagType.SETTING).build();
// Others
public static final Flag ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).type(FlagType.SETTING).build();
public static final Flag MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(FlagType.SETTING).build();
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(FlagType.SETTING).build();
/**
* @return List of all the flags in this class
*/
public static List<Flag> values() {
return Arrays.asList(Flags.class.getFields()).stream().map(field -> {
try {
return (Flag)field.get(null);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}).collect(Collectors.toList());
}
}

View File

@ -3,45 +3,31 @@ 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;
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.Flags;
public class FlagsManager {
private BSkyBlock plugin;
private HashMap<Flags, Flag> flags = new HashMap<>();
private HashMap<String, Flag> flags = new HashMap<>();
public FlagsManager(BSkyBlock plugin) {
this.plugin = plugin;
// Register flags
registerFlags();
// Register default flags
for (Flag flag : Flags.values()) {
registerFlag(flag);
}
}
/**
* Register a new flag with BSkyBlock
* @param flag
*/
public void registerFlag(Flag flag) {
//Bukkit.getLogger().info("DEBUG: registering flag " + flag.getID());
flags.put(flag.getID(), flag);
@ -49,11 +35,16 @@ public class FlagsManager {
flag.getListener().ifPresent(l -> Bukkit.getServer().getPluginManager().registerEvents(l, plugin));
}
public HashMap<Flags, Flag> getFlags() {
public HashMap<String, Flag> getFlags() {
return flags;
}
public Flag getFlagByID(Flags id) {
/**
* Get flag by string
* @param key - string name same as the enum
* @return Flag or null if not known
*/
public Flag getFlagByID(String id) {
//Bukkit.getLogger().info("DEBUG: requesting " + id + " flags size = " + flags.size());
return flags.get(id);
}
@ -64,117 +55,5 @@ public class FlagsManager {
}
return null;
}
private void registerFlags() {
// Break and place blocks
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()
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
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
registerFlag(new FlagBuilder().id(Flags.BREEDING).icon(Material.CARROT).listener(new BreedingListener(plugin)).build());
// Buckets. All bucket use is covered by one listener
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
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
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
registerFlag(new FlagBuilder().id(Flags.EGGS).icon(Material.EGG).listener(new EggListener(plugin)).build());
/*
* 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
*/
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
registerFlag(new FlagBuilder().id(Flags.MOUNT_INVENTORY).icon(Material.IRON_BARDING).listener(new InventoryListener(plugin)).build());
// Hurting things
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
registerFlag(new FlagBuilder().id(Flags.LEASH).icon(Material.LEASH).listener(new LeashListener(plugin)).build());
// Portal use protection
registerFlag(new FlagBuilder().id(Flags.PORTAL).icon(Material.OBSIDIAN).listener(new PortalListener(plugin)).build());
// Shearing
registerFlag(new FlagBuilder().id(Flags.SHEARING).icon(Material.SHEARS).listener(new ShearingListener(plugin)).build());
// Item pickup or drop
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());
/*
* Settings flags (not protection flags)
*/
// PVP
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());
}
/**
* 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 (Flags flag: Flags.values()) {
if (flag.name().equalsIgnoreCase(key)) return this.getFlagByID(flag);
}
return null;
}
public boolean isDefaultAllowed(Flags flag) {
if (flags.containsKey(flag)) return flags.get(flag).isDefaultSetting();
return false;
}
}

View File

@ -10,6 +10,7 @@ import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
@ -22,6 +23,7 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
@ -48,6 +50,8 @@ import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.flags.FlagBuilder;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.generators.IslandWorld;
@ -462,48 +466,7 @@ public class TestBSkyBlock {
@Test
public void TestEventProtection() {
/*
*
* Score approach:
*
* Rank definitions are global and apply to all islands
*
* There are 4 hard-coded ranks:
*
* Owner is the highest rank = 1000
*
* Member ranks are >= 900
*
* Visitors = 0
*
* Banned = -1
*
* Owners have full admin capability over the island. Members are required to give up their own island to be a member.
* Visitors are everyone else.
*
* After those 3, it's possible to have custom ranks, e.g.
*
* Trustees = 750
* Coops = 500
* etc.
*
*
* Each flag has a bypass score.
* If the user's rank is higher or equal to the bypass score, they will bypass the protection.
* Owners can disable/enable the flags.
*
* Each island will track the rank score for each player on the island.
* Unknown players have a rank of 0.
*
*
* Admins will be able to define groups and their rank value.
* During the game, the players will never see the rank value. They will only see the ranks.
*
* It will be possible to island owners to promote or demote players up and down the ranks.
*/
// Now test events
// Test events
FlagListener fl = new FlagListener(plugin);
Bukkit.getLogger().info("SETUP: owner UUID = " + ownerOfIsland.getUniqueId());
@ -525,11 +488,42 @@ public class TestBSkyBlock {
}
private class FlagListener extends AbstractFlagListener {
@Test
public void TestDefaultFlags() {
// Check all the default flags
FlagsManager fm = new FlagsManager(plugin);
Collection<Flag> defaultFlags = Flags.values();
Collection<Flag> f = fm.getFlags().values();
for (Flag flag : defaultFlags) {
assertTrue(flag.getID(), f.contains(flag));
}
for (Flag flag : f) {
assertTrue(flag.getID(), defaultFlags.contains(flag));
}
}
public FlagListener(BSkyBlock plugin) {
super(plugin);
@Test
public void TestCustomFlags() {
// Custom
FlagListener fl = new FlagListener(plugin);
Flag customFlag = new FlagBuilder().id("CUSTOM_FLAG").icon(Material.DIAMOND).listener(fl).build();
assertEquals("CUSTOM_FLAG", customFlag.getID());
assertEquals(Material.DIAMOND, customFlag.getIcon().getItem().getType());
assertEquals(fl, customFlag.getListener().get());
// Add it to the Flag Manager
flagsManager.registerFlag(customFlag);
assertEquals(customFlag, flagsManager.getFlagByID("CUSTOM_FLAG"));
assertEquals(customFlag, flagsManager.getFlagByIcon(customFlag.getIcon()));
}
/**
* Dummy flag listener
*
*/
private class FlagListener extends AbstractFlagListener {
FlagListener(BSkyBlock plugin) {
// Set the plugin explicitly
setPlugin(plugin);
}
}