mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-19 17:25:11 +01:00
Reworked code so it can be tested using automated unit tests.
See TestBSkyBlock.java class for protection tests. More to come!
This commit is contained in:
parent
df0ecca217
commit
c648409858
@ -13,11 +13,15 @@ public class Flag {
|
|||||||
private PanelItem icon;
|
private PanelItem icon;
|
||||||
private Listener listener;
|
private Listener listener;
|
||||||
private boolean defaultSetting;
|
private boolean defaultSetting;
|
||||||
|
|
||||||
|
public Flag() {}
|
||||||
|
|
||||||
public Flag(BSkyBlock plugin, String id, PanelItem icon, Listener listener, boolean defaultSetting) {
|
public Flag(BSkyBlock plugin, String id, PanelItem icon, Listener listener, boolean defaultSetting) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
//System.out.println("DEBUG: " + plugin);
|
||||||
|
//System.out.println("DEBUG: " + plugin.getFlagsManager());
|
||||||
plugin.getFlagsManager().registerFlag(this);
|
plugin.getFlagsManager().registerFlag(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public class Island implements DataObject {
|
|||||||
* @param flag
|
* @param flag
|
||||||
* @return flag rank. Players must have at least this rank to bypass this flag
|
* @return flag rank. Players must have at least this rank to bypass this flag
|
||||||
*/
|
*/
|
||||||
public int getFlag(Flag flag){
|
public int getFlagReq(Flag flag){
|
||||||
if(flags.containsKey(flag)) {
|
if(flags.containsKey(flag)) {
|
||||||
return flags.get(flag);
|
return flags.get(flag);
|
||||||
} else {
|
} else {
|
||||||
@ -411,7 +411,7 @@ public class Island implements DataObject {
|
|||||||
* @return true if allowed, false if not
|
* @return true if allowed, false if not
|
||||||
*/
|
*/
|
||||||
public boolean isAllowed(Flag flag) {
|
public boolean isAllowed(Flag flag) {
|
||||||
return this.getFlag(flag) >= 0 ? true : false;
|
return this.getFlagReq(flag) >= 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -421,7 +421,8 @@ public class Island implements DataObject {
|
|||||||
* @return true if allowed, false if not
|
* @return true if allowed, false if not
|
||||||
*/
|
*/
|
||||||
public boolean isAllowed(User user, Flag flag) {
|
public boolean isAllowed(User user, Flag flag) {
|
||||||
return (this.getRank(user) >= this.getFlag(flag)) ? true : false;
|
Bukkit.getLogger().info("DEBUG: " + flag.getID() + " user score = " + getRank(user) + " flag req = "+ this.getFlagReq(flag));
|
||||||
|
return (this.getRank(user) >= this.getFlagReq(flag)) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,101 +29,148 @@ import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Flags {
|
public class Flags {
|
||||||
private static BSkyBlock p;
|
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;
|
||||||
|
|
||||||
public Flags(BSkyBlock plugin) {
|
public Flags(BSkyBlock plugin) {
|
||||||
p = plugin;
|
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Breeding
|
||||||
|
BREEDING = new FlagBuilder().id("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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Egg throwing
|
||||||
|
EGGS = new FlagBuilder().id("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
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Inventories
|
||||||
|
MOUNT_INVENTORY = new FlagBuilder().id("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);
|
||||||
|
|
||||||
|
// Leashes
|
||||||
|
LEASH = new FlagBuilder().id("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);
|
||||||
|
|
||||||
|
// Shearing
|
||||||
|
SHEARING = new FlagBuilder().id("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);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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);
|
||||||
}
|
}
|
||||||
// Break and place blocks
|
|
||||||
public static final Flag BREAK_BLOCKS = new FlagBuilder().id("BREAK_BLOCKS").icon(Material.STONE).listener(new BreakBlocksListener(p)).build(p);
|
|
||||||
public static final Flag PLACE_BLOCKS = new FlagBuilder().id("PLACE_BLOCKS").icon(Material.DIRT).listener(new PlaceBlocksListener(p)).build(p);
|
|
||||||
|
|
||||||
// Block interactions - all use BlockInteractionListener()
|
|
||||||
public static final Flag ANVIL = new FlagBuilder().id("ANVIL").icon(Material.ANVIL).listener(new BlockInteractionListener(p)).build(p);
|
|
||||||
public static final Flag BEACON = new FlagBuilder().id("BEACON").icon(Material.BEACON).build(p);
|
|
||||||
public static final Flag BED = new FlagBuilder().id("BED").icon(Material.BED).build(p);
|
|
||||||
public static final Flag BREWING = new FlagBuilder().id("BREWING").icon(Material.BREWING_STAND_ITEM).build(p);
|
|
||||||
public static final Flag CHEST = new FlagBuilder().id("CHEST").icon(Material.CHEST).build(p);
|
|
||||||
public static final Flag DOOR = new FlagBuilder().id("DOOR").allowedByDefault(true).icon(Material.WOODEN_DOOR).build(p);
|
|
||||||
public static final Flag CRAFTING = new FlagBuilder().id("CRAFTING").allowedByDefault(true).icon(Material.WORKBENCH).build(p);
|
|
||||||
public static final Flag ENCHANTING = new FlagBuilder().id("ENCHANTING").allowedByDefault(true).icon(Material.ENCHANTMENT_TABLE).build(p);
|
|
||||||
public static final Flag FURNACE = new FlagBuilder().id("FURNACE").icon(Material.FURNACE).build(p);
|
|
||||||
public static final Flag GATE = new FlagBuilder().id("GATE").allowedByDefault(true).icon(Material.FENCE_GATE).build(p);
|
|
||||||
public static final Flag MUSIC = new FlagBuilder().id("MUSIC").icon(Material.JUKEBOX).build(p);
|
|
||||||
public static final Flag LEVER_BUTTON = new FlagBuilder().id("LEVER_BUTTON").icon(Material.LEVER).build(p);
|
|
||||||
public static final Flag REDSTONE = new FlagBuilder().id("REDSTONE").icon(Material.REDSTONE).build(p);
|
|
||||||
public static final Flag SPAWN_EGGS = new FlagBuilder().id("SPAWN_EGGS").icon(Material.MONSTER_EGG).build(p);
|
|
||||||
|
|
||||||
// Entity interactions
|
|
||||||
public static final Flag ARMOR_STAND = new FlagBuilder().id("ARMOR_STAND").icon(Material.ARMOR_STAND).listener(new EntityInteractListener(p)).build(p);
|
|
||||||
public static final Flag RIDING = new FlagBuilder().id("RIDING").icon(Material.GOLD_BARDING).build(p);
|
|
||||||
public static final Flag TRADING = new FlagBuilder().id("TRADING").allowedByDefault(true).icon(Material.EMERALD).build(p);
|
|
||||||
|
|
||||||
// Breeding
|
|
||||||
public static final Flag BREEDING = new FlagBuilder().id("BREEDING").icon(Material.CARROT).listener(new BreedingListener(p)).build(p);
|
|
||||||
|
|
||||||
// Buckets. All bucket use is covered by one listener
|
|
||||||
public static final Flag BUCKET = new FlagBuilder().id("BUCKET").icon(Material.BUCKET).listener(new BucketListener(p)).build(p);
|
|
||||||
public static final Flag COLLECT_LAVA = new FlagBuilder().id("COLLECT_LAVA").icon(Material.LAVA_BUCKET).build(p);
|
|
||||||
public static final Flag COLLECT_WATER = new FlagBuilder().id("COLLECT_WATER").icon(Material.WATER_BUCKET).build(p);
|
|
||||||
public static final Flag MILKING = new FlagBuilder().id("MILKING").icon(Material.MILK_BUCKET).build(p);
|
|
||||||
|
|
||||||
// Chorus Fruit and Enderpearls
|
|
||||||
public static final Flag CHORUS_FRUIT = new FlagBuilder().id("CHORUS_FRUIT").icon(Material.CHORUS_FRUIT).listener(new TeleportationListener(p)).build(p);
|
|
||||||
public static final Flag ENDER_PEARL = new FlagBuilder().id("ENDER_PEARL").icon(Material.ENDER_PEARL).build(p);
|
|
||||||
|
|
||||||
// Physical interactions
|
|
||||||
public static final Flag CROP_TRAMPLE = new FlagBuilder().id("CROP_TRAMPLE").icon(Material.WHEAT).listener(new PhysicalInteractionListener(p)).build(p);
|
|
||||||
public static final Flag PRESSURE_PLATE = new FlagBuilder().id("PRESSURE_PLATE").icon(Material.GOLD_PLATE).build(p);
|
|
||||||
|
|
||||||
// Egg throwing
|
|
||||||
public static final Flag EGGS = new FlagBuilder().id("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
|
|
||||||
*/
|
|
||||||
public static final Flag FIRE = new FlagBuilder().id("FIRE").icon(Material.FLINT_AND_STEEL).listener(new FireListener(p)).build(p);
|
|
||||||
public static final Flag FIRE_EXTINGUISH = new FlagBuilder().id("FIRE_EXTINGUISH").icon(Material.POTION).build(p);
|
|
||||||
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).build(p);
|
|
||||||
|
|
||||||
// Inventories
|
|
||||||
public static final Flag MOUNT_INVENTORY = new FlagBuilder().id("MOUNT_INVENTORY").icon(Material.IRON_BARDING).listener(new InventoryListener(p)).build(p);
|
|
||||||
|
|
||||||
// Hurting things
|
|
||||||
public static final Flag HURT_MOBS = new FlagBuilder().id("HURT_MOBS").icon(Material.STONE_SWORD).listener(new HurtingListener(p)).build(p);
|
|
||||||
public static final Flag HURT_MONSTERS = new FlagBuilder().id("HURT_MONSTERS").icon(Material.WOOD_SWORD).build(p);
|
|
||||||
|
|
||||||
// Leashes
|
|
||||||
public static final Flag LEASH = new FlagBuilder().id("LEASH").icon(Material.LEASH).listener(new LeashListener(p)).build(p);
|
|
||||||
|
|
||||||
// Portal use protection
|
|
||||||
public static final Flag PORTAL = new FlagBuilder().id("PORTAL").icon(Material.OBSIDIAN).listener(new PortalListener(p)).build(p);
|
|
||||||
|
|
||||||
// PVP
|
|
||||||
public static final Flag PVP_OVERWORLD = new FlagBuilder().id("PVP_OVERWORLD").icon(Material.ARROW).listener(new PVPListener(p)).build(p);
|
|
||||||
public static final Flag PVP_NETHER = new FlagBuilder().id("PVP_NETHER").icon(Material.IRON_AXE).build(p);
|
|
||||||
public static final Flag PVP_END = new FlagBuilder().id("PVP_END").icon(Material.END_CRYSTAL).build(p);
|
|
||||||
|
|
||||||
// Shearing
|
|
||||||
public static final Flag SHEARING = new FlagBuilder().id("SHEARING").icon(Material.SHEARS).listener(new ShearingListener(p)).build(p);
|
|
||||||
|
|
||||||
// Item pickup or drop
|
|
||||||
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.DIRT).allowedByDefault(true).listener(new ItemDropPickUpListener(p)).build(p);
|
|
||||||
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.DIRT).build(p);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Non-protection flags
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static final Flag ENTER_EXIT_MESSAGES = new FlagBuilder().id("ENTER_EXIT_MESSAGES").icon(Material.DIRT).allowedByDefault(true).build(p);
|
|
||||||
public static final Flag MOB_SPAWN = new FlagBuilder().id("MOB_SPAWN").icon(Material.APPLE).allowedByDefault(true).build(p);
|
|
||||||
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).build(p);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,15 @@ import org.bukkit.Server;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemFactory;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.Constants;
|
import us.tastybento.bskyblock.Constants;
|
||||||
@ -35,13 +41,15 @@ import us.tastybento.bskyblock.api.commands.User;
|
|||||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
|
import us.tastybento.bskyblock.lists.Flags;
|
||||||
import us.tastybento.bskyblock.managers.FlagsManager;
|
import us.tastybento.bskyblock.managers.FlagsManager;
|
||||||
import us.tastybento.bskyblock.managers.RanksManager;
|
import us.tastybento.bskyblock.managers.RanksManager;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
|
|
||||||
//@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
//@SuppressStaticInitializationFor("us.tastybento.BSkyBlock")
|
//@SuppressStaticInitializationFor("us.tastybento.BSkyBlock")
|
||||||
//@PrepareForTest( { BSkyBlock.class })
|
//@PrepareForTest( { Bukkit.class })
|
||||||
|
@PrepareForTest( { Flags.class })
|
||||||
public class TestBSkyBlock {
|
public class TestBSkyBlock {
|
||||||
private final UUID playerUUID = UUID.randomUUID();
|
private final UUID playerUUID = UUID.randomUUID();
|
||||||
private static CommandSender sender;
|
private static CommandSender sender;
|
||||||
@ -52,6 +60,7 @@ public class TestBSkyBlock {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
|
//PowerMockito.mockStatic(Bukkit.class);
|
||||||
//Mockito.doReturn(plugin).when(BSkyBlock.getPlugin());
|
//Mockito.doReturn(plugin).when(BSkyBlock.getPlugin());
|
||||||
//Mockito.when().thenReturn(plugin);
|
//Mockito.when().thenReturn(plugin);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
@ -69,7 +78,7 @@ public class TestBSkyBlock {
|
|||||||
player = mock(Player.class);
|
player = mock(Player.class);
|
||||||
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true);
|
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true);
|
||||||
|
|
||||||
plugin = mock(BSkyBlock.class);
|
|
||||||
//Mockito.when(plugin.getServer()).thenReturn(server);
|
//Mockito.when(plugin.getServer()).thenReturn(server);
|
||||||
|
|
||||||
location = mock(Location.class);
|
location = mock(Location.class);
|
||||||
@ -78,18 +87,17 @@ public class TestBSkyBlock {
|
|||||||
Mockito.when(location.getBlockY()).thenReturn(0);
|
Mockito.when(location.getBlockY()).thenReturn(0);
|
||||||
Mockito.when(location.getBlockZ()).thenReturn(0);
|
Mockito.when(location.getBlockZ()).thenReturn(0);
|
||||||
|
|
||||||
// This doesn't work!
|
// Mock itemFactory for ItemStack
|
||||||
/*
|
|
||||||
mockStatic(Bukkit.class);
|
|
||||||
ItemFactory itemFactory = PowerMockito.mock(ItemFactory.class);
|
ItemFactory itemFactory = PowerMockito.mock(ItemFactory.class);
|
||||||
PowerMockito.when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
PowerMockito.when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
PowerMockito.when(itemFactory.getItemMeta(any())).thenReturn(PowerMockito.mock(ItemMeta.class));
|
ItemMeta itemMeta = PowerMockito.mock(ItemMeta.class);
|
||||||
|
PowerMockito.when(itemFactory.getItemMeta(Mockito.any())).thenReturn(itemMeta);
|
||||||
mockStatic(BSkyBlock.class);
|
|
||||||
flagsManager = mock(FlagsManager.class);
|
PowerMockito.mockStatic(Flags.class);
|
||||||
PowerMockito.when(BSkyBlock.getInstance()).thenReturn(plugin);
|
|
||||||
|
plugin = Mockito.mock(BSkyBlock.class);
|
||||||
|
flagsManager = Mockito.mock(FlagsManager.class);
|
||||||
Mockito.when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
Mockito.when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -342,11 +350,22 @@ public class TestBSkyBlock {
|
|||||||
assertFalse(island.getBanned().contains(member1));
|
assertFalse(island.getBanned().contains(member1));
|
||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
// Set up protection settings - members can break blocks, visitors and place blocks
|
new Flags(plugin);
|
||||||
// These tests do not work because of static method calls in the code and Bukkit.
|
// Check default settings
|
||||||
/*
|
// Owner should be able to do anything
|
||||||
|
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
|
||||||
|
assertTrue(island.isAllowed(owner, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
|
// Visitor can do nothing
|
||||||
|
assertFalse(island.isAllowed(visitor, Flags.PLACE_BLOCKS));
|
||||||
|
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
|
// Set up protection settings - members can break blocks, visitors and place blocks
|
||||||
island.setFlag(Flags.BREAK_BLOCKS, RanksManager.MEMBER_RANK);
|
island.setFlag(Flags.BREAK_BLOCKS, RanksManager.MEMBER_RANK);
|
||||||
|
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
island.setFlag(Flags.PLACE_BLOCKS, RanksManager.VISITOR_RANK);
|
island.setFlag(Flags.PLACE_BLOCKS, RanksManager.VISITOR_RANK);
|
||||||
|
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
// Owner should be able to do anything
|
// Owner should be able to do anything
|
||||||
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
|
assertTrue(island.isAllowed(owner, Flags.PLACE_BLOCKS));
|
||||||
@ -357,21 +376,22 @@ public class TestBSkyBlock {
|
|||||||
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
|
assertFalse(island.isAllowed(visitor, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
// Check if the members have capability
|
// Check if the members have capability
|
||||||
User mem1 = User.getInstance(member1);
|
User mem1 = User.getInstance(member1); // Visitor
|
||||||
User mem2 = User.getInstance(member2);
|
User mem2 = User.getInstance(member2); // Member
|
||||||
User mem3 = User.getInstance(member3);
|
island.addToBanList(member3);
|
||||||
|
User mem3 = User.getInstance(member3); // Banned
|
||||||
|
|
||||||
assertTrue(island.isAllowed(mem1, Flags.PLACE_BLOCKS));
|
assertTrue(island.isAllowed(mem1, Flags.PLACE_BLOCKS));
|
||||||
assertTrue(island.isAllowed(mem1, Flags.BREAK_BLOCKS));
|
assertFalse(island.isAllowed(mem1, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
assertTrue(island.isAllowed(mem2, Flags.PLACE_BLOCKS));
|
assertTrue(island.isAllowed(mem2, Flags.PLACE_BLOCKS));
|
||||||
assertTrue(island.isAllowed(mem2, Flags.BREAK_BLOCKS));
|
assertTrue(island.isAllowed(mem2, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
// Member 3 is no longer a member and is a visitor
|
// Member 3 is no longer a member and is a visitor
|
||||||
assertTrue(island.isAllowed(mem3, Flags.PLACE_BLOCKS));
|
assertFalse(island.isAllowed(mem3, Flags.PLACE_BLOCKS));
|
||||||
assertTrue(island.isAllowed(mem3, Flags.BREAK_BLOCKS));
|
assertFalse(island.isAllowed(mem3, Flags.BREAK_BLOCKS));
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Score approach:
|
* Score approach:
|
||||||
|
Loading…
Reference in New Issue
Block a user