diff --git a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/NMSSpawnersImpl.java b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/NMSSpawnersImpl.java index 69900125e..3df3cf859 100644 --- a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/NMSSpawnersImpl.java +++ b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/NMSSpawnersImpl.java @@ -44,11 +44,22 @@ import java.util.LinkedList; import java.util.List; import java.util.function.BiPredicate; +import java.util.function.Supplier; public final class NMSSpawnersImpl implements NMSSpawners { private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED = new ReflectField<>( Level.class, List.class, Modifier.PROTECTED | Modifier.FINAL, 1); + private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC = new ReflectField<>( + Level.class, List.class, Modifier.PUBLIC | Modifier.FINAL, 1); + private static final boolean isSparklyPaper = ((Supplier) () -> { + try { + Class.forName("net.sparklypower.sparklypaper.BlockEntityTickersList"); + return true; + } catch (ClassNotFoundException error) { + return false; + } + }).get(); private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); @@ -89,12 +100,7 @@ public void updateStackedSpawners(Chunk chunk) { int chunkX = chunk.getX(); int chunkZ = chunk.getZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); List watchersToAdd = new LinkedList<>(); Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -129,12 +135,7 @@ public void updateStackedSpawner(StackedSpawner stackedSpawner) { int blockY = location.getBlockY(); int blockZ = location.getBlockZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); TickingBlockEntity watcherToAdd = null; Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -333,4 +334,12 @@ public SyncedCreatureSpawner createSyncedSpawner(CreatureSpawner creatureSpawner return new SyncedCreatureSpawnerImpl(bukkitWorld, spawnerBlockEntity); } + private static List getBlockEntityTickers(Level level) { + if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(level); + if (isSparklyPaper && LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.get(level); + return level.blockEntityTickers; + } + } diff --git a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/spawner/SpawnerWatcherTickingBlockEntity.java b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/spawner/SpawnerWatcherTickingBlockEntity.java index 7a62b6669..29304f690 100644 --- a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/spawner/SpawnerWatcherTickingBlockEntity.java +++ b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_3/spawner/SpawnerWatcherTickingBlockEntity.java @@ -1,5 +1,6 @@ package com.bgsoftware.wildstacker.nms.v1_20_3.spawner; +import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildstacker.WildStackerPlugin; import com.bgsoftware.wildstacker.api.objects.StackedSpawner; import net.minecraft.core.BlockPos; @@ -12,6 +13,9 @@ public class SpawnerWatcherTickingBlockEntity implements TickingBlockEntity { + private static final ReflectMethod GET_CHUNK_COORD_KEY = new ReflectMethod<>( + TickingBlockEntity.class, "getChunkCoordinateKey"); + private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); private static final String CLASS_NAME = SpawnerWatcherTickingBlockEntity.class.getSimpleName(); @@ -92,4 +96,8 @@ public String getType() { return this.type; } + public long getChunkCoordinateKey() { + return GET_CHUNK_COORD_KEY.invoke(this.original); + } + } diff --git a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/NMSSpawnersImpl.java b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/NMSSpawnersImpl.java index e461d170d..ce300472d 100644 --- a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/NMSSpawnersImpl.java +++ b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/NMSSpawnersImpl.java @@ -44,11 +44,22 @@ import java.util.LinkedList; import java.util.List; import java.util.function.BiPredicate; +import java.util.function.Supplier; public final class NMSSpawnersImpl implements NMSSpawners { private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED = new ReflectField<>( Level.class, List.class, Modifier.PROTECTED | Modifier.FINAL, 1); + private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC = new ReflectField<>( + Level.class, List.class, Modifier.PUBLIC | Modifier.FINAL, 1); + private static final boolean isSparklyPaper = ((Supplier) () -> { + try { + Class.forName("net.sparklypower.sparklypaper.BlockEntityTickersList"); + return true; + } catch (ClassNotFoundException error) { + return false; + } + }).get(); private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); @@ -89,12 +100,7 @@ public void updateStackedSpawners(Chunk chunk) { int chunkX = chunk.getX(); int chunkZ = chunk.getZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); List watchersToAdd = new LinkedList<>(); Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -129,12 +135,7 @@ public void updateStackedSpawner(StackedSpawner stackedSpawner) { int blockY = location.getBlockY(); int blockZ = location.getBlockZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); TickingBlockEntity watcherToAdd = null; Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -333,4 +334,12 @@ public SyncedCreatureSpawner createSyncedSpawner(CreatureSpawner creatureSpawner return new SyncedCreatureSpawnerImpl(bukkitWorld, spawnerBlockEntity); } + private static List getBlockEntityTickers(Level level) { + if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(level); + if (isSparklyPaper && LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.get(level); + return level.blockEntityTickers; + } + } diff --git a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/spawner/SpawnerWatcherTickingBlockEntity.java b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/spawner/SpawnerWatcherTickingBlockEntity.java index a3b68d7fe..c5bc5f9f1 100644 --- a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/spawner/SpawnerWatcherTickingBlockEntity.java +++ b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildstacker/nms/v1_20_4/spawner/SpawnerWatcherTickingBlockEntity.java @@ -1,5 +1,6 @@ package com.bgsoftware.wildstacker.nms.v1_20_4.spawner; +import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildstacker.WildStackerPlugin; import com.bgsoftware.wildstacker.api.objects.StackedSpawner; import net.minecraft.core.BlockPos; @@ -12,6 +13,9 @@ public class SpawnerWatcherTickingBlockEntity implements TickingBlockEntity { + private static final ReflectMethod GET_CHUNK_COORD_KEY = new ReflectMethod<>( + TickingBlockEntity.class, "getChunkCoordinateKey"); + private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); private static final String CLASS_NAME = SpawnerWatcherTickingBlockEntity.class.getSimpleName(); @@ -76,4 +80,8 @@ public String getType() { return this.type; } + public long getChunkCoordinateKey() { + return GET_CHUNK_COORD_KEY.invoke(this.original); + } + } diff --git a/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/NMSSpawnersImpl.java b/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/NMSSpawnersImpl.java index f86f38b04..9b54a1a90 100644 --- a/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/NMSSpawnersImpl.java +++ b/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/NMSSpawnersImpl.java @@ -44,11 +44,22 @@ import java.util.LinkedList; import java.util.List; import java.util.function.BiPredicate; +import java.util.function.Supplier; public final class NMSSpawnersImpl implements NMSSpawners { private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED = new ReflectField<>( Level.class, List.class, Modifier.PROTECTED | Modifier.FINAL, 1); + private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC = new ReflectField<>( + Level.class, List.class, Modifier.PUBLIC | Modifier.FINAL, 1); + private static final boolean isSparklyPaper = ((Supplier) () -> { + try { + Class.forName("net.sparklypower.sparklypaper.BlockEntityTickersList"); + return true; + } catch (ClassNotFoundException error) { + return false; + } + }).get(); private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); @@ -89,12 +100,7 @@ public void updateStackedSpawners(Chunk chunk) { int chunkX = chunk.getX(); int chunkZ = chunk.getZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); List watchersToAdd = new LinkedList<>(); Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -129,12 +135,7 @@ public void updateStackedSpawner(StackedSpawner stackedSpawner) { int blockY = location.getBlockY(); int blockZ = location.getBlockZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); TickingBlockEntity watcherToAdd = null; Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -333,4 +334,12 @@ public SyncedCreatureSpawner createSyncedSpawner(CreatureSpawner creatureSpawner return new SyncedCreatureSpawnerImpl(bukkitWorld, spawnerBlockEntity); } + private static List getBlockEntityTickers(Level level) { + if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(level); + if (isSparklyPaper && LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.get(level); + return level.blockEntityTickers; + } + } diff --git a/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/spawner/SpawnerWatcherTickingBlockEntity.java b/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/spawner/SpawnerWatcherTickingBlockEntity.java index 4142ddeb3..7c8f13fbd 100644 --- a/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/spawner/SpawnerWatcherTickingBlockEntity.java +++ b/NMS/v1_21/src/main/java/com/bgsoftware/wildstacker/nms/v1_21/spawner/SpawnerWatcherTickingBlockEntity.java @@ -1,5 +1,6 @@ package com.bgsoftware.wildstacker.nms.v1_21.spawner; +import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildstacker.WildStackerPlugin; import com.bgsoftware.wildstacker.api.objects.StackedSpawner; import net.minecraft.core.BlockPos; @@ -12,6 +13,9 @@ public class SpawnerWatcherTickingBlockEntity implements TickingBlockEntity { + private static final ReflectMethod GET_CHUNK_COORD_KEY = new ReflectMethod<>( + TickingBlockEntity.class, "getChunkCoordinateKey"); + private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); private static final String CLASS_NAME = SpawnerWatcherTickingBlockEntity.class.getSimpleName(); @@ -76,4 +80,8 @@ public String getType() { return this.type; } + public long getChunkCoordinateKey() { + return GET_CHUNK_COORD_KEY.invoke(this.original); + } + } diff --git a/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/NMSSpawnersImpl.java b/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/NMSSpawnersImpl.java index 4a219a65b..9c4e33e24 100644 --- a/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/NMSSpawnersImpl.java +++ b/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/NMSSpawnersImpl.java @@ -44,11 +44,22 @@ import java.util.LinkedList; import java.util.List; import java.util.function.BiPredicate; +import java.util.function.Supplier; public final class NMSSpawnersImpl implements NMSSpawners { private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED = new ReflectField<>( Level.class, List.class, Modifier.PROTECTED | Modifier.FINAL, 1); + private static final ReflectField> LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC = new ReflectField<>( + Level.class, List.class, Modifier.PUBLIC | Modifier.FINAL, 1); + private static final boolean isSparklyPaper = ((Supplier) () -> { + try { + Class.forName("net.sparklypower.sparklypaper.BlockEntityTickersList"); + return true; + } catch (ClassNotFoundException error) { + return false; + } + }).get(); private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); @@ -89,12 +100,7 @@ public void updateStackedSpawners(Chunk chunk) { int chunkX = chunk.getX(); int chunkZ = chunk.getZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); List watchersToAdd = new LinkedList<>(); Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -129,12 +135,7 @@ public void updateStackedSpawner(StackedSpawner stackedSpawner) { int blockY = location.getBlockY(); int blockZ = location.getBlockZ(); - List blockEntityTickers; - if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) { - blockEntityTickers = LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(serverLevel); - } else { - blockEntityTickers = serverLevel.blockEntityTickers; - } + List blockEntityTickers = getBlockEntityTickers(serverLevel); TickingBlockEntity watcherToAdd = null; Iterator blockEntityIterator = blockEntityTickers.iterator(); @@ -333,4 +334,12 @@ public SyncedCreatureSpawner createSyncedSpawner(CreatureSpawner creatureSpawner return new SyncedCreatureSpawnerImpl(bukkitWorld, spawnerBlockEntity); } + private static List getBlockEntityTickers(Level level) { + if (LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PROTECTED.get(level); + if (isSparklyPaper && LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.isValid()) + return LEVEL_BLOCK_ENTITY_TICKERS_PUBLIC.get(level); + return level.blockEntityTickers; + } + } diff --git a/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/spawner/SpawnerWatcherTickingBlockEntity.java b/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/spawner/SpawnerWatcherTickingBlockEntity.java index 066a7959c..90c1037f5 100644 --- a/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/spawner/SpawnerWatcherTickingBlockEntity.java +++ b/NMS/v1_21_3/src/main/java/com/bgsoftware/wildstacker/nms/v1_21_3/spawner/SpawnerWatcherTickingBlockEntity.java @@ -1,5 +1,6 @@ package com.bgsoftware.wildstacker.nms.v1_21_3.spawner; +import com.bgsoftware.common.reflection.ReflectMethod; import com.bgsoftware.wildstacker.WildStackerPlugin; import com.bgsoftware.wildstacker.api.objects.StackedSpawner; import net.minecraft.core.BlockPos; @@ -12,6 +13,9 @@ public class SpawnerWatcherTickingBlockEntity implements TickingBlockEntity { + private static final ReflectMethod GET_CHUNK_COORD_KEY = new ReflectMethod<>( + TickingBlockEntity.class, "getChunkCoordinateKey"); + private static final WildStackerPlugin plugin = WildStackerPlugin.getPlugin(); private static final String CLASS_NAME = SpawnerWatcherTickingBlockEntity.class.getSimpleName(); @@ -76,4 +80,8 @@ public String getType() { return this.type; } + public long getChunkCoordinateKey() { + return GET_CHUNK_COORD_KEY.invoke(this.original); + } + }