From f382c619b931fe458d00906391423bf1fc0eb035 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 5 Nov 2023 04:21:21 +0000 Subject: [PATCH] fix(custom-events): call events sync, remove useless online check for player? call --- README.md | 6 +++--- build.gradle.kts | 2 +- .../twilight/event/custom/admin/PlayerDeopEvent.kt | 2 +- .../event/custom/admin/PlayerOpChangeEvent.kt | 2 +- .../twilight/event/custom/admin/PlayerOpEvent.kt | 2 +- .../event/custom/admin/listener/OpEventListener.kt | 14 ++++++++++---- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 267d7d3..e8a7c94 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Maven gg.flyte twilight - 1.0.26 + 1.0.27 ``` @@ -29,14 +29,14 @@ maven { url "https://repo.flyte.gg/releases" } -implementation "gg.flyte:twilight:1.0.26" +implementation "gg.flyte:twilight:1.0.27" ``` Gradle (Kotlin DSL) ```kotlin maven("https://repo.flyte.gg/releases") -implementation("gg.flyte:twilight:1.0.26") +implementation("gg.flyte:twilight:1.0.27") ``` Certain features of Twilight require configuration, which can be done via the Twilight class. To setup a Twilight class instance, you can use the `twilight` method as shown below: diff --git a/build.gradle.kts b/build.gradle.kts index f4d895e..0885bef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "gg.flyte" -version = "1.0.26" +version = "1.0.27" repositories { mavenCentral() diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerDeopEvent.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerDeopEvent.kt index 1f5eb2d..69b13d2 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerDeopEvent.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerDeopEvent.kt @@ -28,5 +28,5 @@ class PlayerDeopEvent( * Represents the online player associated with this event, if available. * This property will be null if the player is not currently online. */ - val player: Player? = if (offlinePlayer.isOnline) offlinePlayer.player else null + val player: Player? = offlinePlayer.player } \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpChangeEvent.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpChangeEvent.kt index 3cb4b7c..fda91dd 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpChangeEvent.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpChangeEvent.kt @@ -28,5 +28,5 @@ class PlayerOpChangeEvent( * Represents the online player associated with this event, if available. * This property will be null if the player is not currently online. */ - val player: Player? = if (offlinePlayer.isOnline) offlinePlayer.player else null + val player: Player? = offlinePlayer.player } diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpEvent.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpEvent.kt index 3354a17..b9b1654 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpEvent.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/PlayerOpEvent.kt @@ -28,5 +28,5 @@ class PlayerOpEvent( * Represents the online player associated with this event, if available. * This property will be null if the player is not currently online. */ - val player: Player? = if (offlinePlayer.isOnline) offlinePlayer.player else null + val player: Player? = offlinePlayer.player } diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/listener/OpEventListener.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/listener/OpEventListener.kt index 57f621d..59af5fa 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/admin/listener/OpEventListener.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/admin/listener/OpEventListener.kt @@ -8,10 +8,12 @@ import gg.flyte.twilight.event.custom.admin.PlayerOpEvent import gg.flyte.twilight.extension.applyForEach import gg.flyte.twilight.gson.GSON import gg.flyte.twilight.scheduler.repeat +import gg.flyte.twilight.scheduler.sync import java.io.File import java.util.* object OpEventListener : CustomTwilightListener() { + private val opsFile = File("${Twilight.plugin.dataFolder}/../../ops.json") private var opsData = mutableSetOf() private var opsLastChanged: Long? = null @@ -31,15 +33,19 @@ object OpEventListener : CustomTwilightListener() { // Removed ops opsData.subtract(newOpsData).toSet().applyForEach { opsData -= this - Twilight.plugin.server.pluginManager.callEvent(PlayerDeopEvent(uuid, name)) - Twilight.plugin.server.pluginManager.callEvent(PlayerOpChangeEvent(uuid, name)) + sync { + Twilight.plugin.server.pluginManager.callEvent(PlayerDeopEvent(uuid, name)) + Twilight.plugin.server.pluginManager.callEvent(PlayerOpChangeEvent(uuid, name)) + } } // Added ops newOpsData.subtract(opsData).toSet().applyForEach { opsData += this - Twilight.plugin.server.pluginManager.callEvent(PlayerOpEvent(uuid, name)) - Twilight.plugin.server.pluginManager.callEvent(PlayerOpChangeEvent(uuid, name)) + sync { + Twilight.plugin.server.pluginManager.callEvent(PlayerOpEvent(uuid, name)) + Twilight.plugin.server.pluginManager.callEvent(PlayerOpChangeEvent(uuid, name)) + } } } }