From 822b2a5a670c03264614dd423592a7dd5bae5061 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 1 Jul 2023 20:09:29 +0200 Subject: [PATCH] Switch to Paper and fix some things --- Chroma-Core/pom.xml | 12 ++++++------ .../main/java/buttondevteam/core/MainPlugin.kt | 3 ++- .../component/towny/RemoveResidentsCommand.kt | 2 +- .../lib/architecture/ConfigData.kt | 17 ++++++++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Chroma-Core/pom.xml b/Chroma-Core/pom.xml index 91eaea5..1a1b3c0 100755 --- a/Chroma-Core/pom.xml +++ b/Chroma-Core/pom.xml @@ -138,8 +138,8 @@ - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + papermc + https://repo.papermc.io/repository/maven-public/ jitpack.io @@ -170,9 +170,9 @@ compile - org.spigotmc - spigot-api - 1.18.1-R0.1-SNAPSHOT + io.papermc.paper + paper-api + 1.19.1-R0.1-SNAPSHOT provided @@ -226,7 +226,7 @@ me.lucko commodore - 1.11 + 2.2 compile diff --git a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.kt b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.kt index 030d58e..11dd0b7 100755 --- a/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.kt +++ b/Chroma-Core/src/main/java/buttondevteam/core/MainPlugin.kt @@ -143,7 +143,7 @@ class MainPlugin : ButtonPlugin { val playerSupplier = Supplier { Bukkit.getOnlinePlayers().map { obj -> obj.name }.asIterable() } command2MC.addParamConverter( OfflinePlayer::class.java, - { name -> @Suppress("DEPRECATION") Bukkit.getOfflinePlayer(name) }, + { name -> Bukkit.getOfflinePlayer(name) }, "Player not found!", playerSupplier ) @@ -187,6 +187,7 @@ class MainPlugin : ButtonPlugin { } companion object { + @JvmStatic lateinit var instance: MainPlugin private set diff --git a/Chroma-Core/src/main/java/buttondevteam/core/component/towny/RemoveResidentsCommand.kt b/Chroma-Core/src/main/java/buttondevteam/core/component/towny/RemoveResidentsCommand.kt index 047a448..2d9bede 100644 --- a/Chroma-Core/src/main/java/buttondevteam/core/component/towny/RemoveResidentsCommand.kt +++ b/Chroma-Core/src/main/java/buttondevteam/core/component/towny/RemoveResidentsCommand.kt @@ -35,7 +35,7 @@ class RemoveResidentsCommand : ICommand2MC() { if (MainPlugin.ess == null) sender.sendMessage("${ChatColor.RED}Essentials not found, players who haven't joined after changing their names are also listed here.") sender.sendMessage("Residents to remove:") - res.values.forEach { op: OfflinePlayer -> sender.sendMessage(op.name) } + res.values.forEach { op: OfflinePlayer -> sender.sendMessage(op.name!!) } if (TownySettings.isDeleteEcoAccount()) sender.sendMessage("${ChatColor.AQUA}Will only remove from town, as delete eco account setting is on") else sender.sendMessage( "${ChatColor.YELLOW}Will completely delete the resident, delete eco account setting is off" ) diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/architecture/ConfigData.kt b/Chroma-Core/src/main/java/buttondevteam/lib/architecture/ConfigData.kt index 8f8034c..ee60dd8 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/architecture/ConfigData.kt +++ b/Chroma-Core/src/main/java/buttondevteam/lib/architecture/ConfigData.kt @@ -6,6 +6,7 @@ import buttondevteam.lib.architecture.config.IConfigData import org.bukkit.Bukkit import org.bukkit.configuration.Configuration import org.bukkit.scheduler.BukkitTask +import java.lang.reflect.Array.newInstance import java.util.function.Function /** @@ -37,7 +38,7 @@ class ConfigData internal constructor( private var value: T? = null init { - get() //Generate config automatically + get(true) //Generate config automatically } override fun toString(): String { @@ -45,10 +46,14 @@ class ConfigData internal constructor( } override fun get(): T { + return get(false) + } + + private fun get(initialGet: Boolean): T { val cachedValue = value if (cachedValue != null) return cachedValue //Speed things up val config = config.config - val freshValue = config?.get(path) ?: primitiveDef.also { setInternal(it) } + val freshValue = config?.get(path) ?: primitiveDef.also { setInternal(it, initialGet) } return getter.apply(convertPrimitiveType(freshValue)).also { value = it } } @@ -56,15 +61,17 @@ class ConfigData internal constructor( value = null } + /** * Converts a value to [T] from the representation returned by [Configuration.get]. */ + @Suppress("UNCHECKED_CAST", "DEPRECATION") private fun convertPrimitiveType(value: Any): Any { return if (primitiveDef is Number) //If we expect a number if (value is Number) ChromaUtils.convertNumber(value, primitiveDef.javaClass) else primitiveDef //If we didn't get a number, return default (which is a number) else if (value is List<*> && primitiveDef.javaClass.isArray) // If we got a list and we expected an array - value.toTypedArray() + value.toArray { newInstance(primitiveDef.javaClass.componentType, it) as Array } else value } @@ -75,12 +82,12 @@ class ConfigData internal constructor( this.value = value } - private fun setInternal(`val`: Any?) { + private fun setInternal(`val`: Any?, initialSet: Boolean = false) { // TODO: Remove initialSet when #109 is done val config = config.config if (config != null) { config.set(path, `val`) signalChange(this.config) - } else if (!ChromaUtils.isTest) { + } else if (!initialSet) { ChromaUtils.logWarn("Attempted to get/set config value with no config! Path: $path, value: $`val`") } }