mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-02 21:20:55 +00:00
Pair programming with @Nanokie on a world swapper plugin :D
This commit is contained in:
parent
53bdc3a4cb
commit
b7ce799593
@ -1,7 +1,11 @@
|
||||
package gay.pizza.foundation.chaos
|
||||
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.Server
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
fun Location.nearestPlayer(): Player? =
|
||||
world?.players?.minByOrNull { it.location.distance(this) }
|
||||
|
||||
fun Server.randomPlayer(): Player? =
|
||||
onlinePlayers.randomOrNull()
|
||||
|
@ -9,6 +9,7 @@ object ChaosModules {
|
||||
KillRandomPlayer(plugin),
|
||||
TntAllPlayers(plugin),
|
||||
MegaTnt(plugin),
|
||||
PlayerSwap(plugin)
|
||||
PlayerSwap(plugin),
|
||||
WorldSwapper(plugin)
|
||||
).shuffled()
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package gay.pizza.foundation.chaos.modules
|
||||
|
||||
import gay.pizza.foundation.chaos.randomPlayer
|
||||
import org.bukkit.ChunkSnapshot
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
class WorldSwapper(val plugin: Plugin) : ChaosModule {
|
||||
override fun id(): String = "world-swapper"
|
||||
override fun name(): String = "World Swapper"
|
||||
override fun what(): String = "Swaps the world vertically on activation, and un-swaps it on deactivation."
|
||||
|
||||
var snapshot: ChunkSnapshot? = null
|
||||
|
||||
override fun activate() {
|
||||
val player = plugin.server.randomPlayer() ?: return
|
||||
val chunk = player.world.getChunkAt(player.location)
|
||||
val localSnapshot = chunk.chunkSnapshot
|
||||
|
||||
for (x in 0..15) {
|
||||
for (z in 0..15) {
|
||||
val heightRange = (chunk.world.minHeight + 1) until chunk.world.maxHeight
|
||||
for (y in heightRange) {
|
||||
val targetBlock = chunk.getBlock(x, y, z)
|
||||
val inverseY = heightRange.random()
|
||||
val nextBlock = localSnapshot.getBlockData(x, inverseY, z)
|
||||
targetBlock.setBlockData(nextBlock, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
snapshot = localSnapshot
|
||||
}
|
||||
|
||||
override fun deactivate() {
|
||||
val localSnapshot = snapshot ?: return
|
||||
val world = plugin.server.getWorld(localSnapshot.worldName) ?: return
|
||||
val chunk = world.getChunkAt(localSnapshot.x, localSnapshot.z)
|
||||
|
||||
for (x in 0..15) {
|
||||
for (z in 0..15) {
|
||||
val heightRange = chunk.world.minHeight + 1 until chunk.world.maxHeight
|
||||
for (y in heightRange) {
|
||||
val originalBlock = localSnapshot.getBlockData(x, y, z)
|
||||
chunk.getBlock(x, y, z).blockData = originalBlock
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user