Fixes breaking rooted dirt exploit (#2371)

This commit is contained in:
tastybento 2024-05-19 15:35:38 -07:00 committed by GitHub
parent 50276cb8e5
commit 8aba736383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 351 additions and 237 deletions

View File

@ -80,16 +80,20 @@ public class BreakBlocksListener extends FlagListener {
Player p = e.getPlayer();
Location l = e.getClickedBlock().getLocation();
Material m = e.getClickedBlock().getType();
// Check for berry picking
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && (e.getClickedBlock().getType() == Material.CAVE_VINES || e.getClickedBlock().getType() == Material.CAVE_VINES_PLANT)) {
if (!((CaveVinesPlant) e.getClickedBlock().getBlockData()).isBerries()) {
return;
// Right click handling
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Material clickedType = e.getClickedBlock().getType();
switch (clickedType) {
case CAVE_VINES, CAVE_VINES_PLANT -> {
if (((CaveVinesPlant) e.getClickedBlock().getBlockData()).isBerries()) {
this.checkIsland(e, p, l, Flags.HARVEST);
}
this.checkIsland(e, p, l, Flags.HARVEST);
return;
}
if (e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock().getType() == Material.SWEET_BERRY_BUSH) {
this.checkIsland(e, p, l, Flags.HARVEST);
}
case SWEET_BERRY_BUSH -> this.checkIsland(e, p, l, Flags.HARVEST);
case ROOTED_DIRT -> this.checkIsland(e, p, l, Flags.BREAK_BLOCKS);
default -> { // Do nothing
}
}
return;
}
// Only handle hitting things

View File

@ -416,7 +416,7 @@ public class IslandsManager {
*/
@Nullable
public Island getIsland(@NonNull World world, @NonNull UUID uuid) {
return islandCache.get(world, uuid);
return islandCache.getIsland(world, uuid);
}
/**
@ -1723,14 +1723,14 @@ public class IslandsManager {
}
/**
* Convenience method. See {@link IslandCache#get(World, UUID)}
* Convenience method. See {@link IslandCache#getIsland(World, UUID)}
*
* @param world world
* @param uuid player's UUID
* @return Island of player or null if there isn't one
*/
public Island getPrimaryIsland(World world, UUID uuid) {
return this.getIslandCache().get(world, uuid);
return this.getIslandCache().getIsland(world, uuid);
}
}

View File

@ -179,7 +179,7 @@ public class IslandCache {
* @return island or null if none
*/
@Nullable
public Island get(@NonNull World world, @NonNull UUID uuid) {
public Island getIsland(@NonNull World world, @NonNull UUID uuid) {
List<Island> islands = getIslands(world, uuid);
if (islands.isEmpty()) {
return null;

View File

@ -89,14 +89,14 @@ public class TestBentoBox extends AbstractCommonSetup {
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(offlinePlayer);
when(offlinePlayer.getName()).thenReturn("tastybento");
when(player.hasPermission(anyString())).thenReturn(true);
when(mockPlayer.hasPermission(anyString())).thenReturn(true);
when(location.getWorld()).thenReturn(world);
when(ownerOfIsland.getLocation()).thenReturn(location);
when(visitorToIsland.getLocation()).thenReturn(location);
when(location.clone()).thenReturn(location);
when(player.getUniqueId()).thenReturn(MEMBER_UUID);
when(mockPlayer.getUniqueId()).thenReturn(MEMBER_UUID);
when(ownerOfIsland.getUniqueId()).thenReturn(uuid);
when(visitorToIsland.getUniqueId()).thenReturn(VISITOR_UUID);
@ -151,36 +151,36 @@ public class TestBentoBox extends AbstractCommonSetup {
String[] args = {""};
// Results are alphabetically sorted
when(Util.tabLimit(any(), any())).thenCallRealMethod();
assertEquals(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(player, "test", args));
assertEquals(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(mockPlayer, "test", args));
assertNotSame(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(sender, "test", args));
args[0] = "su";
assertEquals(Arrays.asList("sub1","sub2"), testCommand.tabComplete(player, "test", args));
assertEquals(Arrays.asList("sub1","sub2"), testCommand.tabComplete(mockPlayer, "test", args));
args[0] = "d";
assertNotSame(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(player, "test", args));
assertNotSame(Arrays.asList("help", "sub1","sub2"), testCommand.tabComplete(mockPlayer, "test", args));
args[0] = "sub1";
assertEquals(Collections.emptyList(), testCommand.tabComplete(player, "test", args));
assertEquals(Collections.emptyList(), testCommand.tabComplete(mockPlayer, "test", args));
String[] args2 = {"sub2",""};
assertEquals(Arrays.asList("help", "subsub"), testCommand.tabComplete(player, "test", args2));
assertEquals(Arrays.asList("help", "subsub"), testCommand.tabComplete(mockPlayer, "test", args2));
args2[1] = "s";
assertEquals(Collections.singletonList("subsub"), testCommand.tabComplete(player, "test", args2));
assertEquals(Collections.singletonList("subsub"), testCommand.tabComplete(mockPlayer, "test", args2));
String[] args3 = {"sub2","subsub", ""};
assertEquals(Arrays.asList("help", "subsubsub"), testCommand.tabComplete(player, "test", args3));
assertEquals(Arrays.asList("help", "subsubsub"), testCommand.tabComplete(mockPlayer, "test", args3));
// Test for overridden tabcomplete
assertEquals(Arrays.asList("Ben", "Bill", "Florian", "Ted", "help"),
testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", ""}));
testCommand.tabComplete(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub", ""}));
// Test for partial word
assertEquals(Arrays.asList("Ben", "Bill"),
testCommand.tabComplete(player, "test", new String[] {"sub2", "subsub", "subsubsub", "b"}));
testCommand.tabComplete(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub", "b"}));
// Test command arguments
CompositeCommand argCmd = new Test3ArgsCommand();
argCmd.setOnlyPlayer(true);
argCmd.setPermission("default.permission");
assertTrue(argCmd.execute(player, "args", new String[]{"give", "100", "ben"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));
assertFalse(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100"}));
assertTrue(testCommand.execute(player, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100", "today"}));
assertTrue(argCmd.execute(mockPlayer, "args", new String[]{"give", "100", "ben"}));
assertFalse(testCommand.execute(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub"}));
assertFalse(testCommand.execute(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub", "ben"}));
assertFalse(testCommand.execute(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100"}));
assertTrue(testCommand.execute(mockPlayer, "test", new String[] {"sub2", "subsub", "subsubsub", "ben", "100", "today"}));
// Usage tests
assertEquals("/test", testCommand.getUsage());
@ -421,8 +421,8 @@ public class TestBentoBox extends AbstractCommonSetup {
Assert.assertTrue(fl.checkIsland(e, ownerOfIsland, location, Flags.BREAK_BLOCKS, true));
// checking events - member
Event e2 = new BlockBreakEvent(block, player);
Assert.assertTrue(fl.checkIsland(e2, player, location, Flags.BREAK_BLOCKS, true));
Event e2 = new BlockBreakEvent(block, mockPlayer);
Assert.assertTrue(fl.checkIsland(e2, mockPlayer, location, Flags.BREAK_BLOCKS, true));
}

View File

@ -68,7 +68,7 @@ public abstract class AbstractCommonSetup {
protected UUID uuid = UUID.randomUUID();
@Mock
protected Player player;
protected Player mockPlayer;
@Mock
protected PluginManager pim;
@Mock
@ -116,15 +116,15 @@ public abstract class AbstractCommonSetup {
when(pm.getPlayer(any(UUID.class))).thenReturn(players);
// Player
when(player.getUniqueId()).thenReturn(uuid);
when(player.getLocation()).thenReturn(location);
when(player.getWorld()).thenReturn(world);
when(player.getName()).thenReturn("tastybento");
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getUniqueId()).thenReturn(uuid);
when(mockPlayer.getLocation()).thenReturn(location);
when(mockPlayer.getWorld()).thenReturn(world);
when(mockPlayer.getName()).thenReturn("tastybento");
when(mockPlayer.getInventory()).thenReturn(inv);
User.setPlugin(plugin);
User.clearUsers();
User.getInstance(player);
User.getInstance(mockPlayer);
// IWM
when(plugin.getIWM()).thenReturn(iwm);
@ -150,7 +150,7 @@ public abstract class AbstractCommonSetup {
// Enable reporting from Flags class
MetadataValue mdv = new FixedMetadataValue(plugin, "_why_debug");
when(player.getMetadata(anyString())).thenReturn(Collections.singletonList(mdv));
when(mockPlayer.getMetadata(anyString())).thenReturn(Collections.singletonList(mdv));
// Locales & Placeholders
LocalesManager lm = mock(LocalesManager.class);

View File

@ -144,7 +144,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
hand = EquipmentSlot.HAND;
// Nothing in hand right now
when(item.getType()).thenReturn(Material.AIR);
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getInventory()).thenReturn(inv);
when(inv.getItemInMainHand()).thenReturn(item);
when(inv.getItemInOffHand()).thenReturn(new ItemStack(Material.BUCKET));
@ -161,7 +161,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
@Test
public void testOnPlayerInteractItemFrameNotAllowed() {
when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals(Event.Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected"));
@ -175,7 +175,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(), eq(Flags.BREAK_BLOCKS))).thenReturn(true);
when(island.isAllowed(any(), eq(Flags.PLACE_BLOCKS))).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals(Event.Result.DENY, e.useInteractedBlock());
verify(notifier).notify(any(), eq("protection.protected"));
@ -188,7 +188,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractNothingInHandPotsNotAllowed() {
Arrays.stream(Material.values()).filter(m -> m.name().startsWith("POTTED")).forEach(bm -> {
when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals("Failure " + bm, Event.Result.DENY, e.useInteractedBlock());
});
@ -208,7 +208,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
when(clickedBlock.getState()).thenReturn(sign);
for (Material bm : clickedBlocks.keySet()) {
when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals("Failure " + bm, Event.Result.DENY, e.useInteractedBlock());
if (clickedBlocks.get(bm).getType().equals(Type.PROTECTION)) {
@ -235,7 +235,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
clickedBlocks.get(bm).setSetting(world, true);
}
when(clickedBlock.getType()).thenReturn(bm);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertNotEquals("Failure " + bm, Event.Result.DENY, e.useInteractedBlock());
verify(notifier, never()).notify(any(), eq("protection.protected"));
@ -250,7 +250,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractSpawnEggInHandNotAllowed() {
when(clickedBlock.getType()).thenReturn(Material.SPAWNER);
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals(Event.Result.DENY, e.useInteractedBlock());
assertEquals(Event.Result.DENY, e.useItemInHand());
@ -265,7 +265,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(), any())).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.SPAWNER);
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertNotEquals(Event.Result.DENY, e.useInteractedBlock());
assertNotEquals(Event.Result.DENY, e.useItemInHand());
@ -281,7 +281,7 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(), eq(Flags.PLACE_BLOCKS))).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.ITEM_FRAME);
when(item.getType()).thenReturn(Material.BLAZE_SPAWN_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.EAST, hand);
bil.onPlayerInteract(e);
assertEquals(Event.Result.DENY, e.useInteractedBlock());
assertEquals(Event.Result.DENY, e.useItemInHand());

View File

@ -16,6 +16,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.CaveVinesPlant;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creeper;
@ -40,6 +41,7 @@ import org.bukkit.inventory.ItemStack;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@ -57,6 +59,10 @@ import world.bentobox.bentobox.util.Util;
public class BreakBlocksListenerTest extends AbstractCommonSetup {
private BreakBlocksListener bbl;
@Mock
private Block mockBlock;
@Mock
private ItemStack mockItem;
@Override
@Before
@ -79,7 +85,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getType()).thenReturn(Material.DIRT);
BlockBreakEvent e = new BlockBreakEvent(block, player);
BlockBreakEvent e = new BlockBreakEvent(block, mockPlayer);
bbl.onBlockBreak(e);
assertFalse(e.isCancelled());
}
@ -93,7 +99,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getType()).thenReturn(Material.DIRT);
when(block.getLocation()).thenReturn(location);
BlockBreakEvent e = new BlockBreakEvent(block, player);
BlockBreakEvent e = new BlockBreakEvent(block, mockPlayer);
bbl.onBlockBreak(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -109,7 +115,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getType()).thenReturn(Material.PUMPKIN);
when(block.getLocation()).thenReturn(location);
BlockBreakEvent e = new BlockBreakEvent(block, player);
BlockBreakEvent e = new BlockBreakEvent(block, mockPlayer);
bbl.onBlockBreak(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -125,7 +131,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getType()).thenReturn(Material.PUMPKIN);
when(block.getLocation()).thenReturn(location);
BlockBreakEvent e = new BlockBreakEvent(block, player);
BlockBreakEvent e = new BlockBreakEvent(block, mockPlayer);
bbl.onBlockBreak(e);
assertFalse(e.isCancelled());
}
@ -138,7 +144,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Hanging hanging = mock(Hanging.class);
when(hanging.getLocation()).thenReturn(location);
RemoveCause cause = RemoveCause.ENTITY;
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, player, cause);
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, mockPlayer, cause);
bbl.onBreakHanging(e);
assertFalse(e.isCancelled());
}
@ -152,7 +158,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Hanging hanging = mock(Hanging.class);
when(hanging.getLocation()).thenReturn(location);
RemoveCause cause = RemoveCause.ENTITY;
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, player, cause);
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, mockPlayer, cause);
bbl.onBreakHanging(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -196,7 +202,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
when(hanging.getLocation()).thenReturn(location);
RemoveCause cause = RemoveCause.PHYSICS;
Arrow arrow = mock(Arrow.class);
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, arrow, cause);
bbl.onBreakHanging(e);
assertTrue(e.isCancelled());
@ -212,7 +218,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
when(hanging.getLocation()).thenReturn(location);
RemoveCause cause = RemoveCause.PHYSICS;
Arrow arrow = mock(Arrow.class);
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, arrow, cause);
bbl.onBreakHanging(e);
assertFalse(e.isCancelled());
@ -227,7 +233,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
ItemStack item = mock(ItemStack.class);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_AIR, item, block, BlockFace.EAST);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_AIR, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e);
assertEquals(e.useInteractedBlock(), Result.ALLOW);
}
@ -241,7 +247,8 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getType()).thenReturn(Material.STONE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.EAST);
bbl.onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -256,15 +263,16 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getType()).thenReturn(Material.CAKE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.EAST);
bbl.onPlayerInteract(e);
assertFalse(e.isCancelled());
when(block.getType()).thenReturn(Material.SPAWNER);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e);
assertFalse(e.isCancelled());
when(block.getType()).thenReturn(Material.DRAGON_EGG);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e);
assertFalse(e.isCancelled());
}
@ -279,15 +287,16 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
when(block.getType()).thenReturn(Material.CAKE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.EAST);
bbl.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
when(block.getType()).thenReturn(Material.SPAWNER);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
when(block.getType()).thenReturn(Material.DRAGON_EGG);
e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, item, block, BlockFace.EAST);
bbl.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
verify(notifier, times(3)).notify(any(), eq("protection.protected"));
@ -301,7 +310,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getLocation()).thenReturn(location);
when(vehicle.getType()).thenReturn(EntityType.MINECART);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, player, 10);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, mockPlayer, 10);
bbl.onVehicleDamageEvent(e);
assertFalse(e.isCancelled());
}
@ -315,7 +324,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getLocation()).thenReturn(location);
when(vehicle.getType()).thenReturn(EntityType.MINECART);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, player, 10);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, mockPlayer, 10);
bbl.onVehicleDamageEvent(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -330,7 +339,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getLocation()).thenReturn(location);
when(vehicle.getType()).thenReturn(EntityType.BOAT);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, player, 10);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, mockPlayer, 10);
bbl.onVehicleDamageEvent(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -345,7 +354,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getLocation()).thenReturn(location);
when(vehicle.getType()).thenReturn(EntityType.TRIDENT);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, player, 10);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, mockPlayer, 10);
bbl.onVehicleDamageEvent(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -359,7 +368,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
Vehicle vehicle = mock(Vehicle.class);
when(vehicle.getLocation()).thenReturn(location);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, player, 10);
VehicleDamageEvent e = new VehicleDamageEvent(vehicle, mockPlayer, 10);
bbl.onVehicleDamageEvent(e);
assertFalse(e.isCancelled());
}
@ -382,8 +391,8 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityDamageNotCovered() {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = player;
Entity damager = player;
Entity damagee = mockPlayer;
Entity damager = mockPlayer;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
@ -396,7 +405,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
public void testOnEntityDamageAllowed() {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = mock(ArmorStand.class);
Entity damager = player;
Entity damager = mockPlayer;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
@ -419,7 +428,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = mock(ArmorStand.class);
when(damagee.getLocation()).thenReturn(location);
Entity damager = player;
Entity damager = mockPlayer;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
@ -444,7 +453,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = mock(ArmorStand.class);
Projectile damager = mock(Projectile.class);
when(damager.getShooter()).thenReturn(player);
when(damager.getShooter()).thenReturn(mockPlayer);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
@ -490,7 +499,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Entity damagee = mock(ArmorStand.class);
when(damagee.getLocation()).thenReturn(location);
Projectile damager = mock(Projectile.class);
when(damager.getShooter()).thenReturn(player);
when(damager.getShooter()).thenReturn(mockPlayer);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
@ -511,4 +520,105 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
verify(notifier, times(3)).notify(any(), eq("protection.protected"));
verify(damagee).setFireTicks(0);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testRightClickCaveVinesWithBerries() {
when(mockBlock.getType()).thenReturn(Material.CAVE_VINES);
when(mockBlock.getLocation()).thenReturn(location);
CaveVinesPlant mockCaveVinesPlant = mock(CaveVinesPlant.class);
when(mockBlock.getBlockData()).thenReturn(mockCaveVinesPlant);
when(mockCaveVinesPlant.isBerries()).thenReturn(true);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testRightClickSweetBerryBush() {
when(mockBlock.getType()).thenReturn(Material.SWEET_BERRY_BUSH);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testRightClickRootedDirt() {
when(mockBlock.getType()).thenReturn(Material.ROOTED_DIRT);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testLeftClickCake() {
when(mockBlock.getType()).thenReturn(Material.CAKE);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testLeftClickSpawner() {
when(mockBlock.getType()).thenReturn(Material.SPAWNER);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testLeftClickDragonEgg() {
when(mockBlock.getType()).thenReturn(Material.DRAGON_EGG);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
/**
* Test method for {@link world.bentobox.bentobox.listeners.flags.protection.BreakBlocksListener#onPlayerInteract(PlayerInteractEvent)}
*/
@Test
public void testLeftClickHopper() {
when(mockBlock.getType()).thenReturn(Material.HOPPER);
when(mockBlock.getLocation()).thenReturn(location);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.LEFT_CLICK_BLOCK, mockItem, mockBlock,
BlockFace.UP);
bbl.onPlayerInteract(e);
assertTrue(e.useInteractedBlock() == Result.ALLOW);
}
}

View File

@ -75,7 +75,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(itemInOffHand.getType()).thenReturn(Material.AIR);
when(inv.getItemInMainHand()).thenReturn(itemInMainHand);
when(inv.getItemInOffHand()).thenReturn(itemInOffHand);
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getInventory()).thenReturn(inv);
}
@ -86,7 +86,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractNotAnimal() {
Entity clickedEntity = mock(Entity.class);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position);
new BreedingListener().onPlayerInteract(e);
assertFalse("Not animal failed", e.isCancelled());
}
@ -98,7 +98,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractAnimalNothingInMainHand() {
Animals clickedEntity = mock(Animals.class);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position);
new BreedingListener().onPlayerInteract(e);
assertFalse("Animal, nothing in main hand failed", e.isCancelled());
}
@ -110,7 +110,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractAnimalNothingInOffHand() {
Animals clickedEntity = mock(Animals.class);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, EquipmentSlot.OFF_HAND);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position, EquipmentSlot.OFF_HAND);
new BreedingListener().onPlayerInteract(e);
assertFalse("Animal, nothing in off hand failed", e.isCancelled());
}
@ -127,7 +127,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position);
BreedingListener bl = new BreedingListener();
Material breedingMat = BREEDABLE_WITH;
@ -149,7 +149,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.COW);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position);
BreedingListener bl = new BreedingListener();
Material breedingMat = BREEDABLE_WITH;
@ -172,7 +172,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, EquipmentSlot.OFF_HAND);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position, EquipmentSlot.OFF_HAND);
BreedingListener bl = new BreedingListener();
Material breedingMat = BREEDABLE_WITH;
@ -194,7 +194,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(ENTITY_TYPE);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, EquipmentSlot.OFF_HAND);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position, EquipmentSlot.OFF_HAND);
BreedingListener bl = new BreedingListener();
Material breedingMat = BREEDABLE_WITH;
@ -212,7 +212,7 @@ public class BreedingListenerTest extends AbstractCommonSetup {
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.COW);
Vector position = new Vector(0,0,0);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position);
BreedingListener bl = new BreedingListener();
Material breedingMat = NOT_BREEDABLE_WITH;

