Switch to Paper and fix some things

This commit is contained in:
Norbi Peti 2023-07-01 20:09:29 +02:00
parent 05fe1c261c
commit 822b2a5a67
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 21 additions and 13 deletions

View file

@ -138,8 +138,8 @@
</build> </build>
<repositories> <repositories>
<repository> <repository>
<id>spigot-repo</id> <id>papermc</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
@ -170,9 +170,9 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>spigot-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version> <version>1.19.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -226,7 +226,7 @@
<dependency> <dependency>
<groupId>me.lucko</groupId> <groupId>me.lucko</groupId>
<artifactId>commodore</artifactId> <artifactId>commodore</artifactId>
<version>1.11</version> <version>2.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -143,7 +143,7 @@ class MainPlugin : ButtonPlugin {
val playerSupplier = Supplier { Bukkit.getOnlinePlayers().map { obj -> obj.name }.asIterable() } val playerSupplier = Supplier { Bukkit.getOnlinePlayers().map { obj -> obj.name }.asIterable() }
command2MC.addParamConverter( command2MC.addParamConverter(
OfflinePlayer::class.java, OfflinePlayer::class.java,
{ name -> @Suppress("DEPRECATION") Bukkit.getOfflinePlayer(name) }, { name -> Bukkit.getOfflinePlayer(name) },
"Player not found!", "Player not found!",
playerSupplier playerSupplier
) )
@ -187,6 +187,7 @@ class MainPlugin : ButtonPlugin {
} }
companion object { companion object {
@JvmStatic
lateinit var instance: MainPlugin lateinit var instance: MainPlugin
private set private set

View file

@ -35,7 +35,7 @@ class RemoveResidentsCommand : ICommand2MC() {
if (MainPlugin.ess == null) 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("${ChatColor.RED}Essentials not found, players who haven't joined after changing their names are also listed here.")
sender.sendMessage("Residents to remove:") 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( 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" "${ChatColor.YELLOW}Will completely delete the resident, delete eco account setting is off"
) )

View file

@ -6,6 +6,7 @@ import buttondevteam.lib.architecture.config.IConfigData
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.configuration.Configuration import org.bukkit.configuration.Configuration
import org.bukkit.scheduler.BukkitTask import org.bukkit.scheduler.BukkitTask
import java.lang.reflect.Array.newInstance
import java.util.function.Function import java.util.function.Function
/** /**
@ -37,7 +38,7 @@ class ConfigData<T : Any?> internal constructor(
private var value: T? = null private var value: T? = null
init { init {
get() //Generate config automatically get(true) //Generate config automatically
} }
override fun toString(): String { override fun toString(): String {
@ -45,10 +46,14 @@ class ConfigData<T : Any?> internal constructor(
} }
override fun get(): T { override fun get(): T {
return get(false)
}
private fun get(initialGet: Boolean): T {
val cachedValue = value val cachedValue = value
if (cachedValue != null) return cachedValue //Speed things up if (cachedValue != null) return cachedValue //Speed things up
val config = config.config 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 } return getter.apply(convertPrimitiveType(freshValue)).also { value = it }
} }
@ -56,15 +61,17 @@ class ConfigData<T : Any?> internal constructor(
value = null value = null
} }
/** /**
* Converts a value to [T] from the representation returned by [Configuration.get]. * Converts a value to [T] from the representation returned by [Configuration.get].
*/ */
@Suppress("UNCHECKED_CAST", "DEPRECATION")
private fun convertPrimitiveType(value: Any): Any { private fun convertPrimitiveType(value: Any): Any {
return if (primitiveDef is Number) //If we expect a number return if (primitiveDef is Number) //If we expect a number
if (value is Number) ChromaUtils.convertNumber(value, primitiveDef.javaClass) 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 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 else if (value is List<*> && primitiveDef.javaClass.isArray) // If we got a list and we expected an array
value.toTypedArray<Any?>() value.toArray { newInstance(primitiveDef.javaClass.componentType, it) as Array<T> }
else value else value
} }
@ -75,12 +82,12 @@ class ConfigData<T : Any?> internal constructor(
this.value = value 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 val config = config.config
if (config != null) { if (config != null) {
config.set(path, `val`) config.set(path, `val`)
signalChange(this.config) 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`") ChromaUtils.logWarn("Attempted to get/set config value with no config! Path: $path, value: $`val`")
} }
} }