mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-01 13:26:30 +00:00
Removed legacy data
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.willfp.ecoskills.data.legacy
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
interface DataHandler {
|
||||
fun <T> read(uuid: UUID, key: String): T?
|
||||
fun <T : Any> read(uuid: UUID, key: String, default: T): T {
|
||||
return read<T>(uuid, key) ?: default
|
||||
}
|
||||
}
|
||||
@@ -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<String, Any>
|
||||
) {
|
||||
private fun <T : Any> read(key: String, default: T): T {
|
||||
return data[key] as T? ?: default
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val handler = EcoSkillsPlugin.getInstance().dataHandler
|
||||
private val loaded = mutableMapOf<UUID, LegacyPlayerProfile>()
|
||||
private val keys = mutableMapOf<String, Type>()
|
||||
private val mappedKeys = mutableMapOf<String, PersistentDataKey<*>>()
|
||||
|
||||
private fun load(uuid: UUID): LegacyPlayerProfile {
|
||||
val found = loaded[uuid]
|
||||
if (found != null) {
|
||||
return found
|
||||
}
|
||||
|
||||
val data = mutableMapOf<String, Any>()
|
||||
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 <T> writeKey(profile: PlayerProfile, key: PersistentDataKey<T>, 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
|
||||
}
|
||||
}
|
||||
@@ -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<Int>(skill.id, IntegerColumnType())
|
||||
.default(0)
|
||||
registerColumn<Double>(skill.id + "_progress", DoubleColumnType())
|
||||
.default(0.0)
|
||||
}
|
||||
|
||||
for (stat in Stats.values()) {
|
||||
registerColumn<Int>(stat.id, IntegerColumnType())
|
||||
.default(0)
|
||||
}
|
||||
|
||||
for (effect in Effects.values()) {
|
||||
registerColumn<Int>(effect.id, IntegerColumnType())
|
||||
.default(0)
|
||||
}
|
||||
}
|
||||
|
||||
SchemaUtils.create(Players)
|
||||
}
|
||||
}
|
||||
|
||||
override fun <T> 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<EntityID<UUID>> = uuid("uuid")
|
||||
.entityId()
|
||||
}
|
||||
}
|
||||
@@ -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 <T> read(uuid: UUID, key: String): T? {
|
||||
return dataYml.get("player.$uuid.$key") as T?
|
||||
}
|
||||
|
||||
class DataYml(
|
||||
plugin: EcoSkillsPlugin
|
||||
) : YamlBaseConfig(
|
||||
"data",
|
||||
false,
|
||||
plugin
|
||||
)
|
||||
}
|
||||
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
# This file exists for legacy support, it will be removed in the future
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user