From 7046ad6663914a78d0d8c3f2796b1ec31a13b9f8 Mon Sep 17 00:00:00 2001 From: devcembeer Date: Fri, 23 Feb 2024 23:23:50 +0100 Subject: [PATCH 01/15] Added freeze() and unfreeze() --- .../kotlin/gg/flyte/twilight/extension/Player.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt index bbe9ada..a3f1672 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt @@ -81,4 +81,18 @@ fun Player.showPlayer() { */ fun Player.removeActivePotionEffects() { activePotionEffects.forEach { removePotionEffect(it.type) } +} +/** + * Freezes the player. + */ +fun Player.freeze() { + walkSpeed = 0.0f + flySpeed = 0.0f +} +/** + * Unfreezes the player. + */ +fun Player.unfreeze() { + walkSpeed = 0.2f + flySpeed = 0.2f } \ No newline at end of file From 8bbf5d17307eed55b29032881edb067ee4850589 Mon Sep 17 00:00:00 2001 From: devcembeer Date: Sat, 24 Feb 2024 14:46:36 +0100 Subject: [PATCH 02/15] Updated freeze system with metadatas. --- src/main/kotlin/gg/flyte/twilight/Twilight.kt | 2 ++ .../kotlin/gg/flyte/twilight/extension/Player.kt | 4 ++++ .../gg/flyte/twilight/listeners/MoveEvent.kt | 14 ++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt diff --git a/src/main/kotlin/gg/flyte/twilight/Twilight.kt b/src/main/kotlin/gg/flyte/twilight/Twilight.kt index 2a30ae7..68d8bab 100644 --- a/src/main/kotlin/gg/flyte/twilight/Twilight.kt +++ b/src/main/kotlin/gg/flyte/twilight/Twilight.kt @@ -7,6 +7,7 @@ import gg.flyte.twilight.event.custom.chat.command.ChatClickCommand import gg.flyte.twilight.event.customEventListeners import gg.flyte.twilight.extension.applyForEach import gg.flyte.twilight.builders.item.ItemBuilder +import gg.flyte.twilight.listeners.MoveEvent import org.bukkit.plugin.java.JavaPlugin class Twilight(javaPlugin: JavaPlugin) { @@ -17,6 +18,7 @@ class Twilight(javaPlugin: JavaPlugin) { customEventListeners ItemBuilder.Companion ChatClickCommand.register() + plugin.server.pluginManager.registerEvents(MoveEvent(), plugin) } } diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt index a3f1672..4d15341 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt @@ -7,6 +7,8 @@ import org.bukkit.Bukkit import org.bukkit.Sound import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack +import org.bukkit.metadata.FixedMetadataValue +import org.bukkit.metadata.MetadataValue /** * Plays a sound at the player's current location with default volume and pitch. @@ -86,6 +88,7 @@ fun Player.removeActivePotionEffects() { * Freezes the player. */ fun Player.freeze() { + setMetadata("frozen", FixedMetadataValue(Twilight.plugin, true)) walkSpeed = 0.0f flySpeed = 0.0f } @@ -93,6 +96,7 @@ fun Player.freeze() { * Unfreezes the player. */ fun Player.unfreeze() { + removeMetadata("frozen", Twilight.plugin) walkSpeed = 0.2f flySpeed = 0.2f } \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt b/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt new file mode 100644 index 0000000..7b70255 --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt @@ -0,0 +1,14 @@ +package gg.flyte.twilight.listeners + +import com.destroystokyo.paper.event.player.PlayerJumpEvent +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener + +class MoveEvent : Listener { + @EventHandler + fun onJump(event: PlayerJumpEvent) { + val player = event.player + if (player.hasMetadata("frozen")) event.isCancelled = true + } + +} \ No newline at end of file From f4e690e96c7b8ea86fe34f6c0cf95bb6b35e5f0d Mon Sep 17 00:00:00 2001 From: devcembeer Date: Sat, 24 Feb 2024 17:21:19 +0100 Subject: [PATCH 03/15] Added support for both players and entities. --- src/main/kotlin/gg/flyte/twilight/Twilight.kt | 4 ++-- .../gg/flyte/twilight/extension/Entity.kt | 16 ++++++++++++++++ .../gg/flyte/twilight/listeners/MoveEvent.kt | 17 ++++++++++------- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/Twilight.kt b/src/main/kotlin/gg/flyte/twilight/Twilight.kt index 68d8bab..af8abcb 100644 --- a/src/main/kotlin/gg/flyte/twilight/Twilight.kt +++ b/src/main/kotlin/gg/flyte/twilight/Twilight.kt @@ -1,12 +1,12 @@ package gg.flyte.twilight +import gg.flyte.twilight.builders.item.ItemBuilder import gg.flyte.twilight.data.MongoDB import gg.flyte.twilight.data.service.NameCacheService import gg.flyte.twilight.environment.Environment import gg.flyte.twilight.event.custom.chat.command.ChatClickCommand import gg.flyte.twilight.event.customEventListeners import gg.flyte.twilight.extension.applyForEach -import gg.flyte.twilight.builders.item.ItemBuilder import gg.flyte.twilight.listeners.MoveEvent import org.bukkit.plugin.java.JavaPlugin @@ -18,7 +18,7 @@ class Twilight(javaPlugin: JavaPlugin) { customEventListeners ItemBuilder.Companion ChatClickCommand.register() - plugin.server.pluginManager.registerEvents(MoveEvent(), plugin) + MoveEvent() } } diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt index 97ddf9a..f59994e 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt @@ -1,6 +1,9 @@ package gg.flyte.twilight.extension +import gg.flyte.twilight.Twilight import org.bukkit.entity.Entity +import org.bukkit.entity.Player +import org.bukkit.metadata.FixedMetadataValue /** * Retrieves a list of nearby entities within the specified range from the current entity. @@ -27,4 +30,17 @@ fun Entity.getNearbyEntities(range: Double): MutableList { */ fun Entity.isOnFire(): Boolean { return fireTicks > 0 +} + +/** + * Freezes the entity. + */ +fun Entity.freeze() { + setMetadata("frozen", FixedMetadataValue(Twilight.plugin, true)) +} +/** + * Unfreezes the entity. + */ +fun Entity.unfreeze() { + removeMetadata("frozen", Twilight.plugin) } \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt b/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt index 7b70255..ed279c3 100644 --- a/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt +++ b/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt @@ -1,14 +1,17 @@ package gg.flyte.twilight.listeners -import com.destroystokyo.paper.event.player.PlayerJumpEvent -import org.bukkit.event.EventHandler +import gg.flyte.twilight.event.event +import io.papermc.paper.event.entity.EntityMoveEvent import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerMoveEvent class MoveEvent : Listener { - @EventHandler - fun onJump(event: PlayerJumpEvent) { - val player = event.player - if (player.hasMetadata("frozen")) event.isCancelled = true + init { + event { + if (player.hasMetadata("frozen")) isCancelled = true + } + event { + if (entity.hasMetadata("frozen")) isCancelled = true + } } - } \ No newline at end of file From 2976e915e8947dfc7fac2199b76ddfdb5700facc Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:19:26 +0000 Subject: [PATCH 04/15] feat: add Entity#frozen to check if an Entity is frozen --- src/main/kotlin/gg/flyte/twilight/extension/Entity.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt index f59994e..8072f4e 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt @@ -2,7 +2,6 @@ package gg.flyte.twilight.extension import gg.flyte.twilight.Twilight import org.bukkit.entity.Entity -import org.bukkit.entity.Player import org.bukkit.metadata.FixedMetadataValue /** @@ -38,9 +37,17 @@ fun Entity.isOnFire(): Boolean { fun Entity.freeze() { setMetadata("frozen", FixedMetadataValue(Twilight.plugin, true)) } + /** * Unfreezes the entity. */ fun Entity.unfreeze() { removeMetadata("frozen", Twilight.plugin) -} \ No newline at end of file +} + +/** + * Checks if the player is currently frozen. + * + * @return `true` if the player is frozen, `false` otherwise. + */ +fun Entity.frozen(): Boolean = hasMetadata("frozen") \ No newline at end of file From 7e2db04b1fcddd13aae6e6e0e1737ad7d6bd7af0 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:19:47 +0000 Subject: [PATCH 05/15] feat: use Entity#frozen to check if an Entity is frozen --- .../listener/EntityMoveEventListener.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt new file mode 100644 index 0000000..5143863 --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt @@ -0,0 +1,22 @@ +package gg.flyte.twilight.event.custom.movement.listener + +import gg.flyte.twilight.Twilight.Companion.isPaper +import gg.flyte.twilight.event.CustomTwilightListener +import gg.flyte.twilight.event.event +import gg.flyte.twilight.extension.frozen +import io.papermc.paper.event.entity.EntityMoveEvent +import org.bukkit.event.player.PlayerMoveEvent + +object EntityMoveEventListener : CustomTwilightListener() { + init { + if (isPaper()) { + event { + if (entity.frozen()) isCancelled = true + } + } else { + event { + if (player.frozen()) isCancelled = true + } + } + } +} \ No newline at end of file From 2986191595f7fbdd1edb1f775e0809b4ba703563 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:20:10 +0000 Subject: [PATCH 06/15] refactor: newline --- src/main/kotlin/gg/flyte/twilight/extension/Player.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt index 4d15341..5726ffa 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt @@ -8,7 +8,6 @@ import org.bukkit.Sound import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import org.bukkit.metadata.FixedMetadataValue -import org.bukkit.metadata.MetadataValue /** * Plays a sound at the player's current location with default volume and pitch. @@ -84,6 +83,7 @@ fun Player.showPlayer() { fun Player.removeActivePotionEffects() { activePotionEffects.forEach { removePotionEffect(it.type) } } + /** * Freezes the player. */ From 473af0426c151c711552e7f04b625f177309a000 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:20:39 +0000 Subject: [PATCH 07/15] feat: add ServerSoftware to identify which software is running --- .../flyte/twilight/server/ServerSoftware.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt diff --git a/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt new file mode 100644 index 0000000..8d52c0d --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt @@ -0,0 +1,24 @@ +package gg.flyte.twilight.server + +enum class ServerSoftware { + PAPER, + SPIGOT, + CRAFT_BUKKIT; + + companion object { + val current: ServerSoftware by lazy { + val hasClass = { name: String -> try { Class.forName(name); true } catch (e: ClassNotFoundException) { false } } + if (hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration")) { + PAPER + } else if (hasClass("org.spigotmc.SpigotConfig")) { + SPIGOT + } else { + CRAFT_BUKKIT + } + } + + fun isPaper(): Boolean = current == PAPER + fun isSpigot(): Boolean = current == SPIGOT + fun isCraftBukkit(): Boolean = current == CRAFT_BUKKIT + } +} \ No newline at end of file From ce658ee100db1de3d64b628d973f4c2ea3ec3c11 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:21:16 +0000 Subject: [PATCH 08/15] feat: init ServerSoftware and add software boolean convenience methods to Twilight --- src/main/kotlin/gg/flyte/twilight/Twilight.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/Twilight.kt b/src/main/kotlin/gg/flyte/twilight/Twilight.kt index af8abcb..5756ea3 100644 --- a/src/main/kotlin/gg/flyte/twilight/Twilight.kt +++ b/src/main/kotlin/gg/flyte/twilight/Twilight.kt @@ -7,7 +7,7 @@ import gg.flyte.twilight.environment.Environment import gg.flyte.twilight.event.custom.chat.command.ChatClickCommand import gg.flyte.twilight.event.customEventListeners import gg.flyte.twilight.extension.applyForEach -import gg.flyte.twilight.listeners.MoveEvent +import gg.flyte.twilight.server.ServerSoftware import org.bukkit.plugin.java.JavaPlugin class Twilight(javaPlugin: JavaPlugin) { @@ -15,10 +15,10 @@ class Twilight(javaPlugin: JavaPlugin) { init { plugin = javaPlugin run { + ServerSoftware customEventListeners ItemBuilder.Companion ChatClickCommand.register() - MoveEvent() } } @@ -26,6 +26,10 @@ class Twilight(javaPlugin: JavaPlugin) { lateinit var plugin: JavaPlugin var usingEnv = false val internalPdc by lazy { "_twilight_${plugin.name.lowercase()}" } + + fun isPaper(): Boolean = ServerSoftware.isPaper() + fun isSpigot(): Boolean = ServerSoftware.isSpigot() + fun isCraftBukkit(): Boolean = ServerSoftware.isCraftBukkit() } fun env(init: Environment.Settings.() -> Unit = {}) { From 4be44d7d03fb8822b3226c53957ba4536e31c146 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:21:30 +0000 Subject: [PATCH 09/15] refactor: MoveEvent to EntityMoveEventListener --- .../gg/flyte/twilight/listeners/MoveEvent.kt | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt diff --git a/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt b/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt deleted file mode 100644 index ed279c3..0000000 --- a/src/main/kotlin/gg/flyte/twilight/listeners/MoveEvent.kt +++ /dev/null @@ -1,17 +0,0 @@ -package gg.flyte.twilight.listeners - -import gg.flyte.twilight.event.event -import io.papermc.paper.event.entity.EntityMoveEvent -import org.bukkit.event.Listener -import org.bukkit.event.player.PlayerMoveEvent - -class MoveEvent : Listener { - init { - event { - if (player.hasMetadata("frozen")) isCancelled = true - } - event { - if (entity.hasMetadata("frozen")) isCancelled = true - } - } -} \ No newline at end of file From 7f854497610262da52e674df205fe648a3a41253 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:21:51 +0000 Subject: [PATCH 10/15] feat: add software boolean convenience extension methods to Bukkit Server --- src/main/kotlin/gg/flyte/twilight/extension/Server.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/kotlin/gg/flyte/twilight/extension/Server.kt diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Server.kt b/src/main/kotlin/gg/flyte/twilight/extension/Server.kt new file mode 100644 index 0000000..1ddd7c5 --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/extension/Server.kt @@ -0,0 +1,8 @@ +package gg.flyte.twilight.extension + +import gg.flyte.twilight.server.ServerSoftware +import org.bukkit.Server + +fun Server.isPaper(): Boolean = ServerSoftware.isPaper() +fun Server.isSpigot(): Boolean = ServerSoftware.isSpigot() +fun Server.isCraftBukkit(): Boolean = ServerSoftware.isCraftBukkit() \ No newline at end of file From a46c60be08938e45708531ed61d6016ff1074adb Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:22:15 +0000 Subject: [PATCH 11/15] feat: register EntityMoveEventListener as a customEventListener --- src/main/kotlin/gg/flyte/twilight/event/Event.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/gg/flyte/twilight/event/Event.kt b/src/main/kotlin/gg/flyte/twilight/event/Event.kt index d7703b0..de0c6d6 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/Event.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/Event.kt @@ -5,6 +5,7 @@ package gg.flyte.twilight.event import gg.flyte.twilight.Twilight import gg.flyte.twilight.event.custom.admin.listener.OpEventListener import gg.flyte.twilight.event.custom.interact.listener.InteractEventListener +import gg.flyte.twilight.event.custom.movement.listener.EntityMoveEventListener import gg.flyte.twilight.extension.applyForEach import gg.flyte.twilight.inventory.GUIListener import org.bukkit.event.* @@ -126,7 +127,8 @@ open class TwilightEvent(async: Boolean = false) : Event(async), Cancellable { val customEventListeners = mutableSetOf( GUIListener, InteractEventListener, - OpEventListener + OpEventListener, + EntityMoveEventListener ) /** From e07329641fb75ab08dd67e1d6814535c2db0c2a5 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:23:01 +0000 Subject: [PATCH 12/15] chore: bump ver v1.1.8 --- README.md | 6 +++--- build.gradle.kts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5fa295d..8173223 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Maven gg.flyte twilight - 1.1.7 + 1.1.8 ``` @@ -31,14 +31,14 @@ maven { url "https://repo.flyte.gg/releases" } -implementation "gg.flyte:twilight:1.1.7" +implementation "gg.flyte:twilight:1.1.8" ``` Gradle (Kotlin DSL) ```kotlin maven("https://repo.flyte.gg/releases") -implementation("gg.flyte:twilight:1.1.7") +implementation("gg.flyte:twilight:1.1.8") ``` 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` function as shown below: diff --git a/build.gradle.kts b/build.gradle.kts index 7c3791b..3c4fae7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "gg.flyte" -version = "1.1.7" +version = "1.1.8" repositories { mavenLocal() From 77f68b2d7310864e3644bc4e7ae94760f82796f2 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:28:49 +0000 Subject: [PATCH 13/15] refactor: parking spaces for an-225 mriya aircraft (at request of stephen) --- .../custom/movement/listener/EntityMoveEventListener.kt | 6 ++++++ src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt index 5143863..ee1bf2c 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt @@ -8,15 +8,21 @@ import io.papermc.paper.event.entity.EntityMoveEvent import org.bukkit.event.player.PlayerMoveEvent object EntityMoveEventListener : CustomTwilightListener() { + init { if (isPaper()) { + event { if (entity.frozen()) isCancelled = true } + } else { + event { if (player.frozen()) isCancelled = true } + } } + } \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt index 8d52c0d..f79a9c8 100644 --- a/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt +++ b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt @@ -1,6 +1,7 @@ package gg.flyte.twilight.server enum class ServerSoftware { + PAPER, SPIGOT, CRAFT_BUKKIT; @@ -8,6 +9,7 @@ enum class ServerSoftware { companion object { val current: ServerSoftware by lazy { val hasClass = { name: String -> try { Class.forName(name); true } catch (e: ClassNotFoundException) { false } } + if (hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration")) { PAPER } else if (hasClass("org.spigotmc.SpigotConfig")) { @@ -21,4 +23,5 @@ enum class ServerSoftware { fun isSpigot(): Boolean = current == SPIGOT fun isCraftBukkit(): Boolean = current == CRAFT_BUKKIT } + } \ No newline at end of file From 84d6985d13ae60293cd3e0cd5181673fea1a3a07 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:30:21 +0000 Subject: [PATCH 14/15] feat: add support to recognise Folia (and #isFolia) --- src/main/kotlin/gg/flyte/twilight/Twilight.kt | 1 + src/main/kotlin/gg/flyte/twilight/extension/Server.kt | 1 + src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/gg/flyte/twilight/Twilight.kt b/src/main/kotlin/gg/flyte/twilight/Twilight.kt index 5756ea3..7805db4 100644 --- a/src/main/kotlin/gg/flyte/twilight/Twilight.kt +++ b/src/main/kotlin/gg/flyte/twilight/Twilight.kt @@ -27,6 +27,7 @@ class Twilight(javaPlugin: JavaPlugin) { var usingEnv = false val internalPdc by lazy { "_twilight_${plugin.name.lowercase()}" } + fun isFolia(): Boolean = ServerSoftware.isFolia() fun isPaper(): Boolean = ServerSoftware.isPaper() fun isSpigot(): Boolean = ServerSoftware.isSpigot() fun isCraftBukkit(): Boolean = ServerSoftware.isCraftBukkit() diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Server.kt b/src/main/kotlin/gg/flyte/twilight/extension/Server.kt index 1ddd7c5..425e4cc 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Server.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Server.kt @@ -3,6 +3,7 @@ package gg.flyte.twilight.extension import gg.flyte.twilight.server.ServerSoftware import org.bukkit.Server +fun Server.isFolia(): Boolean = ServerSoftware.isFolia() fun Server.isPaper(): Boolean = ServerSoftware.isPaper() fun Server.isSpigot(): Boolean = ServerSoftware.isSpigot() fun Server.isCraftBukkit(): Boolean = ServerSoftware.isCraftBukkit() \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt index f79a9c8..40434f8 100644 --- a/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt +++ b/src/main/kotlin/gg/flyte/twilight/server/ServerSoftware.kt @@ -2,6 +2,7 @@ package gg.flyte.twilight.server enum class ServerSoftware { + FOLIA, PAPER, SPIGOT, CRAFT_BUKKIT; @@ -10,7 +11,9 @@ enum class ServerSoftware { val current: ServerSoftware by lazy { val hasClass = { name: String -> try { Class.forName(name); true } catch (e: ClassNotFoundException) { false } } - if (hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration")) { + if (hasClass("io.papermc.paper.threadedregions.RegionizedServer")) { + FOLIA + } else if (hasClass("com.destroystokyo.paper.PaperConfig") || hasClass("io.papermc.paper.configuration.Configuration")) { PAPER } else if (hasClass("org.spigotmc.SpigotConfig")) { SPIGOT @@ -19,6 +22,7 @@ enum class ServerSoftware { } } + fun isFolia(): Boolean = current == FOLIA fun isPaper(): Boolean = current == PAPER fun isSpigot(): Boolean = current == SPIGOT fun isCraftBukkit(): Boolean = current == CRAFT_BUKKIT From 442c8a1fefb3098781680ae5c1a3631271e33f5c Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:32:44 +0000 Subject: [PATCH 15/15] refactor: my fault he only wanted to fit a boeing 777 in the spaces --- .../event/custom/movement/listener/EntityMoveEventListener.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt index ee1bf2c..01487b3 100644 --- a/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt +++ b/src/main/kotlin/gg/flyte/twilight/event/custom/movement/listener/EntityMoveEventListener.kt @@ -11,17 +11,13 @@ object EntityMoveEventListener : CustomTwilightListener() { init { if (isPaper()) { - event { if (entity.frozen()) isCancelled = true } - } else { - event { if (player.frozen()) isCancelled = true } - } }