mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-21 07:32:32 +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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if island exists and members are online
|
// Check if island exists and members are online - excludes spawn
|
||||||
getIslands().getProtectedIslandAt(e.getBlock().getLocation()).ifPresent(i -> {
|
getIslands().getProtectedIslandAt(e.getBlock().getLocation())
|
||||||
|
.filter(i -> !i.isSpawn())
|
||||||
|
.ifPresent(i -> {
|
||||||
for (UUID uuid : i.getMemberSet(RanksManager.COOP_RANK)) {
|
for (UUID uuid : i.getMemberSet(RanksManager.COOP_RANK)) {
|
||||||
if (Bukkit.getPlayer(uuid) != null) {
|
if (Bukkit.getPlayer(uuid) != null) {
|
||||||
return;
|
return;
|
||||||
|
@ -988,6 +988,7 @@ protection:
|
|||||||
&awill not operate on islands
|
&awill not operate on islands
|
||||||
&awhere all members are offline.
|
&awhere all members are offline.
|
||||||
&aMay help reduce lag.
|
&aMay help reduce lag.
|
||||||
|
&aDoes not affect spawn island.
|
||||||
name: "Offline Redstone"
|
name: "Offline Redstone"
|
||||||
PISTON_PUSH:
|
PISTON_PUSH:
|
||||||
description: |-
|
description: |-
|
||||||
|
@ -20,6 +20,7 @@ import org.bukkit.event.block.BlockRedstoneEvent;
|
|||||||
import org.junit.Before;
|
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.Mock;
|
||||||
import org.mockito.Mockito;
|
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;
|
||||||
@ -40,11 +41,18 @@ import world.bentobox.bentobox.util.Util;
|
|||||||
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
@PrepareForTest({BentoBox.class, Util.class, Bukkit.class })
|
||||||
public class OfflineRedstoneListenerTest {
|
public class OfflineRedstoneListenerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
|
@Mock
|
||||||
private IslandsManager im;
|
private IslandsManager im;
|
||||||
|
@Mock
|
||||||
private Location inside;
|
private Location inside;
|
||||||
|
@Mock
|
||||||
private Block block;
|
private Block block;
|
||||||
|
@Mock
|
||||||
private IslandWorldManager iwm;
|
private IslandWorldManager iwm;
|
||||||
|
@Mock
|
||||||
|
private Island island;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@ -52,13 +60,10 @@ public class OfflineRedstoneListenerTest {
|
|||||||
BentoBox plugin = mock(BentoBox.class);
|
BentoBox plugin = mock(BentoBox.class);
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
|
|
||||||
// World
|
|
||||||
world = mock(World.class);
|
|
||||||
// Owner
|
// Owner
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
// Island initialization
|
// Island initialization
|
||||||
Island island = mock(Island.class);
|
|
||||||
when(island.getOwner()).thenReturn(uuid);
|
when(island.getOwner()).thenReturn(uuid);
|
||||||
// Add members
|
// Add members
|
||||||
Builder<UUID> set = new ImmutableSet.Builder<>();
|
Builder<UUID> set = new ImmutableSet.Builder<>();
|
||||||
@ -69,25 +74,21 @@ public class OfflineRedstoneListenerTest {
|
|||||||
when(island.getMemberSet(Mockito.anyInt())).thenReturn(set.build());
|
when(island.getMemberSet(Mockito.anyInt())).thenReturn(set.build());
|
||||||
|
|
||||||
|
|
||||||
im = mock(IslandsManager.class);
|
// Island Manager
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
|
||||||
|
|
||||||
inside = mock(Location.class);
|
|
||||||
|
|
||||||
Optional<Island> opIsland = Optional.ofNullable(island);
|
Optional<Island> opIsland = Optional.ofNullable(island);
|
||||||
when(im.getProtectedIslandAt(eq(inside))).thenReturn(opIsland);
|
when(im.getProtectedIslandAt(eq(inside))).thenReturn(opIsland);
|
||||||
|
|
||||||
// Blocks
|
// Blocks
|
||||||
block = mock(Block.class);
|
|
||||||
when(block.getWorld()).thenReturn(world);
|
when(block.getWorld()).thenReturn(world);
|
||||||
when(block.getLocation()).thenReturn(inside);
|
when(block.getLocation()).thenReturn(inside);
|
||||||
|
|
||||||
|
// Util
|
||||||
PowerMockito.mockStatic(Util.class);
|
PowerMockito.mockStatic(Util.class);
|
||||||
when(Util.getWorld(any())).thenReturn(world);
|
when(Util.getWorld(any())).thenReturn(world);
|
||||||
|
|
||||||
// World Settings
|
// World Settings
|
||||||
iwm = mock(IslandWorldManager.class);
|
|
||||||
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
when(iwm.inWorld(any(World.class))).thenReturn(true);
|
||||||
when(plugin.getIWM()).thenReturn(iwm);
|
when(plugin.getIWM()).thenReturn(iwm);
|
||||||
WorldSettings ws = mock(WorldSettings.class);
|
WorldSettings ws = mock(WorldSettings.class);
|
||||||
@ -149,6 +150,25 @@ public class OfflineRedstoneListenerTest {
|
|||||||
assertEquals(0, e.getNewCurrent());
|
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)}.
|
* Test method for {@link OfflineRedstoneListener#onBlockRedstone(BlockRedstoneEvent)}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user