From 2ad38fa4f91ee61b5d3ccddaf9f15522a1060dd6 Mon Sep 17 00:00:00 2001 From: Sven Date: Tue, 26 May 2026 16:27:07 +0200 Subject: [PATCH] Generate hideStateTypes from hideMaterials --- .../net/trueog/antipierayog/AntiPieRay.kt | 46 ++++--------------- .../trueog/antipierayog/BlockEntityHider.kt | 3 +- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/net/trueog/antipierayog/AntiPieRay.kt b/src/main/kotlin/net/trueog/antipierayog/AntiPieRay.kt index 1a19377..e5a2d63 100644 --- a/src/main/kotlin/net/trueog/antipierayog/AntiPieRay.kt +++ b/src/main/kotlin/net/trueog/antipierayog/AntiPieRay.kt @@ -3,8 +3,8 @@ package net.trueog.antipierayog import com.github.retrooper.packetevents.PacketEvents import com.github.retrooper.packetevents.event.PacketListenerPriority import com.github.retrooper.packetevents.protocol.world.states.type.StateType -import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder +import io.github.retrooper.packetevents.util.SpigotConversionUtil import java.util.* import org.bukkit.Bukkit import org.bukkit.Material @@ -14,7 +14,6 @@ class AntiPieRay : JavaPlugin() { companion object { lateinit var plugin: AntiPieRay lateinit var blockEntityHider: BlockEntityHider - val hideStateTypes: MutableSet = Collections.newSetFromMap(IdentityHashMap()) val hideMaterials: MutableSet = Collections.newSetFromMap(IdentityHashMap()).apply { addAll( @@ -53,47 +52,18 @@ class AntiPieRay : JavaPlugin() { ) ) } + val hideStateTypes: MutableSet = Collections.newSetFromMap(IdentityHashMap(hideMaterials.size)) } override fun onLoad() { PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this)) PacketEvents.getAPI().load() - // Has to be here otherwise the plugin doesn't load - hideStateTypes.addAll( - listOf( - // - StateTypes.CHEST, - StateTypes.TRAPPED_CHEST, - StateTypes.SHULKER_BOX, - StateTypes.WHITE_SHULKER_BOX, - StateTypes.ORANGE_SHULKER_BOX, - StateTypes.MAGENTA_SHULKER_BOX, - StateTypes.LIGHT_BLUE_SHULKER_BOX, - StateTypes.YELLOW_SHULKER_BOX, - StateTypes.LIME_SHULKER_BOX, - StateTypes.PINK_SHULKER_BOX, - StateTypes.GRAY_SHULKER_BOX, - StateTypes.LIGHT_GRAY_SHULKER_BOX, - StateTypes.CYAN_SHULKER_BOX, - StateTypes.PURPLE_SHULKER_BOX, - StateTypes.BLUE_SHULKER_BOX, - StateTypes.BROWN_SHULKER_BOX, - StateTypes.GREEN_SHULKER_BOX, - StateTypes.RED_SHULKER_BOX, - StateTypes.BLACK_SHULKER_BOX, - StateTypes.CAMPFIRE, - StateTypes.SOUL_CAMPFIRE, - StateTypes.BEACON, - StateTypes.ENCHANTING_TABLE, - StateTypes.DRAGON_HEAD, - StateTypes.DRAGON_WALL_HEAD, - StateTypes.CONDUIT, - StateTypes.BELL, - StateTypes.ENDER_CHEST, - StateTypes.SPAWNER, - // - ) - ) + + // Convert all the hidden materials to a PacketEvents StateType + hideMaterials.forEach { + SpigotConversionUtil.fromBukkitItemMaterial(it).placedType?.let { element -> hideStateTypes.add(element) } + } + PacketEvents.getAPI().eventManager.registerListener(ChunkDataPacketListener(), PacketListenerPriority.NORMAL) PacketEvents.getAPI().eventManager.registerListener(BlockChangePacketListener(), PacketListenerPriority.NORMAL) PacketEvents.getAPI() diff --git a/src/main/kotlin/net/trueog/antipierayog/BlockEntityHider.kt b/src/main/kotlin/net/trueog/antipierayog/BlockEntityHider.kt index 9d5a2e7..067e03e 100644 --- a/src/main/kotlin/net/trueog/antipierayog/BlockEntityHider.kt +++ b/src/main/kotlin/net/trueog/antipierayog/BlockEntityHider.kt @@ -93,7 +93,8 @@ class BlockEntityHider { get() { val craftWorld = (world as CraftWorld).handle val serverChunkCache = (craftWorld as ServerLevel).getChunkSource() - val chunk = serverChunkCache.getChunkAtIfLoadedMainThread(this.x shr 4, this.z shr 4) ?: return Material.AIR + val chunk = + serverChunkCache.getChunkAtIfLoadedMainThread(this.x shr 4, this.z shr 4) ?: return Material.AIR val blockState = chunk.getBlockState(BlockPos(this.x, this.y, this.z)) return blockState.bukkitMaterial } -- 2.47.3