Retain swept collision, hazards, loaded chunks and protection checks without requiring a supported exit. Add native paid crafting, item-use packet, target movement and safeguard regression coverage; 201 tests pass.
65 lines
3.3 KiB
Java
65 lines
3.3 KiB
Java
package games.dmg.spigotignis;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.mockito.Mockito.*;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.World;
|
|
import org.bukkit.WorldBorder;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.util.BoundingBox;
|
|
import org.bukkit.util.VoxelShape;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class DaggerSafetyTest {
|
|
@Test
|
|
void requiresClearLoadedInBorderDestinationWithoutGroundOrMutatingPlayerBounds() {
|
|
var world = mock(World.class);
|
|
var border = mock(WorldBorder.class);
|
|
when(world.getWorldBorder()).thenReturn(border);
|
|
when(border.isInside(any())).thenReturn(true);
|
|
when(world.getMinHeight()).thenReturn(-64);
|
|
when(world.getMaxHeight()).thenReturn(320);
|
|
when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true);
|
|
var air = mock(Block.class);
|
|
var shape = mock(VoxelShape.class);
|
|
when(air.getType()).thenReturn(Material.AIR);
|
|
when(air.getCollisionShape()).thenReturn(shape);
|
|
when(shape.getBoundingBoxes()).thenReturn(java.util.List.of());
|
|
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(air);
|
|
var player = mock(Player.class);
|
|
var body = new BoundingBox(-.3, 64, -.3, .3, 65.8, .3);
|
|
when(player.getWorld()).thenReturn(world);
|
|
when(player.getLocation()).thenReturn(new Location(world, 0, 64, 0));
|
|
when(player.getBoundingBox()).thenReturn(body);
|
|
var destination = new Location(world, 0, 64, 3);
|
|
assertTrue(DaggerSafety.safe(player, destination));
|
|
var protruding = mock(Block.class);
|
|
var protrudingShape = mock(VoxelShape.class);
|
|
when(protruding.getType()).thenReturn(Material.STONE);
|
|
when(protruding.getCollisionShape()).thenReturn(protrudingShape);
|
|
when(protrudingShape.getBoundingBoxes()).thenReturn(java.util.List.of(new BoundingBox(-1, 0, 0, 0, 1, 1)));
|
|
when(world.getBlockAt(1, 64, 0)).thenReturn(protruding);
|
|
assertFalse(DaggerSafety.safe(player, destination), "Neighbor collision shapes can protrude outside their block cell");
|
|
when(world.getBlockAt(1, 64, 0)).thenReturn(air);
|
|
assertEquals(new BoundingBox(-.3, 64, -.3, .3, 65.8, .3), body);
|
|
assertTrue(DaggerSafety.safe(player, destination), "unsupported air is a valid exit");
|
|
when(air.getType()).thenReturn(Material.LAVA);
|
|
assertFalse(DaggerSafety.safe(player, destination));
|
|
when(air.getType()).thenReturn(Material.AIR);
|
|
when(shape.getBoundingBoxes()).thenReturn(java.util.List.of(new BoundingBox(0, 0, 0, 1, 1, 1)));
|
|
assertFalse(DaggerSafety.safe(player, destination));
|
|
when(shape.getBoundingBoxes()).thenReturn(java.util.List.of());
|
|
when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(false);
|
|
clearInvocations(world);
|
|
assertFalse(DaggerSafety.safe(player, destination));
|
|
verify(world, never()).getBlockAt(anyInt(), anyInt(), anyInt());
|
|
when(world.isChunkLoaded(anyInt(), anyInt())).thenReturn(true);
|
|
when(border.isInside(any())).thenReturn(false);
|
|
assertFalse(DaggerSafety.safe(player, destination));
|
|
assertFalse(DaggerSafety.safe(player, new Location(world, Double.NaN, 64, 0)));
|
|
assertFalse(DaggerSafety.safe(player, new Location(world, 0, 320, 0)));
|
|
}
|
|
}
|