Merge pull request #2586 from BentoBoxWorld/paper_fixes

Paper fixes
This commit is contained in:
tastybento 2024-12-30 16:52:49 -08:00 committed by GitHub
commit a1c552b006
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 74 additions and 40 deletions

View File

@ -129,6 +129,7 @@ public abstract class AbstractCommonSetup {
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
when(location.toVector()).thenReturn(new Vector(0,0,0));
when(location.clone()).thenReturn(location); // Paper
// Players Manager and meta data
PlayersManager pm = mock(PlayersManager.class);

View File

@ -55,7 +55,6 @@ import world.bentobox.bentobox.util.Util;
* @author tastybento
*
*/
@Ignore("Needs update to work with PaperAPI")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class , ServerBuildInfo.class})
public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
@ -227,6 +226,7 @@ public class IslandTeamInviteCommandTest extends RanksManagerBeforeClassTest {
* Test method for
* {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamInviteCommand#canExecute(User, String, java.util.List)}.
*/
@Ignore("PaperAPI Material issue with Material.get")
@Test
public void testCanExecuteNoTarget() {
assertFalse(itl.canExecute(user, itl.getLabel(), Collections.emptyList()));

View File

@ -46,7 +46,6 @@ import world.bentobox.bentobox.util.Util;
* @author tastybento
*
*/
@Ignore("Paper API update required")
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, Util.class, ServerBuildInfo.class})
public class BlockInteractionListenerTest extends AbstractCommonSetup {
@ -130,8 +129,6 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
}
/**
*/
@Override
@Before
public void setUp() throws Exception {
@ -147,7 +144,9 @@ public class BlockInteractionListenerTest extends AbstractCommonSetup {
when(item.getType()).thenReturn(Material.AIR);
when(mockPlayer.getInventory()).thenReturn(inv);
when(inv.getItemInMainHand()).thenReturn(item);
when(inv.getItemInOffHand()).thenReturn(new ItemStack(Material.BUCKET));
ItemStack mockBucket = mock(ItemStack.class);
when(mockBucket.getType()).thenReturn(Material.BUCKET);
when(inv.getItemInOffHand()).thenReturn(mockBucket);
// FlagsManager
setFlags();

View File

@ -27,7 +27,6 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -45,7 +44,6 @@ import world.bentobox.bentobox.util.Util;
* @author tastybento
*
*/
@Ignore("Needs redo for PaperAPI")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, Util.class , ServerBuildInfo.class})
public class EntityInteractListenerTest extends AbstractCommonSetup {
@ -69,7 +67,9 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
// Hand - main hand
hand = EquipmentSlot.HAND;
position = new Vector(10, 10, 10);
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.NAME_TAG));
ItemStack mockNameTag = mock(ItemStack.class);
when(mockNameTag.getType()).thenReturn(Material.NAME_TAG);
when(inv.getItemInMainHand()).thenReturn(mockNameTag);
// Initialize the Flags class. This is a workaround to prevent weird errors when mocking
// I think it's because the flag class needs to be initialized before use in argument matchers
@ -253,7 +253,9 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(WanderingTrader.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.WANDERING_TRADER);
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.STONE));
ItemStack mockStone = mock(ItemStack.class);
when(mockStone.getType()).thenReturn(Material.STONE);
when(inv.getItemInMainHand()).thenReturn(mockStone);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));
@ -319,7 +321,9 @@ public class EntityInteractListenerTest extends AbstractCommonSetup {
clickedEntity = mock(Sheep.class);
when(clickedEntity.getLocation()).thenReturn(location);
when(clickedEntity.getType()).thenReturn(EntityType.SHEEP);
when(inv.getItemInMainHand()).thenReturn(new ItemStack(Material.AIR));
ItemStack mockAir = mock(ItemStack.class);
when(mockAir.getType()).thenReturn(Material.AIR);
when(inv.getItemInMainHand()).thenReturn(mockAir);
PlayerInteractEntityEvent e = new PlayerInteractEntityEvent(mockPlayer, clickedEntity, hand);
eil.onPlayerInteractEntity(e);
verify(notifier, never()).notify(any(), eq("protection.protected"));

View File

@ -30,7 +30,6 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -56,7 +55,6 @@ import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.mocks.ServerMocks;
import world.bentobox.bentobox.util.Util;
@Ignore("Needs PaperAPI update")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class , ServerBuildInfo.class})
public class LockAndBanListenerTest {
@ -157,6 +155,7 @@ public class LockAndBanListenerTest {
when(loc.getBlockY()).thenReturn(Y);
when(loc.getBlockZ()).thenReturn(Z);
when(island.getCenter()).thenReturn(loc);
when(loc.clone()).thenReturn(loc);
when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE);
// Island is not locked by default
when(island.isAllowed(any(), any())).thenReturn(true);
@ -171,16 +170,19 @@ public class LockAndBanListenerTest {
when(outside.getBlockX()).thenReturn(X + PROTECTION_RANGE + 1);
when(outside.getBlockY()).thenReturn(Y);
when(outside.getBlockZ()).thenReturn(Z);
when(outside.clone()).thenReturn(outside);
when(inside.getWorld()).thenReturn(world);
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 1);
when(inside.getBlockY()).thenReturn(Y);
when(inside.getBlockZ()).thenReturn(Z);
when(inside.clone()).thenReturn(inside);
when(inside.getWorld()).thenReturn(world);
when(inside.getBlockX()).thenReturn(X + PROTECTION_RANGE - 2);
when(inside.getBlockY()).thenReturn(Y);
when(inside.getBlockZ()).thenReturn(Z);
when(inside2.getWorld()).thenReturn(world);
when(inside2.getBlockX()).thenReturn(X + PROTECTION_RANGE - 2);
when(inside2.getBlockY()).thenReturn(Y);
when(inside2.getBlockZ()).thenReturn(Z);
when(inside2.clone()).thenReturn(inside2);
Optional<Island> opIsland = Optional.ofNullable(island);
when(im.getProtectedIslandAt(eq(inside))).thenReturn(opIsland);
@ -231,6 +233,7 @@ public class LockAndBanListenerTest {
assertTrue(e.isCancelled());
}
@SuppressWarnings("deprecation")
@Test
public void testLoginToBannedIsland() {
// Make player
@ -285,11 +288,13 @@ public class LockAndBanListenerTest {
when(from.getBlockX()).thenReturn(X);
when(from.getBlockY()).thenReturn(50);
when(from.getBlockZ()).thenReturn(Z);
when(from.clone()).thenReturn(from);
Location to = mock(Location.class);
when(to.getWorld()).thenReturn(world);
when(to.getBlockX()).thenReturn(X);
when(to.getBlockY()).thenReturn(55);
when(to.getBlockZ()).thenReturn(Z);
when(to.clone()).thenReturn(to);
// Create vehicle and put two players in it.
Vehicle vehicle = mock(Vehicle.class);
Player player2 = mock(Player.class);

View File

@ -12,7 +12,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.bukkit.Bukkit;
@ -21,6 +23,8 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Entity;
@ -33,10 +37,12 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -46,6 +52,8 @@ import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import com.google.common.base.Function;
import io.papermc.paper.ServerBuildInfo;
import world.bentobox.bentobox.AbstractCommonSetup;
import world.bentobox.bentobox.BentoBox;
@ -54,7 +62,6 @@ import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.util.Util;
@Ignore("PaperAPI changes required to fix errors and failures")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BentoBox.class, Util.class, Bukkit.class, ServerBuildInfo.class })
public class TNTListenerTest extends AbstractCommonSetup {
@ -112,6 +119,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
}
@Test
@Ignore("PaperAPI error with Material isn't an item issue")
public void testOnTNTPriming() {
BlockFace clickedFace = BlockFace.DOWN;
Block clickedBlock = mock(Block.class);
@ -324,8 +332,29 @@ public class TNTListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityExplosion() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION, null,
20D);
/*
* org.bukkit.event.entity.EntityDamageByEntityEvent.EntityDamageByEntityEvent(
* @NotNull @NotNull Entity damager,
* @NotNull @NotNull Entity damagee,
* @NotNull @NotNull DamageCause cause,
* @NotNull @NotNull DamageSource damageSource,
* @NotNull @NotNull Map<DamageModifier, Double> modifiers,
* @NotNull @NotNull Map<DamageModifier, ?> modifierFunctions,
* boolean critical)
Attempt to use newer event. This works but then other errors appear. Go figure.
@NotNull
Map<DamageModifier, Double> modifiers = new HashMap<>();
modifiers.put(DamageModifier.BASE, 0.0D);
@NotNull
Map<DamageModifier, ? extends Function<? super Double, Double>> modifier = new HashMap<>();
modifier.put(DamageModifier.BASE, null);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION,
DamageSource.builder(DamageType.EXPLOSION).build(), modifiers, modifier, false);
*/
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, mockPlayer, DamageCause.ENTITY_EXPLOSION,
null, 20D);
listener.onExplosion(e);
assertTrue(e.isCancelled());
}