View File

@ -66,7 +66,7 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(block.getLocation()).thenReturn(location);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketEmpty(e);
assertFalse(e.isCancelled());
}
@ -81,7 +81,7 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(block.getLocation()).thenReturn(location);
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
PlayerBucketEmptyEvent e = new PlayerBucketEmptyEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketEmpty(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -97,22 +97,22 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
when(item.getType()).thenReturn(Material.BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
when(item.getType()).thenReturn(Material.LAVA_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
when(item.getType()).thenReturn(Material.MILK_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
}
@ -128,22 +128,22 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertTrue(e.isCancelled());
when(item.getType()).thenReturn(Material.BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertTrue(e.isCancelled());
when(item.getType()).thenReturn(Material.LAVA_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertTrue(e.isCancelled());
when(item.getType()).thenReturn(Material.MILK_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertTrue(e.isCancelled());
@ -164,22 +164,22 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(block.getRelative(any())).thenReturn(block);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
PlayerBucketFillEvent e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
when(item.getType()).thenReturn(Material.BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertTrue(e.isCancelled());
when(item.getType()).thenReturn(Material.LAVA_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
when(item.getType()).thenReturn(Material.MILK_BUCKET);
e = new PlayerBucketFillEvent(player, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
e = new PlayerBucketFillEvent(mockPlayer, block, block, BlockFace.UP, Material.WATER_BUCKET, item, EquipmentSlot.HAND);
l.onBucketFill(e);
assertFalse(e.isCancelled());
@ -191,7 +191,7 @@ public class BucketListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnTropicalFishScoopingNotFish() {
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, player);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, mockPlayer);
l.onTropicalFishScooping(e);
assertFalse(e.isCancelled());
}
@ -203,12 +203,12 @@ public class BucketListenerTest extends AbstractCommonSetup {
public void testOnTropicalFishScoopingFishNoWaterBucket() {
TropicalFish fish = mock(TropicalFish.class);
when(fish.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, fish );
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, fish );
PlayerInventory inv = mock(PlayerInventory.class);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.STONE);
when(inv.getItemInMainHand()).thenReturn(item);
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getInventory()).thenReturn(inv);
l.onTropicalFishScooping(e);
assertFalse(e.isCancelled());
}
@ -220,12 +220,12 @@ public class BucketListenerTest extends AbstractCommonSetup {
public void testOnTropicalFishScoopingFishWaterBucket() {
TropicalFish fish = mock(TropicalFish.class);
when(fish.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, fish );
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, fish );
PlayerInventory inv = mock(PlayerInventory.class);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
when(inv.getItemInMainHand()).thenReturn(item);
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getInventory()).thenReturn(inv);
l.onTropicalFishScooping(e);
assertFalse(e.isCancelled());
}
@ -238,12 +238,12 @@ public class BucketListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(), any())).thenReturn(false);
TropicalFish fish = mock(TropicalFish.class);
when(fish.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, fish );
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, fish );
PlayerInventory inv = mock(PlayerInventory.class);
ItemStack item = mock(ItemStack.class);
when(item.getType()).thenReturn(Material.WATER_BUCKET);
when(inv.getItemInMainHand()).thenReturn(item);
when(player.getInventory()).thenReturn(inv);
when(mockPlayer.getInventory()).thenReturn(inv);
l.onTropicalFishScooping(e);
assertTrue(e.isCancelled());

View File

@ -54,7 +54,7 @@ public class EggListenerTest extends AbstractCommonSetup {
public void testOnEggThrowAllowed() {
Egg egg = mock(Egg.class);
when(egg.getLocation()).thenReturn(location);
PlayerEggThrowEvent e = new PlayerEggThrowEvent(player, egg, false, (byte) 0, EntityType.CHICKEN);
PlayerEggThrowEvent e = new PlayerEggThrowEvent(mockPlayer, egg, false, (byte) 0, EntityType.CHICKEN);
el.onEggThrow(e);
verify(notifier, never()).notify(any(), anyString());
}
@ -67,7 +67,7 @@ public class EggListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(), any())).thenReturn(false);
Egg egg = mock(Egg.class);
when(egg.getLocation()).thenReturn(location);
PlayerEggThrowEvent e = new PlayerEggThrowEvent(player, egg, false, (byte) 0, EntityType.CHICKEN);
PlayerEggThrowEvent e = new PlayerEggThrowEvent(mockPlayer, egg, false, (byte) 0, EntityType.CHICKEN);
el.onEggThrow(e);
assertFalse(e.isHatching());
verify(notifier).notify(any(), eq("protection.protected"));

