mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-08 09:27:38 +01:00
Added world protection settings to config
https://github.com/BentoBoxWorld/BentoBox/issues/840 This adds (or fixes) the ability for admins to set the default setting of a protection flag. The flags go in the world flags section of a game mode's config.yml.
This commit is contained in:
parent
9422f8ac3d
commit
574fbc182f
@ -141,6 +141,13 @@ public interface WorldSettings extends ConfigObject {
|
||||
*/
|
||||
Map<String, Boolean> getWorldFlags();
|
||||
|
||||
/**
|
||||
* Get world protection flags.
|
||||
* For locations outside of island spaces.
|
||||
* @return Map of world protection flags
|
||||
*/
|
||||
Map<String, Boolean> getWorldProtectionFlags();
|
||||
|
||||
/**
|
||||
* @return the worldName
|
||||
*/
|
||||
|
@ -1,8 +1,6 @@
|
||||
package world.bentobox.bentobox.api.flags;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ -25,7 +23,6 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class Flag implements Comparable<Flag> {
|
||||
|
||||
@ -71,7 +68,6 @@ public class Flag implements Comparable<Flag> {
|
||||
private final Listener listener;
|
||||
private final Type type;
|
||||
private boolean setting;
|
||||
private Map<World, Boolean> defaultWorldSettings = new HashMap<>();
|
||||
private final int defaultRank;
|
||||
private final PanelItem.ClickHandler clickHandler;
|
||||
private final boolean subPanel;
|
||||
@ -121,16 +117,23 @@ public class Flag implements Comparable<Flag> {
|
||||
* If world is not a game world, then the result will always be false!
|
||||
*/
|
||||
public boolean isSetForWorld(World world) {
|
||||
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
|
||||
if (ws == null) return false;
|
||||
if (type.equals(Type.WORLD_SETTING)) {
|
||||
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
|
||||
if (ws != null) {
|
||||
ws.getWorldFlags().putIfAbsent(getID(), setting);
|
||||
return ws.getWorldFlags().get(getID());
|
||||
if (!ws.getWorldFlags().containsKey(getID())) {
|
||||
ws.getWorldFlags().put(getID(), setting);
|
||||
// Save config file
|
||||
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
}
|
||||
return false;
|
||||
return ws.getWorldFlags().get(getID());
|
||||
} else {
|
||||
if (!ws.getWorldProtectionFlags().containsKey(getID())) {
|
||||
ws.getWorldProtectionFlags().put(getID(), setting);
|
||||
// Save config file
|
||||
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
}
|
||||
// Setting
|
||||
return defaultWorldSettings.getOrDefault(Util.getWorld(world), setting);
|
||||
return ws.getWorldProtectionFlags().get(getID());
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,12 +144,17 @@ public class Flag implements Comparable<Flag> {
|
||||
*/
|
||||
public void setSetting(World world, boolean setting) {
|
||||
if (getType().equals(Type.WORLD_SETTING)) {
|
||||
BentoBox.getInstance().getIWM().getWorldSettings(world).getWorldFlags().put(getID(), setting);
|
||||
BentoBox.getInstance()
|
||||
.getIWM()
|
||||
.getWorldSettings(world)
|
||||
.getWorldFlags()
|
||||
.put(getID(), setting);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the status of this flag for locations outside of island spaces
|
||||
* Set the original status of this flag for locations outside of island spaces.
|
||||
* May be overriden by the the setting for this world.
|
||||
* @param defaultSetting - true means it is allowed. false means it is not allowed
|
||||
*/
|
||||
public void setDefaultSetting(boolean defaultSetting) {
|
||||
@ -158,7 +166,11 @@ public class Flag implements Comparable<Flag> {
|
||||
* @param defaultSetting - true means it is allowed. false means it is not allowed
|
||||
*/
|
||||
public void setDefaultSetting(World world, boolean defaultSetting) {
|
||||
this.defaultWorldSettings.put(world, defaultSetting);
|
||||
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
|
||||
if (ws == null) return;
|
||||
ws.getWorldProtectionFlags().put(getID(),defaultSetting);
|
||||
// Save config file
|
||||
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ public abstract class FlagListener implements Listener {
|
||||
* @param flag - the flag that has been checked
|
||||
*/
|
||||
public void noGo(@NonNull Event e, @NonNull Flag flag) {
|
||||
noGo(e, flag, false);
|
||||
noGo(e, flag, false, "protection.protected");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,14 +87,15 @@ public abstract class FlagListener implements Listener {
|
||||
* @param e - event
|
||||
* @param flag - the flag that has been checked
|
||||
* @param silent - if true, message is not sent
|
||||
* @param string
|
||||
*/
|
||||
public void noGo(@NonNull Event e, @NonNull Flag flag, boolean silent) {
|
||||
public void noGo(@NonNull Event e, @NonNull Flag flag, boolean silent, String string) {
|
||||
if (e instanceof Cancellable) {
|
||||
((Cancellable)e).setCancelled(true);
|
||||
}
|
||||
if (user != null) {
|
||||
if (!silent) {
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(flag.getHintReference()));
|
||||
user.notify(string, TextVariables.DESCRIPTION, user.getTranslation(flag.getHintReference()));
|
||||
}
|
||||
user.updateInventory();
|
||||
}
|
||||
@ -170,7 +171,7 @@ public abstract class FlagListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
|
||||
noGo(e, flag, silent);
|
||||
noGo(e, flag, silent, "protection.world-protected");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ public abstract class FlagListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_ON_ISLAND);
|
||||
noGo(e, flag, silent);
|
||||
noGo(e, flag, silent, "protection.protected");
|
||||
return false;
|
||||
}
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
@ -196,7 +197,7 @@ public abstract class FlagListener implements Listener {
|
||||
return true;
|
||||
} else {
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
|
||||
noGo(e, flag, silent);
|
||||
noGo(e, flag, silent, "protection.world-protected");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1047,6 +1047,7 @@ protection:
|
||||
hint: "&cYou cannot teleport back to your island while you are falling."
|
||||
locked: "&cThis island is locked!"
|
||||
protected: "&cIsland protected: [description]"
|
||||
world-protected: "&cWorld protected: [description]"
|
||||
spawn-protected: "&cSpawn protected: [description]"
|
||||
|
||||
panel:
|
||||
|
@ -10,6 +10,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.any;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -81,7 +82,12 @@ public class FlagTest {
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
|
||||
worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
@ -93,7 +99,7 @@ public class FlagTest {
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemF);
|
||||
|
||||
// Flag
|
||||
f = new Flag.Builder("flagID", Material.ACACIA_PLANKS).listener(listener).build();
|
||||
f = new Flag.Builder("flagID", Material.ACACIA_PLANKS).type(Flag.Type.PROTECTION).listener(listener).build();
|
||||
|
||||
}
|
||||
|
||||
@ -194,9 +200,11 @@ public class FlagTest {
|
||||
@Test
|
||||
public void testSetDefaultSettingBoolean() {
|
||||
f.setDefaultSetting(true);
|
||||
// Checking will set it to the default
|
||||
assertTrue(f.isSetForWorld(world));
|
||||
f.setDefaultSetting(false);
|
||||
assertFalse(f.isSetForWorld(world));
|
||||
// Checking again will use the previous default
|
||||
assertTrue(f.isSetForWorld(world));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,6 +212,7 @@ public class FlagTest {
|
||||
*/
|
||||
@Test
|
||||
public void testSetDefaultSettingWorldBoolean() {
|
||||
|
||||
f.setDefaultSetting(world, true);
|
||||
assertTrue(f.isSetForWorld(world));
|
||||
f.setDefaultSetting(world, false);
|
||||
|
@ -31,6 +31,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@ -39,6 +40,7 @@ import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -56,6 +58,9 @@ public class FireListenerTest {
|
||||
|
||||
private Location location;
|
||||
private BentoBox plugin;
|
||||
@Mock
|
||||
private World world;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@ -128,6 +133,11 @@ public class FireListenerTest {
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||
@ -153,26 +163,26 @@ public class FireListenerTest {
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(false);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false);
|
||||
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(true);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true);
|
||||
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
|
||||
// Allow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(false);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false);
|
||||
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(true);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true);
|
||||
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
|
||||
// Fire is not allowed, so should be cancelled
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(false);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false);
|
||||
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
// Fire allowed
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(true);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true);
|
||||
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
}
|
||||
|
||||
@ -196,26 +206,26 @@ public class FireListenerTest {
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(false);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockBurn(e));
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, true);
|
||||
assertTrue(listener.onBlockBurn(e));
|
||||
|
||||
// Allow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(false);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, false);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
|
||||
// Fire is not allowed, so should be cancelled
|
||||
Flags.FIRE_BURNING.setDefaultSetting(false);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockBurn(e));
|
||||
// Fire allowed
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
}
|
||||
|
||||
@ -244,26 +254,26 @@ public class FireListenerTest {
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, true);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
|
||||
// Allow fire spread
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, false);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
|
||||
// Fire spread is not allowed, so should be cancelled
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
// Fire allowed
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
}
|
||||
|
||||
@ -296,26 +306,26 @@ public class FireListenerTest {
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, true);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
|
||||
// Allow fire spread
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, false);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
|
||||
// Fire spread is not allowed, so should be cancelled
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, false);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
// Fire allowed
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(world, true);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
@ -117,6 +118,11 @@ public class MobSpawnListenerTest {
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
|
||||
// Default - plugin is loaded
|
||||
when(plugin.isLoaded()).thenReturn(true);
|
||||
|
@ -60,6 +60,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
@ -196,6 +197,11 @@ public class PVPListenerTest {
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
|
||||
// Notifier
|
||||
notifier = mock(Notifier.class);
|
||||
|
@ -216,7 +216,7 @@ public class EnderChestListenerTest {
|
||||
Flags.ENDER_CHEST.setSetting(world, false);
|
||||
new BlockInteractionListener().onPlayerInteract(e);
|
||||
assertTrue(e.isCancelled());
|
||||
Mockito.verify(notifier).notify(Mockito.any(User.class), Mockito.eq("protection.protected"));
|
||||
Mockito.verify(notifier).notify(Mockito.any(User.class), Mockito.eq("protection.world-protected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -9,6 +9,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
@ -29,6 +30,7 @@ import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
@ -88,6 +90,12 @@ public class IslandRespawnListenerTest {
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
|
||||
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners.flags.worldsettings;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -27,6 +28,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
@ -48,13 +50,13 @@ public class PistonPushListenerTest {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
|
||||
// World
|
||||
world = mock(World.class);
|
||||
|
||||
|
||||
// Owner
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
|
||||
// Island initialization
|
||||
island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
@ -74,12 +76,12 @@ public class PistonPushListenerTest {
|
||||
when(block.getLocation()).thenReturn(inside);
|
||||
|
||||
Block blockPushed = mock(Block.class);
|
||||
|
||||
|
||||
when(block.getRelative(Mockito.any(BlockFace.class))).thenReturn(blockPushed);
|
||||
|
||||
|
||||
// The blocks in the pushed list are all inside the island
|
||||
when(blockPushed.getLocation()).thenReturn(inside);
|
||||
|
||||
|
||||
// Make a list of ten blocks
|
||||
blocks = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
@ -88,7 +90,7 @@ public class PistonPushListenerTest {
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(world);
|
||||
|
||||
|
||||
// World Settings
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
@ -96,7 +98,15 @@ public class PistonPushListenerTest {
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
|
||||
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
|
||||
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
Optional<GameModeAddon> opGma = Optional.of(gma );
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
|
||||
// Set default on
|
||||
Flags.PISTON_PUSH.setSetting(world, true);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -104,32 +114,32 @@ public class PistonPushListenerTest {
|
||||
Flags.PISTON_PUSH.setSetting(world, false);
|
||||
BlockPistonExtendEvent e = new BlockPistonExtendEvent(block, blocks, BlockFace.EAST);
|
||||
new PistonPushListener().onPistonExtend(e);
|
||||
|
||||
|
||||
// Should fail because flag is not set
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnPistonExtendFlagSetOnIsland() {
|
||||
|
||||
public void testOnPistonExtendFlagSetOnIsland() {
|
||||
|
||||
// The blocks in the pushed list are all inside the island
|
||||
when(island.onIsland(Mockito.any())).thenReturn(true);
|
||||
|
||||
|
||||
BlockPistonExtendEvent e = new BlockPistonExtendEvent(block, blocks, BlockFace.EAST);
|
||||
new PistonPushListener().onPistonExtend(e);
|
||||
|
||||
|
||||
// Should fail because on island
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnPistonExtendFlagSetOffIsland() {
|
||||
// The blocks in the pushed list are all outside the island
|
||||
when(island.onIsland(Mockito.any())).thenReturn(false);
|
||||
|
||||
|
||||
BlockPistonExtendEvent e = new BlockPistonExtendEvent(block, blocks, BlockFace.EAST);
|
||||
new PistonPushListener().onPistonExtend(e);
|
||||
|
||||
|
||||
// Should fail because on island
|
||||
assertTrue(e.isCancelled());
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -977,7 +978,7 @@ public class IslandsManagerTest {
|
||||
@Test
|
||||
public void testClearArea() {
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
when(iwm.getWorldSettings(eq(world))).thenReturn(ws);
|
||||
Map<String, Boolean> worldFlags = new HashMap<>();
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user