mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 11:45:31 +01:00
Added island lock class and test class
Island lock is combined with island ban in terms of the Listener. It is LockAndBanListener. It is a flag because after thinking about it, it made sense to be just like any other island setting. Also, island owners can now (in theory) lock out others by rank. Although the test class says everything works, the Settings GUI needs to enable toggling so that players can lock the island. Enjoy banning players!
This commit is contained in:
parent
41631e8a18
commit
6e810747f4
@ -177,8 +177,6 @@ commands:
|
|||||||
noone: "&aNo one is banned on this island"
|
noone: "&aNo one is banned on this island"
|
||||||
the-following: "&bThe following players are banned:"
|
the-following: "&bThe following players are banned:"
|
||||||
names: "&c[line]"
|
names: "&c[line]"
|
||||||
lock:
|
|
||||||
description: "lock/unlock your island so visitors cannot enter it"
|
|
||||||
settings:
|
settings:
|
||||||
description: "display island settings"
|
description: "display island settings"
|
||||||
language:
|
language:
|
||||||
@ -249,6 +247,10 @@ protection:
|
|||||||
ITEM_DROP: "ITEM_DROP"
|
ITEM_DROP: "ITEM_DROP"
|
||||||
ITEM_PICKUP: "ITEM_PICKUP"
|
ITEM_PICKUP: "ITEM_PICKUP"
|
||||||
LEASH: "LEASH"
|
LEASH: "LEASH"
|
||||||
|
LOCK:
|
||||||
|
name: "Lock island"
|
||||||
|
description: |
|
||||||
|
Toggle island lock
|
||||||
MILKING: "MILKING"
|
MILKING: "MILKING"
|
||||||
MOB_SPAWN: "MOB_SPAWN"
|
MOB_SPAWN: "MOB_SPAWN"
|
||||||
MONSTER_SPAWN: "MONSTER_SPAWN"
|
MONSTER_SPAWN: "MONSTER_SPAWN"
|
||||||
|
@ -9,7 +9,6 @@ import us.tastybento.bskyblock.commands.AdminCommand;
|
|||||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||||
import us.tastybento.bskyblock.database.BSBDbSetup;
|
import us.tastybento.bskyblock.database.BSBDbSetup;
|
||||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||||
import us.tastybento.bskyblock.listeners.IslandBanEnforcer;
|
|
||||||
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
||||||
import us.tastybento.bskyblock.listeners.NetherPortals;
|
import us.tastybento.bskyblock.listeners.NetherPortals;
|
||||||
import us.tastybento.bskyblock.listeners.ObsidianToLava;
|
import us.tastybento.bskyblock.listeners.ObsidianToLava;
|
||||||
@ -150,8 +149,6 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
manager.registerEvents(new NetherPortals(this), this);
|
manager.registerEvents(new NetherPortals(this), this);
|
||||||
// Obsidian to lava helper
|
// Obsidian to lava helper
|
||||||
manager.registerEvents(new ObsidianToLava(this), this);
|
manager.registerEvents(new ObsidianToLava(this), this);
|
||||||
// Island ban enforcer
|
|
||||||
manager.registerEvents(new IslandBanEnforcer(this), this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,13 +22,15 @@ public class Flag implements Comparable<Flag> {
|
|||||||
private final Listener listener;
|
private final Listener listener;
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private boolean defaultSetting;
|
private boolean defaultSetting;
|
||||||
|
private final int defaultRank;
|
||||||
|
|
||||||
Flag(String id, Material icon, Listener listener, boolean defaultSetting, Type type) {
|
Flag(String id, Material icon, Listener listener, boolean defaultSetting, Type type, int defaultRank) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.defaultSetting = defaultSetting;
|
this.defaultSetting = defaultSetting;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.defaultRank = defaultRank;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
@ -65,6 +67,13 @@ public class Flag implements Comparable<Flag> {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the defaultRank
|
||||||
|
*/
|
||||||
|
public int getDefaultRank() {
|
||||||
|
return defaultRank;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
@ -129,4 +138,5 @@ public class Flag implements Comparable<Flag> {
|
|||||||
public int compareTo(Flag o) {
|
public int compareTo(Flag o) {
|
||||||
return getID().compareTo(o.getID());
|
return getID().compareTo(o.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.api.flags.Flag.Type;
|
import us.tastybento.bskyblock.api.flags.Flag.Type;
|
||||||
|
import us.tastybento.bskyblock.managers.RanksManager;
|
||||||
|
|
||||||
public class FlagBuilder {
|
public class FlagBuilder {
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ public class FlagBuilder {
|
|||||||
private Listener listener;
|
private Listener listener;
|
||||||
private boolean defaultSetting;
|
private boolean defaultSetting;
|
||||||
private Type type = Type.PROTECTION;
|
private Type type = Type.PROTECTION;
|
||||||
|
private int defaultRank = RanksManager.MEMBER_RANK;
|
||||||
|
|
||||||
public FlagBuilder id(String string) {
|
public FlagBuilder id(String string) {
|
||||||
id = string;
|
id = string;
|
||||||
@ -29,7 +31,7 @@ public class FlagBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Flag build() {
|
public Flag build() {
|
||||||
return new Flag(id, icon, listener, defaultSetting, type);
|
return new Flag(id, icon, listener, defaultSetting, type, defaultRank);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,4 +63,14 @@ public class FlagBuilder {
|
|||||||
id = flag.name();
|
id = flag.name();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a default rank for this flag. If not set, the value of RanksManager.MEMBER_RANK will be used
|
||||||
|
* @param rank
|
||||||
|
* @return FlagBuilder
|
||||||
|
*/
|
||||||
|
public FlagBuilder defaultRank(int rank) {
|
||||||
|
this.defaultRank = rank;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.Constants;
|
import us.tastybento.bskyblock.Constants;
|
||||||
@ -76,12 +77,15 @@ public class IslandBanCommand extends CompositeCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean ban(User user, User targetUser) {
|
private boolean ban(User user, User targetUser) {
|
||||||
if (getIslands().getIsland(user.getUniqueId()).addToBanList(targetUser.getUniqueId())) {
|
Island island = getIslands().getIsland(user.getUniqueId());
|
||||||
|
if (island.addToBanList(targetUser.getUniqueId())) {
|
||||||
user.sendMessage("general.success");
|
user.sendMessage("general.success");
|
||||||
targetUser.sendMessage("commands.island.ban.owner-banned-you", "[owner]", user.getName());
|
targetUser.sendMessage("commands.island.ban.owner-banned-you", "[owner]", user.getName());
|
||||||
if (targetUser.isOnline() && getPlayers().hasIsland(targetUser.getUniqueId())) {
|
// If the player is online, has an island and on the banned island, move them home immediately
|
||||||
|
if (targetUser.isOnline() && getPlayers().hasIsland(targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
|
||||||
getIslands().homeTeleport(targetUser.getPlayer());
|
getIslands().homeTeleport(targetUser.getPlayer());
|
||||||
}
|
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Banning was blocked, maybe due to an event cancellation. Fail silently.
|
// Banning was blocked, maybe due to an event cancellation. Fail silently.
|
||||||
|
@ -87,8 +87,6 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
//// State ////
|
//// State ////
|
||||||
@Expose
|
@Expose
|
||||||
private boolean locked = false;
|
|
||||||
@Expose
|
|
||||||
private boolean spawn = false;
|
private boolean spawn = false;
|
||||||
@Expose
|
@Expose
|
||||||
private boolean purgeProtected = false;
|
private boolean purgeProtected = false;
|
||||||
@ -174,9 +172,9 @@ public class Island implements DataObject {
|
|||||||
public int getFlag(Flag flag){
|
public int getFlag(Flag flag){
|
||||||
if(flags.containsKey(flag)) {
|
if(flags.containsKey(flag)) {
|
||||||
return flags.get(flag);
|
return flags.get(flag);
|
||||||
} else {
|
} else {
|
||||||
flags.put(flag, RanksManager.MEMBER_RANK);
|
flags.put(flag, flag.getDefaultRank());
|
||||||
return RanksManager.MEMBER_RANK;
|
return flag.getDefaultRank();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +193,7 @@ public class Island implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the members
|
* @return the members - key is the UUID, value is the RanksManager enum, e.g. RanksManager.MEMBER_RANK
|
||||||
*/
|
*/
|
||||||
public Map<UUID, Integer> getMembers() {
|
public Map<UUID, Integer> getMembers() {
|
||||||
return members;
|
return members;
|
||||||
@ -426,13 +424,6 @@ public class Island implements DataObject {
|
|||||||
return members.containsKey(targetUUID) && members.get(targetUUID).equals(RanksManager.BANNED_RANK);
|
return members.containsKey(targetUUID) && members.get(targetUUID).equals(RanksManager.BANNED_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if island is locked, false if not
|
|
||||||
*/
|
|
||||||
public boolean isLocked() {
|
|
||||||
return locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return spawn
|
* @return spawn
|
||||||
*/
|
*/
|
||||||
@ -486,7 +477,7 @@ public class Island implements DataObject {
|
|||||||
/**
|
/**
|
||||||
* Set the Island Guard flag rank
|
* Set the Island Guard flag rank
|
||||||
* @param flag
|
* @param flag
|
||||||
* @param value - rank value. If the flag applies to the island, a positive number = true, negative = false
|
* @param value - Use RanksManager settings, e.g. RanksManager.MEMBER
|
||||||
*/
|
*/
|
||||||
public void setFlag(Flag flag, int value){
|
public void setFlag(Flag flag, int value){
|
||||||
flags.put(flag, value);
|
flags.put(flag, value);
|
||||||
@ -513,14 +504,6 @@ public class Island implements DataObject {
|
|||||||
this.levelHandicap = levelHandicap;
|
this.levelHandicap = levelHandicap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Locks/Unlocks the island.
|
|
||||||
* @param locked - the lock state to set
|
|
||||||
*/
|
|
||||||
public void setLocked(boolean locked){
|
|
||||||
this.locked = locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param members the members to set
|
* @param members the members to set
|
||||||
*/
|
*/
|
||||||
|
@ -9,9 +9,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.Constants;
|
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
|
||||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
public class JoinLeaveListener implements Listener {
|
public class JoinLeaveListener implements Listener {
|
||||||
@ -55,15 +53,6 @@ public class JoinLeaveListener implements Listener {
|
|||||||
if (plugin.getSettings().isRemoveMobsOnLogin()) {
|
if (plugin.getSettings().isRemoveMobsOnLogin()) {
|
||||||
plugin.getIslands().removeMobs(user.getLocation());
|
plugin.getIslands().removeMobs(user.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if they logged in to a locked island and expel them or if they are banned
|
|
||||||
Island currentIsland = plugin.getIslands().getIslandAt(user.getLocation()).orElse(null);
|
|
||||||
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
|
|
||||||
if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
|
|
||||||
user.sendMessage("protection.locked");
|
|
||||||
plugin.getIslands().homeTeleport(user.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.listeners;
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -19,42 +17,37 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
|
|||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
|
import us.tastybento.bskyblock.lists.Flags;
|
||||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforces island bans. Checks for teleporting, entry via flying and due to logging in
|
* Listener for the lock flag
|
||||||
|
* Also handles ban protection
|
||||||
|
*
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
public class LockAndBanListener implements Listener {
|
||||||
public class IslandBanEnforcer implements Listener {
|
|
||||||
|
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
private Set<UUID> inTeleport;
|
private enum CheckResult {
|
||||||
|
BANNED,
|
||||||
|
LOCKED,
|
||||||
|
OPEN
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enforces island bans
|
* Enforces island bans and locks
|
||||||
* @param plugin
|
* @param plugin
|
||||||
*/
|
*/
|
||||||
public IslandBanEnforcer(BSkyBlock plugin) {
|
public LockAndBanListener() {
|
||||||
this.im = plugin.getIslands();
|
this.im = BSkyBlock.getInstance().getIslands();
|
||||||
inTeleport = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teleport check
|
// Teleport check
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
public void onPlayerTeleport(PlayerTeleportEvent e) {
|
||||||
// Ignore players who are being ejected
|
e.setCancelled(checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN) ? false : true);
|
||||||
if (inTeleport.contains(e.getPlayer().getUniqueId())) {
|
|
||||||
// Remove them
|
|
||||||
inTeleport.remove(e.getPlayer().getUniqueId());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
e.setCancelled(checkAndNotify(e.getPlayer(), e.getTo()));
|
|
||||||
// Check from - just in case the player is inside the island
|
|
||||||
if (check(e.getPlayer(), e.getFrom())) {
|
|
||||||
eject(e.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Movement check
|
// Movement check
|
||||||
@ -64,10 +57,14 @@ public class IslandBanEnforcer implements Listener {
|
|||||||
if (e.getFrom().getBlockX() - e.getTo().getBlockX() == 0 && e.getFrom().getBlockZ() - e.getTo().getBlockZ() == 0) {
|
if (e.getFrom().getBlockX() - e.getTo().getBlockX() == 0 && e.getFrom().getBlockZ() - e.getTo().getBlockZ() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.setCancelled(checkAndNotify(e.getPlayer(), e.getTo()));
|
e.setCancelled(checkAndNotify(e.getPlayer(), e.getTo()).equals(CheckResult.OPEN) ? false : true);
|
||||||
|
if (e.isCancelled()) {
|
||||||
|
e.getFrom().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||||
|
}
|
||||||
// Check from - just in case the player is inside the island
|
// Check from - just in case the player is inside the island
|
||||||
if (check(e.getPlayer(), e.getFrom())) {
|
if (!check(e.getPlayer(), e.getFrom()).equals(CheckResult.OPEN)) {
|
||||||
eject(e.getPlayer());
|
// Has to be done 1 tick later otherwise it doesn't happen for some reason...
|
||||||
|
Bukkit.getScheduler().runTask(BSkyBlock.getInstance(), () -> eject(e.getPlayer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +77,10 @@ public class IslandBanEnforcer implements Listener {
|
|||||||
}
|
}
|
||||||
// For each Player in the vehicle
|
// For each Player in the vehicle
|
||||||
e.getVehicle().getPassengers().stream().filter(en -> en instanceof Player).map(en -> (Player)en).forEach(p -> {
|
e.getVehicle().getPassengers().stream().filter(en -> en instanceof Player).map(en -> (Player)en).forEach(p -> {
|
||||||
if (checkAndNotify(p, e.getTo())) {
|
if (!checkAndNotify(p, e.getTo()).equals(CheckResult.OPEN)) {
|
||||||
p.leaveVehicle();
|
p.leaveVehicle();
|
||||||
p.teleport(e.getFrom());
|
p.teleport(e.getFrom());
|
||||||
|
e.getFrom().getWorld().playSound(e.getFrom(), Sound.BLOCK_ANVIL_HIT, 1F, 1F);
|
||||||
eject(p);
|
eject(p);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -91,34 +89,45 @@ public class IslandBanEnforcer implements Listener {
|
|||||||
// Login check
|
// Login check
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
public void onPlayerLogin(PlayerJoinEvent e) {
|
public void onPlayerLogin(PlayerJoinEvent e) {
|
||||||
if (checkAndNotify(e.getPlayer(), e.getPlayer().getLocation())) {
|
if (!checkAndNotify(e.getPlayer(), e.getPlayer().getLocation()).equals(CheckResult.OPEN)) {
|
||||||
eject(e.getPlayer());
|
eject(e.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a player is banned from this location
|
* Check if a player is banned or the island is locked
|
||||||
* @param player - player
|
* @param player - player
|
||||||
* @param loc - location to check
|
* @param loc - location to check
|
||||||
* @return true if banned
|
* @return CheckResult LOCKED, BANNED or OPEN. If an island is locked, that will take priority over banned
|
||||||
*/
|
*/
|
||||||
private boolean check(Player player, Location loc) {
|
private CheckResult check(Player player, Location loc) {
|
||||||
// See if player is banned
|
// See if the island is locked to non-members or player is banned
|
||||||
return im.getProtectedIslandAt(loc).map(is -> is.isBanned(player.getUniqueId())).orElse(false);
|
return im.getProtectedIslandAt(loc)
|
||||||
|
.map(is -> !is.isAllowed(User.getInstance(player), Flags.LOCK) ? CheckResult.LOCKED
|
||||||
|
: is.isBanned(player.getUniqueId()) ? CheckResult.BANNED
|
||||||
|
: CheckResult.OPEN)
|
||||||
|
.orElse(CheckResult.OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a player is banned from this location and notifies them if so
|
* Checks if a player is banned from this location and notifies them if so
|
||||||
* @param player - player
|
* @param player - player
|
||||||
* @param loc - location to check
|
* @param loc - location to check
|
||||||
* @return true if banned
|
* @return true if banned
|
||||||
*/
|
*/
|
||||||
private boolean checkAndNotify(Player player, Location loc) {
|
private CheckResult checkAndNotify(Player player, Location loc) {
|
||||||
if (check(player, loc)) {
|
CheckResult r = check(player,loc);
|
||||||
|
switch (r) {
|
||||||
|
case BANNED:
|
||||||
User.getInstance(player).notify("commands.island.ban.you-are-banned");
|
User.getInstance(player).notify("commands.island.ban.you-are-banned");
|
||||||
return true;
|
break;
|
||||||
|
case LOCKED:
|
||||||
|
User.getInstance(player).notify("protection.locked");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,7 +136,6 @@ public class IslandBanEnforcer implements Listener {
|
|||||||
*/
|
*/
|
||||||
private void eject(Player player) {
|
private void eject(Player player) {
|
||||||
// Teleport player to their home
|
// Teleport player to their home
|
||||||
inTeleport.add(player.getUniqueId());
|
|
||||||
if (im.hasIsland(player.getUniqueId())) {
|
if (im.hasIsland(player.getUniqueId())) {
|
||||||
im.homeTeleport(player);
|
im.homeTeleport(player);
|
||||||
} // else, TODO: teleport somewhere else?
|
} // else, TODO: teleport somewhere else?
|
@ -21,12 +21,14 @@ import us.tastybento.bskyblock.listeners.flags.HurtingListener;
|
|||||||
import us.tastybento.bskyblock.listeners.flags.InventoryListener;
|
import us.tastybento.bskyblock.listeners.flags.InventoryListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.ItemDropPickUpListener;
|
import us.tastybento.bskyblock.listeners.flags.ItemDropPickUpListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.LeashListener;
|
import us.tastybento.bskyblock.listeners.flags.LeashListener;
|
||||||
|
import us.tastybento.bskyblock.listeners.flags.LockAndBanListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.PVPListener;
|
import us.tastybento.bskyblock.listeners.flags.PVPListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
|
import us.tastybento.bskyblock.listeners.flags.PhysicalInteractionListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
|
import us.tastybento.bskyblock.listeners.flags.PlaceBlocksListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.PortalListener;
|
import us.tastybento.bskyblock.listeners.flags.PortalListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
||||||
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||||
|
import us.tastybento.bskyblock.managers.RanksManager;
|
||||||
|
|
||||||
public class Flags {
|
public class Flags {
|
||||||
|
|
||||||
@ -116,6 +118,9 @@ public class Flags {
|
|||||||
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.BEETROOT_SOUP).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
|
public static final Flag ITEM_DROP = new FlagBuilder().id("ITEM_DROP").icon(Material.BEETROOT_SOUP).allowedByDefault(true).listener(new ItemDropPickUpListener()).build();
|
||||||
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.BEETROOT_SEEDS).build();
|
public static final Flag ITEM_PICKUP = new FlagBuilder().id("ITEM_PICKUP").icon(Material.BEETROOT_SEEDS).build();
|
||||||
|
|
||||||
|
// Island lock
|
||||||
|
public static final Flag LOCK = new FlagBuilder().id("LOCK").icon(Material.TRIPWIRE_HOOK).type(Type.PROTECTION).allowedByDefault(true).defaultRank(RanksManager.VISITOR_RANK).listener(new LockAndBanListener()).build();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Settings flags (not protection flags)
|
* Settings flags (not protection flags)
|
||||||
*/
|
*/
|
||||||
@ -128,7 +133,7 @@ public class Flags {
|
|||||||
public static final Flag ANIMAL_SPAWN = new FlagBuilder().id("ANIMAL_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(Type.SETTING).build();
|
public static final Flag ANIMAL_SPAWN = new FlagBuilder().id("ANIMAL_SPAWN").icon(Material.APPLE).allowedByDefault(true).type(Type.SETTING).build();
|
||||||
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
|
public static final Flag MONSTER_SPAWN = new FlagBuilder().id("MONSTER_SPAWN").icon(Material.MOB_SPAWNER).allowedByDefault(true).type(Type.SETTING).build();
|
||||||
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).type(Type.SETTING).build();
|
public static final Flag FIRE_SPREAD = new FlagBuilder().id("FIRE_SPREAD").icon(Material.FIREWORK_CHARGE).type(Type.SETTING).build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of all the flags in this class
|
* @return List of all the flags in this class
|
||||||
*/
|
*/
|
||||||
|
@ -25,6 +25,7 @@ import us.tastybento.bskyblock.Constants;
|
|||||||
import us.tastybento.bskyblock.api.user.User;
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
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.island.IslandCache;
|
import us.tastybento.bskyblock.managers.island.IslandCache;
|
||||||
import us.tastybento.bskyblock.util.DeleteIslandChunks;
|
import us.tastybento.bskyblock.util.DeleteIslandChunks;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
@ -246,7 +247,7 @@ public class IslandsManager {
|
|||||||
}
|
}
|
||||||
// Set the owner of the island to no one.
|
// Set the owner of the island to no one.
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
island.setLocked(false);
|
island.setFlag(Flags.LOCK, RanksManager.VISITOR_RANK);
|
||||||
if (removeBlocks) {
|
if (removeBlocks) {
|
||||||
// Remove players from island
|
// Remove players from island
|
||||||
removePlayersFromIsland(island);
|
removePlayersFromIsland(island);
|
||||||
|
@ -46,6 +46,7 @@ import org.mockito.Mockito;
|
|||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.Constants;
|
import us.tastybento.bskyblock.Constants;
|
||||||
@ -66,9 +67,7 @@ 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")
|
@PrepareForTest({ BSkyBlock.class, Flags.class})
|
||||||
//@PrepareForTest( { Bukkit.class })
|
|
||||||
@PrepareForTest( { Flags.class })
|
|
||||||
public class TestBSkyBlock {
|
public class TestBSkyBlock {
|
||||||
private static final UUID MEMBER_UUID = UUID.randomUUID();
|
private static final UUID MEMBER_UUID = UUID.randomUUID();
|
||||||
private static final UUID OWNER_UUID = UUID.randomUUID();
|
private static final UUID OWNER_UUID = UUID.randomUUID();
|
||||||
@ -85,6 +84,10 @@ public class TestBSkyBlock {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
Mockito.when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
@ -108,7 +111,6 @@ public class TestBSkyBlock {
|
|||||||
|
|
||||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
//when(Bukkit.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
sender = mock(CommandSender.class);
|
sender = mock(CommandSender.class);
|
||||||
player = mock(Player.class);
|
player = mock(Player.class);
|
||||||
@ -117,8 +119,6 @@ public class TestBSkyBlock {
|
|||||||
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true);
|
Mockito.when(player.hasPermission(Constants.PERMPREFIX + "default.permission")).thenReturn(true);
|
||||||
|
|
||||||
|
|
||||||
//Mockito.when(plugin.getServer()).thenReturn(server);
|
|
||||||
|
|
||||||
location = mock(Location.class);
|
location = mock(Location.class);
|
||||||
Mockito.when(location.getWorld()).thenReturn(world);
|
Mockito.when(location.getWorld()).thenReturn(world);
|
||||||
Mockito.when(location.getBlockX()).thenReturn(0);
|
Mockito.when(location.getBlockX()).thenReturn(0);
|
||||||
@ -148,9 +148,6 @@ public class TestBSkyBlock {
|
|||||||
Mockito.when(iwm.getNetherWorld()).thenReturn(world);
|
Mockito.when(iwm.getNetherWorld()).thenReturn(world);
|
||||||
Mockito.when(iwm.getEndWorld()).thenReturn(world);
|
Mockito.when(iwm.getEndWorld()).thenReturn(world);
|
||||||
|
|
||||||
// User
|
|
||||||
//User user = Mockito.mock(User.class);
|
|
||||||
//Mockito.when(user.getName()).thenReturn("tastybento");
|
|
||||||
|
|
||||||
// Islands
|
// Islands
|
||||||
IslandsManager im = mock(IslandsManager.class);
|
IslandsManager im = mock(IslandsManager.class);
|
||||||
|
@ -129,7 +129,6 @@ public class MySQLDatabaseHandlerTest {
|
|||||||
}
|
}
|
||||||
island.setFlags(flags);
|
island.setFlags(flags);
|
||||||
island.setLevelHandicap(10);
|
island.setLevelHandicap(10);
|
||||||
island.setLocked(true);
|
|
||||||
Map<UUID, Integer> members = new HashMap<>();
|
Map<UUID, Integer> members = new HashMap<>();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
members.put(UUID.randomUUID(), i);
|
members.put(UUID.randomUUID(), i);
|
||||||
|
@ -38,6 +38,7 @@ import org.mockito.Mockito;
|
|||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.Settings;
|
import us.tastybento.bskyblock.Settings;
|
||||||
@ -51,7 +52,7 @@ import us.tastybento.bskyblock.managers.IslandsManager;
|
|||||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { Flags.class} )
|
@PrepareForTest( {BSkyBlock.class, Flags.class} )
|
||||||
public class FireListenerTest {
|
public class FireListenerTest {
|
||||||
|
|
||||||
private static Location location;
|
private static Location location;
|
||||||
@ -63,6 +64,10 @@ public class FireListenerTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
@ -88,7 +93,6 @@ public class FireListenerTest {
|
|||||||
when(location.getBlockZ()).thenReturn(0);
|
when(location.getBlockZ()).thenReturn(0);
|
||||||
PowerMockito.mockStatic(Flags.class);
|
PowerMockito.mockStatic(Flags.class);
|
||||||
|
|
||||||
plugin = Mockito.mock(BSkyBlock.class);
|
|
||||||
flagsManager = new FlagsManager(plugin);
|
flagsManager = new FlagsManager(plugin);
|
||||||
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
/**
|
package us.tastybento.bskyblock.listeners.flags;
|
||||||
*
|
|
||||||
*/
|
|
||||||
package us.tastybento.bskyblock.listeners;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -30,6 +27,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
@ -40,17 +39,14 @@ import us.tastybento.bskyblock.Settings;
|
|||||||
import us.tastybento.bskyblock.api.user.Notifier;
|
import us.tastybento.bskyblock.api.user.Notifier;
|
||||||
import us.tastybento.bskyblock.api.user.User;
|
import us.tastybento.bskyblock.api.user.User;
|
||||||
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.IslandsManager;
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
import us.tastybento.bskyblock.managers.LocalesManager;
|
import us.tastybento.bskyblock.managers.LocalesManager;
|
||||||
import us.tastybento.bskyblock.managers.PlayersManager;
|
import us.tastybento.bskyblock.managers.PlayersManager;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author tastybento
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
@PrepareForTest({Bukkit.class, BSkyBlock.class, User.class })
|
||||||
public class IslandBanEnforcerTest {
|
public class LockAndBanListenerTest {
|
||||||
|
|
||||||
private static final Integer PROTECTION_RANGE = 200;
|
private static final Integer PROTECTION_RANGE = 200;
|
||||||
private static final Integer X = 600;
|
private static final Integer X = 600;
|
||||||
@ -64,12 +60,13 @@ public class IslandBanEnforcerTest {
|
|||||||
private PlayersManager pm;
|
private PlayersManager pm;
|
||||||
private Island island;
|
private Island island;
|
||||||
private World world;
|
private World world;
|
||||||
private IslandBanEnforcer ibe;
|
private LockAndBanListener listener;
|
||||||
private Location loc;
|
private Location loc;
|
||||||
private Location outside;
|
private Location outside;
|
||||||
private Location inside;
|
private Location inside;
|
||||||
private Notifier notifier;
|
private Notifier notifier;
|
||||||
private Location inside2;
|
private Location inside2;
|
||||||
|
private BukkitScheduler sch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -113,7 +110,7 @@ public class IslandBanEnforcerTest {
|
|||||||
when(plugin.getPlayers()).thenReturn(pm);
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
|
||||||
// Server & Scheduler
|
// Server & Scheduler
|
||||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
sch = mock(BukkitScheduler.class);
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||||
|
|
||||||
@ -126,7 +123,6 @@ public class IslandBanEnforcerTest {
|
|||||||
notifier = mock(Notifier.class);
|
notifier = mock(Notifier.class);
|
||||||
when(plugin.getNotifier()).thenReturn(notifier);
|
when(plugin.getNotifier()).thenReturn(notifier);
|
||||||
|
|
||||||
|
|
||||||
// Island Banned list initialization
|
// Island Banned list initialization
|
||||||
island = mock(Island.class);
|
island = mock(Island.class);
|
||||||
when(island.getBanned()).thenReturn(new HashSet<>());
|
when(island.getBanned()).thenReturn(new HashSet<>());
|
||||||
@ -138,11 +134,13 @@ public class IslandBanEnforcerTest {
|
|||||||
when(loc.getBlockZ()).thenReturn(Z);
|
when(loc.getBlockZ()).thenReturn(Z);
|
||||||
when(island.getCenter()).thenReturn(loc);
|
when(island.getCenter()).thenReturn(loc);
|
||||||
when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE);
|
when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE);
|
||||||
|
// Island is not locked by default
|
||||||
|
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||||
|
|
||||||
when(im.getIsland(Mockito.any(UUID.class))).thenReturn(island);
|
when(im.getIsland(Mockito.any(UUID.class))).thenReturn(island);
|
||||||
|
|
||||||
|
// Create the listener object
|
||||||
|
listener = new LockAndBanListener();
|
||||||
ibe = new IslandBanEnforcer(plugin);
|
|
||||||
|
|
||||||
// Common from to's
|
// Common from to's
|
||||||
outside = mock(Location.class);
|
outside = mock(Location.class);
|
||||||
@ -178,7 +176,7 @@ public class IslandBanEnforcerTest {
|
|||||||
// Simulate a teleport into an island
|
// Simulate a teleport into an island
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
ibe.onPlayerTeleport(e);
|
listener.onPlayerTeleport(e);
|
||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
// User should see no message from this class
|
// User should see no message from this class
|
||||||
@ -197,7 +195,7 @@ public class IslandBanEnforcerTest {
|
|||||||
// Simulate a teleport into an island
|
// Simulate a teleport into an island
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
ibe.onPlayerTeleport(e);
|
listener.onPlayerTeleport(e);
|
||||||
// Should be cancelled
|
// Should be cancelled
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
// Player should see a message
|
// Player should see a message
|
||||||
@ -218,7 +216,7 @@ public class IslandBanEnforcerTest {
|
|||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
|
|
||||||
// Log them in
|
// Log them in
|
||||||
ibe.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
// User should see a message
|
// User should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should be teleported somewhere
|
// User should be teleported somewhere
|
||||||
@ -226,7 +224,7 @@ public class IslandBanEnforcerTest {
|
|||||||
// Call teleport event
|
// Call teleport event
|
||||||
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
ibe.onPlayerTeleport(e);
|
listener.onPlayerTeleport(e);
|
||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
}
|
}
|
||||||
@ -245,7 +243,7 @@ public class IslandBanEnforcerTest {
|
|||||||
when(to.getBlockY()).thenReturn(55);
|
when(to.getBlockY()).thenReturn(55);
|
||||||
when(to.getBlockZ()).thenReturn(Z);
|
when(to.getBlockZ()).thenReturn(Z);
|
||||||
PlayerMoveEvent e = new PlayerMoveEvent(user.getPlayer(), from, to);
|
PlayerMoveEvent e = new PlayerMoveEvent(user.getPlayer(), from, to);
|
||||||
ibe.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertFalse(e.isCancelled());
|
assertFalse(e.isCancelled());
|
||||||
// Confirm no check is done on the island
|
// Confirm no check is done on the island
|
||||||
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
||||||
@ -272,7 +270,7 @@ public class IslandBanEnforcerTest {
|
|||||||
passengers.add(player2);
|
passengers.add(player2);
|
||||||
when(vehicle.getPassengers()).thenReturn(passengers);
|
when(vehicle.getPassengers()).thenReturn(passengers);
|
||||||
// Move vehicle
|
// Move vehicle
|
||||||
ibe.onVehicleMove(new VehicleMoveEvent(vehicle, from, to));
|
listener.onVehicleMove(new VehicleMoveEvent(vehicle, from, to));
|
||||||
// Confirm no check is done on the island
|
// Confirm no check is done on the island
|
||||||
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
Mockito.verify(im, Mockito.never()).getProtectedIslandAt(Mockito.any());
|
||||||
}
|
}
|
||||||
@ -292,7 +290,7 @@ public class IslandBanEnforcerTest {
|
|||||||
|
|
||||||
// Move player
|
// Move player
|
||||||
PlayerMoveEvent e = new PlayerMoveEvent(player, outside, inside);
|
PlayerMoveEvent e = new PlayerMoveEvent(player, outside, inside);
|
||||||
ibe.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
// Player should see a message
|
// Player should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
@ -314,16 +312,16 @@ public class IslandBanEnforcerTest {
|
|||||||
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
when(island.isBanned(Mockito.eq(uuid))).thenReturn(true);
|
||||||
// Move player
|
// Move player
|
||||||
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
||||||
ibe.onPlayerMove(e);
|
listener.onPlayerMove(e);
|
||||||
assertTrue(e.isCancelled());
|
assertTrue(e.isCancelled());
|
||||||
// Player should see a message
|
// Player should see a message
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should be teleported somewhere
|
// User should be teleported somewhere
|
||||||
Mockito.verify(im).homeTeleport(Mockito.eq(player));
|
Mockito.verify(sch).runTask(Mockito.any(), Mockito.any(Runnable.class));
|
||||||
// Call teleport event
|
// Call teleport event
|
||||||
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
ibe.onPlayerTeleport(ev);
|
listener.onPlayerTeleport(ev);
|
||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
@ -350,7 +348,7 @@ public class IslandBanEnforcerTest {
|
|||||||
passengers.add(player2);
|
passengers.add(player2);
|
||||||
when(vehicle.getPassengers()).thenReturn(passengers);
|
when(vehicle.getPassengers()).thenReturn(passengers);
|
||||||
// Move vehicle
|
// Move vehicle
|
||||||
ibe.onVehicleMove(new VehicleMoveEvent(vehicle, outside, inside));
|
listener.onVehicleMove(new VehicleMoveEvent(vehicle, outside, inside));
|
||||||
// Player should see a message and nothing should be sent to Player 2
|
// Player should see a message and nothing should be sent to Player 2
|
||||||
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
// User should be teleported somewhere
|
// User should be teleported somewhere
|
||||||
@ -360,8 +358,224 @@ public class IslandBanEnforcerTest {
|
|||||||
// Call teleport event
|
// Call teleport event
|
||||||
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
||||||
// Pass to event listener
|
// Pass to event listener
|
||||||
ibe.onPlayerTeleport(ev);
|
listener.onPlayerTeleport(ev);
|
||||||
// Should not be cancelled
|
// Should not be cancelled
|
||||||
assertFalse(ev.isCancelled());
|
assertFalse(ev.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Island lock tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTeleportToLockedIsland() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Lock island for player
|
||||||
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
// Simulate a teleport into an island
|
||||||
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
||||||
|
// Pass to event listener
|
||||||
|
listener.onPlayerTeleport(e);
|
||||||
|
// Should be cancelled
|
||||||
|
assertTrue(e.isCancelled());
|
||||||
|
// Player should see a message
|
||||||
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTeleportToLockedIslandAsMember() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Simulate a teleport into an island
|
||||||
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, outside, inside);
|
||||||
|
// Pass to event listener
|
||||||
|
listener.onPlayerTeleport(e);
|
||||||
|
// Should not be not cancelled
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
// Player should not see a message
|
||||||
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginToLockedIsland() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player on the island
|
||||||
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
|
// Lock island for player
|
||||||
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
|
// Log them in
|
||||||
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
|
// User should see a message
|
||||||
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should be teleported somewhere
|
||||||
|
Mockito.verify(im).homeTeleport(Mockito.eq(player));
|
||||||
|
// Call teleport event
|
||||||
|
PlayerTeleportEvent e = new PlayerTeleportEvent(player, inside, outside);
|
||||||
|
// Pass to event listener
|
||||||
|
listener.onPlayerTeleport(e);
|
||||||
|
// Should not be cancelled
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoginToLockedIslandAsMember() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player on the island
|
||||||
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
// Log them in
|
||||||
|
listener.onPlayerLogin(new PlayerJoinEvent(player, "join message"));
|
||||||
|
// User should not see a message
|
||||||
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should not be teleported somewhere
|
||||||
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.eq(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlayerMoveIntoLockedIsland() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player just outside island
|
||||||
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
|
||||||
|
// Lock island for player
|
||||||
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
|
// Move player
|
||||||
|
PlayerMoveEvent e = new PlayerMoveEvent(player, outside, inside);
|
||||||
|
listener.onPlayerMove(e);
|
||||||
|
assertTrue(e.isCancelled());
|
||||||
|
// Player should see a message
|
||||||
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should NOT be teleported somewhere
|
||||||
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.eq(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlayerMoveIntoLockedIslandAsMember() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player just outside island
|
||||||
|
when(player.getLocation()).thenReturn(outside);
|
||||||
|
// Move player
|
||||||
|
PlayerMoveEvent e = new PlayerMoveEvent(player, outside, inside);
|
||||||
|
listener.onPlayerMove(e);
|
||||||
|
// Should not be cancelled
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
// Player should not see a message
|
||||||
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should NOT be teleported somewhere
|
||||||
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.eq(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlayerMoveInsideLockedIsland() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player inside island
|
||||||
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
|
// Lock island for player
|
||||||
|
when(island.isAllowed(Mockito.any(), Mockito.eq(Flags.LOCK))).thenReturn(false);
|
||||||
|
|
||||||
|
// Move player
|
||||||
|
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
||||||
|
listener.onPlayerMove(e);
|
||||||
|
assertTrue(e.isCancelled());
|
||||||
|
// Player should see a message
|
||||||
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should be teleported somewhere
|
||||||
|
Mockito.verify(sch).runTask(Mockito.any(), Mockito.any(Runnable.class));
|
||||||
|
// Call teleport event
|
||||||
|
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
||||||
|
// Pass to event listener
|
||||||
|
listener.onPlayerTeleport(ev);
|
||||||
|
// Should not be cancelled
|
||||||
|
assertFalse(ev.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPlayerMoveInsideLockedIslandAsMember() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
// Place the player inside island
|
||||||
|
when(player.getLocation()).thenReturn(inside);
|
||||||
|
// Move player
|
||||||
|
PlayerMoveEvent e = new PlayerMoveEvent(player, inside, inside2);
|
||||||
|
listener.onPlayerMove(e);
|
||||||
|
assertFalse(e.isCancelled());
|
||||||
|
// Player should not see a message
|
||||||
|
Mockito.verify(notifier, Mockito.never()).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should not be teleported somewhere
|
||||||
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.eq(player));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVehicleMoveIntoLockedIsland() {
|
||||||
|
// Make player
|
||||||
|
Player player = mock(Player.class);
|
||||||
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
|
// Give player an island
|
||||||
|
when(im.hasIsland(uuid)).thenReturn(true);
|
||||||
|
Player player2 = mock(Player.class);
|
||||||
|
UUID uuid2 = UUID.randomUUID();
|
||||||
|
when(player2.getUniqueId()).thenReturn(uuid2);
|
||||||
|
|
||||||
|
// Player 1 is not a member, player 2 is an island member
|
||||||
|
when(island.isAllowed(Mockito.any(User.class), Mockito.any())).thenAnswer(new Answer<Boolean>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
return invocation.getArgumentAt(0, User.class).getUniqueId().equals(uuid2) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create vehicle and put two players in it. One is a member, the other is not
|
||||||
|
Vehicle vehicle = mock(Vehicle.class);
|
||||||
|
List<Entity> passengers = new ArrayList<>();
|
||||||
|
passengers.add(player);
|
||||||
|
passengers.add(player2);
|
||||||
|
when(vehicle.getPassengers()).thenReturn(passengers);
|
||||||
|
// Move vehicle
|
||||||
|
listener.onVehicleMove(new VehicleMoveEvent(vehicle, outside, inside));
|
||||||
|
// Player should see a message and nothing should be sent to Player 2
|
||||||
|
Mockito.verify(notifier).notify(Mockito.any(), Mockito.anyString());
|
||||||
|
// User should be teleported somewhere
|
||||||
|
Mockito.verify(im).homeTeleport(Mockito.eq(player));
|
||||||
|
// Player 2 should not be teleported
|
||||||
|
Mockito.verify(im, Mockito.never()).homeTeleport(Mockito.eq(player2));
|
||||||
|
// Call teleport event
|
||||||
|
PlayerTeleportEvent ev = new PlayerTeleportEvent(player, inside, outside);
|
||||||
|
// Pass to event listener
|
||||||
|
listener.onPlayerTeleport(ev);
|
||||||
|
// Should not be cancelled
|
||||||
|
assertFalse(ev.isCancelled());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -31,6 +31,7 @@ import org.mockito.Mockito;
|
|||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
@ -40,7 +41,7 @@ import us.tastybento.bskyblock.managers.FlagsManager;
|
|||||||
import us.tastybento.bskyblock.managers.IslandsManager;
|
import us.tastybento.bskyblock.managers.IslandsManager;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { Flags.class })
|
@PrepareForTest( {BSkyBlock.class, Flags.class })
|
||||||
public class MobSpawnListenerTest {
|
public class MobSpawnListenerTest {
|
||||||
|
|
||||||
private static Location location;
|
private static Location location;
|
||||||
@ -52,6 +53,13 @@ public class MobSpawnListenerTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
IslandsManager im = mock(IslandsManager.class);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
@ -77,7 +85,6 @@ public class MobSpawnListenerTest {
|
|||||||
when(location.getBlockZ()).thenReturn(0);
|
when(location.getBlockZ()).thenReturn(0);
|
||||||
PowerMockito.mockStatic(Flags.class);
|
PowerMockito.mockStatic(Flags.class);
|
||||||
|
|
||||||
plugin = Mockito.mock(BSkyBlock.class);
|
|
||||||
flagsManager = new FlagsManager(plugin);
|
flagsManager = new FlagsManager(plugin);
|
||||||
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
when(plugin.getFlagsManager()).thenReturn(flagsManager);
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.powermock.api.mockito.PowerMockito;
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
import org.powermock.reflect.Whitebox;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.flags.Flag;
|
import us.tastybento.bskyblock.api.flags.Flag;
|
||||||
@ -35,12 +36,22 @@ import us.tastybento.bskyblock.listeners.flags.BreakBlocksListener;
|
|||||||
import us.tastybento.bskyblock.lists.Flags;
|
import us.tastybento.bskyblock.lists.Flags;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest( { Flags.class} )
|
@PrepareForTest( {BSkyBlock.class, Flags.class} )
|
||||||
public class FlagsManagerTest {
|
public class FlagsManagerTest {
|
||||||
|
|
||||||
|
|
||||||
|
private static BSkyBlock plugin;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
// Set up plugin
|
||||||
|
plugin = mock(BSkyBlock.class);
|
||||||
|
Whitebox.setInternalState(BSkyBlock.class, "instance", plugin);
|
||||||
|
|
||||||
|
IslandsManager im = mock(IslandsManager.class);
|
||||||
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
|
|
||||||
Server server = mock(Server.class);
|
Server server = mock(Server.class);
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
@ -65,13 +76,11 @@ public class FlagsManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlagsManager() {
|
public void testFlagsManager() {
|
||||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
|
||||||
assertNotNull(new FlagsManager(plugin));
|
assertNotNull(new FlagsManager(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegisterFlag() {
|
public void testRegisterFlag() {
|
||||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
|
||||||
FlagsManager fm = new FlagsManager(plugin);
|
FlagsManager fm = new FlagsManager(plugin);
|
||||||
// Try to register every single flag - it should fail every time
|
// Try to register every single flag - it should fail every time
|
||||||
Flags.values().forEach(dupe -> assertFalse(fm.registerFlag(dupe)));
|
Flags.values().forEach(dupe -> assertFalse(fm.registerFlag(dupe)));
|
||||||
@ -90,14 +99,12 @@ public class FlagsManagerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFlags() {
|
public void testGetFlags() {
|
||||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
|
||||||
FlagsManager fm = new FlagsManager(plugin);
|
FlagsManager fm = new FlagsManager(plugin);
|
||||||
assertThat(fm.getFlags(), is(Flags.values()));
|
assertThat(fm.getFlags(), is(Flags.values()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFlagByID() {
|
public void testGetFlagByID() {
|
||||||
BSkyBlock plugin = mock(BSkyBlock.class);
|
|
||||||
FlagsManager fm = new FlagsManager(plugin);
|
FlagsManager fm = new FlagsManager(plugin);
|
||||||
// Test in forward and reverse order so that any duplicates are caught
|
// Test in forward and reverse order so that any duplicates are caught
|
||||||
Flags.values().stream().sorted().forEach(flag -> assertEquals(flag, fm.getFlagByID(flag.getID())));
|
Flags.values().stream().sorted().forEach(flag -> assertEquals(flag, fm.getFlagByID(flag.getID())));
|
||||||
|
Loading…
Reference in New Issue
Block a user