Skip to content

Commit

Permalink
V1.0.3 传送/跨世界 检测
Browse files Browse the repository at this point in the history
  • Loading branch information
YsGqHY committed Jan 26, 2024
1 parent c0b7882 commit 42bba5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=kim.hhhhhy.regions
version=1.0.2
version=1.0.3
16 changes: 10 additions & 6 deletions src/main/kotlin/kim/hhhhhy/regions/data/AreaSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ data class AreaSettings(
val x = location.x
val y = location.y
val z = location.z
return areasData.filter {
it.value.position.world == location.world?.name
&& (x in it.value.position.xMax .. it.value.position.xMin || x in it.value.position.xMin .. it.value.position.xMax)
&& (y in it.value.position.yMax .. it.value.position.yMin || y in it.value.position.yMin .. it.value.position.yMax)
&& (z in it.value.position.zMax .. it.value.position.zMin || z in it.value.position.zMin .. it.value.position.zMax)
}.map { it.key }
val worldName = location.world?.name

return areasData.filter { area ->
val pos = area.value.position
val isSameWorld = pos.world == worldName
val isXInRange = x in pos.xMin..pos.xMax || x in pos.xMax..pos.xMin
val isYInRange = y in pos.yMin..pos.yMax || y in pos.yMax..pos.yMin
val isZInRange = z in pos.zMin..pos.zMax || z in pos.zMax..pos.zMin

isSameWorld && isXInRange && isYInRange && isZInRange
}.map { it.key }
}

private fun runEnterAction(player: Player, id: String) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/kim/hhhhhy/regions/listeners/AreaListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import kim.hhhhhy.regions.data.AreaSettings
import kim.hhhhhy.regions.data.area.AreaType
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.event.player.PlayerChangedWorldEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.event.player.PlayerQuitEvent
import org.bukkit.event.player.PlayerTeleportEvent
import taboolib.common.platform.event.SubscribeEvent

object AreaListener {
Expand All @@ -21,6 +23,15 @@ object AreaListener {
check(player, to)
}

@SubscribeEvent
fun onTeleport(e: PlayerTeleportEvent) {
val from = e.from
val to = e.to ?: return
if (from.world?.name == to.world?.name && from.x == to.x && from.y == to.y && from.z == to.z) return
val player = e.player
check(player, to)
}

@SubscribeEvent
fun onPlayerJoin(e: PlayerJoinEvent) {
check(e.player, e.player.location)
Expand Down

0 comments on commit 42bba5d

Please sign in to comment.