Compare commits
3
Commits
7eb0534d21
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e35905599 | ||
|
|
3c60d4a433 | ||
|
|
9673e1e6e9 |
+9
-4
@@ -2,8 +2,8 @@ group = "net.hareworks"
|
|||||||
version = "1.1"
|
version = "1.1"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "2.2.21"
|
kotlin("jvm") version "2.3.21"
|
||||||
id("de.eldoria.plugin-yml.paper") version "0.8.0"
|
id("de.eldoria.plugin-yml.paper") version "0.9.0"
|
||||||
id("com.gradleup.shadow") version "9.2.2"
|
id("com.gradleup.shadow") version "9.2.2"
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
@@ -12,9 +12,14 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:26.1.2.build.49-beta")
|
||||||
paperLibrary("org.jetbrains.kotlin:kotlin-stdlib")
|
paperLibrary("org.jetbrains.kotlin:kotlin-stdlib")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvmToolchain(25)
|
||||||
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
withType<Jar> {
|
withType<Jar> {
|
||||||
archiveBaseName.set("Permits-Lib")
|
archiveBaseName.set("Permits-Lib")
|
||||||
@@ -30,7 +35,7 @@ paper {
|
|||||||
name = "permits-lib"
|
name = "permits-lib"
|
||||||
description = "Permission Library"
|
description = "Permission Library"
|
||||||
version = getVersion().toString()
|
version = getVersion().toString()
|
||||||
apiVersion = "1.21.10"
|
apiVersion = "26.1"
|
||||||
authors =
|
authors =
|
||||||
listOf(
|
listOf(
|
||||||
"Hare-K02",
|
"Hare-K02",
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class AttachmentSynchronizer(
|
|||||||
permissible: Permissible,
|
permissible: Permissible,
|
||||||
patch: AttachmentPatch,
|
patch: AttachmentPatch,
|
||||||
) {
|
) {
|
||||||
ThreadChecks.ensurePrimaryThread("AttachmentSynchronizer.applyPatch")
|
ThreadChecks.ensureRegionThread("AttachmentSynchronizer.applyPatch", permissible)
|
||||||
if (patch.changes.isEmpty()) return
|
if (patch.changes.isEmpty()) return
|
||||||
val handle = ensureHandle(permissible)
|
val handle = ensureHandle(permissible)
|
||||||
patch.changes.forEach { (id, value) ->
|
patch.changes.forEach { (id, value) ->
|
||||||
@@ -58,7 +58,7 @@ class AttachmentSynchronizer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clear(permissible: Permissible) {
|
fun clear(permissible: Permissible) {
|
||||||
ThreadChecks.ensurePrimaryThread("AttachmentSynchronizer.clear")
|
ThreadChecks.ensureRegionThread("AttachmentSynchronizer.clear", permissible)
|
||||||
handles.remove(permissible)?.attachment?.remove()
|
handles.remove(permissible)?.attachment?.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,30 @@
|
|||||||
package net.hareworks.permits_lib.util
|
package net.hareworks.permits_lib.util
|
||||||
|
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.permissions.Permissible
|
||||||
|
|
||||||
internal object ThreadChecks {
|
internal object ThreadChecks {
|
||||||
|
/**
|
||||||
|
* For Bukkit-global operations (e.g. PluginManager permission registration).
|
||||||
|
* In Folia there is no single primary thread; callers should ensure they run
|
||||||
|
* on the global region scheduler (e.g. during onEnable / onDisable).
|
||||||
|
*/
|
||||||
fun ensurePrimaryThread(action: String) {
|
fun ensurePrimaryThread(action: String) {
|
||||||
check(Bukkit.isPrimaryThread()) {
|
// no-op for global ops: Folia has no single primary thread.
|
||||||
"$action must be invoked from the primary server thread."
|
// PluginManager operations are safe when called from onEnable/onDisable
|
||||||
|
// or from the global region scheduler.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For player-bound operations (e.g. PermissionAttachment mutation).
|
||||||
|
* Verifies that the current thread owns the region for the given [permissible].
|
||||||
|
* Non-player permissibles are skipped since they have no region owner.
|
||||||
|
*/
|
||||||
|
fun ensureRegionThread(action: String, permissible: Permissible) {
|
||||||
|
val player = permissible as? Player ?: return
|
||||||
|
check(Bukkit.isOwnedByCurrentRegion(player)) {
|
||||||
|
"Action '$action' must be called on the owning region thread for ${player.name}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user