Corrects wrong branch commit for world protection flags.

https://github.com/BentoBoxWorld/BentoBox/issues/840
The previous commit was a different approach. This is the correct one.
Does not break API.
This commit is contained in:
tastybento 2019-07-13 19:31:20 -07:00
parent 574fbc182f
commit 5fe4cccf7b
8 changed files with 33 additions and 56 deletions

View File

@ -141,13 +141,6 @@ public interface WorldSettings extends ConfigObject {
*/ */
Map<String, Boolean> getWorldFlags(); 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 * @return the worldName
*/ */

View File

@ -119,22 +119,15 @@ public class Flag implements Comparable<Flag> {
public boolean isSetForWorld(World world) { public boolean isSetForWorld(World world) {
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world); WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
if (ws == null) return false; if (ws == null) return false;
if (type.equals(Type.WORLD_SETTING)) { if (type.equals(Type.WORLD_SETTING) || type.equals(Type.PROTECTION)) {
if (!ws.getWorldFlags().containsKey(getID())) { if (!ws.getWorldFlags().containsKey(getID())) {
ws.getWorldFlags().put(getID(), setting); ws.getWorldFlags().put(getID(), setting);
// Save config file // Save config file
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings); BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
} }
return ws.getWorldFlags().get(getID()); 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 ws.getWorldProtectionFlags().get(getID());
} }
return setting;
} }
/** /**
@ -167,8 +160,7 @@ public class Flag implements Comparable<Flag> {
*/ */
public void setDefaultSetting(World world, boolean defaultSetting) { public void setDefaultSetting(World world, boolean defaultSetting) {
WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world); WorldSettings ws = BentoBox.getInstance().getIWM().getWorldSettings(world);
if (ws == null) return; ws.getWorldFlags().put(getID(), defaultSetting);
ws.getWorldProtectionFlags().put(getID(),defaultSetting);
// Save config file // Save config file
BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings); BentoBox.getInstance().getIWM().getAddon(world).ifPresent(GameModeAddon::saveWorldSettings);
} }

View File

@ -86,8 +86,6 @@ public class FlagTest {
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
worldFlags = new HashMap<>(); worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags); when(ws.getWorldFlags()).thenReturn(worldFlags);

View File

