Skip to content

Commit

Permalink
Added some things, currently in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
byPixelTV committed Apr 30, 2024
1 parent 04cc1b9 commit b5fa471
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 53 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "de.bypixeltv"
version = "1.6"
version = "1.7.0"

repositories {
mavenCentral()
Expand Down
38 changes: 20 additions & 18 deletions src/main/kotlin/de/bypixeltv/skcloudnet/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ 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 de.bypixeltv.skcloudnet.utils.VersionUtils
import de.bypixeltv.skcloudnet.utils.IngameUpdateMessage
import dev.jorel.commandapi.CommandAPI
import dev.jorel.commandapi.CommandAPIBukkitConfig
import net.axay.kspigot.event.listen
import net.axay.kspigot.main.KSpigot
import net.kyori.adventure.text.minimessage.MiniMessage
import org.bukkit.event.player.PlayerJoinEvent
import java.io.IOException

class Main : KSpigot() {
Expand Down Expand Up @@ -54,38 +52,42 @@ class Main : KSpigot() {
server.consoleSender.sendMessage(miniMessages.deserialize("<aqua>Successfully enabled SkCloudnet v${this.description.version}!</aqua>"))


val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble()
val githubVersion = VersionUtils().getLatestAddonVersion()?.replace("v", "")
val currentVersion = this.description.version.replace("v", "")

if (githubVersion != null) {
if (githubVersion > this.description.version.replace("v", "").toDouble()) {
if (VersionUtils().isVersionGreater(githubVersion, currentVersion)) {
// There is an update available
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
// You're on the latest version
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#43fa00>You're on the latest version of SkCloudnet!</color> <aqua>Version <yellow>v${this.description.version}</yellow></aqua>"))
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
} else if (githubVersion == currentVersion) {
// You're running a development version
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#43fa00>There is an update available for SkCloudnet!</color> <aqua>You're on version <yellow>v${this.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>"))
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
} else {
if (githubVersion == this.description.version.replace("v", "").toDouble()) {
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#43fa00>You're on the latest version of SkCloudnet!</color> <aqua>Version <yellow>v${this.description.version}</yellow></aqua>"))
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
} else if (githubVersion < this.description.version.replace("v", "").toDouble()) {
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#ff0000>You're running a development version of SkCloudnet! Please note that this version may contain bugs!</color> <aqua>Version <color:#ff0000>v${this.description.version}</color> > <color:#43fa00>${GetVersion().getLatestAddonVersion()}</color></aqua>"))
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#ff0000>You're running a development version of SkCloudnet! Please note that this version may contain bugs!</color> <aqua>Version <color:#ff0000>v${this.description.version}</color> > <color:#43fa00>${VersionUtils().getLatestAddonVersion()}</color></aqua>"))
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
}
}
} else {
// Unable to fetch the latest version from GitHub
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(miniMessages.deserialize("<color:#ff0000>Unable to fetch the latest version from Github!</color> <aqua>Are you rate limited?</aqua>"))
server.consoleSender.sendMessage(" ")
server.consoleSender.sendMessage(" ")
}

UpdateChecker
IngameUpdateMessage
UpdateCheck

val metrics: Metrics = Metrics(this, 21526)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ 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.VersionUtils
import dev.jorel.commandapi.kotlindsl.commandTree
import dev.jorel.commandapi.kotlindsl.literalArgument
import dev.jorel.commandapi.kotlindsl.playerExecutor
import dev.jorel.commandapi.kotlindsl.stringArgument
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 java.nio.file.Files
import java.nio.file.Paths
Expand All @@ -34,7 +30,7 @@ class SkCloudnetCommands {
val addonsList = if (addonMessages.isNotEmpty()) addonMessages.joinToString("\n") else "<color:#ff0000>No other addons found</color>"
player.sendMessage(
miniMessages.deserialize(
"<dark_grey>--- <aqua>SkCloudnet</aqua> <grey>Info:</grey> ---</dark_grey>\n\n<grey>SkCloudnet Version: <aqua>${Main.INSTANCE.description.version}</aqua>\nSkript Version: <aqua>${GetVersion().getSkriptVersion()}</aqua>\nServer Version: <aqua>${Main.INSTANCE.server.minecraftVersion}</aqua>\nServer Implementation: <aqua>${Main.INSTANCE.server.version}</aqua>\nAddons:\n$addonsList</grey>"
"<dark_grey>--- <aqua>SkCloudnet</aqua> <grey>Info:</grey> ---</dark_grey>\n\n<grey>SkCloudnet Version: <aqua>${Main.INSTANCE.description.version}</aqua>\nSkript Version: <aqua>${VersionUtils().getSkriptVersion()}</aqua>\nServer Version: <aqua>${Main.INSTANCE.server.minecraftVersion}</aqua>\nServer Implementation: <aqua>${Main.INSTANCE.server.version}</aqua>\nAddons:\n$addonsList</grey>"
)
)
}
Expand All @@ -52,15 +48,15 @@ class SkCloudnetCommands {
literalArgument("version") {
withPermission("skcloudnet.admin.version")
playerExecutor { player, _ ->
val githubVersion = GetVersion().getLatestAddonVersion()?.replace("v", "")?.toDouble()
val githubVersion = VersionUtils().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>"))
} 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:#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>"))
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>${VersionUtils().getLatestAddonVersion()}</color></aqua>"))
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.bypixeltv.skcloudnet.elements.effects
package de.bypixeltv.skcloudnet.elements.effects.players

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
Expand All @@ -9,9 +9,7 @@ import ch.njol.skript.lang.Effect
import ch.njol.skript.lang.Expression
import ch.njol.skript.lang.SkriptParser
import ch.njol.util.Kleenean
import de.bypixeltv.skcloudnet.Main
import eu.cloudnetservice.driver.inject.InjectionLayer
import eu.cloudnetservice.driver.provider.CloudServiceProvider
import eu.cloudnetservice.driver.registry.ServiceRegistry
import eu.cloudnetservice.modules.bridge.player.PlayerManager
import net.axay.kspigot.chat.literalText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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 Task of Player")
@Description("Returns the CloudNet task of a player.")
@Examples("send cloudnet task of \"byPixelTV\" parsed as player")
@Since("1.7")

class ExprGetCloudnetPlayerTask : 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(
ExprGetCloudnetPlayerTask::class.java, String::class.java,
ExpressionType.SIMPLE, "cloudnet task of [the] [player] %player%")
}
}

private var player: Expression<Player>? = null

override fun isSingle(): Boolean {
return true
}

@Suppress("UNCHECKED_CAST")
override fun init(
exprs: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parseResult: SkriptParser.ParseResult?
): Boolean {
this.player = exprs[0] as Expression<Player>?
return true
}

override fun get(e: Event?): Array<String?> {
val player = this.player?.getSingle(e)
if (player != null) {
val serviceInfo = playerManager.onlinePlayer(player.uniqueId)?.connectedService()?.taskName()
return arrayOf(serviceInfo)
}
return arrayOfNulls(0)
}

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

override fun toString(e: Event?, debug: Boolean): String {
return "cloudnet task of ${player?.getSingle(e)}"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package de.bypixeltv.skcloudnet.elements.expressions.services

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.provider.CloudServiceProvider
import eu.cloudnetservice.driver.service.ServiceInfoSnapshot
import eu.cloudnetservice.modules.bridge.BridgeDocProperties
import eu.cloudnetservice.modules.bridge.BridgeServiceHelper
import eu.cloudnetservice.modules.bridge.player.ServicePlayer
import org.bukkit.event.Event
import org.jetbrains.annotations.UnknownNullability


@Name("All CloudNet players on service.")
@Description("Returns all CloudNet players on a service.")
@Examples("broadcast all cloudnet players on service \"Lobby\"")
@Since("1.0")

class ExprGetAllCloudnetPlayersOnService : SimpleExpression<String>() {

private val cnServiceProvider: CloudServiceProvider = InjectionLayer.ext().instance(CloudServiceProvider::class.java)

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

override fun isSingle(): Boolean {
return false
}

private var service: Expression<String>? = null

@Suppress("UNCHECKED_CAST")
override fun init(
exprs: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parseResult: SkriptParser.ParseResult?
): Boolean {
this.service = exprs[0] as Expression<String>?
return true
}

override fun get(e: Event?): Array<String?>? {
val service = this.service?.getSingle(e)
val servicePlayers = service?.let { cnServiceProvider.serviceByName(it)!!.readProperty(BridgeDocProperties.PLAYERS) }
return servicePlayers?.map { it.name }?.toTypedArray()
}

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

override fun toString(e: Event?, debug: Boolean): String {
return "all cloudnet players on service ${this.service?.getSingle(e)}"
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.bypixeltv.skcloudnet.elements.expressions.services
package de.bypixeltv.skcloudnet.elements.expressions.tasks

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
Expand All @@ -11,7 +11,6 @@ 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.provider.CloudServiceProvider
import eu.cloudnetservice.driver.provider.ServiceTaskProvider
import org.bukkit.event.Event

Expand All @@ -23,7 +22,7 @@ import org.bukkit.event.Event

class ExprAllCloudnetTasks : SimpleExpression<String>() {

val serviceTaskProvider = InjectionLayer.ext().instance(ServiceTaskProvider::class.java)
private val serviceTaskProvider: ServiceTaskProvider = InjectionLayer.ext().instance(ServiceTaskProvider::class.java)

companion object{
init {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.bypixeltv.skcloudnet.elements.expressions.services
package de.bypixeltv.skcloudnet.elements.expressions.tasks

import ch.njol.skript.Skript
import ch.njol.skript.doc.Description
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.bypixeltv.skcloudnet.elements.expressions.tasks

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.event.Event


@Name("All CloudNet players on task.")
@Description("Returns all CloudNet players on a task.")
@Examples("broadcast all cloudnet players on task \"Lobby\"")
@Since("1.0")

class ExprGetAllCloudnetPlayersOnTask : 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(
ExprGetAllCloudnetPlayersOnTask::class.java, String::class.java,
ExpressionType.SIMPLE, "all [of the] cloudnet players on [the] task %string%")
}
}

override fun isSingle(): Boolean {
return false
}

private var task: Expression<String>? = null

@Suppress("UNCHECKED_CAST")
override fun init(
exprs: Array<Expression<*>>,
matchedPattern: Int,
isDelayed: Kleenean?,
parseResult: SkriptParser.ParseResult?
): Boolean {
this.task = exprs[0] as Expression<String>?
return true
}

override fun get(e: Event?): Array<String>? {
val task = this.task?.getSingle(e)
return task?.let { playerManager.taskOnlinePlayers(it).names().toTypedArray() }
}

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

override fun toString(e: Event?, debug: Boolean): String {
return "all cloudnet players on task ${this.task?.getSingle(e)}"
}

}
Loading

0 comments on commit b5fa471

Please sign in to comment.