mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-23 15:50:30 +02:00
Update BlockTracker to use Spigot API directly instead of compatibility
layer Fixes #4692 Fixes #4698
This commit is contained in:
@@ -4,7 +4,6 @@ package com.gmail.nossr50.util.blockmeta;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.compat.CompatibilityManager;
|
||||
import com.gmail.nossr50.util.compat.layers.world.WorldCompatibilityLayer;
|
||||
import com.gmail.nossr50.util.platform.PlatformManager;
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -39,10 +38,7 @@ class ChunkStoreTest {
|
||||
}
|
||||
|
||||
private World mockWorld;
|
||||
private CompatibilityManager compatibilityManager;
|
||||
private WorldCompatibilityLayer worldCompatibilityLayer;
|
||||
private PlatformManager platformManager;
|
||||
|
||||
|
||||
private MockedStatic<Bukkit> bukkitMock;
|
||||
private MockedStatic<mcMMO> mcMMOMock;
|
||||
|
||||
@@ -57,24 +53,10 @@ class ChunkStoreTest {
|
||||
bukkitMock = Mockito.mockStatic(Bukkit.class);
|
||||
bukkitMock.when(() -> Bukkit.getWorld(worldUUID)).thenReturn(mockWorld);
|
||||
|
||||
platformManager = Mockito.mock(PlatformManager.class);
|
||||
compatibilityManager = Mockito.mock(CompatibilityManager.class);
|
||||
worldCompatibilityLayer = Mockito.mock(WorldCompatibilityLayer.class);
|
||||
|
||||
mcMMOMock = Mockito.mockStatic(mcMMO.class);
|
||||
|
||||
mcMMOMock.when(() -> mcMMO.getPlatformManager()).thenReturn(platformManager);
|
||||
Assertions.assertNotNull(mcMMO.getPlatformManager());
|
||||
|
||||
mcMMOMock.when(() -> mcMMO.getCompatibilityManager()).thenReturn(compatibilityManager);
|
||||
Assertions.assertNotNull(mcMMO.getCompatibilityManager());
|
||||
|
||||
Mockito.when(platformManager.getCompatibilityManager()).thenReturn(compatibilityManager);
|
||||
Mockito.when(platformManager.getCompatibilityManager().getWorldCompatibilityLayer()).thenReturn(worldCompatibilityLayer);
|
||||
Assertions.assertNotNull(mcMMO.getCompatibilityManager().getWorldCompatibilityLayer());
|
||||
Mockito.when(worldCompatibilityLayer.getMinWorldHeight(mockWorld)).thenReturn(LEGACY_WORLD_HEIGHT_MIN);
|
||||
Mockito.when(worldCompatibilityLayer.getMaxWorldHeight(mockWorld)).thenReturn(LEGACY_WORLD_HEIGHT_MAX);
|
||||
|
||||
Mockito.when(mockWorld.getMinHeight()).thenReturn(LEGACY_WORLD_HEIGHT_MIN);
|
||||
Mockito.when(mockWorld.getMaxHeight()).thenReturn(LEGACY_WORLD_HEIGHT_MAX);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -85,7 +67,7 @@ class ChunkStoreTest {
|
||||
|
||||
@Test
|
||||
void testIndexOutOfBounds() {
|
||||
Mockito.when(mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(mockWorld)).thenReturn(-64);
|
||||
Mockito.when(mockWorld.getMinHeight()).thenReturn(-64);
|
||||
HashChunkManager hashChunkManager = new HashChunkManager();
|
||||
|
||||
// Top Block
|
||||
@@ -96,7 +78,7 @@ class ChunkStoreTest {
|
||||
|
||||
@Test
|
||||
void testSetTrue() {
|
||||
Mockito.when(mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(mockWorld)).thenReturn(-64);
|
||||
Mockito.when(mockWorld.getMinHeight()).thenReturn(-64);
|
||||
HashChunkManager hashChunkManager = new HashChunkManager();
|
||||
int radius = 2; // Could be anything but drastically changes test time
|
||||
|
||||
@@ -117,7 +99,7 @@ class ChunkStoreTest {
|
||||
Block bottomBlock = initMockBlock(1337, 0, -1337);
|
||||
Assertions.assertFalse(hashChunkManager.isTrue(bottomBlock));
|
||||
|
||||
Assertions.assertTrue(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, bottomBlock));
|
||||
Assertions.assertTrue(BlockUtils.isWithinWorldBounds(bottomBlock));
|
||||
hashChunkManager.setTrue(bottomBlock);
|
||||
Assertions.assertTrue(hashChunkManager.isTrue(bottomBlock));
|
||||
|
||||
@@ -125,7 +107,7 @@ class ChunkStoreTest {
|
||||
Block topBlock = initMockBlock(1337, 255, -1337);
|
||||
Assertions.assertFalse(hashChunkManager.isTrue(topBlock));
|
||||
|
||||
Assertions.assertTrue(BlockUtils.isWithinWorldBounds(worldCompatibilityLayer, topBlock));
|
||||
Assertions.assertTrue(BlockUtils.isWithinWorldBounds(topBlock));
|
||||
hashChunkManager.setTrue(topBlock);
|
||||
Assertions.assertTrue(hashChunkManager.isTrue(topBlock));
|
||||
}
|
||||
@@ -161,7 +143,7 @@ class ChunkStoreTest {
|
||||
|
||||
@Test
|
||||
void testNegativeWorldMin() throws IOException {
|
||||
Mockito.when(mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(mockWorld)).thenReturn(-64);
|
||||
Mockito.when(mockWorld.getMinHeight()).thenReturn(-64);
|
||||
|
||||
BitSetChunkStore original = new BitSetChunkStore(mockWorld, 1, 2);
|
||||
original.setTrue(14, -32, 12);
|
||||
@@ -180,8 +162,9 @@ class ChunkStoreTest {
|
||||
original.setTrue(13, 3, 12);
|
||||
byte[] serializedBytes = serializeChunkstore(original);
|
||||
|
||||
Mockito.when(mcMMO.getCompatibilityManager().getWorldCompatibilityLayer().getMinWorldHeight(mockWorld)).thenReturn(-64);
|
||||
Mockito.when(mockWorld.getMinHeight()).thenReturn(-64);
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assert deserialized != null;
|
||||
assertEqualIgnoreMinMax(original, deserialized);
|
||||
}
|
||||
|
||||
@@ -202,6 +185,7 @@ class ChunkStoreTest {
|
||||
original.setTrue(13, 89, 12);
|
||||
byte[] serializedBytes = serializeChunkstore(original);
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(new DataInputStream(new ByteArrayInputStream(serializedBytes)));
|
||||
assert deserialized != null;
|
||||
assertEqual(original, deserialized);
|
||||
}
|
||||
|
||||
@@ -221,6 +205,7 @@ class ChunkStoreTest {
|
||||
try (DataInputStream is = region.getInputStream(original.getChunkX(), original.getChunkZ())) {
|
||||
Assertions.assertNotNull(is);
|
||||
ChunkStore deserialized = BitSetChunkStore.Serialization.readChunkStore(is);
|
||||
assert deserialized != null;
|
||||
assertEqual(original, deserialized);
|
||||
}
|
||||
region.close();
|
||||
@@ -299,7 +284,6 @@ class ChunkStoreTest {
|
||||
}
|
||||
|
||||
public static class LegacyChunkStore implements ChunkStore, Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1L;
|
||||
transient private boolean dirty = false;
|
||||
public boolean[][][] store;
|
||||
|
Reference in New Issue
Block a user