View File

@ -34,7 +34,6 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.PluginManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@ -68,7 +67,6 @@ import world.bentobox.bentobox.util.Util;
public class ChestDamageListenerTest extends AbstractCommonSetup
{
private Location location;
private BentoBox plugin;
private World world;
@ -104,11 +102,7 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
location = mock(Location.class);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
PowerMockito.mockStatic(Flags.class);
FlagsManager flagsManager = new FlagsManager(plugin);
@ -180,28 +174,37 @@ public class ChestDamageListenerTest extends AbstractCommonSetup
* Test method for {@link ChestDamageListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionChestDamageNotAllowed() {
// Srt the flag to not allow chest damage
Flags.CHEST_DAMAGE.setSetting(world, false);
// Set the entity that is causing the damage (TNT)
Entity entity = mock(Entity.class);
when(entity.getType()).thenReturn(EntityType.TNT);
// Create a list of blocks that will potentially be damaged by TNT
List<Block> list = new ArrayList<>();
Block chest = mock(Block.class);
when(chest.getType()).thenReturn(Material.CHEST);
when(chest.getType()).thenReturn(Material.CHEST); // Regular chest
when(chest.getLocation()).thenReturn(location);
Block trappedChest = mock(Block.class);
when(trappedChest.getType()).thenReturn(Material.TRAPPED_CHEST);
when(trappedChest.getType()).thenReturn(Material.TRAPPED_CHEST);// Trapped chest
when(trappedChest.getLocation()).thenReturn(location);
Block stone = mock(Block.class);
when(stone.getType()).thenReturn(Material.STONE);
when(stone.getType()).thenReturn(Material.STONE); // Stone
when(stone.getLocation()).thenReturn(location);
list.add(chest);
list.add(trappedChest);
list.add(stone);
// Create the event
EntityExplodeEvent e = getExplodeEvent(entity, location, list);
// Listener to test
ChestDamageListener listener = new ChestDamageListener();
listener.setPlugin(plugin);
listener.onExplosion(e);
// Verify
assertFalse(e.isCancelled());
assertEquals(1, e.blockList().size());
assertFalse(e.blockList().contains(chest));

View File

@ -24,7 +24,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@ -52,8 +51,6 @@ public class WitherListenerTest extends AbstractCommonSetup {
private WitherListener wl;
@Mock
private Location location;
@Mock
private Location location2;
@Mock
private World world;
@ -82,15 +79,11 @@ public class WitherListenerTest extends AbstractCommonSetup {
when(ws.getWorldFlags()).thenReturn(map);
when(iwm.getWorldSettings(any())).thenReturn(ws);
when(location.getWorld()).thenReturn(world);
when(location.getBlockX()).thenReturn(0);
when(location.getBlockY()).thenReturn(0);
when(location.getBlockZ()).thenReturn(0);
when(location2.getWorld()).thenReturn(world2);
when(location2.getBlockX()).thenReturn(0);
when(location2.getBlockY()).thenReturn(0);
when(location2.getBlockZ()).thenReturn(0);
when(location2.clone()).thenReturn(location2); // Paper
blocks = new ArrayList<>();
for (int i = 0; i < 4; i++) {
@ -119,12 +112,12 @@ public class WitherListenerTest extends AbstractCommonSetup {
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionWither() {
Entity entity = mock(Entity.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER);
when(location.clone()).thenReturn(location);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertTrue(blocks.isEmpty());
@ -165,12 +158,12 @@ public class WitherListenerTest extends AbstractCommonSetup {
* Test method for {@link world.bentobox.bentobox.listeners.flags.worldsettings.WitherListener#onExplosion(org.bukkit.event.entity.EntityExplodeEvent)}.
*/
@Test
@Ignore("Fixes required for failures PaperAPI")
public void testOnExplosionWitherSkull() {
Entity entity = mock(Entity.class);
when(entity.getLocation()).thenReturn(location);
when(entity.getWorld()).thenReturn(world);
when(entity.getType()).thenReturn(EntityType.WITHER_SKULL);
when(location.clone()).thenReturn(location);
EntityExplodeEvent e = getExplodeEvent(entity, location, blocks);
wl.onExplosion(e);
assertTrue(blocks.isEmpty());