View File

@ -40,7 +40,7 @@ public class ElytraListenerTest extends AbstractCommonSetup {
super.setUp();
// Player
when(player.isGliding()).thenReturn(true);
when(mockPlayer.isGliding()).thenReturn(true);
// Default is that everything is allowed
when(island.isAllowed(any(), any())).thenReturn(true);
@ -54,7 +54,7 @@ public class ElytraListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnGlideAllowed() {
EntityToggleGlideEvent e = new EntityToggleGlideEvent(player, false);
EntityToggleGlideEvent e = new EntityToggleGlideEvent(mockPlayer, false);
el.onGlide(e);
assertFalse(e.isCancelled());
verify(notifier, never()).notify(any(), anyString());
@ -66,7 +66,7 @@ public class ElytraListenerTest extends AbstractCommonSetup {
@Test
public void testOnGlideNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
EntityToggleGlideEvent e = new EntityToggleGlideEvent(player, false);
EntityToggleGlideEvent e = new EntityToggleGlideEvent(mockPlayer, false);
el.onGlide(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -77,7 +77,7 @@ public class ElytraListenerTest extends AbstractCommonSetup {
*/
@Test
public void testGlidingAllowed() {
PlayerTeleportEvent e = new PlayerTeleportEvent(player, location, location);
PlayerTeleportEvent e = new PlayerTeleportEvent(mockPlayer, location, location);
el.onGliding(e);
verify(notifier, never()).notify(any(), anyString());
assertFalse(e.isCancelled());
@ -89,7 +89,7 @@ public class ElytraListenerTest extends AbstractCommonSetup {
@Test
public void testGlidingNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
PlayerTeleportEvent e = new PlayerTeleportEvent(player, location, location);
PlayerTeleportEvent e = new PlayerTeleportEvent(mockPlayer, location, location);
el.onGliding(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -100,8 +100,8 @@ public class ElytraListenerTest extends AbstractCommonSetup {
@Test
public void testGlidingNotGliding() {
when(island.isAllowed(any(), any())).thenReturn(false);
when(player.isGliding()).thenReturn(false);
PlayerTeleportEvent e = new PlayerTeleportEvent(player, location, location);
when(mockPlayer.isGliding()).thenReturn(false);
PlayerTeleportEvent e = new PlayerTeleportEvent(mockPlayer, location, location);
el.onGliding(e);
verify(notifier, never()).notify(any(), anyString());
assertFalse(e.isCancelled());

View File

@ -83,7 +83,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractAtEntityArmorStandNoInteraction() {
clickedEntity = mock(ArmorStand.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, hand);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position, hand);
eil.onPlayerInteractAtEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -97,7 +97,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), any())).thenReturn(true);
clickedEntity = mock(ArmorStand.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(player, clickedEntity, position, hand);
PlayerInteractAtEntityEvent e = new PlayerInteractAtEntityEvent(mockPlayer, clickedEntity, position, hand);
eil.onPlayerInteractAtEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -110,7 +110,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractEntityHorseNoInteraction() {
clickedEntity = mock(Horse.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -124,7 +124,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), any())).thenReturn(true);
clickedEntity = mock(Horse.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -137,7 +137,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractEntityMinecartNoInteraction() {
clickedEntity = mock(RideableMinecart.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -151,7 +151,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), any())).thenReturn(true);
clickedEntity = mock(RideableMinecart.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -164,7 +164,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractEntityBoatNoInteraction() {
clickedEntity = mock(Boat.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -178,7 +178,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), any())).thenReturn(true);
clickedEntity = mock(Boat.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -191,7 +191,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractEntityVillagerNoInteraction() {
clickedEntity = mock(Villager.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, times(2)).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -205,7 +205,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), any())).thenReturn(true);
clickedEntity = mock(Villager.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -221,7 +221,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), eq(Flags.NAME_TAG))).thenReturn(true);
clickedEntity = mock(Villager.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -236,7 +236,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(island.isAllowed(any(User.class), eq(Flags.NAME_TAG))).thenReturn(false);
clickedEntity = mock(Villager.class);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -250,7 +250,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, times(2)).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -265,7 +265,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -284,7 +284,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -301,7 +301,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(clickedEntity.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());
@ -316,7 +316,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.SHEEP);
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.AIR));
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
assertFalse(e.isCancelled());
@ -330,7 +330,7 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(Sheep.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.SHEEP);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, clickedEntity, hand);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier).notify(any(), eq("protection.protected"));
assertTrue(e.isCancelled());

