Implement chaos module for rotating chunks when a player enters.

This commit is contained in:
Alex Zenla 2023-04-02 01:51:26 -07:00
parent 83ccc31222
commit 56886a24e1
Signed by: alex
GPG Key ID: C0780728420EBFE5
2 changed files with 44 additions and 1 deletions

View File

@ -10,6 +10,7 @@ object ChaosModules {
TntAllPlayers(plugin),
MegaTnt(plugin),
PlayerSwap(plugin),
WorldSwapper(plugin)
WorldSwapper(plugin),
ChunkEnterRotate()
).shuffled()
}

View File

@ -0,0 +1,42 @@
package gay.pizza.foundation.chaos.modules
import org.bukkit.Chunk
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerMoveEvent
import java.util.WeakHashMap
class ChunkEnterRotate : ChaosModule {
override fun id(): String = "chunk-enter-rotate"
override fun name(): String = "Chunk Enter Rotate"
override fun what(): String = "Rotates the chunk when the player enters a chunk."
private val playerChunkMap = WeakHashMap<Player, Chunk>()
@EventHandler
fun onPotentialChunkMove(event: PlayerMoveEvent) {
val player = event.player
val currentChunk = event.player.chunk
val previousChunk = playerChunkMap.put(player, currentChunk)
if (previousChunk == null || previousChunk == currentChunk) {
return
}
rotateChunk(currentChunk)
if (!player.isFlying) {
player.teleport(player.location.toHighestLocation().add(0.0, 1.0, 0.0))
}
}
private fun rotateChunk(chunk: Chunk) {
val snapshot = chunk.chunkSnapshot
for (x in 0..15) {
for (z in 0..15) {
for (y in chunk.world.minHeight until chunk.world.maxHeight) {
val rotatedBlock = chunk.getBlock(z, y, x)
val originalBlockData = snapshot.getBlockData(x, y, z)
rotatedBlock.blockData = originalBlockData
}
}
}
}
}