From 2083fb60ef03024d1900ce62008c551e4e355363 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 26 Nov 2021 15:26:58 +0000 Subject: [PATCH] Removed legacy data --- eco-core/core-plugin/build.gradle | 4 - .../com/willfp/ecoskills/EcoSkillsPlugin.java | 23 +--- .../ecoskills/data/legacy/DataHandler.kt | 10 -- .../data/legacy/LegacyPlayerProfile.kt | 117 ------------------ .../ecoskills/data/legacy/MySQLDataHandler.kt | 70 ----------- .../ecoskills/data/legacy/YamlDataHandler.kt | 24 ---- .../core-plugin/src/main/resources/config.yml | 21 +--- .../core-plugin/src/main/resources/data.yml | 1 - .../core-plugin/src/main/resources/plugin.yml | 4 - 9 files changed, 4 insertions(+), 270 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/DataHandler.kt delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/LegacyPlayerProfile.kt delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/MySQLDataHandler.kt delete mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/YamlDataHandler.kt delete mode 100644 eco-core/core-plugin/src/main/resources/data.yml diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 8445a62..5fbebee 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -8,10 +8,6 @@ dependencies { compileOnly 'com.willfp:EcoEnchants:8.2.0' compileOnly 'net.kyori:adventure-api:4.9.2' compileOnly 'net.essentialsx:EssentialsX:2.19.0' - compileOnly 'org.jetbrains.exposed:exposed-core:0.34.1' - compileOnly 'org.jetbrains.exposed:exposed-dao:0.34.1' - compileOnly 'org.jetbrains.exposed:exposed-jdbc:0.34.1' - compileOnly 'mysql:mysql-connector-java:5.1.48' } build.dependsOn publishToMavenLocal diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java index 25c3e89..773b191 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java @@ -13,10 +13,6 @@ import com.willfp.ecoskills.commands.CommandSkills; import com.willfp.ecoskills.config.EffectsYml; import com.willfp.ecoskills.data.DataListener; import com.willfp.ecoskills.data.LeaderboardHandler; -import com.willfp.ecoskills.data.legacy.DataHandler; -import com.willfp.ecoskills.data.legacy.LegacyPlayerProfile; -import com.willfp.ecoskills.data.legacy.MySQLDataHandler; -import com.willfp.ecoskills.data.legacy.YamlDataHandler; import com.willfp.ecoskills.effects.Effect; import com.willfp.ecoskills.effects.Effects; import com.willfp.ecoskills.integrations.EcoEnchantsEnchantingLeveller; @@ -39,11 +35,6 @@ public class EcoSkillsPlugin extends EcoPlugin { */ private static EcoSkillsPlugin instance; - /** - * data.yml. - */ - private final DataHandler dataHandler; - /** * effects.yml. */ @@ -56,13 +47,10 @@ public class EcoSkillsPlugin extends EcoPlugin { super(1351, 13052, "&#ff00ae", true); instance = this; effectsYml = new EffectsYml(this); - dataHandler = this.getConfigYml().getBool("mysql.enabled") - ? new MySQLDataHandler(this) : new YamlDataHandler(this); } @Override protected void handleEnable() { - LegacyPlayerProfile.Companion.migrateAll(); Skills.update(); } @@ -88,15 +76,6 @@ public class EcoSkillsPlugin extends EcoPlugin { this.getScheduler().runTimer(new LeaderboardHandler.Runnable(), 50, 2400); } - /** - * Get data handler. - * - * @return data handler. - */ - public DataHandler getDataHandler() { - return dataHandler; - } - /** * Get effects.yml. * @@ -152,6 +131,6 @@ public class EcoSkillsPlugin extends EcoPlugin { @Override public String getMinimumEcoVersion() { - return "6.6.0"; + return "6.13.10"; } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/DataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/DataHandler.kt deleted file mode 100644 index 4768d86..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/DataHandler.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.willfp.ecoskills.data.legacy - -import java.util.UUID - -interface DataHandler { - fun read(uuid: UUID, key: String): T? - fun read(uuid: UUID, key: String, default: T): T { - return read(uuid, key) ?: default - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/LegacyPlayerProfile.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/LegacyPlayerProfile.kt deleted file mode 100644 index 34bbeb5..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/LegacyPlayerProfile.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.willfp.ecoskills.data.legacy - -import com.willfp.eco.core.Eco -import com.willfp.eco.core.data.PlayerProfile -import com.willfp.eco.core.data.keys.PersistentDataKey -import com.willfp.ecoskills.EcoSkillsPlugin -import com.willfp.ecoskills.effects.Effects -import com.willfp.ecoskills.skills.Skills -import com.willfp.ecoskills.stats.Stats -import org.bukkit.Bukkit -import org.bukkit.OfflinePlayer -import java.util.UUID - -private val plugin = EcoSkillsPlugin.getInstance() - -@Suppress("UNCHECKED_CAST", "DEPRECATED") -class LegacyPlayerProfile private constructor( - private val data: MutableMap -) { - private fun read(key: String, default: T): T { - return data[key] as T? ?: default - } - - companion object { - private val handler = EcoSkillsPlugin.getInstance().dataHandler - private val loaded = mutableMapOf() - private val keys = mutableMapOf() - private val mappedKeys = mutableMapOf>() - - private fun load(uuid: UUID): LegacyPlayerProfile { - val found = loaded[uuid] - if (found != null) { - return found - } - - val data = mutableMapOf() - for ((key, type) in keys) { - when (type) { - Type.INT -> data[key] = handler.read(uuid, key, 0) - Type.DOUBLE -> data[key] = handler.read(uuid, key, 0.0) - } - } - - val profile = LegacyPlayerProfile(data) - loaded[uuid] = profile - return profile - } - - fun migrateAll() { - if (plugin.configYml.getBool("mysql.migrated")) { - return - } - plugin.logger.info("-----------------------------------------") - plugin.logger.info("Migrating player data! (Automatic)") - plugin.logger.info("This will only run once, ever - not every time your server starts up") - plugin.logger.info("so there's no need to worry about how long it takes. Once this is complete,") - plugin.logger.info("feel free to delete data.yml as it won't be used anymore") - plugin.logger.info("-----------------------------------------") - Bukkit.getLogger().info(keys.toString()) - Bukkit.getLogger().info(mappedKeys.toString()) - for (offlinePlayer in Bukkit.getServer().offlinePlayers) { - plugin.logger.info("Migrating player ${offlinePlayer.uniqueId}...") - migrate(offlinePlayer) - } - plugin.logger.info("Saving...") - plugin.configYml.set("mysql.migrated", true) - plugin.configYml.save() - Eco.getHandler().playerProfileHandler.saveAll(false) - plugin.logger.info("Migration complete!") - } - - private fun migrate(player: OfflinePlayer) { - fun writeKey(profile: PlayerProfile, key: PersistentDataKey, value: Any) { - value as T - profile.write(key, value) - } - - val ecoProfile = PlayerProfile.load(player) - - for ((key, type) in keys) { - val value = load(player.uniqueId).read( - key, when (type) { - Type.INT -> 0 - Type.DOUBLE -> 0.0 - } - ) - - val newKey = mappedKeys[key] ?: continue - writeKey(ecoProfile, newKey, value) - } - } - - init { - for (skill in Skills.values()) { - keys[skill.id] = Type.INT - mappedKeys[skill.id] = skill.dataKey - keys[skill.id + "_progress"] = Type.DOUBLE - mappedKeys[skill.id + "_progress"] = skill.dataXPKey - } - - for (stat in Stats.values()) { - keys[stat.id] = Type.INT - mappedKeys[stat.id] = stat.dataKey - } - - for (effect in Effects.values()) { - keys[effect.id] = Type.INT - mappedKeys[effect.id] = effect.dataKey - } - } - } - - private enum class Type { - DOUBLE, - INT - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/MySQLDataHandler.kt deleted file mode 100644 index 8fe10ff..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/MySQLDataHandler.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.willfp.ecoskills.data.legacy - -import com.willfp.ecoskills.EcoSkillsPlugin -import com.willfp.ecoskills.effects.Effects -import com.willfp.ecoskills.skills.Skills -import com.willfp.ecoskills.stats.Stats -import org.jetbrains.exposed.dao.id.EntityID -import org.jetbrains.exposed.dao.id.UUIDTable -import org.jetbrains.exposed.sql.Column -import org.jetbrains.exposed.sql.Database -import org.jetbrains.exposed.sql.DoubleColumnType -import org.jetbrains.exposed.sql.IntegerColumnType -import org.jetbrains.exposed.sql.SchemaUtils -import org.jetbrains.exposed.sql.select -import org.jetbrains.exposed.sql.transactions.transaction -import java.util.UUID - -@Suppress("UNCHECKED_CAST") -class MySQLDataHandler( - plugin: EcoSkillsPlugin -) : DataHandler { - init { - Database.connect( - "jdbc:mysql://" + - "${plugin.configYml.getString("mysql.host")}:" + - "${plugin.configYml.getString("mysql.port")}/" + - plugin.configYml.getString("mysql.database"), - driver = "com.mysql.cj.jdbc.Driver", - user = plugin.configYml.getString("mysql.user"), - password = plugin.configYml.getString("mysql.password") - ) - - transaction { - Players.apply { - for (skill in Skills.values()) { - registerColumn(skill.id, IntegerColumnType()) - .default(0) - registerColumn(skill.id + "_progress", DoubleColumnType()) - .default(0.0) - } - - for (stat in Stats.values()) { - registerColumn(stat.id, IntegerColumnType()) - .default(0) - } - - for (effect in Effects.values()) { - registerColumn(effect.id, IntegerColumnType()) - .default(0) - } - } - - SchemaUtils.create(Players) - } - } - - override fun read(uuid: UUID, key: String): T? { - var value: T? = null - transaction { - val player = Players.select { Players.id eq uuid }.firstOrNull() ?: return@transaction - value = player[Players.columns.stream().filter { it.name == key }.findFirst().get()] as T? - } - return value - } - - object Players : UUIDTable("EcoSkills_Players") { - override val id: Column> = uuid("uuid") - .entityId() - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/YamlDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/YamlDataHandler.kt deleted file mode 100644 index 1c2beaa..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/data/legacy/YamlDataHandler.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.willfp.ecoskills.data.legacy - -import com.willfp.eco.core.config.yaml.YamlBaseConfig -import com.willfp.ecoskills.EcoSkillsPlugin -import java.util.UUID - -@Suppress("UNCHECKED_CAST") -class YamlDataHandler( - plugin: EcoSkillsPlugin -) : DataHandler { - private val dataYml = DataYml(plugin) - - override fun read(uuid: UUID, key: String): T? { - return dataYml.get("player.$uuid.$key") as T? - } - - class DataYml( - plugin: EcoSkillsPlugin - ) : YamlBaseConfig( - "data", - false, - plugin - ) -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 59f5056..0d2a048 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -3,6 +3,8 @@ # by Auxilor # +# Go to /plugins/eco/config.yml to change MySQL settings + gui: rows: 6 @@ -325,21 +327,4 @@ persistent-action-bar: commands: top: # If displayname (including rank) should be used - use-display-name: true - -# Everything below this line is legacy configuration -# Don't touch it - it will be removed soon. - -# EcoSkills now uses eco's data storage system, this section will be removed in the future -# This exists purely to be able to migrate player data -# Go to /plugins/eco/config.yml to change MySQL settings - -# If you didn't use EcoSkills before version 1.10.0 then ignore this. -mysql: - migrated: true # Internal value - DO NOT CHANGE, YOU RISK LOSING PLAYER DATA - enabled: false # Set to false, data.yml will be used instead. - host: localhost - port: 3306 - database: database - user: username - password: passy + use-display-name: true \ 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 deleted file mode 100644 index 496b31e..0000000 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ /dev/null @@ -1 +0,0 @@ -# This file exists for legacy support, it will be removed in the future \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 4c10403..c10cfc1 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -12,10 +12,6 @@ softdepend: - EcoEnchants libraries: - 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21' - - 'org.jetbrains.exposed:exposed-core:0.34.1' - - 'org.jetbrains.exposed:exposed-dao:0.34.1' - - 'org.jetbrains.exposed:exposed-jdbc:0.34.1' - - 'mysql:mysql-connector-java:5.1.48' commands: ecoskills: