mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-20 23:21:33 +01:00
Excludes spawn island from offline redstone prevention flag
https://github.com/BentoBoxWorld/BentoBox/issues/1031
This commit is contained in:
parent
2f4dae52e4
commit
cd7b02fdf2
@ -24,8 +24,10 @@ public class OfflineRedstoneListener extends FlagListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if island exists and members are online
|
||||
getIslands().getProtectedIslandAt(e.getBlock().getLocation()).ifPresent(i -> {
|
||||
// Check if island exists and members are online - excludes spawn
|
||||
getIslands().getProtectedIslandAt(e.getBlock().getLocation())
|
||||
.filter(i -> !i.isSpawn())
|
||||
.ifPresent(i -> {
|
||||
for (UUID uuid : i.getMemberSet(RanksManager.COOP_RANK)) {
|
||||
if (Bukkit.getPlayer(uuid) != null) {
|
||||
return;
|
||||
|
@ -988,6 +988,7 @@ protection:
|
||||
&awill not operate on islands
|
||||
&awhere all members are offline.
|
||||
&aMay help reduce lag.
|
||||
&aDoes not affect spawn island.
|
||||
name: "Offline Redstone"
|
||||
PISTON_PUSH:
|
||||
description: |-
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.event.block.BlockRedstoneEvent;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@ -40,11 +41,18 @@ import world.bentobox.bentobox.util.Util;
|
||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||
public class OfflineRedstoneListenerTest {
|
||||
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Location inside;
|
||||
@Mock
|
||||
private Block block;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private Island island;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@ -52,13 +60,10 @@ public class OfflineRedstoneListenerTest {
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// World
|
||||
world = mock(World.class);
|
||||
// Owner
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
// Island initialization
|
||||
Island island = mock(Island.class);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
// Add members
|
||||
Builder<UUID> set = new ImmutableSet.Builder<>();
|
||||
@ -69,25 +74,21 @@ public class OfflineRedstoneListenerTest {
|
||||
when(island.getMemberSet(Mockito.anyInt())).thenReturn(set.build());
|
||||
|
||||
|
||||
im = mock(IslandsManager.class);
|
||||
// Island Manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||
|
||||
inside = mock(Location.class);
|
||||
|
||||
Optional<Island> opIsland = Optional.ofNullable(island);
|
||||
when(im.getProtectedIslandAt(eq(inside))).thenReturn(opIsland);
|
||||
|
||||
// Blocks
|
||||
block = mock(Block.class);
|
||||
when(block.getWorld()).thenReturn(world);
|
||||
when(block.getLocation()).thenReturn(inside);
|
||||
|
||||
// Util
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(any())).thenReturn(world);
|
||||
|
||||
// World Settings
|
||||
iwm = mock(IslandWorldManager.class);
|
||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
@ -149,6 +150,25 @@ public class OfflineRedstoneListenerTest {
|
||||
assertEquals(0, e.getNewCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link OfflineRedstoneListener#onBlockRedstone(BlockRedstoneEvent)}.
|
||||
*/
|
||||
@Test
|
||||
public void testOnBlockRedstoneMembersOfflineSpawn() {
|
||||
when(island.isSpawn()).thenReturn(true);
|
||||
// Make an event to give some current to block
|
||||
BlockRedstoneEvent e = new BlockRedstoneEvent(block, 0, 10);
|
||||
OfflineRedstoneListener orl = new OfflineRedstoneListener();
|
||||
// Offline redstone not allowed
|
||||
Flags.OFFLINE_REDSTONE.setSetting(world, false);
|
||||
// Members are online
|
||||
when(Bukkit.getPlayer(any(UUID.class))).thenReturn(null);
|
||||
|
||||
orl.onBlockRedstone(e);
|
||||
// Current remains 10
|
||||
assertEquals(10, e.getNewCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link OfflineRedstoneListener#onBlockRedstone(BlockRedstoneEvent)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user