From 47772c3ff7f42db0187e9e85d7828995f8548d20 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 14:21:03 +0000 Subject: [PATCH 01/27] Reverted Shaped Recipe changes --- .../spigot/recipes/ShapedRecipeListener.kt | 34 +++---------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/ShapedRecipeListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/ShapedRecipeListener.kt index 4b77582f..7c2bf477 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/ShapedRecipeListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/ShapedRecipeListener.kt @@ -49,15 +49,13 @@ class ShapedRecipeListener : Listener { } isStackedRecipe = true } else if (inMatrix != null) { - val max = Math.floorDiv(inMatrix.amount, inRecipe.item.amount) + val max = inMatrix.amount if (max < upperBound) { upperBound = max } - isStackedRecipe = true } } - if (!isStackedRecipe) { return } @@ -68,10 +66,8 @@ class ShapedRecipeListener : Listener { upperBound-- } - val newMatrix = matrix; - for (i in 0..8) { - val inMatrix = matrix[i] + val inMatrix = event.inventory.matrix[i] val inRecipe = matched.parts[i] if (inRecipe is TestableStack) { @@ -80,35 +76,13 @@ class ShapedRecipeListener : Listener { for (j in 0..upperBound) { amount -= inRecipe.amount } - inMatrix.amount = amount; - newMatrix[i] = inMatrix - + inMatrix.amount = amount } else { inMatrix.amount = inMatrix.amount - (inRecipe.amount - 1) - newMatrix[i] = inMatrix - } - } else { - @Suppress("SENSELESS_COMPARISON") - if (inMatrix == null) { - continue - } - - if (event.isShiftClick) { - var amount = inMatrix.amount + 1 - for (j in 0..upperBound) { - amount -= inRecipe.item.amount - } - inMatrix.amount = amount; - newMatrix[i] = inMatrix - } else { - inMatrix.amount = inMatrix.amount - (inRecipe.item.amount - 1) - newMatrix[i] = inMatrix } } } - event.inventory.matrix = newMatrix; - if (event.isShiftClick) { val result = event.inventory.result ?: return @@ -161,4 +135,4 @@ class ShapedRecipeListener : Listener { listeners.add(listener) } } -} \ No newline at end of file +} From aa1ce34cbc48f3e541b4aa8590276cf6bde2cfa8 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 14:21:49 +0000 Subject: [PATCH 02/27] Updated to 6.24.4 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 2377fa38..95fba16f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.24.3 +version = 6.24.4 plugin-name = eco kotlin.code.style = official \ No newline at end of file From eeefb9f40ea9642d03c0affaf0ea144d0bde302a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 16:01:55 +0000 Subject: [PATCH 03/27] Server persistence changes --- .../eco/core/data/keys/PersistentDataKey.java | 48 ++++++++ .../willfp/eco/internal/spigot/EcoHandler.kt | 2 +- .../internal/spigot/data/EcoKeyRegistry.kt | 5 +- .../spigot/data/storage/MySQLDataHandler.kt | 110 ++++++++++++++---- .../spigot/data/storage/YamlDataHandler.kt | 2 +- 5 files changed, 136 insertions(+), 31 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java index fd1a5f01..171098ba 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java @@ -3,7 +3,9 @@ package com.willfp.eco.core.data.keys; import com.willfp.eco.core.Eco; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.Set; /** @@ -27,6 +29,11 @@ public class PersistentDataKey { */ private final PersistentDataKeyType type; + /** + * If the key is for server data. + */ + private final boolean isServerKey; + /** * Create a new Persistent Data Key. * @@ -37,9 +44,25 @@ public class PersistentDataKey { public PersistentDataKey(@NotNull final NamespacedKey key, @NotNull final PersistentDataKeyType type, @NotNull final T defaultValue) { + this(key, type, defaultValue, false); + } + + /** + * Create a new Persistent Data Key. + * + * @param key The key. + * @param type The data type. + * @param defaultValue The default value. + * @param isServerKey If the key is for server data. + */ + public PersistentDataKey(@NotNull final NamespacedKey key, + @NotNull final PersistentDataKeyType type, + @NotNull final T defaultValue, + final boolean isServerKey) { this.key = key; this.defaultValue = defaultValue; this.type = type; + this.isServerKey = isServerKey; Eco.getHandler().getKeyRegistry().registerKey(this); } @@ -80,6 +103,15 @@ public class PersistentDataKey { return this.type; } + /** + * Get if the key is for server data. + * + * @return If server key. + */ + public boolean isServerKey() { + return isServerKey; + } + /** * Get all persistent data keys. * @@ -88,4 +120,20 @@ public class PersistentDataKey { public static Set> values() { return Eco.getHandler().getKeyRegistry().getRegisteredKeys(); } + + @Override + public boolean equals(@Nullable final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof PersistentDataKey that)) { + return false; + } + return Objects.equals(this.getKey(), that.getKey()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getKey()); + } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt index a05c95fa..5db4d328 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt @@ -43,7 +43,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler { @Suppress("DEPRECATION") private val requirementFactory = com.willfp.eco.internal.requirement.EcoRequirementFactory() private var adventure: BukkitAudiences? = null - private val keyRegistry = EcoKeyRegistry(this) + private val keyRegistry = EcoKeyRegistry() private val playerProfileHandler = EcoProfileHandler(this.configYml.getBool("mysql.enabled"), this) @Suppress("RedundantNullableReturnType") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt index 05c76fcc..ed856251 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt @@ -4,12 +4,9 @@ import com.willfp.eco.core.Eco import com.willfp.eco.core.data.keys.KeyRegistry import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType -import com.willfp.eco.internal.spigot.EcoSpigotPlugin import org.bukkit.NamespacedKey -class EcoKeyRegistry( - private val plugin: EcoSpigotPlugin -) : KeyRegistry { +class EcoKeyRegistry: KeyRegistry { private val registry = mutableMapOf>() override fun registerKey(key: PersistentDataKey<*>) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 00b6aba5..3fd15f60 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -2,10 +2,12 @@ package com.willfp.eco.internal.spigot.data.storage import com.google.common.util.concurrent.ThreadFactoryBuilder import com.willfp.eco.core.Eco +import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.data.EcoProfileHandler +import com.willfp.eco.internal.spigot.data.serverProfileUUID import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariDataSource import org.apache.logging.log4j.Level @@ -31,8 +33,64 @@ import java.util.concurrent.Executors @Suppress("UNCHECKED_CAST") class MySQLDataHandler( plugin: EcoSpigotPlugin, - private val handler: EcoProfileHandler + handler: EcoProfileHandler ) : DataHandler { + private val playerHandler = ImplementedMySQLHandler( + handler, + UUIDTable("eco_players"), + plugin + ) { !it.isServerKey } + + private val serverHandler = ImplementedMySQLHandler( + handler, + UUIDTable("eco_server"), + plugin + ) { it.isServerKey } + + override fun saveAll(uuids: Iterable) { + serverHandler.saveAll(uuids.filter { it == serverProfileUUID }) + playerHandler.saveAll(uuids.filter { it != serverProfileUUID }) + } + + override fun write(uuid: UUID, key: NamespacedKey, value: T) { + applyFor(uuid) { + it.write(uuid, key, value) + } + } + + override fun saveKeysForPlayer(uuid: UUID, keys: Set>) { + applyFor(uuid) { + it.saveKeysForRow(uuid, keys) + } + } + + override fun read(uuid: UUID, key: NamespacedKey): T? { + return applyFor(uuid) { + it.read(uuid, key) + } + } + + override fun updateKeys() { + playerHandler.updateKeys() + serverHandler.updateKeys() + } + + private inline fun applyFor(uuid: UUID, function: (ImplementedMySQLHandler) -> R): R { + return if (uuid == serverProfileUUID) { + function(serverHandler) + } else { + function(playerHandler) + } + } +} + +@Suppress("UNCHECKED_CAST") +private class ImplementedMySQLHandler( + private val handler: EcoProfileHandler, + private val table: UUIDTable, + plugin: EcoPlugin, + private val validator: (PersistentDataKey<*>) -> Boolean +) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) @@ -52,7 +110,7 @@ class MySQLDataHandler( transaction { - SchemaUtils.create(Players) + SchemaUtils.create(table) } // Get Exposed to shut the hell up @@ -67,18 +125,20 @@ class MySQLDataHandler( } } - override fun updateKeys() { + fun updateKeys() { transaction { for (key in Eco.getHandler().keyRegistry.registeredKeys) { - registerColumn(key, Players) + if (validator(key)) { + registerColumn(key, table) + } } - SchemaUtils.createMissingTablesAndColumns(Players, withLogs = false) + SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) } } - override fun write(uuid: UUID, key: NamespacedKey, value: T) { - getPlayer(uuid) + fun write(uuid: UUID, key: NamespacedKey, value: T) { + getRow(uuid) writeAsserted(uuid, key, value) } @@ -87,42 +147,44 @@ class MySQLDataHandler( executor.submit { transaction { - Players.update({ Players.id eq uuid }) { + table.update({ table.id eq uuid }) { it[column] = value } } } } - override fun saveKeysForPlayer(uuid: UUID, keys: Set>) { - savePlayer(uuid, keys) + fun saveKeysForRow(uuid: UUID, keys: Set>) { + saveRow(uuid, keys) } - override fun saveAll(uuids: Iterable) { + fun saveAll(uuids: Iterable) { for (uuid in uuids) { - savePlayer(uuid) + saveRow(uuid, PersistentDataKey.values()) } } - private fun savePlayer(uuid: UUID, keys: Set>) { + private fun saveRow(uuid: UUID, keys: Set>) { val profile = handler.loadGenericProfile(uuid) executor.submit { transaction { - getPlayer(uuid) + getRow(uuid) for (key in keys) { - writeAsserted(uuid, key.key, profile.read(key)) + if (validator(key)) { + writeAsserted(uuid, key.key, profile.read(key)) + } } } } } - override fun read(uuid: UUID, key: NamespacedKey): T? { + fun read(uuid: UUID, key: NamespacedKey): T? { val doRead = Callable { var value: T? = null transaction { - val player = getPlayer(uuid) + val player = getRow(uuid) value = player[getColumn(key.toString())] as T? } @@ -136,8 +198,6 @@ class MySQLDataHandler( } } - object Players : UUIDTable("eco_players") - private fun registerColumn(key: PersistentDataKey, table: UUIDTable) { table.apply { if (this.columns.stream().anyMatch { it.name == key.key.toString() }) { @@ -165,22 +225,22 @@ class MySQLDataHandler( return cached } - columns[name] = Players.columns.stream().filter { it.name == name }.findFirst().get() + columns[name] = table.columns.stream().filter { it.name == name }.findFirst().get() return getColumn(name) } - private fun getPlayer(uuid: UUID): ResultRow { + private fun getRow(uuid: UUID): ResultRow { val player = transaction { - Players.select { Players.id eq uuid }.limit(1).singleOrNull() + table.select { table.id eq uuid }.limit(1).singleOrNull() } return if (player != null) { player } else { transaction { - Players.insert { it[id] = uuid } + table.insert { it[id] = uuid } } - getPlayer(uuid) + getRow(uuid) } } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt index dbd6f08b..f43a1993 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt @@ -51,4 +51,4 @@ class YamlDataHandler( false, ConfigType.YAML ) -} \ No newline at end of file +} From 9a51fb8358289e1c6dc67c977a196ca79c7d1d0a Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 16:11:31 +0000 Subject: [PATCH 04/27] Updated to 6.25.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 95fba16f..54e24ff0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.24.4 +version = 6.25.0 plugin-name = eco kotlin.code.style = official \ No newline at end of file From 5aeeafc0417c5bed44e5f35dfb219f482afb4684 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 16:32:38 +0000 Subject: [PATCH 05/27] MySQL Data Changes: Keys are now registered on first read/write --- .../eco/core/data/keys/KeyRegistry.java | 11 +++ .../eco/core/data/keys/PersistentDataKey.java | 30 --------- .../internal/spigot/data/EcoKeyRegistry.kt | 6 +- .../spigot/data/storage/DataHandler.kt | 8 +-- .../spigot/data/storage/MySQLDataHandler.kt | 67 +++++++++---------- .../spigot/data/storage/YamlDataHandler.kt | 2 +- 6 files changed, 51 insertions(+), 73 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java index 3827eab1..4673ee01 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java @@ -1,6 +1,8 @@ package com.willfp.eco.core.data.keys; +import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -21,4 +23,13 @@ public interface KeyRegistry { * @return The keys. */ Set> getRegisteredKeys(); + + /** + * Get persistent data key from namespaced key. + * + * @param namespacedKey The key. + * @return The key, or null if not found. + */ + @Nullable + PersistentDataKey getKeyFrom(@NotNull NamespacedKey namespacedKey); } diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java index 171098ba..e1937c3e 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java @@ -29,11 +29,6 @@ public class PersistentDataKey { */ private final PersistentDataKeyType type; - /** - * If the key is for server data. - */ - private final boolean isServerKey; - /** * Create a new Persistent Data Key. * @@ -44,25 +39,9 @@ public class PersistentDataKey { public PersistentDataKey(@NotNull final NamespacedKey key, @NotNull final PersistentDataKeyType type, @NotNull final T defaultValue) { - this(key, type, defaultValue, false); - } - - /** - * Create a new Persistent Data Key. - * - * @param key The key. - * @param type The data type. - * @param defaultValue The default value. - * @param isServerKey If the key is for server data. - */ - public PersistentDataKey(@NotNull final NamespacedKey key, - @NotNull final PersistentDataKeyType type, - @NotNull final T defaultValue, - final boolean isServerKey) { this.key = key; this.defaultValue = defaultValue; this.type = type; - this.isServerKey = isServerKey; Eco.getHandler().getKeyRegistry().registerKey(this); } @@ -103,15 +82,6 @@ public class PersistentDataKey { return this.type; } - /** - * Get if the key is for server data. - * - * @return If server key. - */ - public boolean isServerKey() { - return isServerKey; - } - /** * Get all persistent data keys. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt index ed856251..5fed77c4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt @@ -43,4 +43,8 @@ class EcoKeyRegistry: KeyRegistry { else -> throw NullPointerException("Null value found!") } } -} \ No newline at end of file + + override fun getKeyFrom(namespacedKey: NamespacedKey): PersistentDataKey<*>? { + return registry[namespacedKey] + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt index 309c1a52..c923102d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt @@ -11,15 +11,11 @@ interface DataHandler { fun saveAll(uuids: Iterable) - fun updateKeys() { - - } - fun savePlayer(uuid: UUID) { - saveKeysForPlayer(uuid, PersistentDataKey.values()) + saveKeysFor(uuid, PersistentDataKey.values()) } fun write(uuid: UUID, key: NamespacedKey, value: T) - fun saveKeysForPlayer(uuid: UUID, keys: Set>) + fun saveKeysFor(uuid: UUID, keys: Set>) fun read(uuid: UUID, key: NamespacedKey): T? } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 3fd15f60..a3a572ed 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -28,6 +28,7 @@ import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.update import java.util.UUID import java.util.concurrent.Callable +import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executors @Suppress("UNCHECKED_CAST") @@ -39,13 +40,13 @@ class MySQLDataHandler( handler, UUIDTable("eco_players"), plugin - ) { !it.isServerKey } + ) private val serverHandler = ImplementedMySQLHandler( handler, UUIDTable("eco_server"), plugin - ) { it.isServerKey } + ) override fun saveAll(uuids: Iterable) { serverHandler.saveAll(uuids.filter { it == serverProfileUUID }) @@ -58,7 +59,7 @@ class MySQLDataHandler( } } - override fun saveKeysForPlayer(uuid: UUID, keys: Set>) { + override fun saveKeysFor(uuid: UUID, keys: Set>) { applyFor(uuid) { it.saveKeysForRow(uuid, keys) } @@ -70,11 +71,6 @@ class MySQLDataHandler( } } - override fun updateKeys() { - playerHandler.updateKeys() - serverHandler.updateKeys() - } - private inline fun applyFor(uuid: UUID, function: (ImplementedMySQLHandler) -> R): R { return if (uuid == serverProfileUUID) { function(serverHandler) @@ -88,12 +84,12 @@ class MySQLDataHandler( private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, - plugin: EcoPlugin, - private val validator: (PersistentDataKey<*>) -> Boolean + plugin: EcoPlugin ) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) + private val registeredKeys = ConcurrentHashMap.newKeySet() init { val config = HikariConfig() @@ -108,7 +104,6 @@ private class ImplementedMySQLHandler( Database.connect(HikariDataSource(config)) - transaction { SchemaUtils.create(table) } @@ -125,25 +120,27 @@ private class ImplementedMySQLHandler( } } - fun updateKeys() { - transaction { - for (key in Eco.getHandler().keyRegistry.registeredKeys) { - if (validator(key)) { - registerColumn(key, table) - } - } + fun ensureKeyRegistration(key: NamespacedKey) { + if (registeredKeys.contains(key)) { + return + } + transaction { + val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key)!! + + registerColumn(persistentKey, table) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) + registeredKeys.add(key) } } fun write(uuid: UUID, key: NamespacedKey, value: T) { - getRow(uuid) - writeAsserted(uuid, key, value) + getOrCreateRow(uuid) + doWrite(uuid, key, value) } - private fun writeAsserted(uuid: UUID, key: NamespacedKey, value: T) { - val column: Column = getColumn(key.toString()) as Column + private fun doWrite(uuid: UUID, key: NamespacedKey, value: T) { + val column: Column = getColumn(key) as Column executor.submit { transaction { @@ -169,12 +166,10 @@ private class ImplementedMySQLHandler( executor.submit { transaction { - getRow(uuid) + getOrCreateRow(uuid) for (key in keys) { - if (validator(key)) { - writeAsserted(uuid, key.key, profile.read(key)) - } + doWrite(uuid, key.key, profile.read(key)) } } } @@ -184,8 +179,8 @@ private class ImplementedMySQLHandler( val doRead = Callable { var value: T? = null transaction { - val player = getRow(uuid) - value = player[getColumn(key.toString())] as T? + val row = getOrCreateRow(uuid) + value = row[getColumn(key)] as T? } return@Callable value @@ -219,28 +214,30 @@ private class ImplementedMySQLHandler( } } - private fun getColumn(name: String): Column<*> { + private fun getColumn(key: NamespacedKey): Column<*> { + ensureKeyRegistration(key) + val name = key.toString() val cached = columns[name] if (cached != null) { return cached } columns[name] = table.columns.stream().filter { it.name == name }.findFirst().get() - return getColumn(name) + return getColumn(key) } - private fun getRow(uuid: UUID): ResultRow { - val player = transaction { + private fun getOrCreateRow(uuid: UUID): ResultRow { + val row = transaction { table.select { table.id eq uuid }.limit(1).singleOrNull() } - return if (player != null) { - player + return if (row != null) { + row } else { transaction { table.insert { it[id] = uuid } } - getRow(uuid) + getOrCreateRow(uuid) } } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt index f43a1993..851ab08b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt @@ -27,7 +27,7 @@ class YamlDataHandler( save() } - override fun saveKeysForPlayer(uuid: UUID, keys: Set>) { + override fun saveKeysFor(uuid: UUID, keys: Set>) { val profile = handler.loadGenericProfile(uuid) for (key in keys) { From 511a7e48304654db3100bec681895e99f1ebb5b0 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 16:42:47 +0000 Subject: [PATCH 06/27] Added optimisations to lazy column creation --- .../willfp/eco/internal/spigot/EcoHandler.kt | 3 ++ .../eco/internal/spigot/EcoSpigotPlugin.kt | 3 ++ .../eco/internal/spigot/data/DataYml.kt | 14 +++++++ .../internal/spigot/data/EcoKeyRegistry.kt | 3 -- .../internal/spigot/data/EcoProfileHandler.kt | 4 -- .../spigot/data/storage/MySQLDataHandler.kt | 38 +++++++++++++++---- .../spigot/data/storage/YamlDataHandler.kt | 13 +------ .../core-plugin/src/main/resources/data.yml | 5 ++- 8 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt index 5db4d328..2c23705e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt @@ -24,6 +24,7 @@ import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI import com.willfp.eco.internal.logging.EcoLogger import com.willfp.eco.internal.proxy.EcoProxyFactory import com.willfp.eco.internal.scheduling.EcoScheduler +import com.willfp.eco.internal.spigot.data.DataYml import com.willfp.eco.internal.spigot.data.EcoKeyRegistry import com.willfp.eco.internal.spigot.data.EcoProfileHandler import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler @@ -38,6 +39,8 @@ import java.util.logging.Logger @Suppress("UNUSED") class EcoHandler : EcoSpigotPlugin(), Handler { + override val dataYml = DataYml(this) + private val cleaner = EcoCleaner() @Suppress("DEPRECATION") diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 54e64b5c..2fc3f9ae 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -47,6 +47,7 @@ import com.willfp.eco.internal.items.ArgParserTexture import com.willfp.eco.internal.items.ArgParserUnbreakable import com.willfp.eco.internal.spigot.arrows.ArrowDataListener import com.willfp.eco.internal.spigot.data.DataListener +import com.willfp.eco.internal.spigot.data.DataYml import com.willfp.eco.internal.spigot.data.PlayerBlockListener import com.willfp.eco.internal.spigot.data.storage.ProfileSaver import com.willfp.eco.internal.spigot.display.PacketAutoRecipe @@ -122,6 +123,8 @@ import org.bukkit.event.Listener import org.bukkit.inventory.ItemStack abstract class EcoSpigotPlugin : EcoPlugin() { + abstract val dataYml: DataYml + init { Items.registerArgParser(ArgParserEnchantment()) Items.registerArgParser(ArgParserColor()) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt new file mode 100644 index 00000000..89c57f56 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataYml.kt @@ -0,0 +1,14 @@ +package com.willfp.eco.internal.spigot.data + +import com.willfp.eco.core.config.BaseConfig +import com.willfp.eco.core.config.ConfigType +import com.willfp.eco.internal.spigot.EcoSpigotPlugin + +class DataYml( + plugin: EcoSpigotPlugin +) : BaseConfig( + "data", + plugin, + false, + ConfigType.YAML +) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt index 5fed77c4..1497bab9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt @@ -1,6 +1,5 @@ package com.willfp.eco.internal.spigot.data -import com.willfp.eco.core.Eco import com.willfp.eco.core.data.keys.KeyRegistry import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType @@ -17,8 +16,6 @@ class EcoKeyRegistry: KeyRegistry { validateKey(key) this.registry[key.key] = key - - (Eco.getHandler().profileHandler as EcoProfileHandler).updateKeys() } override fun getRegisteredKeys(): MutableSet> { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt index 4655e5a1..d439cc86 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt @@ -63,8 +63,4 @@ class EcoProfileHandler( override fun save() { handler.save() } - - fun updateKeys() { - handler.updateKeys() - } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index a3a572ed..e14ad292 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -8,6 +8,7 @@ import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.data.EcoProfileHandler import com.willfp.eco.internal.spigot.data.serverProfileUUID +import com.willfp.eco.util.NamespacedKeyUtils import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariDataSource import org.apache.logging.log4j.Level @@ -33,19 +34,23 @@ import java.util.concurrent.Executors @Suppress("UNCHECKED_CAST") class MySQLDataHandler( - plugin: EcoSpigotPlugin, + private val plugin: EcoSpigotPlugin, handler: EcoProfileHandler ) : DataHandler { private val playerHandler = ImplementedMySQLHandler( handler, UUIDTable("eco_players"), - plugin + plugin, + plugin.dataYml.getStrings("known-player-keys") + .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } ) private val serverHandler = ImplementedMySQLHandler( handler, UUIDTable("eco_server"), - plugin + plugin, + plugin.dataYml.getStrings("known-server-keys") + .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } ) override fun saveAll(uuids: Iterable) { @@ -78,18 +83,31 @@ class MySQLDataHandler( function(playerHandler) } } + + override fun save() { + plugin.dataYml.set( + "known-player-keys", + playerHandler.registeredKeys.map { it.toString() } + ) + plugin.dataYml.set( + "known-server-keys", + serverHandler.registeredKeys.map { it.toString() } + ) + plugin.dataYml.save() + } } @Suppress("UNCHECKED_CAST") private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, - plugin: EcoPlugin + plugin: EcoPlugin, + knownKeys: Collection ) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) - private val registeredKeys = ConcurrentHashMap.newKeySet() + val registeredKeys: MutableSet = ConcurrentHashMap.newKeySet() init { val config = HikariConfig() @@ -118,6 +136,12 @@ private class ImplementedMySQLHandler( } } } + + plugin.scheduler.runLater(1) { + for (key in knownKeys) { + ensureKeyRegistration(key) + } + } } fun ensureKeyRegistration(key: NamespacedKey) { @@ -125,9 +149,9 @@ private class ImplementedMySQLHandler( return } - transaction { - val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key)!! + val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return + transaction { registerColumn(persistentKey, table) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) registeredKeys.add(key) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt index 851ab08b..bd470c30 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/YamlDataHandler.kt @@ -1,7 +1,5 @@ package com.willfp.eco.internal.spigot.data.storage -import com.willfp.eco.core.config.BaseConfig -import com.willfp.eco.core.config.ConfigType import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.data.EcoProfileHandler @@ -13,7 +11,7 @@ class YamlDataHandler( plugin: EcoSpigotPlugin, private val handler: EcoProfileHandler ) : DataHandler { - private val dataYml = DataYml(plugin) + private val dataYml = plugin.dataYml override fun save() { dataYml.save() @@ -42,13 +40,4 @@ class YamlDataHandler( override fun read(uuid: UUID, key: NamespacedKey): T? { return dataYml.get("player.$uuid.$key") as T? } - - class DataYml( - plugin: EcoSpigotPlugin - ) : BaseConfig( - "data", - plugin, - false, - ConfigType.YAML - ) } diff --git a/eco-core/core-plugin/src/main/resources/data.yml b/eco-core/core-plugin/src/main/resources/data.yml index 80ad14ee..ef09cebe 100644 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ b/eco-core/core-plugin/src/main/resources/data.yml @@ -1 +1,4 @@ -# For internal storage use only, do not modify. \ No newline at end of file +# For internal storage use only, do not modify. + +known-player-keys: [] +known-server-keys: [] From ad3cb3a620e09f1b8cc76976ee46294aed651f31 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 16:48:40 +0000 Subject: [PATCH 07/27] Fixed postInit --- .../willfp/eco/internal/spigot/EcoSpigotPlugin.kt | 2 ++ .../eco/internal/spigot/data/EcoProfileHandler.kt | 4 ++++ .../internal/spigot/data/storage/DataHandler.kt | 7 ++++--- .../spigot/data/storage/MySQLDataHandler.kt | 15 ++++++++++----- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 2fc3f9ae..26e9675e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -48,6 +48,7 @@ import com.willfp.eco.internal.items.ArgParserUnbreakable import com.willfp.eco.internal.spigot.arrows.ArrowDataListener import com.willfp.eco.internal.spigot.data.DataListener import com.willfp.eco.internal.spigot.data.DataYml +import com.willfp.eco.internal.spigot.data.EcoProfileHandler import com.willfp.eco.internal.spigot.data.PlayerBlockListener import com.willfp.eco.internal.spigot.data.storage.ProfileSaver import com.willfp.eco.internal.spigot.display.PacketAutoRecipe @@ -215,6 +216,7 @@ abstract class EcoSpigotPlugin : EcoPlugin() { CustomItemsManager.registerAllItems() CustomEntitiesManager.registerAllEntities() ShopManager.registerEcoProvider() + (Eco.getHandler().profileHandler as EcoProfileHandler).runPostInit() } override fun loadIntegrationLoaders(): List { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt index d439cc86..2ae5bb91 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt @@ -63,4 +63,8 @@ class EcoProfileHandler( override fun save() { handler.save() } + + fun runPostInit() { + handler.runPostInit() + } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt index c923102d..6bf177ee 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt @@ -5,12 +5,13 @@ import org.bukkit.NamespacedKey import java.util.UUID interface DataHandler { - fun save() { + fun save() + fun saveAll(uuids: Iterable) + + fun runPostInit() { } - fun saveAll(uuids: Iterable) - fun savePlayer(uuid: UUID) { saveKeysFor(uuid, PersistentDataKey.values()) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index e14ad292..d414803d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -95,6 +95,11 @@ class MySQLDataHandler( ) plugin.dataYml.save() } + + override fun runPostInit() { + playerHandler.runPostInit() + serverHandler.runPostInit() + } } @Suppress("UNCHECKED_CAST") @@ -102,7 +107,7 @@ private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, plugin: EcoPlugin, - knownKeys: Collection + private val knownKeys: Collection ) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() @@ -136,11 +141,11 @@ private class ImplementedMySQLHandler( } } } + } - plugin.scheduler.runLater(1) { - for (key in knownKeys) { - ensureKeyRegistration(key) - } + fun runPostInit() { + for (key in knownKeys) { + ensureKeyRegistration(key) } } From 7b6c8d68a8fa667068a0b2a01f024b40d38d3973 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 17:38:07 +0000 Subject: [PATCH 08/27] Key registration changes --- .../spigot/data/storage/MySQLDataHandler.kt | 36 ++++++++++++++----- .../core-plugin/src/main/resources/data.yml | 5 +-- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index d414803d..2500bda6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -41,7 +41,7 @@ class MySQLDataHandler( handler, UUIDTable("eco_players"), plugin, - plugin.dataYml.getStrings("known-player-keys") + plugin.dataYml.getStrings("categorized-keys.player") .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } ) @@ -49,7 +49,7 @@ class MySQLDataHandler( handler, UUIDTable("eco_server"), plugin, - plugin.dataYml.getStrings("known-server-keys") + plugin.dataYml.getStrings("categorized-keys.server") .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } ) @@ -86,11 +86,11 @@ class MySQLDataHandler( override fun save() { plugin.dataYml.set( - "known-player-keys", + "categorized-keys.player", playerHandler.registeredKeys.map { it.toString() } ) plugin.dataYml.set( - "known-server-keys", + "categorized-keys.server", serverHandler.registeredKeys.map { it.toString() } ) plugin.dataYml.save() @@ -106,7 +106,7 @@ class MySQLDataHandler( private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, - plugin: EcoPlugin, + private val plugin: EcoPlugin, private val knownKeys: Collection ) { private val columns = mutableMapOf>() @@ -144,8 +144,20 @@ private class ImplementedMySQLHandler( } fun runPostInit() { - for (key in knownKeys) { - ensureKeyRegistration(key) + plugin.logger.info("Loading known keys: $knownKeys") + + val persistentKeys = knownKeys + .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } + + transaction { + for (key in persistentKeys) { + registerColumn(key, table) + } + + SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) + for (key in persistentKeys) { + registeredKeys.add(key.key) + } } } @@ -156,11 +168,17 @@ private class ImplementedMySQLHandler( val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return + if (table.columns.any { it.name == key.toString() }) { + registeredKeys.add(key) + return + } + transaction { registerColumn(persistentKey, table) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) - registeredKeys.add(key) } + + registeredKeys.add(key) } fun write(uuid: UUID, key: NamespacedKey, value: T) { @@ -215,6 +233,8 @@ private class ImplementedMySQLHandler( return@Callable value } + ensureKeyRegistration(key) // DON'T DELETE THIS LINE! I know it's covered in getColumn, but I need to do it here as well. + return if (Eco.getHandler().ecoPlugin.configYml.getBool("mysql.async-reads")) { executor.submit(doRead).get() } else { diff --git a/eco-core/core-plugin/src/main/resources/data.yml b/eco-core/core-plugin/src/main/resources/data.yml index ef09cebe..bfb4aa12 100644 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ b/eco-core/core-plugin/src/main/resources/data.yml @@ -1,4 +1,5 @@ # For internal storage use only, do not modify. -known-player-keys: [] -known-server-keys: [] +categorized-keys: + player: [] + server: [] From 28018430e7573d3fb880069f30fe45d19fe004b8 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 18:01:41 +0000 Subject: [PATCH 09/27] Categorized keys are now saved completely serialized --- .../eco/core/data/keys/PersistentDataKey.java | 1 + .../eco/internal/spigot/data/KeyHelpers.kt | 42 +++++++++++++++++++ .../spigot/data/storage/MySQLDataHandler.kt | 24 ++++++----- 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java index e1937c3e..063f19d7 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java @@ -1,6 +1,7 @@ package com.willfp.eco.core.data.keys; import com.willfp.eco.core.Eco; +import com.willfp.eco.util.NamespacedKeyUtils; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt new file mode 100644 index 00000000..95c4ee21 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt @@ -0,0 +1,42 @@ +package com.willfp.eco.internal.spigot.data + +import com.willfp.eco.core.data.keys.PersistentDataKey +import com.willfp.eco.core.data.keys.PersistentDataKeyType +import com.willfp.eco.util.NamespacedKeyUtils + +@Suppress("UNCHECKED_CAST") +object KeyHelpers { + fun deserializeFromString(serialized: String): PersistentDataKey<*>? { + val split = serialized.split("::").toTypedArray() + if (split.size != 3) { + return null + } + val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null + val type = PersistentDataKeyType.valueOf(split[1]) ?: return null + return when (type.name()) { + "STRING" -> PersistentDataKey( + key, + type as PersistentDataKeyType, + split[2] + ) + "INT" -> PersistentDataKey( + key, + type as PersistentDataKeyType, split[2].toInt() + ) + "DOUBLE" -> PersistentDataKey( + key, + type as PersistentDataKeyType, split[2].toDouble() + ) + "BOOLEAN" -> PersistentDataKey( + key, + type as PersistentDataKeyType, + java.lang.Boolean.parseBoolean(split[2]) + ) + else -> null + } + } + + fun serializeToString(key: PersistentDataKey<*>): String { + return "${key.key}::${key.type.name()}::${key.defaultValue}" + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 2500bda6..40fb1250 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -7,8 +7,8 @@ import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.internal.spigot.EcoSpigotPlugin import com.willfp.eco.internal.spigot.data.EcoProfileHandler +import com.willfp.eco.internal.spigot.data.KeyHelpers import com.willfp.eco.internal.spigot.data.serverProfileUUID -import com.willfp.eco.util.NamespacedKeyUtils import com.zaxxer.hikari.HikariConfig import com.zaxxer.hikari.HikariDataSource import org.apache.logging.log4j.Level @@ -42,7 +42,7 @@ class MySQLDataHandler( UUIDTable("eco_players"), plugin, plugin.dataYml.getStrings("categorized-keys.player") - .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } + .mapNotNull { KeyHelpers.deserializeFromString(it) } ) private val serverHandler = ImplementedMySQLHandler( @@ -50,7 +50,7 @@ class MySQLDataHandler( UUIDTable("eco_server"), plugin, plugin.dataYml.getStrings("categorized-keys.server") - .mapNotNull { NamespacedKeyUtils.fromStringOrNull(it) } + .mapNotNull { KeyHelpers.deserializeFromString(it) } ) override fun saveAll(uuids: Iterable) { @@ -87,11 +87,15 @@ class MySQLDataHandler( override fun save() { plugin.dataYml.set( "categorized-keys.player", - playerHandler.registeredKeys.map { it.toString() } + playerHandler.registeredKeys + .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } + .map { KeyHelpers.serializeToString(it) } ) plugin.dataYml.set( "categorized-keys.server", - serverHandler.registeredKeys.map { it.toString() } + serverHandler.registeredKeys + .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } + .map { KeyHelpers.serializeToString(it) } ) plugin.dataYml.save() } @@ -107,7 +111,7 @@ private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, private val plugin: EcoPlugin, - private val knownKeys: Collection + private val knownKeys: Collection> ) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() @@ -146,16 +150,13 @@ private class ImplementedMySQLHandler( fun runPostInit() { plugin.logger.info("Loading known keys: $knownKeys") - val persistentKeys = knownKeys - .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } - transaction { - for (key in persistentKeys) { + for (key in knownKeys) { registerColumn(key, table) } SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) - for (key in persistentKeys) { + for (key in knownKeys) { registeredKeys.add(key.key) } } @@ -173,6 +174,7 @@ private class ImplementedMySQLHandler( return } + plugin.logger.info("Registering new key: $key...") transaction { registerColumn(persistentKey, table) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) From b5c49c79b87b7a31f577851fb0fa68bddae033b4 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 18:13:04 +0000 Subject: [PATCH 10/27] Improvements to key saving --- .../spigot/data/storage/MySQLDataHandler.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 40fb1250..9150d4ae 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -87,14 +87,12 @@ class MySQLDataHandler( override fun save() { plugin.dataYml.set( "categorized-keys.player", - playerHandler.registeredKeys - .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } + playerHandler.registeredKeys.values .map { KeyHelpers.serializeToString(it) } ) plugin.dataYml.set( "categorized-keys.server", - serverHandler.registeredKeys - .mapNotNull { Eco.getHandler().keyRegistry.getKeyFrom(it) } + serverHandler.registeredKeys.values .map { KeyHelpers.serializeToString(it) } ) plugin.dataYml.save() @@ -116,7 +114,7 @@ private class ImplementedMySQLHandler( private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) - val registeredKeys: MutableSet = ConcurrentHashMap.newKeySet() + val registeredKeys = ConcurrentHashMap>() init { val config = HikariConfig() @@ -157,7 +155,7 @@ private class ImplementedMySQLHandler( SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) for (key in knownKeys) { - registeredKeys.add(key.key) + registeredKeys[key.key] = key } } } @@ -170,7 +168,7 @@ private class ImplementedMySQLHandler( val persistentKey = Eco.getHandler().keyRegistry.getKeyFrom(key) ?: return if (table.columns.any { it.name == key.toString() }) { - registeredKeys.add(key) + registeredKeys[key] = persistentKey return } @@ -180,7 +178,7 @@ private class ImplementedMySQLHandler( SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) } - registeredKeys.add(key) + registeredKeys[key] = persistentKey } fun write(uuid: UUID, key: NamespacedKey, value: T) { From cc557378cc4c305743d08bf36c210ba2da7cb950 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Feb 2022 18:16:09 +0000 Subject: [PATCH 11/27] Preloaded known data keys --- .../spigot/data/storage/MySQLDataHandler.kt | 3 - .../core-plugin/src/main/resources/data.yml | 69 ++++++++++++++++++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 9150d4ae..68f71538 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -146,8 +146,6 @@ private class ImplementedMySQLHandler( } fun runPostInit() { - plugin.logger.info("Loading known keys: $knownKeys") - transaction { for (key in knownKeys) { registerColumn(key, table) @@ -172,7 +170,6 @@ private class ImplementedMySQLHandler( return } - plugin.logger.info("Registering new key: $key...") transaction { registerColumn(persistentKey, table) SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) diff --git a/eco-core/core-plugin/src/main/resources/data.yml b/eco-core/core-plugin/src/main/resources/data.yml index bfb4aa12..d539fb0e 100644 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ b/eco-core/core-plugin/src/main/resources/data.yml @@ -1,5 +1,70 @@ # For internal storage use only, do not modify. categorized-keys: - player: [] - server: [] + # Preloading known keys (as of the release of 6.25.0) for optimal performance. + player: + - ecoskills:crit_damage::INT::0 + - ecoskills:strong_impact::INT::0 + - ecoskills:shamanism::INT::0 + - ecoskills:reimbursement::INT::0 + - ecoskills:armory_xp::DOUBLE::0.0 + - ecoskills:bravery::INT::0 + - ecoskills:seamless_movement::INT::0 + - ecoskills:fishing::INT::0 + - ecoskills:armory::INT::0 + - ecoskills:accelerated_escape::INT::0 + - ecoskills:alchemy_xp::DOUBLE::0.0 + - boosters:2sell_multiplier::INT::0 + - ecoskills:second_chance::INT::0 + - ecoskills:health::INT::0 + - ecoskills:spelunking::INT::0 + - eco:player_name::STRING::Unknown Player + - ecoskills:strength::INT::0 + - ecoskills:woodcutting_xp::DOUBLE::0.0 + - ecoskills:versatile_tools::INT::0 + - boosters:skill_xp::INT::0 + - ecoskills:infernal_resistance::INT::0 + - ecoskills:wisdom::INT::0 + - ecoskills:master_lumberjack::INT::0 + - ecoskills:defense::INT::0 + - ecoskills:mystic_resilience::INT::0 + - ecoskills:gainsound::BOOLEAN::true + - ecoskills:golden_yield::INT::0 + - ecoskills:dazzle::INT::0 + - ecoskills:dodging::INT::0 + - ecoskills:efficient_brewing::INT::0 + - ecoskills:bountiful_harvest::INT::0 + - ecoskills:actionbar_enabled::BOOLEAN::true + - ecoskills:enchanting_xp::DOUBLE::0.0 + - ecoskills:overcompensation::INT::0 + - ecoskills:alchemy::INT::0 + - ecoskills:woodcutting::INT::0 + - ecoskills:mining::INT::0 + - ecoskills:magnetic_rod::INT::0 + - ecoskills:fishing_xp::DOUBLE::0.0 + - ecoskills:farming_xp::DOUBLE::0.0 + - ecoskills:speed::INT::0 + - ecoskills:potionmaster::INT::0 + - ecoskills:combat_xp::DOUBLE::0.0 + - ecoskills:eye_of_the_depths::INT::0 + - ecoskills:ferocity::INT::0 + - ecoskills:combat::INT::0 + - ecoskills:mining_xp::DOUBLE::0.0 + - ecoskills:satiation::INT::0 + - ecoskills:craftsmanship::INT::0 + - ecoskills:crit_chance::INT::0 + - ecoskills:dynamic_mining::INT::0 + - ecoskills:exploration::INT::0 + - boosters:1_5sell_multiplier::INT::0 + - ecoskills:enchanting::INT::0 + - ecoskills:endangering::INT::0 + - ecoskills:serrated_strikes::INT::0 + - ecoskills:exploration_xp::DOUBLE::0.0 + - ecoskills:farming::INT::0 + server: + - 'talismans:known_points::STRING::' + - 'ecoarmor:known_points::STRING::' + - 'ecoenchants:known_points::STRING::' + - 'ecoitems:known_points::STRING::' + - 'boosters:known_points::STRING::' + - 'reforges:known_points::STRING::' From 00da717f6da6d8993f38b51bb4b77f5c2754cba7 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 11:49:26 +0000 Subject: [PATCH 12/27] Changed key serialization --- .../eco/internal/spigot/data/KeyHelpers.kt | 16 ++- .../core-plugin/src/main/resources/data.yml | 128 +++++++++--------- 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt index 95c4ee21..8714f23e 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt @@ -7,25 +7,29 @@ import com.willfp.eco.util.NamespacedKeyUtils @Suppress("UNCHECKED_CAST") object KeyHelpers { fun deserializeFromString(serialized: String): PersistentDataKey<*>? { - val split = serialized.split("::").toTypedArray() - if (split.size != 3) { + val split = serialized.split(";").toTypedArray() + + if (split.size < 2) { return null } + val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null val type = PersistentDataKeyType.valueOf(split[1]) ?: return null return when (type.name()) { "STRING" -> PersistentDataKey( key, type as PersistentDataKeyType, - split[2] + if(split.size >= 3) split.toList().subList(2, split.size).joinToString("") else "" ) "INT" -> PersistentDataKey( key, - type as PersistentDataKeyType, split[2].toInt() + type as PersistentDataKeyType, + split[2].toInt() ) "DOUBLE" -> PersistentDataKey( key, - type as PersistentDataKeyType, split[2].toDouble() + type as PersistentDataKeyType, + split[2].toDouble() ) "BOOLEAN" -> PersistentDataKey( key, @@ -37,6 +41,6 @@ object KeyHelpers { } fun serializeToString(key: PersistentDataKey<*>): String { - return "${key.key}::${key.type.name()}::${key.defaultValue}" + return "${key.key};${key.type.name()};${key.defaultValue}" } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/data.yml b/eco-core/core-plugin/src/main/resources/data.yml index d539fb0e..fe2f1f1b 100644 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ b/eco-core/core-plugin/src/main/resources/data.yml @@ -3,68 +3,68 @@ categorized-keys: # Preloading known keys (as of the release of 6.25.0) for optimal performance. player: - - ecoskills:crit_damage::INT::0 - - ecoskills:strong_impact::INT::0 - - ecoskills:shamanism::INT::0 - - ecoskills:reimbursement::INT::0 - - ecoskills:armory_xp::DOUBLE::0.0 - - ecoskills:bravery::INT::0 - - ecoskills:seamless_movement::INT::0 - - ecoskills:fishing::INT::0 - - ecoskills:armory::INT::0 - - ecoskills:accelerated_escape::INT::0 - - ecoskills:alchemy_xp::DOUBLE::0.0 - - boosters:2sell_multiplier::INT::0 - - ecoskills:second_chance::INT::0 - - ecoskills:health::INT::0 - - ecoskills:spelunking::INT::0 - - eco:player_name::STRING::Unknown Player - - ecoskills:strength::INT::0 - - ecoskills:woodcutting_xp::DOUBLE::0.0 - - ecoskills:versatile_tools::INT::0 - - boosters:skill_xp::INT::0 - - ecoskills:infernal_resistance::INT::0 - - ecoskills:wisdom::INT::0 - - ecoskills:master_lumberjack::INT::0 - - ecoskills:defense::INT::0 - - ecoskills:mystic_resilience::INT::0 - - ecoskills:gainsound::BOOLEAN::true - - ecoskills:golden_yield::INT::0 - - ecoskills:dazzle::INT::0 - - ecoskills:dodging::INT::0 - - ecoskills:efficient_brewing::INT::0 - - ecoskills:bountiful_harvest::INT::0 - - ecoskills:actionbar_enabled::BOOLEAN::true - - ecoskills:enchanting_xp::DOUBLE::0.0 - - ecoskills:overcompensation::INT::0 - - ecoskills:alchemy::INT::0 - - ecoskills:woodcutting::INT::0 - - ecoskills:mining::INT::0 - - ecoskills:magnetic_rod::INT::0 - - ecoskills:fishing_xp::DOUBLE::0.0 - - ecoskills:farming_xp::DOUBLE::0.0 - - ecoskills:speed::INT::0 - - ecoskills:potionmaster::INT::0 - - ecoskills:combat_xp::DOUBLE::0.0 - - ecoskills:eye_of_the_depths::INT::0 - - ecoskills:ferocity::INT::0 - - ecoskills:combat::INT::0 - - ecoskills:mining_xp::DOUBLE::0.0 - - ecoskills:satiation::INT::0 - - ecoskills:craftsmanship::INT::0 - - ecoskills:crit_chance::INT::0 - - ecoskills:dynamic_mining::INT::0 - - ecoskills:exploration::INT::0 - - boosters:1_5sell_multiplier::INT::0 - - ecoskills:enchanting::INT::0 - - ecoskills:endangering::INT::0 - - ecoskills:serrated_strikes::INT::0 - - ecoskills:exploration_xp::DOUBLE::0.0 - - ecoskills:farming::INT::0 + - ecoskills:crit_damage;INT;0 + - ecoskills:strong_impact;INT;0 + - ecoskills:shamanism;INT;0 + - ecoskills:reimbursement;INT;0 + - ecoskills:armory_xp;DOUBLE;0.0 + - ecoskills:bravery;INT;0 + - ecoskills:seamless_movement;INT;0 + - ecoskills:fishing;INT;0 + - ecoskills:armory;INT;0 + - ecoskills:accelerated_escape;INT;0 + - ecoskills:alchemy_xp;DOUBLE;0.0 + - boosters:2sell_multiplier;INT;0 + - ecoskills:second_chance;INT;0 + - ecoskills:health;INT;0 + - ecoskills:spelunking;INT;0 + - eco:player_name;STRING;Unknown Player + - ecoskills:strength;INT;0 + - ecoskills:woodcutting_xp;DOUBLE;0.0 + - ecoskills:versatile_tools;INT;0 + - boosters:skill_xp;INT;0 + - ecoskills:infernal_resistance;INT;0 + - ecoskills:wisdom;INT;0 + - ecoskills:master_lumberjack;INT;0 + - ecoskills:defense;INT;0 + - ecoskills:mystic_resilience;INT;0 + - ecoskills:gainsound;BOOLEAN;true + - ecoskills:golden_yield;INT;0 + - ecoskills:dazzle;INT;0 + - ecoskills:dodging;INT;0 + - ecoskills:efficient_brewing;INT;0 + - ecoskills:bountiful_harvest;INT;0 + - ecoskills:actionbar_enabled;BOOLEAN;true + - ecoskills:enchanting_xp;DOUBLE;0.0 + - ecoskills:overcompensation;INT;0 + - ecoskills:alchemy;INT;0 + - ecoskills:woodcutting;INT;0 + - ecoskills:mining;INT;0 + - ecoskills:magnetic_rod;INT;0 + - ecoskills:fishing_xp;DOUBLE;0.0 + - ecoskills:farming_xp;DOUBLE;0.0 + - ecoskills:speed;INT;0 + - ecoskills:potionmaster;INT;0 + - ecoskills:combat_xp;DOUBLE;0.0 + - ecoskills:eye_of_the_depths;INT;0 + - ecoskills:ferocity;INT;0 + - ecoskills:combat;INT;0 + - ecoskills:mining_xp;DOUBLE;0.0 + - ecoskills:satiation;INT;0 + - ecoskills:craftsmanship;INT;0 + - ecoskills:crit_chance;INT;0 + - ecoskills:dynamic_mining;INT;0 + - ecoskills:exploration;INT;0 + - boosters:1_5sell_multiplier;INT;0 + - ecoskills:enchanting;INT;0 + - ecoskills:endangering;INT;0 + - ecoskills:serrated_strikes;INT;0 + - ecoskills:exploration_xp;DOUBLE;0.0 + - ecoskills:farming;INT;0 server: - - 'talismans:known_points::STRING::' - - 'ecoarmor:known_points::STRING::' - - 'ecoenchants:known_points::STRING::' - - 'ecoitems:known_points::STRING::' - - 'boosters:known_points::STRING::' - - 'reforges:known_points::STRING::' + - 'talismans:known_points;STRING;' + - 'ecoarmor:known_points;STRING;' + - 'ecoenchants:known_points;STRING;' + - 'ecoitems:known_points;STRING;' + - 'boosters:known_points;STRING;' + - 'reforges:known_points;STRING;' From c88dac56b716cb2e94322fc71bc4b45bdc77d2f5 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 12:21:26 +0000 Subject: [PATCH 13/27] Added ability to manually categorize keys to improve performance --- .../eco/core/data/keys/KeyRegistry.java | 28 ++++++++++++ .../eco/core/data/keys/PersistentDataKey.java | 29 +++++++++++- .../eco/internal/spigot/EcoSpigotPlugin.kt | 6 +-- .../internal/spigot/data/EcoKeyRegistry.kt | 9 +++- .../eco/internal/spigot/data/EcoProfile.kt | 2 +- .../internal/spigot/data/EcoProfileHandler.kt | 6 +-- .../eco/internal/spigot/data/KeyHelpers.kt | 14 +++--- .../spigot/data/storage/DataHandler.kt | 7 ++- .../spigot/data/storage/MySQLDataHandler.kt | 45 ++++++++++++++----- .../core-plugin/src/main/resources/data.yml | 1 + 10 files changed, 118 insertions(+), 29 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java index 4673ee01..f1ed8713 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java @@ -1,6 +1,8 @@ package com.willfp.eco.core.data.keys; +import com.willfp.eco.core.Eco; import org.bukkit.NamespacedKey; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,6 +11,8 @@ import java.util.Set; /** * API to register persistent data keys. */ +@ApiStatus.Internal +@Eco.HandlerComponent public interface KeyRegistry { /** * Register a persistent data key to be stored. @@ -24,6 +28,15 @@ public interface KeyRegistry { */ Set> getRegisteredKeys(); + /** + * Mark key as category. + * + * @param key The key. + * @param category The category. + */ + void markKeyAs(@NotNull PersistentDataKey key, + @NotNull KeyRegistry.KeyCategory category); + /** * Get persistent data key from namespaced key. * @@ -32,4 +45,19 @@ public interface KeyRegistry { */ @Nullable PersistentDataKey getKeyFrom(@NotNull NamespacedKey namespacedKey); + + /** + * Locations for key categorization. + */ + enum KeyCategory { + /** + * Player keys. + */ + PLAYER, + + /** + * Server keys. + */ + SERVER + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java index 063f19d7..35f26e95 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java +++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java @@ -1,7 +1,6 @@ package com.willfp.eco.core.data.keys; import com.willfp.eco.core.Eco; -import com.willfp.eco.util.NamespacedKeyUtils; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,7 +13,7 @@ import java.util.Set; * * @param The type of the data. */ -public class PersistentDataKey { +public final class PersistentDataKey { /** * The key of the persistent data value. */ @@ -83,6 +82,32 @@ public class PersistentDataKey { return this.type; } + /** + * Categorize key as a server key, will register new column to MySQL + * database immediately rather than waiting for auto-categorization. + *

+ * This will improve performance. + * + * @return The key. + */ + public PersistentDataKey server() { + Eco.getHandler().getKeyRegistry().markKeyAs(this, KeyRegistry.KeyCategory.SERVER); + return this; + } + + /** + * Categorize key as a player key, will register new column to MySQL + * database immediately rather than waiting for auto-categorization. + *

+ * This will improve performance. + * + * @return The key. + */ + public PersistentDataKey player() { + Eco.getHandler().getKeyRegistry().markKeyAs(this, KeyRegistry.KeyCategory.PLAYER); + return this; + } + /** * Get all persistent data keys. * diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 26e9675e..52611123 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -187,10 +187,11 @@ abstract class EcoSpigotPlugin : EcoPlugin() { (Eco.getHandler() as EcoHandler).setAdventure(BukkitAudiences.create(this)) } - this.logger.info("Ignore messages about deprecated events!") - // Init FIS this.getProxy(FastItemStackFactoryProxy::class.java).create(ItemStack(Material.AIR)).unwrap() + + // Preload categorized persistent data keys + (Eco.getHandler().profileHandler as EcoProfileHandler).initialize() } override fun handleDisable() { @@ -216,7 +217,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() { CustomItemsManager.registerAllItems() CustomEntitiesManager.registerAllEntities() ShopManager.registerEcoProvider() - (Eco.getHandler().profileHandler as EcoProfileHandler).runPostInit() } override fun loadIntegrationLoaders(): List { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt index 1497bab9..efbc4c50 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt @@ -1,12 +1,14 @@ package com.willfp.eco.internal.spigot.data +import com.willfp.eco.core.Eco import com.willfp.eco.core.data.keys.KeyRegistry import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType import org.bukkit.NamespacedKey -class EcoKeyRegistry: KeyRegistry { +class EcoKeyRegistry : KeyRegistry { private val registry = mutableMapOf>() + private val categories = mutableMapOf() override fun registerKey(key: PersistentDataKey<*>) { if (this.registry.containsKey(key.key)) { @@ -41,6 +43,11 @@ class EcoKeyRegistry: KeyRegistry { } } + override fun markKeyAs(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) { + categories[key.key] = category + (Eco.getHandler().profileHandler as EcoProfileHandler).handler.categorize(key, category) // ew + } + override fun getKeyFrom(namespacedKey: NamespacedKey): PersistentDataKey<*>? { return registry[namespacedKey] } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt index daba4d9e..fef4e092 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfile.kt @@ -65,4 +65,4 @@ class EcoServerProfile( override fun toString(): String { return "EcoServerProfile" } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt index 2ae5bb91..83064da0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt @@ -18,7 +18,7 @@ class EcoProfileHandler( plugin: EcoSpigotPlugin ) : ProfileHandler { private val loaded = mutableMapOf() - private val handler: DataHandler = if (useSql) MySQLDataHandler(plugin, this) else + val handler: DataHandler = if (useSql) MySQLDataHandler(plugin, this) else YamlDataHandler(plugin, this) fun loadGenericProfile(uuid: UUID): Profile { @@ -64,7 +64,7 @@ class EcoProfileHandler( handler.save() } - fun runPostInit() { - handler.runPostInit() + fun initialize() { + handler.initialize() } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt index 8714f23e..2240ec9b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyHelpers.kt @@ -15,23 +15,23 @@ object KeyHelpers { val key = NamespacedKeyUtils.fromStringOrNull(split[0]) ?: return null val type = PersistentDataKeyType.valueOf(split[1]) ?: return null - return when (type.name()) { - "STRING" -> PersistentDataKey( + return when (type) { + PersistentDataKeyType.STRING -> PersistentDataKey( key, type as PersistentDataKeyType, - if(split.size >= 3) split.toList().subList(2, split.size).joinToString("") else "" + if (split.size >= 3) split.toList().subList(2, split.size).joinToString("") else "" ) - "INT" -> PersistentDataKey( + PersistentDataKeyType.INT -> PersistentDataKey( key, type as PersistentDataKeyType, split[2].toInt() ) - "DOUBLE" -> PersistentDataKey( + PersistentDataKeyType.DOUBLE -> PersistentDataKey( key, type as PersistentDataKeyType, split[2].toDouble() ) - "BOOLEAN" -> PersistentDataKey( + PersistentDataKeyType.BOOLEAN -> PersistentDataKey( key, type as PersistentDataKeyType, java.lang.Boolean.parseBoolean(split[2]) @@ -43,4 +43,4 @@ object KeyHelpers { fun serializeToString(key: PersistentDataKey<*>): String { return "${key.key};${key.type.name()};${key.defaultValue}" } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt index 6bf177ee..72310c8f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/DataHandler.kt @@ -1,5 +1,6 @@ package com.willfp.eco.internal.spigot.data.storage +import com.willfp.eco.core.data.keys.KeyRegistry import com.willfp.eco.core.data.keys.PersistentDataKey import org.bukkit.NamespacedKey import java.util.UUID @@ -8,7 +9,11 @@ interface DataHandler { fun save() fun saveAll(uuids: Iterable) - fun runPostInit() { + fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) { + + } + + fun initialize() { } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 68f71538..932be7a7 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -3,6 +3,7 @@ package com.willfp.eco.internal.spigot.data.storage import com.google.common.util.concurrent.ThreadFactoryBuilder import com.willfp.eco.core.Eco import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.data.keys.KeyRegistry import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.internal.spigot.EcoSpigotPlugin @@ -31,6 +32,7 @@ import java.util.UUID import java.util.concurrent.Callable import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executors +import java.util.concurrent.Future @Suppress("UNCHECKED_CAST") class MySQLDataHandler( @@ -42,7 +44,8 @@ class MySQLDataHandler( UUIDTable("eco_players"), plugin, plugin.dataYml.getStrings("categorized-keys.player") - .mapNotNull { KeyHelpers.deserializeFromString(it) } + .mapNotNull { KeyHelpers.deserializeFromString(it) }, + KeyRegistry.KeyCategory.PLAYER ) private val serverHandler = ImplementedMySQLHandler( @@ -50,7 +53,8 @@ class MySQLDataHandler( UUIDTable("eco_server"), plugin, plugin.dataYml.getStrings("categorized-keys.server") - .mapNotNull { KeyHelpers.deserializeFromString(it) } + .mapNotNull { KeyHelpers.deserializeFromString(it) }, + KeyRegistry.KeyCategory.SERVER ) override fun saveAll(uuids: Iterable) { @@ -84,6 +88,14 @@ class MySQLDataHandler( } } + override fun categorize(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) { + if (category == KeyRegistry.KeyCategory.SERVER) { + serverHandler.ensureKeyRegistration(key.key) + } else { + playerHandler.ensureKeyRegistration(key.key) + } + } + override fun save() { plugin.dataYml.set( "categorized-keys.player", @@ -98,9 +110,9 @@ class MySQLDataHandler( plugin.dataYml.save() } - override fun runPostInit() { - playerHandler.runPostInit() - serverHandler.runPostInit() + override fun initialize() { + playerHandler.initialize() + serverHandler.initialize() } } @@ -109,12 +121,14 @@ private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, private val plugin: EcoPlugin, - private val knownKeys: Collection> + private val knownKeys: Collection>, + private val category: KeyRegistry.KeyCategory ) { private val columns = mutableMapOf>() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) val registeredKeys = ConcurrentHashMap>() + private val currentlyProcessingRegistration = ConcurrentHashMap>() init { val config = HikariConfig() @@ -145,7 +159,7 @@ private class ImplementedMySQLHandler( } } - fun runPostInit() { + fun initialize() { transaction { for (key in knownKeys) { registerColumn(key, table) @@ -170,12 +184,21 @@ private class ImplementedMySQLHandler( return } - transaction { - registerColumn(persistentKey, table) - SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) + val future = currentlyProcessingRegistration[key] + + if (future != null) { + future.get() + return } - registeredKeys[key] = persistentKey + currentlyProcessingRegistration[key] = executor.submit { + transaction { + registerColumn(persistentKey, table) + SchemaUtils.createMissingTablesAndColumns(table, withLogs = false) + } + registeredKeys[key] = persistentKey + currentlyProcessingRegistration.remove(key) + } } fun write(uuid: UUID, key: NamespacedKey, value: T) { diff --git a/eco-core/core-plugin/src/main/resources/data.yml b/eco-core/core-plugin/src/main/resources/data.yml index fe2f1f1b..3209391d 100644 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ b/eco-core/core-plugin/src/main/resources/data.yml @@ -2,6 +2,7 @@ categorized-keys: # Preloading known keys (as of the release of 6.25.0) for optimal performance. + # This is only used when MySQL is enabled as the columns must be added each time a new key is registered. player: - ecoskills:crit_damage;INT;0 - ecoskills:strong_impact;INT;0 From 041575a1037b6551a6ce26df9def01b1bbe80cea Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 12:47:32 +0000 Subject: [PATCH 14/27] Cached rows and columns with Caffeine --- .../spigot/data/storage/MySQLDataHandler.kt | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 932be7a7..536bd581 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -1,5 +1,6 @@ package com.willfp.eco.internal.spigot.data.storage +import com.github.benmanes.caffeine.cache.Caffeine import com.google.common.util.concurrent.ThreadFactoryBuilder import com.willfp.eco.core.Eco import com.willfp.eco.core.EcoPlugin @@ -33,6 +34,7 @@ import java.util.concurrent.Callable import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executors import java.util.concurrent.Future +import java.util.concurrent.TimeUnit @Suppress("UNCHECKED_CAST") class MySQLDataHandler( @@ -44,8 +46,7 @@ class MySQLDataHandler( UUIDTable("eco_players"), plugin, plugin.dataYml.getStrings("categorized-keys.player") - .mapNotNull { KeyHelpers.deserializeFromString(it) }, - KeyRegistry.KeyCategory.PLAYER + .mapNotNull { KeyHelpers.deserializeFromString(it) } ) private val serverHandler = ImplementedMySQLHandler( @@ -53,8 +54,7 @@ class MySQLDataHandler( UUIDTable("eco_server"), plugin, plugin.dataYml.getStrings("categorized-keys.server") - .mapNotNull { KeyHelpers.deserializeFromString(it) }, - KeyRegistry.KeyCategory.SERVER + .mapNotNull { KeyHelpers.deserializeFromString(it) } ) override fun saveAll(uuids: Iterable) { @@ -121,10 +121,16 @@ private class ImplementedMySQLHandler( private val handler: EcoProfileHandler, private val table: UUIDTable, private val plugin: EcoPlugin, - private val knownKeys: Collection>, - private val category: KeyRegistry.KeyCategory + private val knownKeys: Collection> ) { - private val columns = mutableMapOf>() + private val columns = Caffeine.newBuilder() + .expireAfterWrite(5, TimeUnit.SECONDS) + .build>() + + private val rows = Caffeine.newBuilder() + .expireAfterWrite(5, TimeUnit.SECONDS) + .build() + private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() private val executor = Executors.newFixedThreadPool(plugin.configYml.getInt("mysql.threads"), threadFactory) val registeredKeys = ConcurrentHashMap>() @@ -285,28 +291,28 @@ private class ImplementedMySQLHandler( private fun getColumn(key: NamespacedKey): Column<*> { ensureKeyRegistration(key) - val name = key.toString() - val cached = columns[name] - if (cached != null) { - return cached - } - columns[name] = table.columns.stream().filter { it.name == name }.findFirst().get() - return getColumn(key) + val name = key.toString() + + return columns.get(name) { + table.columns.first { it.name == name } + } } private fun getOrCreateRow(uuid: UUID): ResultRow { - val row = transaction { - table.select { table.id eq uuid }.limit(1).singleOrNull() - } - - return if (row != null) { - row - } else { - transaction { - table.insert { it[id] = uuid } + return rows.get(uuid) { + val row = transaction { + table.select { table.id eq uuid }.limit(1).singleOrNull() + } + + return@get if (row != null) { + row + } else { + transaction { + table.insert { it[id] = uuid } + } + getOrCreateRow(uuid) } - getOrCreateRow(uuid) } } } From 5bc2cb31a48d82198f5aa4c0104f65133d55169d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 12:47:59 +0000 Subject: [PATCH 15/27] Switched expiry from write to access (MySQL) --- .../eco/internal/spigot/data/storage/MySQLDataHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 536bd581..a3b59597 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -124,11 +124,11 @@ private class ImplementedMySQLHandler( private val knownKeys: Collection> ) { private val columns = Caffeine.newBuilder() - .expireAfterWrite(5, TimeUnit.SECONDS) + .expireAfterAccess(5, TimeUnit.SECONDS) .build>() private val rows = Caffeine.newBuilder() - .expireAfterWrite(5, TimeUnit.SECONDS) + .expireAfterAccess(5, TimeUnit.SECONDS) .build() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() From 8e6d98c997a180d47ea012b3e7815b856b5d108b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 12:51:43 +0000 Subject: [PATCH 16/27] More MySQL Changes --- .../spigot/data/storage/MySQLDataHandler.kt | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index a3b59597..548d3213 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -114,6 +114,31 @@ class MySQLDataHandler( playerHandler.initialize() serverHandler.initialize() } + + init { + val config = HikariConfig() + config.driverClassName = "com.mysql.cj.jdbc.Driver" + config.username = plugin.configYml.getString("mysql.user") + config.password = plugin.configYml.getString("mysql.password") + config.jdbcUrl = "jdbc:mysql://" + + "${plugin.configYml.getString("mysql.host")}:" + + "${plugin.configYml.getString("mysql.port")}/" + + plugin.configYml.getString("mysql.database") + config.maximumPoolSize = plugin.configYml.getInt("mysql.connections") + + Database.connect(HikariDataSource(config)) + + // Get Exposed to shut the hell up + runCatching { + exposedLogger::class.java.getDeclaredField("logger").apply { isAccessible = true } + .apply { + get(exposedLogger).apply { + this.javaClass.getDeclaredMethod("setLevel", Level::class.java) + .invoke(this, Level.OFF) + } + } + } + } } @Suppress("UNCHECKED_CAST") @@ -137,32 +162,9 @@ private class ImplementedMySQLHandler( private val currentlyProcessingRegistration = ConcurrentHashMap>() init { - val config = HikariConfig() - config.driverClassName = "com.mysql.cj.jdbc.Driver" - config.username = plugin.configYml.getString("mysql.user") - config.password = plugin.configYml.getString("mysql.password") - config.jdbcUrl = "jdbc:mysql://" + - "${plugin.configYml.getString("mysql.host")}:" + - "${plugin.configYml.getString("mysql.port")}/" + - plugin.configYml.getString("mysql.database") - config.maximumPoolSize = plugin.configYml.getInt("mysql.connections") - - Database.connect(HikariDataSource(config)) - transaction { SchemaUtils.create(table) } - - // Get Exposed to shut the hell up - runCatching { - exposedLogger::class.java.getDeclaredField("logger").apply { isAccessible = true } - .apply { - get(exposedLogger).apply { - this.javaClass.getDeclaredMethod("setLevel", Level::class.java) - .invoke(this, Level.OFF) - } - } - } } fun initialize() { From 89d6f2f86728619d2a5582834e3e5b3c90541217 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 12:53:54 +0000 Subject: [PATCH 17/27] Fixed initialization order --- .../spigot/data/storage/MySQLDataHandler.kt | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 548d3213..f428093a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -41,21 +41,49 @@ class MySQLDataHandler( private val plugin: EcoSpigotPlugin, handler: EcoProfileHandler ) : DataHandler { - private val playerHandler = ImplementedMySQLHandler( - handler, - UUIDTable("eco_players"), - plugin, - plugin.dataYml.getStrings("categorized-keys.player") - .mapNotNull { KeyHelpers.deserializeFromString(it) } - ) + private val playerHandler: ImplementedMySQLHandler + private val serverHandler: ImplementedMySQLHandler - private val serverHandler = ImplementedMySQLHandler( - handler, - UUIDTable("eco_server"), - plugin, - plugin.dataYml.getStrings("categorized-keys.server") - .mapNotNull { KeyHelpers.deserializeFromString(it) } - ) + init { + val config = HikariConfig() + config.driverClassName = "com.mysql.cj.jdbc.Driver" + config.username = plugin.configYml.getString("mysql.user") + config.password = plugin.configYml.getString("mysql.password") + config.jdbcUrl = "jdbc:mysql://" + + "${plugin.configYml.getString("mysql.host")}:" + + "${plugin.configYml.getString("mysql.port")}/" + + plugin.configYml.getString("mysql.database") + config.maximumPoolSize = plugin.configYml.getInt("mysql.connections") + + Database.connect(HikariDataSource(config)) + + // Get Exposed to shut the hell up + runCatching { + exposedLogger::class.java.getDeclaredField("logger").apply { isAccessible = true } + .apply { + get(exposedLogger).apply { + this.javaClass.getDeclaredMethod("setLevel", Level::class.java) + .invoke(this, Level.OFF) + } + } + } + + playerHandler = ImplementedMySQLHandler( + handler, + UUIDTable("eco_players"), + plugin, + plugin.dataYml.getStrings("categorized-keys.player") + .mapNotNull { KeyHelpers.deserializeFromString(it) } + ) + + serverHandler = ImplementedMySQLHandler( + handler, + UUIDTable("eco_server"), + plugin, + plugin.dataYml.getStrings("categorized-keys.server") + .mapNotNull { KeyHelpers.deserializeFromString(it) } + ) + } override fun saveAll(uuids: Iterable) { serverHandler.saveAll(uuids.filter { it == serverProfileUUID }) @@ -114,31 +142,6 @@ class MySQLDataHandler( playerHandler.initialize() serverHandler.initialize() } - - init { - val config = HikariConfig() - config.driverClassName = "com.mysql.cj.jdbc.Driver" - config.username = plugin.configYml.getString("mysql.user") - config.password = plugin.configYml.getString("mysql.password") - config.jdbcUrl = "jdbc:mysql://" + - "${plugin.configYml.getString("mysql.host")}:" + - "${plugin.configYml.getString("mysql.port")}/" + - plugin.configYml.getString("mysql.database") - config.maximumPoolSize = plugin.configYml.getInt("mysql.connections") - - Database.connect(HikariDataSource(config)) - - // Get Exposed to shut the hell up - runCatching { - exposedLogger::class.java.getDeclaredField("logger").apply { isAccessible = true } - .apply { - get(exposedLogger).apply { - this.javaClass.getDeclaredMethod("setLevel", Level::class.java) - .invoke(this, Level.OFF) - } - } - } - } } @Suppress("UNCHECKED_CAST") From 1513578266cbc95dc59a74528a88a823c3aed6bd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 17:01:42 +0000 Subject: [PATCH 18/27] Fixed recursive caching bug --- .../internal/spigot/data/storage/MySQLDataHandler.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index f428093a..870bc6a9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -305,10 +305,14 @@ private class ImplementedMySQLHandler( } private fun getOrCreateRow(uuid: UUID): ResultRow { - return rows.get(uuid) { - val row = transaction { + fun select(uuid: UUID): ResultRow? { + return transaction { table.select { table.id eq uuid }.limit(1).singleOrNull() } + } + + return rows.get(uuid) { + val row = select(uuid) return@get if (row != null) { row @@ -316,7 +320,7 @@ private class ImplementedMySQLHandler( transaction { table.insert { it[id] = uuid } } - getOrCreateRow(uuid) + select(uuid)!! } } } From c9b84889e70a5ee609ec66f1362589ed8bc17454 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 17:03:10 +0000 Subject: [PATCH 19/27] Fixed recursive caching bug --- .../willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index 870bc6a9..b7207a77 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -320,7 +320,7 @@ private class ImplementedMySQLHandler( transaction { table.insert { it[id] = uuid } } - select(uuid)!! + select(uuid) } } } From 13772002e848e0ad1eec6f76c70eb4dbf9419f1b Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 17 Feb 2022 17:03:16 +0000 Subject: [PATCH 20/27] Updated to 6.25.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 54e24ff0..e53664af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.25.0 +version = 6.25.1 plugin-name = eco kotlin.code.style = official \ No newline at end of file From 0d8308d6cd2cbb9f386be2e5ec8ef254b9687e36 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 11:48:38 +0000 Subject: [PATCH 21/27] Updated dependencies --- eco-core/core-plugin/build.gradle | 6 +++--- eco-core/core-plugin/src/main/resources/plugin.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index f6813a57..808a3df8 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -30,9 +30,9 @@ dependencies { compileOnly 'com.github.brcdev-minecraft:shopgui-api:2.2.0' compileOnly 'com.github.LoneDev6:API-ItemsAdder:2.4.7' compileOnly 'com.arcaniax:HeadDatabase-API:1.3.0' - compileOnly 'org.jetbrains.exposed:exposed-core:0.36.2' - compileOnly 'org.jetbrains.exposed:exposed-dao:0.36.2' - compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.36.2' + compileOnly 'org.jetbrains.exposed:exposed-core:0.37.3' + compileOnly 'org.jetbrains.exposed:exposed-dao:0.37.3' + compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.37.3' compileOnly 'mysql:mysql-connector-java:8.0.25' compileOnly 'com.zaxxer:HikariCP:5.0.0' compileOnly 'com.gmail.filoghost.holographicdisplays:holographicdisplays-api:2.4.0' diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index ba8270f5..ea66a6f4 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -51,9 +51,9 @@ libraries: - 'net.kyori:adventure-api:4.9.3' - 'net.kyori:adventure-text-serializer-gson:4.9.3' - 'net.kyori:adventure-text-serializer-legacy:4.9.3' - - 'org.jetbrains.exposed:exposed-core:0.36.2' - - 'org.jetbrains.exposed:exposed-dao:0.36.2' - - 'org.jetbrains.exposed:exposed-jdbc:0.36.2' + - 'org.jetbrains.exposed:exposed-core:0.37.3' + - 'org.jetbrains.exposed:exposed-dao:0.37.3' + - 'org.jetbrains.exposed:exposed-jdbc:0.37.3' - 'mysql:mysql-connector-java:8.0.25' - 'com.google.guava:guava:31.0.1-jre' - 'com.zaxxer:HikariCP:5.0.0' From a9fafeec007a259633c9dcda94d3b6fea2621b32 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 11:51:05 +0000 Subject: [PATCH 22/27] Lightened cache on MySQL --- .../eco/internal/spigot/data/storage/MySQLDataHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt index b7207a77..0c82ab93 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/MySQLDataHandler.kt @@ -152,11 +152,11 @@ private class ImplementedMySQLHandler( private val knownKeys: Collection> ) { private val columns = Caffeine.newBuilder() - .expireAfterAccess(5, TimeUnit.SECONDS) + .expireAfterWrite(3, TimeUnit.SECONDS) .build>() private val rows = Caffeine.newBuilder() - .expireAfterAccess(5, TimeUnit.SECONDS) + .expireAfterWrite(3, TimeUnit.SECONDS) .build() private val threadFactory = ThreadFactoryBuilder().setNameFormat("eco-mysql-thread-%d").build() From 4fad66cd907a845f71d78dc244c9e9338defc979 Mon Sep 17 00:00:00 2001 From: Will FP <38837418+WillFP@users.noreply.github.com> Date: Sat, 19 Feb 2022 18:26:37 +0000 Subject: [PATCH 23/27] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 086fb8cb..3114415f 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ and many more. # For server owners - Requires ProtocolLib to be installed: get the latest version [here](https://www.spigotmc.org/resources/protocollib.1997/) -- Supports 1.16.5+ +- Supports 1.17+ ## Downloads From 2ebab99a06012c2671933c31f6e0c358506d0acc Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 18:31:36 +0000 Subject: [PATCH 24/27] Removed support for 1.16.5 --- build.gradle.kts | 1 - .../com/willfp/eco/core/Prerequisite.java | 3 + .../java/com/willfp/eco/util/TeamUtils.java | 21 +-- eco-core/core-nms/v1_16_R3/build.gradle | 6 - .../spigot/proxy/v1_16_R3/AutoCraft.kt | 14 -- .../spigot/proxy/v1_16_R3/BlockBreak.kt | 18 -- .../spigot/proxy/v1_16_R3/ChatComponent.kt | 93 --------- .../spigot/proxy/v1_16_R3/DummyEntity.kt | 15 -- .../proxy/v1_16_R3/FastItemStackFactory.kt | 11 -- .../internal/spigot/proxy/v1_16_R3/Skull.kt | 44 ----- .../eco/internal/spigot/proxy/v1_16_R3/TPS.kt | 11 -- .../spigot/proxy/v1_16_R3/VillagerTrade.kt | 40 ---- .../proxy/v1_16_R3/fast/FastItemStackUtils.kt | 17 -- .../proxy/v1_16_R3/fast/NMSFastItemStack.kt | 176 ------------------ .../spigot/display/PacketHeldWindowItems.kt | 8 +- .../core-plugin/src/main/resources/plugin.yml | 2 +- 16 files changed, 15 insertions(+), 465 deletions(-) delete mode 100644 eco-core/core-nms/v1_16_R3/build.gradle delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/AutoCraft.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/BlockBreak.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/ChatComponent.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/DummyEntity.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/FastItemStackFactory.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/Skull.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/TPS.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/VillagerTrade.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/FastItemStackUtils.kt delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/NMSFastItemStack.kt diff --git a/build.gradle.kts b/build.gradle.kts index 26fd2a24..61da86a5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,7 +21,6 @@ dependencies { implementation(project(":eco-core:core-plugin")) implementation(project(":eco-core:core-proxy")) implementation(project(":eco-core:core-backend")) - implementation(project(":eco-core:core-nms:v1_16_R3")) implementation(project(path = ":eco-core:core-nms:v1_17_R1", configuration = "reobf")) implementation(project(path = ":eco-core:core-nms:v1_18_R1", configuration = "reobf")) } diff --git a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java index 223bc1d0..1006138a 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java +++ b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java @@ -51,7 +51,10 @@ public class Prerequisite { /** * Requires the server to be running 1.17. + * + * @deprecated eco no longer supports versions before 1.17. */ + @Deprecated(since = "6.25.2") public static final Prerequisite HAS_1_17 = new Prerequisite( () -> ProxyConstants.NMS_VERSION.contains("17") || HAS_1_18.isMet(), "Requires server to be running 1.17+" diff --git a/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java b/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java index c40c2458..49b85e71 100644 --- a/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java +++ b/eco-api/src/main/java/com/willfp/eco/util/TeamUtils.java @@ -2,7 +2,6 @@ package com.willfp.eco.util; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.willfp.eco.core.Prerequisite; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -91,17 +90,15 @@ public final class TeamUtils { MATERIAL_COLORS.put(Material.EMERALD_ORE, ChatColor.GREEN); MATERIAL_COLORS.put(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED); - if (Prerequisite.HAS_1_17.isMet()) { - MATERIAL_COLORS.put(Material.COPPER_ORE, ChatColor.GOLD); - MATERIAL_COLORS.put(Material.DEEPSLATE_COPPER_ORE, ChatColor.GOLD); - MATERIAL_COLORS.put(Material.DEEPSLATE_COAL_ORE, ChatColor.BLACK); - MATERIAL_COLORS.put(Material.DEEPSLATE_IRON_ORE, ChatColor.GRAY); - MATERIAL_COLORS.put(Material.DEEPSLATE_GOLD_ORE, ChatColor.YELLOW); - MATERIAL_COLORS.put(Material.DEEPSLATE_LAPIS_ORE, ChatColor.BLUE); - MATERIAL_COLORS.put(Material.DEEPSLATE_REDSTONE_ORE, ChatColor.RED); - MATERIAL_COLORS.put(Material.DEEPSLATE_DIAMOND_ORE, ChatColor.AQUA); - MATERIAL_COLORS.put(Material.DEEPSLATE_EMERALD_ORE, ChatColor.GREEN); - } + MATERIAL_COLORS.put(Material.COPPER_ORE, ChatColor.GOLD); + MATERIAL_COLORS.put(Material.DEEPSLATE_COPPER_ORE, ChatColor.GOLD); + MATERIAL_COLORS.put(Material.DEEPSLATE_COAL_ORE, ChatColor.BLACK); + MATERIAL_COLORS.put(Material.DEEPSLATE_IRON_ORE, ChatColor.GRAY); + MATERIAL_COLORS.put(Material.DEEPSLATE_GOLD_ORE, ChatColor.YELLOW); + MATERIAL_COLORS.put(Material.DEEPSLATE_LAPIS_ORE, ChatColor.BLUE); + MATERIAL_COLORS.put(Material.DEEPSLATE_REDSTONE_ORE, ChatColor.RED); + MATERIAL_COLORS.put(Material.DEEPSLATE_DIAMOND_ORE, ChatColor.AQUA); + MATERIAL_COLORS.put(Material.DEEPSLATE_EMERALD_ORE, ChatColor.GREEN); } private TeamUtils() { diff --git a/eco-core/core-nms/v1_16_R3/build.gradle b/eco-core/core-nms/v1_16_R3/build.gradle deleted file mode 100644 index aa9e602b..00000000 --- a/eco-core/core-nms/v1_16_R3/build.gradle +++ /dev/null @@ -1,6 +0,0 @@ -group 'com.willfp' -version rootProject.version - -dependencies { - compileOnly 'org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT' -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/AutoCraft.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/AutoCraft.kt deleted file mode 100644 index 8168a246..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/AutoCraft.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 -import com.willfp.eco.internal.spigot.proxy.AutoCraftProxy -import net.minecraft.server.v1_16_R3.MinecraftKey -import net.minecraft.server.v1_16_R3.PacketPlayOutAutoRecipe - -class AutoCraft : AutoCraftProxy { - override fun modifyPacket(packet: Any) { - val recipePacket = packet as PacketPlayOutAutoRecipe - val fKey = recipePacket.javaClass.getDeclaredField("b") - fKey.isAccessible = true - val key = fKey[recipePacket] as MinecraftKey - fKey[recipePacket] = MinecraftKey(key.namespace, key.key + "_displayed") - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/BlockBreak.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/BlockBreak.kt deleted file mode 100644 index 32825338..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/BlockBreak.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 -import com.willfp.eco.internal.spigot.proxy.BlockBreakProxy -import net.minecraft.server.v1_16_R3.BlockPosition -import org.bukkit.block.Block -import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer -import org.bukkit.entity.Player - -class BlockBreak : BlockBreakProxy { - override fun breakBlock( - player: Player, - block: Block - ) { - if (player !is CraftPlayer) { - return - } - player.handle.playerInteractManager.breakBlock(BlockPosition(block.x, block.y, block.z)) - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/ChatComponent.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/ChatComponent.kt deleted file mode 100644 index 04625e0d..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/ChatComponent.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 - -import com.willfp.eco.core.display.Display -import com.willfp.eco.internal.spigot.proxy.ChatComponentProxy -import net.kyori.adventure.nbt.api.BinaryTagHolder -import net.kyori.adventure.text.BuildableComponent -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.TranslatableComponent -import net.kyori.adventure.text.event.HoverEvent -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer -import net.minecraft.server.v1_16_R3.IChatBaseComponent -import net.minecraft.server.v1_16_R3.MojangsonParser -import org.bukkit.Material -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack -import org.bukkit.entity.Player - -@Suppress("UNCHECKED_CAST") -class ChatComponent : ChatComponentProxy { - private val gsonComponentSerializer = GsonComponentSerializer.gson() - - override fun modifyComponent(obj: Any, player: Player): Any { - if (obj !is IChatBaseComponent) { - return obj - } - - val component = gsonComponentSerializer.deserialize( - IChatBaseComponent.ChatSerializer.a( - obj - ) - ).asComponent() as BuildableComponent<*, *> - - val newComponent = modifyBaseComponent(component, player) - - return IChatBaseComponent.ChatSerializer.a( - gsonComponentSerializer.serialize(newComponent.asComponent()) - ) ?: obj - } - - private fun modifyBaseComponent(baseComponent: Component, player: Player): Component { - var component = baseComponent - - if (component is TranslatableComponent) { - val args = mutableListOf() - for (arg in component.args()) { - args.add(modifyBaseComponent(arg, player)) - } - component = component.args(args) - } - - val children = mutableListOf() - for (child in component.children()) { - children.add(modifyBaseComponent(child, player)) - } - component = component.children(children) - - val hoverEvent: HoverEvent = component.style().hoverEvent() as HoverEvent? ?: return component - - val showItem = hoverEvent.value() - - if (showItem !is HoverEvent.ShowItem) { - return component - } - - val newShowItem = showItem.nbt( - BinaryTagHolder.of( - CraftItemStack.asNMSCopy( - Display.display( - CraftItemStack.asBukkitCopy( - CraftItemStack.asNMSCopy( - org.bukkit.inventory.ItemStack( - Material.matchMaterial( - showItem.item() - .toString() - ) ?: return component, - showItem.count() - ) - ).apply { - this.tag = MojangsonParser.parse( - showItem.nbt()?.string() ?: return component - ) ?: return component - } - ), - player - ) - ).orCreateTag.toString() - ) - ) - - val newHover = hoverEvent.value(newShowItem) - val style = component.style().hoverEvent(newHover) - return component.style(style) - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/DummyEntity.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/DummyEntity.kt deleted file mode 100644 index 3ba96fe7..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/DummyEntity.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 - -import com.willfp.eco.internal.spigot.proxy.DummyEntityProxy -import org.bukkit.Location -import org.bukkit.craftbukkit.v1_16_R3.CraftWorld -import org.bukkit.entity.Entity -import org.bukkit.entity.EntityType - -class DummyEntity : DummyEntityProxy { - override fun createDummyEntity(location: Location): Entity { - val world = location.world as CraftWorld - @Suppress("UsePropertyAccessSyntax") - return world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity() - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/FastItemStackFactory.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/FastItemStackFactory.kt deleted file mode 100644 index 453ca91d..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/FastItemStackFactory.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 -import com.willfp.eco.core.fast.FastItemStack -import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy -import com.willfp.eco.internal.spigot.proxy.v1_16_R3.fast.NMSFastItemStack -import org.bukkit.inventory.ItemStack - -class FastItemStackFactory : FastItemStackFactoryProxy { - override fun create(itemStack: ItemStack): FastItemStack { - return NMSFastItemStack(itemStack) - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/Skull.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/Skull.kt deleted file mode 100644 index 093e16f0..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/Skull.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 - -import com.mojang.authlib.GameProfile -import com.mojang.authlib.properties.Property -import com.willfp.eco.internal.spigot.proxy.SkullProxy -import org.bukkit.inventory.meta.SkullMeta -import java.lang.reflect.Field -import java.lang.reflect.Method -import java.util.UUID - -class Skull : SkullProxy { - private lateinit var setProfile: Method - private lateinit var profile: Field - - override fun setSkullTexture( - meta: SkullMeta, - base64: String - ) { - if (!this::setProfile.isInitialized) { - setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java) - setProfile.isAccessible = true - } - val uuid = UUID( - base64.substring(base64.length - 20).hashCode().toLong(), - base64.substring(base64.length - 10).hashCode().toLong() - ) - val profile = GameProfile(uuid, "eco") - profile.properties.put("textures", Property("textures", base64)) - setProfile.invoke(meta, profile) - } - - override fun getSkullTexture( - meta: SkullMeta - ): String? { - if (!this::profile.isInitialized) { - profile = meta.javaClass.getDeclaredField("profile") - profile.isAccessible = true - } - val profile = profile[meta] as GameProfile? ?: return null - val properties = profile.properties ?: return null - val prop = properties["textures"] ?: return null - return prop.toMutableList().firstOrNull()?.name - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/TPS.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/TPS.kt deleted file mode 100644 index 2229fd82..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/TPS.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 - -import com.willfp.eco.internal.spigot.proxy.TPSProxy -import org.bukkit.Bukkit -import org.bukkit.craftbukkit.v1_16_R3.CraftServer - -class TPS : TPSProxy { - override fun getTPS(): Double { - return (Bukkit.getServer() as CraftServer).handle.server.recentTps[0] - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/VillagerTrade.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/VillagerTrade.kt deleted file mode 100644 index c96e1f86..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/VillagerTrade.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3 - -import com.willfp.eco.core.display.Display -import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftMerchantRecipe -import org.bukkit.entity.Player -import org.bukkit.inventory.MerchantRecipe -import java.lang.reflect.Field - -class VillagerTrade : VillagerTradeProxy { - private val handle: Field = CraftMerchantRecipe::class.java.getDeclaredField("handle") - - override fun displayTrade( - recipe: MerchantRecipe, - player: Player - ): MerchantRecipe { - val oldRecipe = recipe as CraftMerchantRecipe - val newRecipe = CraftMerchantRecipe( - Display.display(recipe.getResult().clone(), player), - recipe.getUses(), - recipe.getMaxUses(), - recipe.hasExperienceReward(), - recipe.getVillagerExperience(), - recipe.getPriceMultiplier() - ) - for (ingredient in recipe.getIngredients()) { - newRecipe.addIngredient(Display.display(ingredient.clone(), player)) - } - getHandle(newRecipe).specialPrice = getHandle(oldRecipe).specialPrice - return newRecipe - } - - private fun getHandle(recipe: CraftMerchantRecipe): net.minecraft.server.v1_16_R3.MerchantRecipe { - return handle[recipe] as net.minecraft.server.v1_16_R3.MerchantRecipe - } - - init { - handle.isAccessible = true - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/FastItemStackUtils.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/FastItemStackUtils.kt deleted file mode 100644 index 76058373..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/FastItemStackUtils.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3.fast - -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack -import org.bukkit.inventory.ItemStack -import java.lang.reflect.Field - -private val field: Field = CraftItemStack::class.java.getDeclaredField("handle").apply { - isAccessible = true -} - -fun ItemStack.getNMSStack(): net.minecraft.server.v1_16_R3.ItemStack { - return if (this !is CraftItemStack) { - CraftItemStack.asNMSCopy(this) - } else { - field[this] as net.minecraft.server.v1_16_R3.ItemStack? ?: CraftItemStack.asNMSCopy(this) - } -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/NMSFastItemStack.kt b/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/NMSFastItemStack.kt deleted file mode 100644 index 736e71f5..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_16_R3/fast/NMSFastItemStack.kt +++ /dev/null @@ -1,176 +0,0 @@ -package com.willfp.eco.internal.spigot.proxy.v1_16_R3.fast - -import com.willfp.eco.internal.fast.EcoFastItemStack -import com.willfp.eco.util.NamespacedKeyUtils -import com.willfp.eco.util.StringUtils -import net.minecraft.server.v1_16_R3.Item -import net.minecraft.server.v1_16_R3.ItemEnchantedBook -import net.minecraft.server.v1_16_R3.ItemStack -import net.minecraft.server.v1_16_R3.Items -import net.minecraft.server.v1_16_R3.NBTTagCompound -import net.minecraft.server.v1_16_R3.NBTTagList -import net.minecraft.server.v1_16_R3.NBTTagString -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack -import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers -import org.bukkit.enchantments.Enchantment -import org.bukkit.inventory.ItemFlag -import kotlin.experimental.and - -class NMSFastItemStack(itemStack: org.bukkit.inventory.ItemStack) : EcoFastItemStack( - itemStack.getNMSStack(), itemStack -) { - private var loreCache: List? = null - override fun getEnchants(checkStored: Boolean): Map { - val enchantmentNBT = if (checkStored && handle.item === Items.ENCHANTED_BOOK) ItemEnchantedBook.d( - handle - ) else handle.enchantments - val foundEnchantments: MutableMap = HashMap() - for (base in enchantmentNBT) { - val compound = base as NBTTagCompound - val key = compound.getString("id") - val level: Int = ('\uffff'.code.toShort() and compound.getShort("lvl")).toInt() - val found = Enchantment.getByKey(NamespacedKeyUtils.fromStringOrNull(key)) - if (found != null) { - foundEnchantments[found] = level - } - } - return foundEnchantments - } - - override fun getLevelOnItem( - enchantment: Enchantment, - checkStored: Boolean - ): Int { - val enchantmentNBT = if (checkStored && handle.item === Items.ENCHANTED_BOOK) ItemEnchantedBook.d( - handle - ) else handle.enchantments - for (base in enchantmentNBT) { - val compound = base as NBTTagCompound - val key = compound.getString("id") - if (key != enchantment.key.toString()) { - continue - } - return ('\uffff'.code.toShort() and compound.getShort("lvl")).toInt() - } - return 0 - } - - override fun setLore(lore: List?) { - loreCache = null - val jsonLore: MutableList = ArrayList() - if (lore != null) { - for (s in lore) { - jsonLore.add(StringUtils.legacyToJson(s)) - } - } - val displayTag = handle.a("display") - if (!displayTag.hasKey("Lore")) { - displayTag["Lore"] = NBTTagList() - } - val loreTag = displayTag.getList("Lore", CraftMagicNumbers.NBT.TAG_STRING) - loreTag.clear() - for (s in jsonLore) { - loreTag.add(NBTTagString.a(s)) - } - apply() - } - - override fun getLore(): List { - if (loreCache != null) { - return loreCache as List - } - val lore: MutableList = ArrayList() - for (s in getLoreJSON()) { - lore.add(StringUtils.jsonToLegacy(s)) - } - loreCache = lore - return lore - } - - private fun getLoreJSON(): List { - val displayTag = handle.b("display") ?: return emptyList() - return if (displayTag.hasKey("Lore")) { - val loreTag = displayTag.getList("Lore", CraftMagicNumbers.NBT.TAG_STRING) - val lore: MutableList = ArrayList(loreTag.size) - for (i in loreTag.indices) { - lore.add(loreTag.getString(i)) - } - lore - } else { - emptyList() - } - } - - override fun addItemFlags(vararg hideFlags: ItemFlag) { - for (flag in hideFlags) { - this.flagBits = this.flagBits or getBitModifier(flag) - } - - apply() - } - - override fun removeItemFlags(vararg hideFlags: ItemFlag) { - for (flag in hideFlags) { - this.flagBits = this.flagBits and getBitModifier(flag) - } - - apply() - } - - override fun getItemFlags(): MutableSet { - val flags = mutableSetOf() - - var flagArr: Array - val size = ItemFlag.values().also { flagArr = it }.size - - for (i in 0 until size) { - val flag = flagArr[i] - if (this.hasItemFlag(flag)) { - flags.add(flag) - } - } - - return flags - } - - override fun hasItemFlag(flag: ItemFlag): Boolean { - val bitModifier = getBitModifier(flag) - return this.flagBits and bitModifier == bitModifier - } - - private var flagBits: Int - get() = - if (handle.hasTag() && handle.tag!!.hasKeyOfType( - "HideFlags", - 99 - ) - ) handle.tag!!.getInt("HideFlags") else 0 - set(value) = - handle.orCreateTag.setInt("HideFlags", value) - - override fun getRepairCost(): Int { - return handle.repairCost - } - - override fun setRepairCost(cost: Int) { - handle.repairCost = cost - } - - override fun equals(other: Any?): Boolean { - if (other !is NMSFastItemStack) { - return false - } - - return other.hashCode() == this.hashCode() - } - - override fun hashCode(): Int { - return handle.tag?.hashCode() ?: (0b00010101 * 31 + Item.getId(handle.item)) - } - - private fun apply() { - if (bukkit !is CraftItemStack) { - bukkit.itemMeta = CraftItemStack.asCraftMirror(handle).itemMeta - } - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/display/PacketHeldWindowItems.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/display/PacketHeldWindowItems.kt index 4b9f79e2..1797188a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/display/PacketHeldWindowItems.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/display/PacketHeldWindowItems.kt @@ -5,21 +5,17 @@ import com.comphenix.protocol.events.PacketContainer import com.comphenix.protocol.events.PacketEvent import com.willfp.eco.core.AbstractPacketAdapter import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.Prerequisite import com.willfp.eco.core.display.Display import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack -class PacketHeldWindowItems(plugin: EcoPlugin) : AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) { +class PacketHeldWindowItems(plugin: EcoPlugin) : + AbstractPacketAdapter(plugin, PacketType.Play.Server.WINDOW_ITEMS, false) { override fun onSend( packet: PacketContainer, player: Player, event: PacketEvent ) { - if (!Prerequisite.HAS_1_17.isMet) { - return - } - packet.itemModifier.modify(0) { item: ItemStack? -> Display.display( item!!, player diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index ea66a6f4..94ada954 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: eco version: ${projectVersion} main: com.willfp.eco.internal.spigot.EcoHandler -api-version: 1.16 +api-version: 1.17 authors: [ Auxilor ] website: willfp.com load: STARTUP From 1a524aea94bf486623c8876e5ba365e04f3e7b13 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 18:32:29 +0000 Subject: [PATCH 25/27] Updated to 6.25.2 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e53664af..aab2c291 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.25.1 +version = 6.25.2 plugin-name = eco kotlin.code.style = official \ No newline at end of file From b6cd56ad157009879cb4059c048f72a0bf1521f6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 18:33:04 +0000 Subject: [PATCH 26/27] Fixed supported versions --- .../main/kotlin/com/willfp/eco/internal/proxy/EcoProxyFactory.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/proxy/EcoProxyFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/proxy/EcoProxyFactory.kt index fc8cbc7f..4b7c296c 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/proxy/EcoProxyFactory.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/proxy/EcoProxyFactory.kt @@ -77,7 +77,6 @@ class EcoProxyFactory( companion object { val SUPPORTED_VERSIONS = listOf( - "v1_16_R3", "v1_17_R1", "v1_18_R1" ) From 36c77d81eb6bc7f0904def0e0c33e021871d8fbf Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 19 Feb 2022 18:33:16 +0000 Subject: [PATCH 27/27] Fixed included modules --- settings.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/settings.gradle.kts b/settings.gradle.kts index 234a096f..66c08b24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,7 +11,6 @@ rootProject.name = "eco" include(":eco-api") include(":eco-core") include(":eco-core:core-nms") -include(":eco-core:core-nms:v1_16_R3") include(":eco-core:core-nms:v1_17_R1") include(":eco-core:core-nms:v1_18_R1") include(":eco-core:core-proxy")