Skip to content

Commit

Permalink
Revert piston intersections to cancelling event due to a stack overfl…
Browse files Browse the repository at this point in the history
…ow crash
  • Loading branch information
0ffz committed Dec 6, 2023
1 parent 2e2bcf9 commit 32cb88e
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mineinabyss.deeperworld.synchronization

import com.mineinabyss.deeperworld.world.section.correspondingLocation
import com.mineinabyss.deeperworld.world.section.correspondingSection
import com.mineinabyss.deeperworld.world.section.inSectionOverlap
import io.papermc.paper.event.block.BlockBreakBlockEvent
import org.bukkit.Material
Expand All @@ -14,25 +15,31 @@ object ExploitPreventionListener : Listener {

@EventHandler(ignoreCancelled = true)
fun BlockPistonExtendEvent.onPistonExtendEvent() {
val corrBlock = block.location.correspondingLocation?.block ?: return
val corrBlocks = mutableListOf<Block>()

if (blocks.all { b -> !b.location.inSectionOverlap }) return
if (!corrBlock.location.isChunkLoaded) corrBlock.chunk.load()
corrBlocks.addAll(blocks.map { b -> b.location.correspondingLocation?.block ?: return@map null }.filterNotNull())
BlockPistonExtendEvent(corrBlock, corrBlocks, direction).callEvent()
//TODO handle pistons properly instead of just cancelling the event
if (blocks.any { it.location.correspondingSection != null })
isCancelled = true
// val corrBlock = block.location.correspondingLocation?.block ?: return
// val corrBlocks = mutableListOf<Block>()
//
// if (blocks.all { b -> !b.location.inSectionOverlap }) return
// if (!corrBlock.location.isChunkLoaded) corrBlock.chunk.load()
// corrBlocks.addAll(blocks.map { b -> b.location.correspondingLocation?.block ?: return@map null }.filterNotNull())
// BlockPistonExtendEvent(corrBlock, corrBlocks, direction).callEvent()
}

@EventHandler(ignoreCancelled = true)
fun BlockPistonRetractEvent.onPistonRetractEvent() {
val corrBlock = block.location.correspondingLocation?.block ?: return
val corrBlocks = mutableListOf<Block>()

if (blocks.all { b -> !b.location.inSectionOverlap }) return
if (!corrBlock.location.isChunkLoaded) corrBlock.chunk.load()

corrBlocks.addAll(blocks.map { b -> b.location.correspondingLocation?.block ?: return@map null }.filterNotNull())
BlockPistonRetractEvent(corrBlock, corrBlocks, direction).callEvent()
//TODO handle pistons properly instead of just cancelling the event
if (blocks.any { it.location.correspondingSection != null })
isCancelled = true
// val corrBlock = block.location.correspondingLocation?.block ?: return
// val corrBlocks = mutableListOf<Block>()
//
// if (blocks.all { b -> !b.location.inSectionOverlap }) return
// if (!corrBlock.location.isChunkLoaded) corrBlock.chunk.load()
//
// corrBlocks.addAll(blocks.map { b -> b.location.correspondingLocation?.block ?: return@map null }.filterNotNull())
// BlockPistonRetractEvent(corrBlock, corrBlocks, direction).callEvent()
}

@EventHandler
Expand Down

0 comments on commit 32cb88e

Please sign in to comment.