Compare commits

..
4 Commits
9 changed files with 225 additions and 21 deletions
-3
View File
@@ -1,6 +1,3 @@
[submodule "kommand-lib"]
path = kommand-lib
url = git@gitea.hareworks.net:Hare/kommand-lib.git
[submodule "permits-lib"]
path = permits-lib
url = git@gitea.hareworks.net:Hare/permits-lib.git
+13 -13
View File
@@ -18,21 +18,21 @@ val exposedVersion = "1.0.0-rc-4"
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
compileOnly("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlin:kotlin-stdlib")
compileOnly("net.kyori:adventure-api:4.25.0")
compileOnly("net.kyori:adventure-text-minimessage:4.25.0")
implementation("net.kyori:adventure-api:4.25.0")
implementation("net.kyori:adventure-text-minimessage:4.25.0")
compileOnly("org.postgresql:postgresql:42.7.8")
compileOnly("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
compileOnly("org.jetbrains.exposed:exposed-core:$exposedVersion")
compileOnly("org.jetbrains.exposed:exposed-dao:$exposedVersion")
compileOnly("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
compileOnly("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion")
compileOnly("com.michael-bull.kotlin-result:kotlin-result:2.1.0")
compileOnly("net.hareworks:kommand-lib:1.1")
compileOnly("net.hareworks:permits-lib:1.1")
implementation("org.postgresql:postgresql:42.7.8")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion")
implementation("com.michael-bull.kotlin-result:kotlin-result:2.1.0")
implementation("net.hareworks:kommand-lib:1.1")
implementation("net.hareworks:permits-lib:1.1")
}
tasks {
withType<Jar> {
Submodule permits-lib deleted from 660f9a3436
+1 -2
View File
@@ -1,4 +1,3 @@
rootProject.name = "elevator"
includeBuild("kommand-lib")
includeBuild("permits-lib")
includeBuild("kommand-lib")
@@ -1,8 +1,18 @@
package com.github.kaaariyaaa.elevator;
import com.github.kaaariyaaa.elevator.command.CommandRegistrar
import net.hareworks.kommand_lib.KommandLib
import net.hareworks.permits_lib.PermitsLib
import net.hareworks.permits_lib.domain.NodeRegistration
import org.bukkit.permissions.PermissionDefault
import org.bukkit.plugin.java.JavaPlugin
public class App : JavaPlugin() {
private var commands: KommandLib? = null
private val permits = PermitsLib.session(this)
companion object {
lateinit var instance: App
private set
@@ -10,6 +20,10 @@ public class App : JavaPlugin() {
override fun onEnable() {
instance = this
logger.info("SamplePlugin enabled!!!!")
saveDefaultConfig()
server.pluginManager.registerEvents(com.github.kaaariyaaa.elevator.listeners.EventListener(this), this)
logger.info("Elevator plugin enabled!")
commands = CommandRegistrar.register(this, permits)
}
}
@@ -0,0 +1,42 @@
package com.github.kaaariyaaa.elevator.command
import com.github.kaaariyaaa.elevator.App
import net.hareworks.kommand_lib.KommandLib
import net.hareworks.kommand_lib.kommand
import net.hareworks.permits_lib.bukkit.MutationSession
import org.bukkit.permissions.PermissionDefault
object CommandRegistrar {
fun register(plugin: App, permits: MutationSession): KommandLib {
return kommand(plugin) {
// Permission configuration
permissions {
namespace = "elevator"
defaultValue = PermissionDefault.TRUE
session(permits)
}
// Main command structure
command("elevator", "el") {
description = "Elevator plugin main command"
// Default execution if no arguments
executes {
sender.sendMessage("Elevator plugin v${plugin.description.version}")
}
// Subcommand: /elevator reload
literal("reload") {
permission {
description = "Allows reloading the plugin"
defaultValue = PermissionDefault.OP
}
executes {
plugin.reloadConfig()
sender.sendMessage("Configuration reloaded.")
}
}
}
}
}
}
@@ -0,0 +1,138 @@
package com.github.kaaariyaaa.elevator.listeners
import org.bukkit.event.Listener
import org.bukkit.event.EventHandler
import org.bukkit.event.player.PlayerToggleSneakEvent
import com.destroystokyo.paper.event.player.PlayerJumpEvent
import org.bukkit.entity.Player
import org.bukkit.Material
import org.bukkit.block.Block
import org.bukkit.Location
import org.bukkit.util.BoundingBox
import com.github.kaaariyaaa.elevator.App
class EventListener(private val plugin: App) : Listener {
private val oreBlock: Set<Material>
get() = plugin.config.getStringList("elevatorBlocks")
.mapNotNull { Material.matchMaterial(it) }
.toSet()
@EventHandler
fun onJump(event: PlayerJumpEvent) {
val player = event.player
val blockUnder = player.location.subtract(0.0, 1.0, 0.0).block
if (blockUnder.type.isSolid && blockUnder.type in oreBlock) {
var location = blockUnder.location.clone()
location.add(0.0, 1.0, 0.0)
val maxHeight = plugin.config.getInt("maxHeight", 64)
var distance = 0
while (distance < maxHeight) {
if (location.block.type in oreBlock) {
val feet = location.clone().add(0.0, 1.0, 0.0)
if (isSafe(player, feet)) {
val dest = location.clone().add(0.5, 1.0, 0.5)
dest.yaw = player.location.yaw
dest.pitch = player.location.pitch
player.teleport(dest)
return
}
}
location.add(0.0, 1.0, 0.0)
distance++
}
}
}
@EventHandler
fun onSneak(event: PlayerToggleSneakEvent) {
if (!event.isSneaking) return
val player = event.player
val blockUnder = player.location.subtract(0.0, 1.0, 0.0).block
if (blockUnder.type in oreBlock) {
var location = blockUnder.location.clone()
location.subtract(0.0, 1.0, 0.0)
val maxHeight = plugin.config.getInt("maxHeight", 64)
var distance = 0
while (distance < maxHeight) {
if (location.block.type in oreBlock) {
val feet = location.clone().add(0.0, 1.0, 0.0)
if (isSafe(player, feet)) {
val dest = location.clone().add(0.5, 1.0, 0.5)
dest.yaw = player.location.yaw
dest.pitch = player.location.pitch
player.teleport(dest)
return
}
}
location.subtract(0.0, 1.0, 0.0)
distance++
}
}
}
private fun isSafe(player: Player, feetLocation: Location): Boolean {
val x = feetLocation.blockX + 0.5
val y = feetLocation.blockY.toDouble()
val z = feetLocation.blockZ + 0.5
val playerBox = player.boundingBox
val halfW = playerBox.widthX / 2.0
val halfD = playerBox.widthZ / 2.0
val h = playerBox.height
// 足元の座標からプレイヤーの高さ分のBoundingBoxを作成し、全身(上半身含む)の衝突判定を行う
val targetBox = org.bukkit.util.BoundingBox(x - halfW, y, z - halfD, x + halfW, y + h, z + halfD)
val world = feetLocation.world
val minX = kotlin.math.floor(targetBox.minX).toInt()
val maxX = kotlin.math.ceil(targetBox.maxX).toInt()
val minY = kotlin.math.floor(targetBox.minY).toInt()
val maxY = kotlin.math.ceil(targetBox.maxY).toInt()
val minZ = kotlin.math.floor(targetBox.minZ).toInt()
val maxZ = kotlin.math.ceil(targetBox.maxZ).toInt()
for (bx in minX..maxX) {
for (by in minY..maxY) {
for (bz in minZ..maxZ) {
val block = world.getBlockAt(bx, by, bz)
if (block.isEmpty) continue
val voxelShape = block.collisionShape
for (box in voxelShape.boundingBoxes as Collection<BoundingBox>) {
val absBox = box.clone().shift(bx.toDouble(), by.toDouble(), bz.toDouble())
// 先に交差判定を行う
if (!targetBox.overlaps(absBox)) continue
// カーペット(高さ <= 0.0625)や開いた/下付きトラップドアのような軽微な衝突は無視する
// 物体が大きく遮っている場合はテレポートを阻止する
// カーペットの高さは0.0625。下付きトラップドアは通常0.1875。
// 足元の障害物が最小限であればテレポートを許可する。
val intersection = targetBox.clone().intersection(absBox)
val intHeight = intersection.height
// 交差が非常に小さい場合(カーペットに触れている程度など)は許可する
// 足元にあり、高さが0.2未満(トラップドアは約0.1875)であれば許容する
val isAtFeetLevel = (absBox.minY - y) < 0.1
if (isAtFeetLevel && absBox.height < 0.2) {
continue
}
return false
}
}
}
}
return true
}
}
+15
View File
@@ -0,0 +1,15 @@
# Elevator Plugin Configuration
# The maximum distance (in blocks) the elevator will search for a valid destination.
maxHeight: 64
# Blocks that function as elevators
elevatorBlocks:
- minecraft:iron_block
- minecraft:gold_block
- minecraft:diamond_block
- minecraft:lapis_block
- minecraft:redstone_block
- minecraft:emerald_block
- minecraft:netherite_block
- minecraft:coal_block