Skip to content

Commit b472080

Browse files
committed
[ChunkDataThrottle] Not to always rebuild cache on reload
1 parent a6d7ea5 commit b472080

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

bukkit/version/v1_18/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/chunkdatathrottle/v1_18/ChunkDataThrottleHandlerImpl.kt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,36 @@ class ChunkDataThrottleHandlerImpl: ChunkDataThrottleHandler,
122122

123123
override val counter = ChunkDataThrottleHandler.Counter()
124124

125+
private var previousNonInvisible: Set<Material>? = null
126+
125127
override fun onReload() {
126-
val nonInvisible = config.nonInvisibleBlocksOverrides
127-
BLOCKS_VIEW = PacketEvents.getAPI().serverManager.version.toClientVersion().let { version ->
128-
ByteArray(Block.BLOCK_STATE_REGISTRY.size()) { id ->
129-
val wrapped = WrappedBlockState.getByGlobalId(version, id, false)
130-
if (wrapped.type.materialType == MaterialType.LAVA) {
131-
LAVA_MIN = min(id, LAVA_MIN)
132-
LAVA_MAX = max(id, LAVA_MAX)
133-
}
134-
val material = try {
135-
SpigotConversionUtil.toBukkitBlockData(wrapped).material
136-
} catch (_: Exception) {
137-
SpigotConversionUtil.toBukkitMaterialData(wrapped).itemType
138-
}
139-
if (nonInvisible.contains(material))
140-
false.toByte()
141-
else when (material) {
142-
Material.GLOWSTONE -> true.toByte()
143-
Material.BARRIER -> false.toByte()
144-
else -> material.isOccluding.toByte()
145-
}
146-
}.apply {
147-
for (i in LAVA_MIN..LAVA_MAX) {
148-
this[i] = BV_LAVA_COVERED
128+
if (previousNonInvisible != config.nonInvisibleBlocksOverrides) {
129+
val nonInvisible = config.nonInvisibleBlocksOverrides
130+
BLOCKS_VIEW = PacketEvents.getAPI().serverManager.version.toClientVersion().let { version ->
131+
ByteArray(Block.BLOCK_STATE_REGISTRY.size()) { id ->
132+
val wrapped = WrappedBlockState.getByGlobalId(version, id, false)
133+
if (wrapped.type.materialType == MaterialType.LAVA) {
134+
LAVA_MIN = min(id, LAVA_MIN)
135+
LAVA_MAX = max(id, LAVA_MAX)
136+
}
137+
val material = try {
138+
SpigotConversionUtil.toBukkitBlockData(wrapped).material
139+
} catch (_: Exception) {
140+
SpigotConversionUtil.toBukkitMaterialData(wrapped).itemType
141+
}
142+
if (nonInvisible.contains(material)) false.toByte()
143+
else when (material) {
144+
Material.GLOWSTONE -> true.toByte()
145+
Material.BARRIER -> false.toByte()
146+
else -> material.isOccluding.toByte()
147+
}
148+
}.apply {
149+
for (i in LAVA_MIN..LAVA_MAX) {
150+
this[i] = BV_LAVA_COVERED
151+
}
149152
}
150153
}
154+
previousNonInvisible = nonInvisible
151155
}
152156
}
153157

0 commit comments

Comments
 (0)