Skip to content

Commit

Permalink
Added ExprGetAllCloudnetPlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
byPixelTV committed Apr 8, 2024
1 parent 8df8417 commit b0dec51
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.bypixeltv.skcloudnet.commands

import ch.njol.skript.Skript
import de.bypixeltv.skcloudnet.Main
import de.bypixeltv.skcloudnet.tasks.UpdateCheck
import de.bypixeltv.skcloudnet.utils.GetVersion
import de.bypixeltv.skcloudnet.utils.UpdateChecker
import dev.jorel.commandapi.kotlindsl.commandTree
Expand Down Expand Up @@ -56,9 +57,11 @@ class SkCloudnetCommands {
val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble()
if (githubVersion != null) {
if (githubVersion > Main.INSTANCE.description.version.replace("v", "").toDouble()) {
player.sendMessage(miniMessages.deserialize("<dark_grey>[<gradient:aqua:blue:aqua>SkCloudnet</gradient>]</dark_grey> <color:#43fa00>There is an update available for SkCloudnet!</color> <aqua>You're on version <yellow>${Main.INSTANCE.description.version}</yellow> and the latest version is <yellow>$githubVersion</yellow></aqua>!\n\n<color:#43fa00>Download the latest version here:</color> <blue>https://github.com/byPixelTV/SkCloudnet/releases</blue><aqua>"))
player.sendMessage(miniMessages.deserialize("<dark_grey>[<gradient:aqua:blue:aqua>SkCloudnet</gradient>]</dark_grey> <color:#43fa00>There is an update available for SkCloudnet!</color> <aqua>You're on version <yellow>${Main.INSTANCE.description.version}</yellow> and the latest version is <yellow>$githubVersion</yellow></aqua>!\n\n<color:#43fa00>Download the latest version here:</color> <blue>https://github.com/byPixelTV/SkCloudnet/releases</blue> <aqua>"))
} else {
if (githubVersion < Main.INSTANCE.description.version.replace("v", "").toDouble()) {
if (githubVersion == Main.INSTANCE.description.version.replace("v", "").toDouble()) {
player.sendMessage(miniMessages.deserialize("<dark_grey>[<gradient:aqua:blue:aqua>SkCloudnet</gradient>]</dark_grey> <color:#43fa00>You're on the latest version of SkCloudnet!</color> <aqua>Version <yellow>${Main.INSTANCE.description.version}</yellow></aqua>"))
} else if (githubVersion < Main.INSTANCE.description.version.replace("v", "").toDouble()) {
player.sendMessage(miniMessages.deserialize("<dark_grey>[<gradient:aqua:blue:aqua>SkCloudnet</gradient>]</dark_grey> <color:#ff0000>You're running a development version of SkCloudnet! Please note that this version may contain bugs!</color> <aqua>Version <color:#ff0000>${Main.INSTANCE.description.version}</color> > <color:#43fa00>${GetVersion().getLatestAddonVersion()}</color></aqua>"))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.bypixeltv.skcloudnet.elements.expressions.players

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.Expression
import ch.njol.skript.lang.ExpressionType
import ch.njol.skript.lang.SkriptParser
import ch.njol.skript.lang.util.SimpleExpression
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 org.bukkit.entity.Player
import org.bukkit.event.Event


@Name("CloudNet Proxy of Player")
@Description("Returns the CloudNet proxy of a player.")
@Examples("send cloudnet proxy of \"byPixelTV\" parsed as player")
@Since("1.0")

class ExprGetAllCloudnetPlayers : SimpleExpression<String>() {

private val serviceRegistry: ServiceRegistry = InjectionLayer.ext().instance(ServiceRegistry::class.java)
private val playerManager: PlayerManager = serviceRegistry.firstProvider(PlayerManager::class.java)

companion object{
init {
Skript.registerExpression(
ExprGetAllCloudnetPlayers::class.java, String::class.java,
ExpressionType.SIMPLE, "all [of the] cloudnet players")
}
}

override fun isSingle(): Boolean {
return false
}

@Suppress("UNCHECKED_CAST")
override fun init(
exprs: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parseResult: SkriptParser.ParseResult?
): Boolean {
return true
}
override fun get(e: Event?): Array<String?> {
return playerManager.onlinePlayers().names().toTypedArray()
}

override fun getReturnType(): Class<out String> {
return String::class.java
}

override fun toString(e: Event?, debug: Boolean): String {
return "all cloudnet players"
}

}

0 comments on commit b0dec51

Please sign in to comment.