feat: folia対応

This commit is contained in:
Keisuke Hirata 2026-03-11 19:41:00 +09:00
parent bf9979414f
commit ae4d23db7c
5 changed files with 10 additions and 11 deletions

View File

@ -29,6 +29,7 @@ paper {
name = "MannequinNPC"
version = project.version as String
apiVersion = "1.21"
foliaSupported = true
description = "Mannequin!"
authors = listOf("Hareworks")
}

@ -1 +1 @@
Subproject commit 1e2476a27b7ad934c45f309042579a6f821ca24d
Subproject commit 9e1ee75736bbbecc7ef69f229c2bb55a8f4fbce8

View File

@ -12,13 +12,12 @@ import net.hareworks.permits_lib.PermitsLib
import net.hareworks.permits_lib.bukkit.MutationSession
import org.bukkit.plugin.ServicePriority
import org.bukkit.plugin.java.JavaPlugin
import org.bukkit.scheduler.BukkitRunnable
class Plugin : JavaPlugin() {
private var kommand: KommandLib? = null
private lateinit var registry: MannequinRegistry
private var permissionSession: MutationSession? = null
private var tickTask: BukkitRunnable? = null
private var tickTask: io.papermc.paper.threadedregions.scheduler.ScheduledTask? = null
override fun onEnable() {
val storage = MannequinStorage(this)
@ -34,8 +33,8 @@ class Plugin : JavaPlugin() {
server.servicesManager.register(MannequinRegistry::class.java, registry, this, ServicePriority.Normal)
// Start tick task for dynamic behavior (e.g. look-at)
tickTask = MannequinTickTask(registry)
tickTask?.runTaskTimer(this, 20L, 2L)
val task = MannequinTickTask(registry)
tickTask = server.globalRegionScheduler.runAtFixedRate(this, { _ -> task.tick() }, 20L, 2L)
logger.info("Loaded ${registry.all().size} mannequin definitions.")
}

View File

@ -148,7 +148,7 @@ class MannequinRegistry(
val updated = record.updateLocation(stored)
val entity = if (teleport) controller.locate(updated) else null
val finalRecord = if (entity != null) {
entity.teleport(location)
entity.teleportAsync(location)
updated.updateEntityId(entity.uniqueId)
} else {
updated

View File

@ -1,10 +1,9 @@
package net.hareworks.npc_mannequin.service
import org.bukkit.GameMode
import org.bukkit.scheduler.BukkitRunnable
class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnable() {
override fun run() {
class MannequinTickTask(private val registry: MannequinRegistry) {
fun tick() {
registry.all().forEach { record ->
val settings = record.settings
val entity = registry.locate(record.id) ?: return@forEach
@ -64,7 +63,7 @@ class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnabl
state.isResetting = false
if (kotlin.math.abs(location.yaw - newLoc.yaw) > 1.0f || kotlin.math.abs(location.pitch - newLoc.pitch) > 1.0f) {
entity.teleport(newLoc)
entity.teleportAsync(newLoc)
}
} else {
// Return Home logic
@ -116,7 +115,7 @@ class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnabl
newLoc.pitch = currentPitch
if (kotlin.math.abs(location.yaw - newLoc.yaw) > 0.1f || kotlin.math.abs(location.pitch - newLoc.pitch) > 0.1f) {
entity.teleport(newLoc)
entity.teleportAsync(newLoc)
}
}
}