Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
detektPlugins(libs.detekt.ktlint)
testImplementation(libs.mockk)
testImplementation(libs.kotest.runner)
testImplementation(libs.kotest.datatest)
testImplementation(libs.mockbukkit)
testImplementation("io.papermc.paper:paper-api:$buildPaperVersion.build.+")
}
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mysql-connector = { module = "com.mysql:mysql-connector-j", version.ref = "mysql
detekt-ktlint = { module = "dev.detekt:detekt-rules-ktlint-wrapper", version.ref = "detekt" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
kotest-runner = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotest-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }
mockbukkit = { module = "org.mockbukkit.mockbukkit:mockbukkit-v26.1.2", version.ref = "mockbukkit" }

[plugins]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xyz.atrius.waystones.data.config.property

import org.koin.core.annotation.Single
import xyz.atrius.waystones.command.resolver.EnumArgumentType
import xyz.atrius.waystones.data.config.ConfigProperty
import xyz.atrius.waystones.data.config.property.type.SafeLiquids
import xyz.atrius.waystones.utility.sanitizedStringFormat

@Single(binds = [ConfigProperty::class])
class SafeLiquidsProperty : ConfigProperty<SafeLiquids>(
property = "safe-liquids",
default = SafeLiquids.WATER,
parser = EnumArgumentType(SafeLiquids::class),
propertyType = SafeLiquids::class,
format = { it.sanitizedStringFormat() },
serialize = { it.name },
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package xyz.atrius.waystones.data.config.property.type

@Suppress("unused")
enum class SafeLiquids {
NONE,
WATER,
ALL,
}
54 changes: 54 additions & 0 deletions src/main/kotlin/xyz/atrius/waystones/service/BlockSafetyService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package xyz.atrius.waystones.service

import org.bukkit.Location
import org.bukkit.Material
import org.koin.core.annotation.Single
import xyz.atrius.waystones.data.config.property.SafeLiquidsProperty
import xyz.atrius.waystones.data.config.property.type.SafeLiquids
import xyz.atrius.waystones.utility.UP

@Single
class BlockSafetyService(
private val safeLiquids: SafeLiquidsProperty,
) {
// Blocks that are non-collidable but still hazardous to teleport into.
// These deal damage or apply harmful effects to entities occupying their space.
private val hazardBlocks = setOf(
Material.FIRE,
Material.SOUL_FIRE,
Material.CAMPFIRE,
Material.SOUL_CAMPFIRE,
Material.SWEET_BERRY_BUSH,
Material.WITHER_ROSE,
)

fun isLocationSafe(waystone: Location): Boolean {
val feet = waystone.UP
val head = feet.UP
// Check the two blocks above the waystone (head and feet clearance).
// Uses isCollidable which reflects actual entity collision geometry,
// unlike isSolid which incorrectly marks signs/pressure plates as solid.
return checkBlock(feet) &&
checkBlock(head)
}

private fun checkBlock(checkLocation: Location): Boolean {
val block = checkLocation.world
?.getBlockAt(checkLocation)
?: return false
val material = block.type
// Physical obstruction check: catches doors, potted plants, fences,
// redstone components with physical presence, all full blocks,
// and any blocks that may cause damage to the player
if (block.isCollidable || material in hazardBlocks) {
return false
}
// Liquid check: configurable via safe-liquids property.
// Liquids have no collision but can still be dangerous or undesirable to land in.
return when (material) {
Material.LAVA -> safeLiquids.value() == SafeLiquids.ALL
Material.WATER -> safeLiquids.value() != SafeLiquids.NONE
else -> true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import xyz.atrius.waystones.manager.LocalizationManager
import xyz.atrius.waystones.manager.LocalizedString
import xyz.atrius.waystones.repository.WaystoneInfoRepository
import xyz.atrius.waystones.utility.isActive
import xyz.atrius.waystones.utility.isSafe
import xyz.atrius.waystones.utility.powerBlock
import xyz.atrius.waystones.utility.sameDimension

Expand All @@ -45,6 +44,7 @@ class WaystoneService(
private val worldRatioService: WorldRatioService,
private val limitDistance: LimitDistanceProperty,
private val waystoneInfoRepository: WaystoneInfoRepository,
private val blockSafetyService: BlockSafetyService,
) {

fun process(player: Player, block: Block, keyLocation: Location): Either<WaystoneServiceError, Warp> = either {
Expand Down Expand Up @@ -209,7 +209,7 @@ class WaystoneService(
return WaystoneStatus.Unpowered(localization)
}

if (!block.location.isSafe) {
if (!blockSafetyService.isLocationSafe(block.location)) {
return WaystoneStatus.Obstructed(localization)
}

Expand Down
12 changes: 0 additions & 12 deletions src/main/kotlin/xyz/atrius/waystones/utility/Location.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ val Location.neighbors: List<Location>
val Location.locationCode
get() = "${world?.name}@$blockX:$blockY:$blockZ"

// Determines if the selected block is safe to spawn on
val Location.isSafe: Boolean
get() = !listOf(UP, UP.UP)
.map {
world
?.getBlockAt(it)
?.type
?.isSolid
?: true
}
.any { it }

fun Location.rotateY(angle: Double, amp: Double = 1.0) = add(
Vector(
cos(angle) * amp,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ relinkable-keys: true
enable-key-items: true
enable-advancements: true
show-compass-coordinates: true
safe-liquids: WATER
key-recipe:
- AIR
- IRON_INGOT
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locale-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ property-warp-animations-info: "Whether to use particle animations while warping
property-default-world-ratio-info: "The world ratio to use for worlds which have no ratio set"
property-base-distance-info: "The baseline for which all waystones are given as a minimum teleport distance"
property-show-compass-coordinates-info: "Whether to show waystone coordinates in the compass lore upon linking"
property-safe-liquids-info: "Determines which liquids are considered safe when obstructing a waystone"
default-subcommand-desc: "No description provided"
ws-ratio-subcommand-desc: "Adjust the warp distance ratios between worlds"
ws-reload-subcommand-desc: "Reload aspects of the plugin"
Expand Down
Loading
Loading