-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update, fix and add more sync stuff (#93)
- Loading branch information
Showing
8 changed files
with
127 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.mineinabyss.deeperworld | ||
|
||
object Permissions { | ||
const val CHANGE_SECTION_PERMISSION = "deeperworld.changesection" | ||
const val ADMIN_PERMISSION = "deeperworld.admin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 31 additions & 11 deletions
42
src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ExploitPreventionListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,44 @@ | ||
package com.mineinabyss.deeperworld.synchronization | ||
|
||
import com.mineinabyss.deeperworld.world.section.correspondingSection | ||
import com.mineinabyss.deeperworld.world.section.correspondingLocation | ||
import com.mineinabyss.deeperworld.world.section.inSectionOverlap | ||
import io.papermc.paper.event.block.BlockBreakBlockEvent | ||
import org.bukkit.Material | ||
import org.bukkit.block.Block | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.block.BlockPistonExtendEvent | ||
import org.bukkit.event.block.BlockPistonRetractEvent | ||
|
||
object ExploitPreventionListener : Listener { | ||
/** Disables pistons extending if they are in the overlap of two sections */ | ||
@EventHandler | ||
fun onPistonExtendEvent(event: BlockPistonExtendEvent) { | ||
//TODO handle pistons properly instead of just cancelling the event | ||
if (event.blocks.any { it.location.correspondingSection != null }) | ||
event.isCancelled = true | ||
|
||
@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() | ||
} | ||
|
||
@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() | ||
} | ||
|
||
/** Disables pistons retracting if they are in the overlap of two sections */ | ||
@EventHandler | ||
fun onPistonRetractEvent(event: BlockPistonRetractEvent) { | ||
if (event.blocks.any { it.location.correspondingSection != null }) | ||
event.isCancelled = true | ||
fun BlockBreakBlockEvent.onPistonBreakBlock() { | ||
val corrBlock = block.location.correspondingLocation?.block ?: return | ||
source.location.correspondingLocation?.block ?: return | ||
corrBlock.setType(Material.AIR, false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.