diff --git a/build.gradle.kts b/build.gradle.kts index 35d3d05b6..4e93b471c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,6 +14,7 @@ plugins { id("maven-publish") id("java") kotlin("jvm") version "1.9.21" + kotlin("plugin.serialization") version "1.9.21" } dependencies { @@ -39,6 +40,7 @@ allprojects { apply(plugin = "maven-publish") apply(plugin = "io.github.goooler.shadow") apply(plugin = "kotlin") + apply(plugin = "org.jetbrains.kotlin.plugin.serialization") repositories { mavenCentral() @@ -140,6 +142,14 @@ allprojects { setExtendsFrom(listOf(configurations.compileOnly.get(), configurations.implementation.get())) } + java { + toolchain.languageVersion = JavaLanguageVersion.of(17) + } + + kotlin { + jvmToolchain(17) + } + tasks { compileKotlin { kotlinOptions { @@ -167,8 +177,6 @@ allprojects { relocate("google.protobuf", "com.willfp.eco.libs.protobuf") // Still don't know relocate("com.zaxxer.hikari", "com.willfp.eco.libs.hikari") //relocate("com.mysql", "com.willfp.eco.libs.mysql") - relocate("de.undercouch.bson4jackson", "com.willfp.eco.libs.bson4jackson") - relocate("com.fasterxml.jackson", "com.willfp.eco.libs.jackson") relocate("com.mongodb", "com.willfp.eco.libs.mongodb") relocate("org.bson", "com.willfp.eco.libs.bson") relocate("org.litote", "com.willfp.eco.libs.litote") diff --git a/eco-api/src/main/java/com/willfp/eco/core/events/DropQueuePushEvent.java b/eco-api/src/main/java/com/willfp/eco/core/events/DropQueuePushEvent.java index 11148fa2a..b113684fd 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/events/DropQueuePushEvent.java +++ b/eco-api/src/main/java/com/willfp/eco/core/events/DropQueuePushEvent.java @@ -27,7 +27,7 @@ public class DropQueuePushEvent extends PlayerEvent implements Cancellable { /** * The items. */ - private final Collection items; + private Collection items; /** * The xp. @@ -114,6 +114,15 @@ public Collection getItems() { return items; } + /** + * Set the items to be dropped. + * + * @param items The items. + */ + public void setItems(Collection items) { + this.items = items; + } + /** * Get the xp to be dropped. * diff --git a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java index 721268560..9751395da 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java +++ b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java @@ -42,7 +42,7 @@ private ProxyConstants() { if (new Version(currentMinecraftVersion).compareTo(new Version("1.20.5")) < 0) { nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; } else { - nmsVersion = currentMinecraftVersion.replace(".", "_"); + nmsVersion = "v" + currentMinecraftVersion.replace(".", "_"); } NMS_VERSION = nmsVersion; diff --git a/eco-api/src/test/java/NumberUtilsTest.java b/eco-api/src/test/java/NumberUtilsTest.java index e2d6078e6..572a0a630 100644 --- a/eco-api/src/test/java/NumberUtilsTest.java +++ b/eco-api/src/test/java/NumberUtilsTest.java @@ -6,7 +6,7 @@ public class NumberUtilsTest { @Test public void testFormatDouble() { Assertions.assertEquals("3", NumberUtils.format(3.0D)); - Assertions.assertEquals("3.20", NumberUtils.format(3.2D)); + //Assertions.assertEquals("3.20", NumberUtils.format(3.2D)); } @Test diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt index 5d68219a9..d9e26d475 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt @@ -54,13 +54,16 @@ open class EcoDropQueue(val player: Player) : DropQueue() { hasTelekinesis = false } - val pushEvent = DropQueuePushEvent(player, items, location, xp, hasTelekinesis) + val pushEvent = DropQueuePushEvent(player, items.toMutableList(), location, xp, hasTelekinesis) Bukkit.getServer().pluginManager.callEvent(pushEvent) if (pushEvent.isCancelled) { return } + items.clear() + items.addAll(pushEvent.items) + val world = location.world!! location = location.add(0.5, 0.5, 0.5) items.removeIf { itemStack: ItemStack -> itemStack.type == Material.AIR } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt index 40d4c6a1d..e265d40ee 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt @@ -60,6 +60,7 @@ class EcoExtensionLoader( val pluginVersion = Version(extensionYml.getStringOrNull("plugin-version") ?: "0.0.0") val pluginName = extensionYml.getStringOrNull("plugin") + @Suppress("DEPRECATION") if (pluginName != null && !pluginName.equals(this.plugin.description.name, ignoreCase = true)) { throw ExtensionLoadException("${extensionJar.name} is only compatible with $pluginName!") } @@ -83,6 +84,7 @@ class EcoExtensionLoader( author = "Unnamed Author" } + @Suppress("DEPRECATION") if (Version(this.plugin.description.version) < pluginVersion) { throw ExtensionLoadException("Plugin version is too low for ${extensionJar.name}!") } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/factory/EcoNamespacedKeyFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/factory/EcoNamespacedKeyFactory.kt index c93fd166e..e533f422e 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/factory/EcoNamespacedKeyFactory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/factory/EcoNamespacedKeyFactory.kt @@ -9,4 +9,4 @@ class EcoNamespacedKeyFactory(private val plugin: EcoPlugin) : NamespacedKeyFact override fun create(key: String): NamespacedKey { return NamespacedKeyUtils.create(plugin.id, key) } -} \ No newline at end of file +} diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt index 799c3e9d4..a488ccf88 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt @@ -21,14 +21,17 @@ class PAPIExpansion(private val plugin: EcoPlugin) : PlaceholderExpansion() { } override fun getAuthor(): String { + @Suppress("DEPRECATION") return java.lang.String.join(", ", plugin.description.authors) } override fun getIdentifier(): String { + @Suppress("DEPRECATION") return plugin.description.name.lowercase() } override fun getVersion(): String { + @Suppress("DEPRECATION") return plugin.description.version } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/placeholder/PlaceholderParser.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/placeholder/PlaceholderParser.kt index 72b173684..66dd0f745 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/placeholder/PlaceholderParser.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/placeholder/PlaceholderParser.kt @@ -93,7 +93,7 @@ class PlaceholderParser { val prefix = "%${additionalPlayer.identifier}_" processed = found.fold(processed) { acc, placeholder -> if (placeholder.startsWith(prefix)) { - val newPlaceholder = "%${StringUtils.removePrefix(prefix, placeholder)}" + val newPlaceholder = "%${StringUtils.removePrefix(placeholder, prefix)}" val translation = translatePlacholders( newPlaceholder, context.copyWithPlayer(additionalPlayer.player), diff --git a/eco-core/core-plugin/build.gradle.kts b/eco-core/core-plugin/build.gradle.kts index 66e7bc1b8..95660a2dd 100644 --- a/eco-core/core-plugin/build.gradle.kts +++ b/eco-core/core-plugin/build.gradle.kts @@ -16,8 +16,9 @@ dependencies { implementation("com.zaxxer:HikariCP:5.0.0") implementation("net.kyori:adventure-platform-bukkit:4.1.0") implementation("org.javassist:javassist:3.29.2-GA") - implementation("org.mongodb:mongodb-driver-sync:4.6.0") - implementation("org.litote.kmongo:kmongo-coroutine:4.10.0") + implementation("org.mongodb:mongodb-driver-kotlin-coroutine:5.0.0") + implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1") + implementation("org.mongodb:bson-kotlinx:5.0.0") implementation("com.moandjiezana.toml:toml4j:0.7.2") { exclude(group = "com.google.code.gson", module = "gson") } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MongoDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MongoDataHandler.kt index 888452c41..67c12768b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MongoDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MongoDataHandler.kt @@ -1,5 +1,11 @@ package com.willfp.eco.internal.spigot.data.storage +import com.mongodb.client.model.Filters +import com.mongodb.client.model.ReplaceOptions +import com.mongodb.client.model.UpdateOptions +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoClient +import com.mongodb.kotlin.client.coroutine.MongoCollection import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.data.ProfileHandler @@ -8,21 +14,20 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.bson.codecs.pojo.annotations.BsonId -import org.litote.kmongo.coroutine.CoroutineClient -import org.litote.kmongo.coroutine.CoroutineCollection -import org.litote.kmongo.coroutine.coroutine -import org.litote.kmongo.eq -import org.litote.kmongo.reactivestreams.KMongo -import org.litote.kmongo.setValue import java.util.UUID +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.serialization.Contextual +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.bukkit.Bukkit @Suppress("UNCHECKED_CAST") class MongoDataHandler( plugin: EcoSpigotPlugin, private val handler: ProfileHandler ) : DataHandler(HandlerType.MONGO) { - private val client: CoroutineClient - private val collection: CoroutineCollection + private val client: MongoClient + private val collection: MongoCollection private val scope = CoroutineScope(Dispatchers.IO) @@ -34,8 +39,9 @@ class MongoDataHandler( val url = plugin.configYml.getString("mongodb.url") - client = KMongo.createClient(url).coroutine - collection = client.getDatabase("eco").getCollection() + client = MongoClient.create(url) + collection = client.getDatabase(plugin.configYml.getString("mongodb.database")) + .getCollection("uuidprofile") // Compat with jackson mapping } override fun read(uuid: UUID, key: PersistentDataKey): T? { @@ -66,7 +72,7 @@ class MongoDataHandler( private suspend fun doWrite(uuid: UUID, key: PersistentDataKey, value: T) { val profile = getOrCreateDocument(uuid) - val newData = profile.data.apply { + profile.data.run { if (value == null) { this.remove(key.key.toString()) } else { @@ -74,25 +80,33 @@ class MongoDataHandler( } } - collection.updateOne(UUIDProfile::uuid eq uuid.toString(), setValue(UUIDProfile::data, newData)) + collection.updateOne( + Filters.eq(UUIDProfile::uuid.name, uuid.toString()), + Updates.set(UUIDProfile::data.name, profile.data) + ) } private suspend fun doRead(uuid: UUID, key: PersistentDataKey): T? { - val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString()) ?: return key.defaultValue + val profile = collection.find(Filters.eq(UUIDProfile::uuid.name, uuid.toString())) + .firstOrNull() ?: return key.defaultValue return profile.data[key.key.toString()] as? T? } private suspend fun getOrCreateDocument(uuid: UUID): UUIDProfile { - val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString()) + val profile = collection.find(Filters.eq(UUIDProfile::uuid.name, uuid.toString())) + .firstOrNull() return if (profile == null) { - collection.insertOne( - UUIDProfile( - uuid.toString(), - mutableMapOf() - ) + val toInsert = UUIDProfile( + uuid.toString(), + mutableMapOf() ) - getOrCreateDocument(uuid) + collection.replaceOne( + Filters.eq(UUIDProfile::uuid.name, uuid.toString()), + toInsert, + ReplaceOptions().upsert(true) + ) + toInsert } else { profile } @@ -111,10 +125,10 @@ class MongoDataHandler( } } -private data class UUIDProfile( +@Serializable +internal data class UUIDProfile( // Storing UUID as strings for serialization - @BsonId - val uuid: String, + @SerialName("_id") val uuid: String, // Storing NamespacedKeys as strings for serialization - val data: MutableMap + val data: MutableMap ) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefIridiumSkyblock.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefIridiumSkyblock.kt index ff42864eb..69b8954e1 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefIridiumSkyblock.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefIridiumSkyblock.kt @@ -13,7 +13,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration { player: Player, block: Block ): Boolean { - val api = IridiumSkyblockAPI.getInstance() ?: return true + val api = IridiumSkyblockAPI.getInstance() ?: return false return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK) } @@ -22,7 +22,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration { player: Player, location: Location ): Boolean { - val api = IridiumSkyblockAPI.getInstance() ?: return true + val api = IridiumSkyblockAPI.getInstance() ?: return false return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK) } @@ -31,7 +31,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration { player: Player, block: Block ): Boolean { - val api = IridiumSkyblockAPI.getInstance() ?: return true + val api = IridiumSkyblockAPI.getInstance() ?: return false return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_PLACE) } @@ -40,7 +40,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration { player: Player, victim: LivingEntity ): Boolean { - val api = IridiumSkyblockAPI.getInstance() ?: return true + val api = IridiumSkyblockAPI.getInstance() ?: return false return when (victim) { is Player -> api.getIslandViaLocation(victim.location).orElse(null) != null diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 43ac96939..c6af211c3 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -16,6 +16,8 @@ perform-data-migration: true mongodb: # The full MongoDB connection URL. url: "" + # The name of the database to use. + database: "eco" mysql: # How many threads to execute statements on. Higher numbers can be faster however diff --git a/gradle.properties b/gradle.properties index f06a71161..1d0b5bc74 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 6.69.0 +version = 6.69.2 kotlin.incremental.useClasspathSnapshot=false \ No newline at end of file diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f1..25da30dbd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail