feat: folia対応
This commit is contained in:
parent
bf9979414f
commit
ae4d23db7c
|
|
@ -29,6 +29,7 @@ paper {
|
||||||
name = "MannequinNPC"
|
name = "MannequinNPC"
|
||||||
version = project.version as String
|
version = project.version as String
|
||||||
apiVersion = "1.21"
|
apiVersion = "1.21"
|
||||||
|
foliaSupported = true
|
||||||
description = "Mannequin!"
|
description = "Mannequin!"
|
||||||
authors = listOf("Hareworks")
|
authors = listOf("Hareworks")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1e2476a27b7ad934c45f309042579a6f821ca24d
|
Subproject commit 9e1ee75736bbbecc7ef69f229c2bb55a8f4fbce8
|
||||||
|
|
@ -12,13 +12,12 @@ import net.hareworks.permits_lib.PermitsLib
|
||||||
import net.hareworks.permits_lib.bukkit.MutationSession
|
import net.hareworks.permits_lib.bukkit.MutationSession
|
||||||
import org.bukkit.plugin.ServicePriority
|
import org.bukkit.plugin.ServicePriority
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
import org.bukkit.scheduler.BukkitRunnable
|
|
||||||
|
|
||||||
class Plugin : JavaPlugin() {
|
class Plugin : JavaPlugin() {
|
||||||
private var kommand: KommandLib? = null
|
private var kommand: KommandLib? = null
|
||||||
private lateinit var registry: MannequinRegistry
|
private lateinit var registry: MannequinRegistry
|
||||||
private var permissionSession: MutationSession? = null
|
private var permissionSession: MutationSession? = null
|
||||||
private var tickTask: BukkitRunnable? = null
|
private var tickTask: io.papermc.paper.threadedregions.scheduler.ScheduledTask? = null
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
val storage = MannequinStorage(this)
|
val storage = MannequinStorage(this)
|
||||||
|
|
@ -34,8 +33,8 @@ class Plugin : JavaPlugin() {
|
||||||
server.servicesManager.register(MannequinRegistry::class.java, registry, this, ServicePriority.Normal)
|
server.servicesManager.register(MannequinRegistry::class.java, registry, this, ServicePriority.Normal)
|
||||||
|
|
||||||
// Start tick task for dynamic behavior (e.g. look-at)
|
// Start tick task for dynamic behavior (e.g. look-at)
|
||||||
tickTask = MannequinTickTask(registry)
|
val task = MannequinTickTask(registry)
|
||||||
tickTask?.runTaskTimer(this, 20L, 2L)
|
tickTask = server.globalRegionScheduler.runAtFixedRate(this, { _ -> task.tick() }, 20L, 2L)
|
||||||
|
|
||||||
logger.info("Loaded ${registry.all().size} mannequin definitions.")
|
logger.info("Loaded ${registry.all().size} mannequin definitions.")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ class MannequinRegistry(
|
||||||
val updated = record.updateLocation(stored)
|
val updated = record.updateLocation(stored)
|
||||||
val entity = if (teleport) controller.locate(updated) else null
|
val entity = if (teleport) controller.locate(updated) else null
|
||||||
val finalRecord = if (entity != null) {
|
val finalRecord = if (entity != null) {
|
||||||
entity.teleport(location)
|
entity.teleportAsync(location)
|
||||||
updated.updateEntityId(entity.uniqueId)
|
updated.updateEntityId(entity.uniqueId)
|
||||||
} else {
|
} else {
|
||||||
updated
|
updated
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
package net.hareworks.npc_mannequin.service
|
package net.hareworks.npc_mannequin.service
|
||||||
|
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.scheduler.BukkitRunnable
|
|
||||||
|
|
||||||
class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnable() {
|
class MannequinTickTask(private val registry: MannequinRegistry) {
|
||||||
override fun run() {
|
fun tick() {
|
||||||
registry.all().forEach { record ->
|
registry.all().forEach { record ->
|
||||||
val settings = record.settings
|
val settings = record.settings
|
||||||
val entity = registry.locate(record.id) ?: return@forEach
|
val entity = registry.locate(record.id) ?: return@forEach
|
||||||
|
|
@ -64,7 +63,7 @@ class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnabl
|
||||||
state.isResetting = false
|
state.isResetting = false
|
||||||
|
|
||||||
if (kotlin.math.abs(location.yaw - newLoc.yaw) > 1.0f || kotlin.math.abs(location.pitch - newLoc.pitch) > 1.0f) {
|
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 {
|
} else {
|
||||||
// Return Home logic
|
// Return Home logic
|
||||||
|
|
@ -116,7 +115,7 @@ class MannequinTickTask(private val registry: MannequinRegistry) : BukkitRunnabl
|
||||||
newLoc.pitch = currentPitch
|
newLoc.pitch = currentPitch
|
||||||
|
|
||||||
if (kotlin.math.abs(location.yaw - newLoc.yaw) > 0.1f || kotlin.math.abs(location.pitch - newLoc.pitch) > 0.1f) {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user