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

View file

@ -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

View file

@ -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"
)

View file

@ -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<T : Any?> 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<T : Any?> 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<T : Any?> 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<Any?>()
value.toArray { newInstance(primitiveDef.javaClass.componentType, it) as Array<T> }
else value
}
@ -75,12 +82,12 @@ class ConfigData<T : Any?> 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`")
}
}