Add pit wall replace function

This commit is contained in:
TDSTOS
2026-04-17 03:45:14 +02:00
parent f30108ca1d
commit 601eddca30
2 changed files with 63 additions and 2 deletions

View File

@@ -116,13 +116,29 @@ class PitManager(private val plugin: SpeedHG) {
// ── 2. Luftschacht von Boden+1 bis über die Oberfläche ──────────────── // ── 2. Luftschacht von Boden+1 bis über die Oberfläche ────────────────
WorldEditUtils.createCylinder( world, airStartLoc, PIT_RADIUS, true, airHeight, Material.AIR ) WorldEditUtils.createCylinder( world, airStartLoc, PIT_RADIUS, true, airHeight, Material.AIR )
// ── 3. Broadcast sofort ─────────────────────────────────────────────── // ── 3. Wasser & Lava in den Wänden durch Glas ersetzen ────────────────
// Radius + 1: erfasst die 1-Block-dicke Wand direkt außerhalb des Schachts.
// Nur WATER, LAVA und AIR werden ersetzt — kein Terrain-Block wird angefasst.
val wallLoc = Location( world, PIT_X, ( pitFloorY + 1 ).toDouble(), PIT_Z )
WorldEditUtils.replaceCylinder(
world,
wallLoc,
PIT_RADIUS + 1,
airHeight,
setOf( Material.WATER, Material.LAVA, Material.AIR ),
Material.GRAY_STAINED_GLASS
)
// ── 4. Pit-Inneres nochmals mit Luft freiräumen (Glas das rein gerutscht ist) ─
WorldEditUtils.createCylinder( world, airStartLoc, PIT_RADIUS, true, airHeight, Material.AIR )
// ── 5. Broadcast sofort ───────────────────────────────────────────────
Bukkit.getOnlinePlayers().forEach { p -> Bukkit.getOnlinePlayers().forEach { p ->
p.sendMsg( "pit.spawned" ) p.sendMsg( "pit.spawned" )
p.playSound( p.location, Sound.ENTITY_WITHER_SPAWN, 1f, 0.5f ) p.playSound( p.location, Sound.ENTITY_WITHER_SPAWN, 1f, 0.5f )
} }
// ── 4. Spieler teleportieren (kurz nach WorldEdit-Commit) ───────────── // ── 6. Spieler teleportieren (kurz nach WorldEdit-Commit) ─────────────
Bukkit.getScheduler().runTaskLater( plugin, { -> Bukkit.getScheduler().runTaskLater( plugin, { ->
teleportPlayersToPit( world ) teleportPlayersToPit( world )
startEscapeCheck( world ) startEscapeCheck( world )

View File

@@ -2,7 +2,11 @@ package club.mcscrims.speedhg.util
import com.sk89q.worldedit.WorldEdit import com.sk89q.worldedit.WorldEdit
import com.sk89q.worldedit.bukkit.BukkitAdapter import com.sk89q.worldedit.bukkit.BukkitAdapter
import com.sk89q.worldedit.function.mask.BlockTypeMask
import com.sk89q.worldedit.math.Vector2
import com.sk89q.worldedit.regions.CylinderRegion
import com.sk89q.worldedit.util.SideEffectSet import com.sk89q.worldedit.util.SideEffectSet
import com.sk89q.worldedit.world.block.BlockTypes
import org.bukkit.Location import org.bukkit.Location
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.World import org.bukkit.World
@@ -86,4 +90,45 @@ object WorldEditUtils {
e.printStackTrace() e.printStackTrace()
} }
fun replaceCylinder(
world: World,
center: Location,
radius: Int,
height: Int,
replaceMaterials: Set<Material>,
replacement: Material
) = try {
val weWorld = BukkitAdapter.adapt( world )
val centerVec = BukkitAdapter.asBlockVector( center )
val radiusVec = Vector2.at( radius.toDouble(), radius.toDouble() )
val region = CylinderRegion(
weWorld,
centerVec,
radiusVec,
centerVec.y,
centerVec.y + height - 1
)
val editSession = WorldEdit.getInstance().newEditSessionBuilder()
.world( weWorld ).maxBlocks( -1 ).build()
editSession.sideEffectApplier = SideEffectSet.defaults()
val mask = BlockTypeMask(
editSession,
replaceMaterials.mapNotNull { mat ->
BlockTypes.get("minecraft:${mat.key.key}")
}
)
val replacementState = BukkitAdapter.asBlockState( ItemStack( replacement ) )
editSession.replaceBlocks( region, mask, replacementState )
editSession.commit()
editSession.close()
} catch ( e: Exception ) {
e.printStackTrace()
}
} }