From ad9201be50647c4ddbc49e25d56a42e43fad0e6a Mon Sep 17 00:00:00 2001 From: Lukas <113579672+byPixelTV@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:35:34 +0200 Subject: [PATCH] Added some other things and prepared for release --- .../kotlin/de/bypixeltv/skcloudnet/Main.kt | 2 + .../skcloudnet/commands/SkCloudnetCommands.kt | 23 ++----- .../effects/players/EffSendCloudnetMessage.kt | 65 ------------------- .../bypixeltv/skcloudnet/tasks/UpdateCheck.kt | 50 ++++++++++++++ .../skcloudnet/utils/UpdateChecker.kt | 6 +- 5 files changed, 62 insertions(+), 84 deletions(-) delete mode 100644 src/main/kotlin/de/bypixeltv/skcloudnet/elements/effects/players/EffSendCloudnetMessage.kt create mode 100644 src/main/kotlin/de/bypixeltv/skcloudnet/tasks/UpdateCheck.kt diff --git a/src/main/kotlin/de/bypixeltv/skcloudnet/Main.kt b/src/main/kotlin/de/bypixeltv/skcloudnet/Main.kt index 8e1272b..1639772 100644 --- a/src/main/kotlin/de/bypixeltv/skcloudnet/Main.kt +++ b/src/main/kotlin/de/bypixeltv/skcloudnet/Main.kt @@ -3,6 +3,7 @@ package de.bypixeltv.skcloudnet import ch.njol.skript.Skript import ch.njol.skript.SkriptAddon import de.bypixeltv.skcloudnet.commands.SkCloudnetCommands +import de.bypixeltv.skcloudnet.tasks.UpdateCheck import de.bypixeltv.skcloudnet.utils.GetVersion import de.bypixeltv.skcloudnet.utils.UpdateChecker import dev.jorel.commandapi.CommandAPI @@ -85,6 +86,7 @@ class Main : KSpigot() { } UpdateChecker + UpdateCheck val metrics: Metrics = Metrics(this, 21526) } diff --git a/src/main/kotlin/de/bypixeltv/skcloudnet/commands/SkCloudnetCommands.kt b/src/main/kotlin/de/bypixeltv/skcloudnet/commands/SkCloudnetCommands.kt index a7531ed..96a7daa 100644 --- a/src/main/kotlin/de/bypixeltv/skcloudnet/commands/SkCloudnetCommands.kt +++ b/src/main/kotlin/de/bypixeltv/skcloudnet/commands/SkCloudnetCommands.kt @@ -3,6 +3,7 @@ package de.bypixeltv.skcloudnet.commands import ch.njol.skript.Skript import de.bypixeltv.skcloudnet.Main import de.bypixeltv.skcloudnet.utils.GetVersion +import de.bypixeltv.skcloudnet.utils.UpdateChecker import dev.jorel.commandapi.kotlindsl.commandTree import dev.jorel.commandapi.kotlindsl.literalArgument import dev.jorel.commandapi.kotlindsl.playerExecutor @@ -52,27 +53,17 @@ class SkCloudnetCommands { literalArgument("version") { withPermission("skcloudnet.admin.version") playerExecutor { player, _ -> - val githubVersion = GetVersion().getLatestAddonVersion() + val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble() if (githubVersion != null) { - if (githubVersion != Main.INSTANCE.description.version) { - player.sendMessage(" ") - player.sendMessage(" ") - player.sendMessage(miniMessages.deserialize("[SkCloudnet] There is an update available for SkCloudnet! You're on version ${Main.INSTANCE.description.version} and the latest version is $githubVersion!\n\nDownload the latest version here: https://github.com/byPixelTV/SkCloudnet/releases ")) - player.sendMessage(" ") - player.sendMessage(" ") + if (githubVersion > Main.INSTANCE.description.version.replace("v", "").toDouble()) { + player.sendMessage(miniMessages.deserialize("[SkCloudnet] There is an update available for SkCloudnet! You're on version ${Main.INSTANCE.description.version} and the latest version is $githubVersion!\n\nDownload the latest version here: https://github.com/byPixelTV/SkCloudnet/releases")) } else { - player.sendMessage(" ") - player.sendMessage(" ") - player.sendMessage(miniMessages.deserialize("[SkCloudnet] You're on the latest version of SkCloudnet! Version ${Main.INSTANCE.description.version}")) - player.sendMessage(" ") - player.sendMessage(" ") + if (githubVersion < Main.INSTANCE.description.version.replace("v", "").toDouble()) { + player.sendMessage(miniMessages.deserialize("[SkCloudnet] You're running a development version of SkCloudnet! Please note that this version may contain bugs! Version ${Main.INSTANCE.description.version} > ${GetVersion().getLatestAddonVersion()}")) + } } } else { - player.sendMessage(" ") - player.sendMessage(" ") player.sendMessage(miniMessages.deserialize("[SkCloudnet] Unable to fetch the latest version from Github! Are you rate limited?")) - player.sendMessage(" ") - player.sendMessage(" ") } } } diff --git a/src/main/kotlin/de/bypixeltv/skcloudnet/elements/effects/players/EffSendCloudnetMessage.kt b/src/main/kotlin/de/bypixeltv/skcloudnet/elements/effects/players/EffSendCloudnetMessage.kt deleted file mode 100644 index 56f6fc2..0000000 --- a/src/main/kotlin/de/bypixeltv/skcloudnet/elements/effects/players/EffSendCloudnetMessage.kt +++ /dev/null @@ -1,65 +0,0 @@ -package de.bypixeltv.skcloudnet.elements.effects - -import ch.njol.skript.Skript -import ch.njol.skript.doc.Description -import ch.njol.skript.doc.Examples -import ch.njol.skript.doc.Name -import ch.njol.skript.doc.Since -import ch.njol.skript.lang.Effect -import ch.njol.skript.lang.Expression -import ch.njol.skript.lang.SkriptParser -import ch.njol.util.Kleenean -import eu.cloudnetservice.driver.inject.InjectionLayer -import eu.cloudnetservice.driver.registry.ServiceRegistry -import eu.cloudnetservice.modules.bridge.player.PlayerManager -import net.kyori.adventure.text.minimessage.MiniMessage -import org.bukkit.entity.Player -import org.bukkit.event.Event - -@Name("Stop Service") -@Description("Start a CloudNet service by its name.") -@Examples("start cloudnet service \"Lobby-1\"") -@Since("1.0") - -class EffSendCloudnetMessage : Effect() { - private val miniMessages = MiniMessage.miniMessage() - private val serviceRegistry: ServiceRegistry = InjectionLayer.ext().instance(ServiceRegistry::class.java) - private val playerManager: PlayerManager = serviceRegistry.firstProvider(PlayerManager::class.java) - - companion object{ - init { - Skript.registerEffect(EffSendCloudnetMessage::class.java, "send cloudnet message %string% to [(the player|player)] %player%") - } - } - - private var text: Expression? = null - private var player: Expression? = null - - @Suppress("UNCHECKED_CAST") - override fun init( - expressions: Array>, - matchedPattern: Int, - isDelayed: Kleenean, - parser: SkriptParser.ParseResult - ): Boolean { - this.text = expressions[0] as Expression - this.player = expressions[0] as Expression - return true - } - - override fun toString(event: Event?, debug: Boolean): String { - return "send cloudnet message ${text?.getSingle(event)} to the player ${player?.getSingle(event)}" - } - - override fun execute(event: Event?) { - val player = player?.getSingle(event) - val text = text?.getSingle(event) - if (player != null) { - val serviceInfo = text?.let { - miniMessages.deserialize( - it - ) - }?.let { playerManager.playerExecutor(player.uniqueId).sendChatMessage(it) } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/de/bypixeltv/skcloudnet/tasks/UpdateCheck.kt b/src/main/kotlin/de/bypixeltv/skcloudnet/tasks/UpdateCheck.kt new file mode 100644 index 0000000..273c1cf --- /dev/null +++ b/src/main/kotlin/de/bypixeltv/skcloudnet/tasks/UpdateCheck.kt @@ -0,0 +1,50 @@ +package de.bypixeltv.skcloudnet.tasks + +import de.bypixeltv.skcloudnet.Main +import de.bypixeltv.skcloudnet.utils.GetVersion +import net.axay.kspigot.runnables.task +import net.kyori.adventure.text.minimessage.MiniMessage + +object UpdateCheck { + private val miniMessages = MiniMessage.miniMessage() + + fun scheudle() { + task(false, 36000, 72000) { + val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble() + if (githubVersion != null) { + if (githubVersion > Main.INSTANCE.description.version.replace("v", "").toDouble()) { + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(miniMessages.deserialize("There is an update available for SkCloudnet! You're on version ${Main.INSTANCE.description.version} and the latest version is $githubVersion!\n\nDownload the latest version here: https://github.com/byPixelTV/SkCloudnet/releases ")) + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + } else { + if (githubVersion == Main.INSTANCE.description.version.replace("v", "").toDouble()) { + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(miniMessages.deserialize("You're on the latest version of SkCloudnet! Version ${Main.INSTANCE.description.version}")) + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + } else if (githubVersion < Main.INSTANCE.description.version.replace("v", "").toDouble()) { + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(miniMessages.deserialize("You're running a development version of SkCloudnet! Please note that this version may contain bugs! Version ${Main.INSTANCE.description.version} > ${GetVersion().getLatestAddonVersion()}")) + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + } + } + } else { + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(miniMessages.deserialize("Unable to fetch the latest version from Github! Are you rate limited?")) + Main.INSTANCE.server.consoleSender.sendMessage(" ") + Main.INSTANCE.server.consoleSender.sendMessage(" ") + } + } + } + + init { + scheudle() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/de/bypixeltv/skcloudnet/utils/UpdateChecker.kt b/src/main/kotlin/de/bypixeltv/skcloudnet/utils/UpdateChecker.kt index 519d203..f8624fd 100644 --- a/src/main/kotlin/de/bypixeltv/skcloudnet/utils/UpdateChecker.kt +++ b/src/main/kotlin/de/bypixeltv/skcloudnet/utils/UpdateChecker.kt @@ -18,14 +18,14 @@ object UpdateChecker { val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble() if (githubVersion != null) { if (githubVersion > Main.INSTANCE.description.version.replace("v", "").toDouble()) { - player.sendMessage(miniMessages.deserialize("\n\n[SkCloudnet] There is an update available for SkCloudnet! You're on version ${Main.INSTANCE.description.version} and the latest version is $githubVersion!\n\nDownload the latest version here: https://github.com/byPixelTV/SkCloudnet/releases ")) + player.sendMessage(miniMessages.deserialize("[SkCloudnet] There is an update available for SkCloudnet! You're on version ${Main.INSTANCE.description.version} and the latest version is $githubVersion!Download the latest version here: https://github.com/byPixelTV/SkCloudnet/releases ")) } else { if (githubVersion < Main.INSTANCE.description.version.replace("v", "").toDouble()) { - player.sendMessage(miniMessages.deserialize("\n\n[SkCloudnet] You're running a development version of SkCloudnet! Please note that this version may contain bugs! Version ${Main.INSTANCE.description.version} > ${GetVersion().getLatestAddonVersion()}")) + player.sendMessage(miniMessages.deserialize("[SkCloudnet] You're running a development version of SkCloudnet! Please note that this version may contain bugs! Version ${Main.INSTANCE.description.version} > ${GetVersion().getLatestAddonVersion()}")) } } } else { - player.sendMessage(miniMessages.deserialize("\n\n[SkCloudnet] Unable to fetch the latest version from Github! Are you rate limited?")) + player.sendMessage(miniMessages.deserialize("[SkCloudnet] Unable to fetch the latest version from Github! Are you rate limited?")) } } }