View File

@ -55,7 +55,7 @@ public class ExperiencePickupListenerTest extends AbstractCommonSetup {
when(entity.getLocation()).thenReturn(location);
TargetReason reason = TargetReason.CLOSEST_PLAYER;
e = new EntityTargetLivingEntityEvent(entity, player, reason);
e = new EntityTargetLivingEntityEvent(entity, mockPlayer, reason);
epl = new ExperiencePickupListener();
}

View File

@ -69,7 +69,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
when(Util.isHostileEntity(any())).thenCallRealMethod();
// User & player
user = User.getInstance(player);
user = User.getInstance(mockPlayer);
}
/**
@ -88,7 +88,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityDamagePlayeronMonster() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, null, 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(mockPlayer, enderman, null, null, 0);
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertTrue(e.isCancelled());
@ -100,8 +100,8 @@ public class HurtingListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityDamagePlayeronMonsterOp() {
when(player.isOp()).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, null, 0);
when(mockPlayer.isOp()).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(mockPlayer, enderman, null, null, 0);
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertFalse(e.isCancelled());
@ -116,7 +116,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
ArmorStand entity = mock(ArmorStand.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
@ -131,7 +131,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
ArmorStand entity = mock(ArmorStand.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
// Allow
when(island.isAllowed(any(), any())).thenReturn(true);
@ -148,7 +148,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
Animals entity = mock(Animals.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
@ -163,7 +163,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
Animals entity = mock(Animals.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
// Allow
when(island.isAllowed(any(), any())).thenReturn(true);
@ -180,7 +180,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
Monster entity = mock(Monster.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
@ -195,7 +195,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
Monster entity = mock(Monster.class);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
// Allow
when(island.isAllowed(any(), any())).thenReturn(true);
@ -213,7 +213,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.VILLAGER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
@ -229,7 +229,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
when(entity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(entity.getLocation()).thenReturn(location);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
hl.onFishing(e);
// Verify
@ -246,7 +246,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.VILLAGER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
// Allow
when(island.isAllowed(any(), any())).thenReturn(true);
@ -264,7 +264,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
when(entity.getLocation()).thenReturn(location);
when(entity.getType()).thenReturn(EntityType.WANDERING_TRADER);
State state = State.CAUGHT_ENTITY;
PlayerFishEvent e = new PlayerFishEvent(player, entity, hookEntity, state);
PlayerFishEvent e = new PlayerFishEvent(mockPlayer, entity, hookEntity, state);
HurtingListener hl = new HurtingListener();
// Allow
when(island.isAllowed(any(), any())).thenReturn(true);

View File

@ -89,7 +89,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
@Test
public void testOnInventoryClickEnchantingAllowed() {
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
EnchantingInventory inv = mock(EnchantingInventory.class);
when(inv.getSize()).thenReturn(9);
when(view.getTopInventory()).thenReturn(inv);
@ -108,7 +108,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
@Test
public void testOnInventoryClickAllowed() {
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getSize()).thenReturn(9);
@ -148,7 +148,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
@Test
public void testOnInventoryClickNullHolder() {
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getLocation()).thenReturn(location);
when(inv.getSize()).thenReturn(9);
@ -191,7 +191,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
public void testOnInventoryClickNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getLocation()).thenReturn(location);
when(inv.getSize()).thenReturn(9);
@ -222,7 +222,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
public void testOnInventoryClickEnchantingNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
EnchantingInventory inv = mock(EnchantingInventory.class);
when(inv.getSize()).thenReturn(9);
when(view.getTopInventory()).thenReturn(inv);
@ -252,7 +252,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
@Test
public void testOnInventoryClickOtherHolderAllowed() {
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getLocation()).thenReturn(location);
when(inv.getSize()).thenReturn(9);
@ -274,7 +274,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
public void testOnInventoryClickOtherHolderNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getLocation()).thenReturn(location);
when(inv.getSize()).thenReturn(9);
@ -296,7 +296,7 @@ public class InventoryListenerTest extends AbstractCommonSetup {
public void testOnInventoryClickOtherHolderPlayerNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory inv = mock(Inventory.class);
when(inv.getLocation()).thenReturn(location);
when(inv.getSize()).thenReturn(9);

View File

@ -79,7 +79,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
@Test
public void testOnPlayerInteractNotPhysical() {
when(clickedBlock.getType()).thenReturn(Material.STONE);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_AIR, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_AIR, item, clickedBlock, BlockFace.UP);
new PhysicalInteractionListener().onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -91,7 +91,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractWrongMaterial() {
when(clickedBlock.getType()).thenReturn(Material.STONE);
when(Tag.PRESSURE_PLATES.isTagged(clickedBlock.getType())).thenReturn(false);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
new PhysicalInteractionListener().onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -102,7 +102,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
@Test
public void testOnPlayerInteractFarmland() {
when(clickedBlock.getType()).thenReturn(Material.FARMLAND);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
@ -115,9 +115,9 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnPlayerInteractFarmlandOp() {
when(player.isOp()).thenReturn(true);
when(mockPlayer.isOp()).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.FARMLAND);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
@ -128,9 +128,9 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnPlayerInteractFarmlandPermission() {
when(player.hasPermission(anyString())).thenReturn(true);
when(mockPlayer.hasPermission(anyString())).thenReturn(true);
when(clickedBlock.getType()).thenReturn(Material.FARMLAND);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
@ -142,7 +142,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
@Test
public void testOnPlayerInteractTurtleEgg() {
when(clickedBlock.getType()).thenReturn(Material.TURTLE_EGG);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
@ -157,7 +157,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
public void testOnPlayerInteractPressurePlate() {
Arrays.stream(Material.values()).filter(m -> m.name().contains("PRESSURE_PLATE")).forEach(p -> {
when(clickedBlock.getType()).thenReturn(p);
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.PHYSICAL, item, clickedBlock, BlockFace.UP);
PhysicalInteractionListener i = new PhysicalInteractionListener();
i.onPlayerInteract(e);
assertEquals(Result.DENY, e.useInteractedBlock());
@ -214,7 +214,7 @@ public class PhysicalInteractionListenerTest extends AbstractCommonSetup {
@Test
public void testOnProjectileHitProjectilePlayer() {
Projectile entity = mock(Projectile.class);
ProjectileSource source = player ;
ProjectileSource source = mockPlayer ;
when(entity.getShooter()).thenReturn(source);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);

View File

@ -73,7 +73,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
Block placedAgainst = mock(Block.class);
ItemStack itemInHand = mock(ItemStack.class);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertFalse(e.isCancelled());
}
@ -92,7 +92,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.STONE);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertFalse(e.isCancelled());
}
@ -105,7 +105,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
Hanging hanging = mock(Hanging.class);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null, null);
HangingPlaceEvent e = new HangingPlaceEvent(hanging, mockPlayer, block, BlockFace.EAST, null, null);
pbl.onHangingPlace(e);
assertFalse(e.isCancelled());
verify(notifier, never()).notify(any(), eq("protection.protected"));
@ -120,7 +120,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
Hanging hanging = mock(Hanging.class);
Block block = mock(Block.class);
when(block.getLocation()).thenReturn(location);
HangingPlaceEvent e = new HangingPlaceEvent(hanging, player, block, BlockFace.EAST, null, null);
HangingPlaceEvent e = new HangingPlaceEvent(hanging, mockPlayer, block, BlockFace.EAST, null, null);
pbl.onHangingPlace(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -137,7 +137,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
BlockState replacedBlockState = mock(BlockState.class);
Block placedAgainst = mock(Block.class);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, null, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, null, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertFalse(e.isCancelled());
}
@ -157,7 +157,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.STONE);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -179,7 +179,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.WHEAT_SEEDS);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertFalse(e.isCancelled());
}
@ -200,7 +200,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.DIRT);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -222,7 +222,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.WHEAT_SEEDS);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -243,7 +243,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemStack itemInHand = mock(ItemStack.class);
when(itemInHand.getType()).thenReturn(Material.WRITTEN_BOOK);
EquipmentSlot hand = EquipmentSlot.HAND;
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, player, true, hand);
BlockPlaceEvent e = new BlockPlaceEvent(placedBlock, replacedBlockState, placedAgainst, itemInHand, mockPlayer, true, hand);
pbl.onBlockPlace(e);
assertFalse(e.isCancelled());
verify(notifier, never()).notify(any(), eq("protection.protected"));
@ -263,7 +263,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
Creeper creeper = mock(Creeper.class);
when(creeper.getLocation()).thenReturn(location);
when(creeper.getType()).thenReturn(EntityType.CREEPER);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, creeper, EquipmentSlot.HAND);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, creeper, EquipmentSlot.HAND);
pbl.onPlayerHitItemFrame(e);
assertFalse(e.isCancelled());
}
@ -276,7 +276,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemFrame itemFrame = mock(ItemFrame.class);
when(itemFrame.getType()).thenReturn(EntityType.ITEM_FRAME);
when(itemFrame.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, itemFrame, EquipmentSlot.HAND);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, itemFrame, EquipmentSlot.HAND);
pbl.onPlayerHitItemFrame(e);
assertFalse(e.isCancelled());
}
@ -290,7 +290,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
ItemFrame itemFrame = mock(ItemFrame.class);
when(itemFrame.getType()).thenReturn(EntityType.ITEM_FRAME);
when(itemFrame.getLocation()).thenReturn(location);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(player, itemFrame, EquipmentSlot.HAND);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, itemFrame, EquipmentSlot.HAND);
pbl.onPlayerHitItemFrame(e);
assertTrue(e.isCancelled());
verify(notifier).notify(any(), eq("protection.protected"));
@ -307,7 +307,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
when(clickedBlock.getLocation()).thenReturn(location);
when(clickedBlock.getType()).thenReturn(Material.GRASS_BLOCK);
for (int i = 0; i < 7; i++) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
pbl.onPlayerInteract(e);
assertEquals("Failed on " + item.getType().toString(), Result.ALLOW, e.useInteractedBlock());
}
@ -325,7 +325,7 @@ public class PlaceBlocksListenerTest extends AbstractCommonSetup {
when(clickedBlock.getLocation()).thenReturn(location);
when(clickedBlock.getType()).thenReturn(Material.GRASS_BLOCK);
for (int i = 0; i < 7; i++) {
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, Action.RIGHT_CLICK_BLOCK, item, clickedBlock, BlockFace.UP, EquipmentSlot.HAND);
pbl.onPlayerInteract(e);
assertEquals("Failed on " + item.getType().toString(), Result.DENY, e.useInteractedBlock());
}

View File

@ -57,9 +57,9 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
when(block.getLocation()).thenReturn(location);
// User
when(player.getWorld()).thenReturn(world);
when(player.getLocation()).thenReturn(location);
User.getInstance(player);
when(mockPlayer.getWorld()).thenReturn(world);
when(mockPlayer.getLocation()).thenReturn(location);
User.getInstance(mockPlayer);
ssl = new SculkSensorListener();
}
@ -70,7 +70,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
@Test
public void testOnSculkSensorNotAllowed() {
when(island.isAllowed(any(), any())).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertTrue(e.isCancelled());
}
@ -80,7 +80,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnSculkSensorAllowed() {
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -91,7 +91,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
@Test
public void testOnSculkSensorNotInWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -103,7 +103,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
public void testOnSculkSensorNotAllowedCalibrated() {
when(block.getType()).thenReturn(Material.CALIBRATED_SCULK_SENSOR);
when(island.isAllowed(any(), any())).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertTrue(e.isCancelled());
}
@ -114,7 +114,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
@Test
public void testOnSculkSensorAllowedCalibrated() {
when(block.getType()).thenReturn(Material.CALIBRATED_SCULK_SENSOR);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -126,7 +126,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
public void testOnSculkSensorNotInWorldCalibrated() {
when(block.getType()).thenReturn(Material.CALIBRATED_SCULK_SENSOR);
when(iwm.inWorld(any(World.class))).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -138,7 +138,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
public void testOnSculkSensorNotAllowedNotSculk() {
when(block.getType()).thenReturn(Material.SHULKER_BOX);
when(island.isAllowed(any(), any())).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -149,7 +149,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
@Test
public void testOnSculkSensorAllowedNotSculk() {
when(block.getType()).thenReturn(Material.SHULKER_BOX);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}
@ -161,7 +161,7 @@ public class SculkSensorListenerTest extends AbstractCommonSetup {
public void testOnSculkSensorNotInWorldNotSculk() {
when(block.getType()).thenReturn(Material.SHULKER_BOX);
when(iwm.inWorld(any(World.class))).thenReturn(false);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, player);
BlockReceiveGameEvent e = new BlockReceiveGameEvent(GameEvent.BLOCK_ACTIVATE, block, mockPlayer);
ssl.onSculkSensor(e);
assertFalse(e.isCancelled());
}

View File

@ -98,7 +98,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(clickedBlock.getLocation()).thenReturn(location);
ItemStack item = new ItemStack(Material.FLINT_AND_STEEL);
Action action = Action.RIGHT_CLICK_BLOCK;
PlayerInteractEvent e = new PlayerInteractEvent(player , action, item, clickedBlock, clickedFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer , action, item, clickedBlock, clickedFace);
listener.onTNTPriming(e);
assertEquals(Result.DENY, e.useInteractedBlock());
@ -155,7 +155,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Block on fire
when(block.getType()).thenReturn(Material.TNT);
// Entity is not a projectile
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
EntityChangeBlockEvent e = new EntityChangeBlockEvent(mockPlayer, block, Material.AIR.createBlockData());
listener.onTNTDamage(e);
assertFalse(e.isCancelled());
@ -166,7 +166,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(block.getType()).thenReturn(Material.TNT);
// Out of world
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
EntityChangeBlockEvent e = new EntityChangeBlockEvent(mockPlayer, block, Material.AIR.createBlockData());
listener.onTNTDamage(e);
assertFalse(e.isCancelled());
}
@ -176,7 +176,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
when(block.getType()).thenReturn(Material.OBSIDIAN);
// Out of world
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
EntityChangeBlockEvent e = new EntityChangeBlockEvent(mockPlayer, block, Material.AIR.createBlockData());
listener.onTNTDamage(e);
assertFalse(e.isCancelled());
}
@ -208,7 +208,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Entity is an arrow
Arrow arrow = mock(Arrow.class);
// Shooter is a player
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
// Not fire arrow
when(arrow.getFireTicks()).thenReturn(0);
@ -227,7 +227,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Entity is an arrow
Arrow arrow = mock(Arrow.class);
// Shooter is a player
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
// Fire arrow
when(arrow.getFireTicks()).thenReturn(10);
@ -246,7 +246,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Entity is an arrow
Arrow arrow = mock(Arrow.class);
// Shooter is a player
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
// Fire arrow
when(arrow.getFireTicks()).thenReturn(10);
// Allowed on island
@ -269,7 +269,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Entity is an arrow
Arrow arrow = mock(Arrow.class);
// Shooter is a player
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
// Fire arrow
when(arrow.getFireTicks()).thenReturn(10);
@ -290,7 +290,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
// Entity is an arrow
Arrow arrow = mock(Arrow.class);
// Shooter is a player
when(arrow.getShooter()).thenReturn(player);
when(arrow.getShooter()).thenReturn(mockPlayer);
// Fire arrow
when(arrow.getFireTicks()).thenReturn(10);
@ -303,7 +303,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityExplosion() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertTrue(e.isCancelled());
@ -314,7 +314,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
Flags.WORLD_TNT_DAMAGE.setDefaultSetting(false);
assertFalse(Flags.WORLD_TNT_DAMAGE.isSetForWorld(world));
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertTrue(e.isCancelled());
@ -325,7 +325,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
Flags.WORLD_TNT_DAMAGE.setDefaultSetting(true);
assertTrue(Flags.WORLD_TNT_DAMAGE.isSetForWorld(world));
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertFalse(e.isCancelled());
@ -334,7 +334,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityExplosionWrongWorld() {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertFalse(e.isCancelled());

View File

@ -52,7 +52,7 @@ public class ThrowingListenerTest extends AbstractCommonSetup {
public void testOnPlayerThrowPotion() {
ThrownPotion entity = mock(ThrownPotion.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getShooter()).thenReturn(player);
when(entity.getShooter()).thenReturn(mockPlayer);
ProjectileLaunchEvent e = new ProjectileLaunchEvent(entity);
tl.onPlayerThrowPotion(e);
assertFalse(e.isCancelled());
@ -67,7 +67,7 @@ public class ThrowingListenerTest extends AbstractCommonSetup {
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
ThrownPotion entity = mock(ThrownPotion.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getShooter()).thenReturn(player);
when(entity.getShooter()).thenReturn(mockPlayer);
ProjectileLaunchEvent e = new ProjectileLaunchEvent(entity);
tl.onPlayerThrowPotion(e);
assertTrue(e.isCancelled());

View File

@ -60,7 +60,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
Flags.ENDER_CHEST.setSetting(world, false);
// No special perms
when(player.hasPermission(anyString())).thenReturn(false);
when(mockPlayer.hasPermission(anyString())).thenReturn(false);
// Action, Item and clicked block
action = Action.RIGHT_CLICK_BLOCK;
@ -73,7 +73,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
public void testOnEnderChestOpenNotRightClick() {
action = Action.LEFT_CLICK_AIR;
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
new BlockInteractionListener().onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -81,7 +81,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
@Test
public void testOnEnderChestOpenEnderChestNotInWorld() {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
// Not in world
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
@ -92,9 +92,9 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
@Test
public void testOnEnderChestOpenEnderChestOpPlayer() {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
// Op player
when(player.isOp()).thenReturn(true);
when(mockPlayer.isOp()).thenReturn(true);
new BlockInteractionListener().onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -102,9 +102,9 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
@Test
public void testOnEnderChestOpenEnderChestHasBypassPerm() {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
// Has bypass perm
when(player.hasPermission(anyString())).thenReturn(true);
when(mockPlayer.hasPermission(anyString())).thenReturn(true);
new BlockInteractionListener().onPlayerInteract(e);
assertEquals(Result.ALLOW, e.useInteractedBlock());
}
@ -112,7 +112,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
@Test
public void testOnEnderChestOpenEnderChestOkay() {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
// Enderchest use is okay
Flags.ENDER_CHEST.setSetting(world, true);
BlockInteractionListener bil = new BlockInteractionListener();
@ -124,7 +124,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
@Test
public void testOnEnderChestOpenEnderChestBlocked() {
BlockFace clickedBlockFace = BlockFace.EAST;
PlayerInteractEvent e = new PlayerInteractEvent(player, action, item, clickedBlock, clickedBlockFace);
PlayerInteractEvent e = new PlayerInteractEvent(mockPlayer, action, item, clickedBlock, clickedBlockFace);
// Enderchest use is blocked
Flags.ENDER_CHEST.setSetting(world, false);
new BlockInteractionListener().onPlayerInteract(e);
@ -139,7 +139,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
when(item.getType()).thenReturn(Material.STONE);
when(recipe.getResult()).thenReturn(item);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory top = mock(Inventory.class);
when(top.getSize()).thenReturn(9);
when(view.getTopInventory()).thenReturn(top);
@ -158,7 +158,7 @@ public class EnderChestListenerTest extends AbstractCommonSetup {
when(item.getType()).thenReturn(Material.ENDER_CHEST);
when(recipe.getResult()).thenReturn(item);
InventoryView view = mock(InventoryView.class);
when(view.getPlayer()).thenReturn(player);
when(view.getPlayer()).thenReturn(mockPlayer);
Inventory top = mock(Inventory.class);
when(top.getSize()).thenReturn(9);
when(view.getTopInventory()).thenReturn(top);

View File

@ -61,7 +61,7 @@ public class PetTeleportListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnPetTeleportNotTameable() {
EntityTeleportEvent e = new EntityTeleportEvent(player, location, location);
EntityTeleportEvent e = new EntityTeleportEvent(mockPlayer, location, location);
ptl.onPetTeleport(e);
assertFalse(e.isCancelled());
}
@ -71,7 +71,7 @@ public class PetTeleportListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnPetTeleportNullTo() {
EntityTeleportEvent e = new EntityTeleportEvent(player, location, null);
EntityTeleportEvent e = new EntityTeleportEvent(mockPlayer, location, null);
ptl.onPetTeleport(e);
assertFalse(e.isCancelled());
}

View File

@ -73,7 +73,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
public void testOnEntityPortalWrongWorld() {
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
when(Util.getWorld(any())).thenReturn(null);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
@ -84,7 +84,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityPortalWrongWorld2() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
@ -95,7 +95,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityPortalNullTo() {
EntityPortalEvent event = new EntityPortalEvent(player, location, null, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, null, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
}
@ -106,7 +106,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityPortalTeleportDisabled() {
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
}
@ -122,7 +122,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location, 10);
etl.onEntityPortal(event);
assertFalse(event.isCancelled());
@ -145,7 +145,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
when(location.getWorld()).thenReturn(world);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location2, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location2, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
@ -167,7 +167,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
when(Util.getWorld(any())).thenReturn(world2);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world2, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location2, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location2, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());
@ -192,7 +192,7 @@ public class EntityTeleportListenerTest extends AbstractCommonSetup {
when(Util.getWorld(any())).thenReturn(world2);
Flags.ENTITY_PORTAL_TELEPORT.setSetting(world2, true);
EntityPortalEvent event = new EntityPortalEvent(player, location, location2, 10);
EntityPortalEvent event = new EntityPortalEvent(mockPlayer, location, location2, 10);
etl.onEntityPortal(event);
assertTrue(event.isCancelled());

View File

@ -254,7 +254,7 @@ public class IslandsManagerTest extends AbstractCommonSetup {
// Mock island cache
when(islandCache.getIslandAt(any(Location.class))).thenReturn(island);
when(islandCache.get(any(), any())).thenReturn(island);
when(islandCache.getIsland(any(), any())).thenReturn(island);
optionalIsland = Optional.ofNullable(island);
when(islandCache.getIslands(world, uuid)).thenReturn(List.of(island));

View File

@ -118,7 +118,7 @@ public class IslandCacheTest {
public void testAddIsland() {
assertTrue(ic.addIsland(island));
// Check if they are added
assertEquals(island, ic.get(world, owner));
assertEquals(island, ic.getIsland(world, owner));
}
/**
@ -129,8 +129,8 @@ public class IslandCacheTest {
UUID playerUUID = UUID.randomUUID();
ic.addPlayer(playerUUID, island);
// Check if they are added
assertEquals(island, ic.get(world, playerUUID));
assertNotSame(island, ic.get(world, UUID.randomUUID()));
assertEquals(island, ic.getIsland(world, playerUUID));
assertNotSame(island, ic.getIsland(world, UUID.randomUUID()));
}
@ -141,19 +141,19 @@ public class IslandCacheTest {
public void testClear() {
ic.addIsland(island);
// Check if they are added
assertEquals(island, ic.get(world, owner));
assertEquals(island, ic.getIsland(world, owner));
ic.clear();
assertNull(ic.get(world, owner));
assertNull(ic.getIsland(world, owner));
}
/**
* Test for {@link IslandCache#get(World, UUID)}
* Test for {@link IslandCache#getIsland(World, UUID)}
*/
@Test
public void testGetUUID() {
ic.addIsland(island);
// Check if they are added
assertEquals(island, ic.get(world, owner));
assertEquals(island, ic.getIsland(world, owner));
}
/**
@ -255,7 +255,7 @@ public class IslandCacheTest {
ic.setOwner(island, newOwnerUUID);
Mockito.verify(island).setOwner(newOwnerUUID);
assertEquals(island, ic.get(world, newOwnerUUID));
assertEquals(island, ic.getIsland(world, newOwnerUUID));
}
/**