@ -61,9 +61,12 @@ public class FireListenerTest {
@Mock @Mock
private World world; private World world;
private Map<String, Boolean> worldFlags = new HashMap<>();
@Before @Before
public void setUp() { public void setUp() {
worldFlags.clear();
PowerMockito.mockStatic(Bukkit.class); PowerMockito.mockStatic(Bukkit.class);
// Set up plugin // Set up plugin
plugin = mock(BentoBox.class); plugin = mock(BentoBox.class);
@ -131,13 +134,11 @@ public class FireListenerTest {
// World Settings // World Settings
WorldSettings ws = mock(WorldSettings.class); WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags); when(ws.getWorldFlags()).thenReturn(worldFlags);
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
PowerMockito.mockStatic(Util.class); PowerMockito.mockStatic(Util.class);
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class)); when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
@ -163,23 +164,23 @@ public class FireListenerTest {
// Disallow fire // Disallow fire
when(island.isAllowed(Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any())).thenReturn(false);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false); Flags.FLINT_AND_STEEL.setDefaultSetting(false);
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL)); assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true); Flags.FLINT_AND_STEEL.setDefaultSetting(true);
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL)); assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
// Allow fire // Allow fire
when(island.isAllowed(Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any())).thenReturn(true);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false); Flags.FLINT_AND_STEEL.setDefaultSetting(false);
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL)); assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true); Flags.FLINT_AND_STEEL.setDefaultSetting(true);
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL)); assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
// Check with no island // Check with no island
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty()); when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Fire is not allowed, so should be cancelled // Fire is not allowed, so should be cancelled
Flags.FLINT_AND_STEEL.setDefaultSetting(world, false); Flags.FLINT_AND_STEEL.setDefaultSetting(false);
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL)); assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
// Fire allowed // Fire allowed
Flags.FLINT_AND_STEEL.setDefaultSetting(world, true); Flags.FLINT_AND_STEEL.setDefaultSetting(world, true);
@ -206,26 +207,28 @@ public class FireListenerTest {
// Disallow fire // Disallow fire
when(island.isAllowed(Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any())).thenReturn(false);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
Flags.FIRE_BURNING.setDefaultSetting(world, false); Flags.FIRE_BURNING.setDefaultSetting(false);
assertTrue(listener.onBlockBurn(e)); assertTrue(listener.onBlockBurn(e));
Flags.FIRE_BURNING.setDefaultSetting(world, true); Flags.FIRE_BURNING.setDefaultSetting(true);
assertTrue(listener.onBlockBurn(e)); assertTrue(listener.onBlockBurn(e));
// Allow fire // Allow fire
when(island.isAllowed(Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any())).thenReturn(true);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
Flags.FIRE_BURNING.setDefaultSetting(world, false); Flags.FIRE_BURNING.setDefaultSetting(false);
assertFalse(listener.onBlockBurn(e)); assertFalse(listener.onBlockBurn(e));
Flags.FIRE_BURNING.setDefaultSetting(world, true); Flags.FIRE_BURNING.setDefaultSetting(true);
assertFalse(listener.onBlockBurn(e)); assertFalse(listener.onBlockBurn(e));
// Check with no island // Check with no island
e = new BlockBurnEvent(block, block);
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty()); when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Fire is not allowed, so should be cancelled // Fire is not allowed, so should be cancelled
Flags.FIRE_BURNING.setDefaultSetting(world, false); Flags.FIRE_BURNING.setDefaultSetting(false);
assertTrue(listener.onBlockBurn(e)); listener.onBlockBurn(e);
assertTrue(e.isCancelled());
// Fire allowed // Fire allowed
Flags.FIRE_BURNING.setDefaultSetting(world, true); Flags.FIRE_BURNING.setDefaultSetting(true);
assertFalse(listener.onBlockBurn(e)); assertFalse(listener.onBlockBurn(e));
} }
@ -254,26 +257,26 @@ public class FireListenerTest {
// Disallow fire // Disallow fire
when(island.isAllowed(Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any())).thenReturn(false);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
Flags.FIRE_SPREAD.setDefaultSetting(world, false); Flags.FIRE_SPREAD.setDefaultSetting(false);
assertTrue(listener.onBlockSpread(e)); assertTrue(listener.onBlockSpread(e));
Flags.FIRE_SPREAD.setDefaultSetting(world, true); Flags.FIRE_SPREAD.setDefaultSetting(true);
assertTrue(listener.onBlockSpread(e)); assertTrue(listener.onBlockSpread(e));
// Allow fire spread // Allow fire spread
when(island.isAllowed(Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any())).thenReturn(true);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
Flags.FIRE_SPREAD.setDefaultSetting(world, false); Flags.FIRE_SPREAD.setDefaultSetting(false);
assertFalse(listener.onBlockSpread(e)); assertFalse(listener.onBlockSpread(e));
Flags.FIRE_SPREAD.setDefaultSetting(world, true); Flags.FIRE_SPREAD.setDefaultSetting(true);
assertFalse(listener.onBlockSpread(e)); assertFalse(listener.onBlockSpread(e));
// Check with no island // Check with no island
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty()); when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Fire spread is not allowed, so should be cancelled // Fire spread is not allowed, so should be cancelled
Flags.FIRE_SPREAD.setDefaultSetting(world, false); Flags.FIRE_SPREAD.setDefaultSetting(false);
assertTrue(listener.onBlockSpread(e)); assertTrue(listener.onBlockSpread(e));
// Fire allowed // Fire allowed
Flags.FIRE_SPREAD.setDefaultSetting(world, true); Flags.FIRE_SPREAD.setDefaultSetting(true);
assertFalse(listener.onBlockSpread(e)); assertFalse(listener.onBlockSpread(e));
} }
@ -306,26 +309,26 @@ public class FireListenerTest {
// Disallow fire // Disallow fire
when(island.isAllowed(Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any())).thenReturn(false);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
Flags.FIRE_IGNITE.setDefaultSetting(world, false); Flags.FIRE_IGNITE.setDefaultSetting(false);
assertTrue(listener.onBlockIgnite(e)); assertTrue(listener.onBlockIgnite(e));
Flags.FIRE_IGNITE.setDefaultSetting(world, true); Flags.FIRE_IGNITE.setDefaultSetting(true);
assertTrue(listener.onBlockIgnite(e)); assertTrue(listener.onBlockIgnite(e));
// Allow fire spread // Allow fire spread
when(island.isAllowed(Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any())).thenReturn(true);
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true); when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
Flags.FIRE_IGNITE.setDefaultSetting(world, false); Flags.FIRE_IGNITE.setDefaultSetting(false);
assertFalse(listener.onBlockIgnite(e)); assertFalse(listener.onBlockIgnite(e));
Flags.FIRE_IGNITE.setDefaultSetting(world, true); Flags.FIRE_IGNITE.setDefaultSetting(true);
assertFalse(listener.onBlockIgnite(e)); assertFalse(listener.onBlockIgnite(e));
// Check with no island // Check with no island
when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty()); when(im.getIslandAt(Matchers.any())).thenReturn(Optional.empty());
// Fire spread is not allowed, so should be cancelled // Fire spread is not allowed, so should be cancelled
Flags.FIRE_IGNITE.setDefaultSetting(world, false); Flags.FIRE_IGNITE.setDefaultSetting(false);
assertTrue(listener.onBlockIgnite(e)); assertTrue(listener.onBlockIgnite(e));
// Fire allowed // Fire allowed
Flags.FIRE_IGNITE.setDefaultSetting(world, true); Flags.FIRE_IGNITE.setDefaultSetting(true);
assertFalse(listener.onBlockIgnite(e)); assertFalse(listener.onBlockIgnite(e));
} }
} }

View File

@ -121,8 +121,6 @@ public class MobSpawnListenerTest {
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
// Default - plugin is loaded // Default - plugin is loaded
when(plugin.isLoaded()).thenReturn(true); when(plugin.isLoaded()).thenReturn(true);

View File

@ -200,8 +200,6 @@ public class PVPListenerTest {
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
// Notifier // Notifier
notifier = mock(Notifier.class); notifier = mock(Notifier.class);

View File

@ -93,9 +93,6 @@ public class IslandRespawnListenerTest {
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
im = mock(IslandsManager.class); im = mock(IslandsManager.class);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true); when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);

View File

@ -98,8 +98,6 @@ public class PistonPushListenerTest {
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws); when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>(); Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags); when(ws.getWorldFlags()).thenReturn(worldFlags);
Map<String, Boolean> worldProtectionFlags = new HashMap<>();
when(ws.getWorldProtectionFlags()).thenReturn(worldProtectionFlags);
GameModeAddon gma = mock(GameModeAddon.class); GameModeAddon gma = mock(GameModeAddon.class);
Optional<GameModeAddon> opGma = Optional.of(gma ); Optional<GameModeAddon> opGma = Optional.of(gma );
when(iwm.getAddon(any())).thenReturn(opGma); when(iwm.getAddon(any())).thenReturn(opGma);