diff --git a/build.gradle b/build.gradle index d79e928d..fbd8c945 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,3 @@ -buildscript { - repositories { - mavenCentral() - } - - dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" - } -} - plugins { id 'java-library' id 'com.github.johnrengelman.shadow' version '7.0.0' @@ -24,7 +14,6 @@ allprojects { apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: 'com.github.johnrengelman.shadow' - apply plugin: 'kotlin' repositories { mavenCentral() @@ -61,10 +50,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.9.4' - - compileOnly 'org.jetbrains:annotations:19.0.0' - compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21' + compileOnly 'com.willfp:eco:6.12.0' compileOnly 'org.projectlombok:lombok:1.18.20' annotationProcessor 'org.projectlombok:lombok:1.18.20' diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index bfcee705..f8d2b096 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -11,10 +11,6 @@ import com.willfp.ecoenchants.command.CommandEnchantinfo; import com.willfp.ecoenchants.config.RarityYml; import com.willfp.ecoenchants.config.TargetYml; import com.willfp.ecoenchants.config.VanillaEnchantsYml; -import com.willfp.ecoenchants.data.SaveHandler; -import com.willfp.ecoenchants.data.storage.DataHandler; -import com.willfp.ecoenchants.data.storage.MySQLDataHandler; -import com.willfp.ecoenchants.data.storage.YamlDataHandler; import com.willfp.ecoenchants.display.EnchantDisplay; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; @@ -59,11 +55,6 @@ public class EcoEnchantsPlugin extends EcoPlugin { */ private final VanillaEnchantsYml vanillaEnchantsYml; - /** - * The data handler. - */ - private final DataHandler dataHandler; - /** * Internal constructor called by bukkit on plugin load. */ @@ -74,8 +65,6 @@ public class EcoEnchantsPlugin extends EcoPlugin { rarityYml = new RarityYml(this); targetYml = new TargetYml(this); vanillaEnchantsYml = new VanillaEnchantsYml(this); - dataHandler = this.getConfigYml().getBool("mysql.enabled") - ? new MySQLDataHandler(this) : new YamlDataHandler(this); } @Override @@ -87,7 +76,6 @@ public class EcoEnchantsPlugin extends EcoPlugin { @Override protected void handleDisable() { - SaveHandler.Companion.save(this); for (World world : Bukkit.getServer().getWorlds()) { world.getPopulators().removeIf(blockPopulator -> blockPopulator instanceof LootPopulator); } @@ -113,9 +101,6 @@ public class EcoEnchantsPlugin extends EcoPlugin { enchant.clearCachedRequirements(); } }, 300, 300); - - SaveHandler.Companion.save(this); - this.getScheduler().runTimer(new SaveHandler.Runnable(this), 20000, 20000); } @Override @@ -169,7 +154,7 @@ public class EcoEnchantsPlugin extends EcoPlugin { @Override public String getMinimumEcoVersion() { - return "6.10.0"; + return "6.12.0"; } /** @@ -209,13 +194,4 @@ public class EcoEnchantsPlugin extends EcoPlugin { public VanillaEnchantsYml getVanillaEnchantsYml() { return this.vanillaEnchantsYml; } - - /** - * Get the data handler. - * - * @return The data handler. - */ - public DataHandler getDataHandler() { - return this.dataHandler; - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandToggleDescriptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandToggleDescriptions.java index ef0900fd..a533445b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandToggleDescriptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandToggleDescriptions.java @@ -2,12 +2,23 @@ package com.willfp.ecoenchants.command; import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.impl.Subcommand; +import com.willfp.eco.core.data.PlayerProfile; +import com.willfp.eco.core.data.keys.PersistentDataKey; +import com.willfp.eco.core.data.keys.PersistentDataKeyType; import com.willfp.ecoenchants.EcoEnchantsPlugin; -import com.willfp.ecoenchants.data.storage.PlayerProfile; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; public class CommandToggleDescriptions extends Subcommand { + /** + * Persistent data key for descriptions. + */ + private final PersistentDataKey descriptionsKey = new PersistentDataKey<>( + this.getPlugin().getNamespacedKeyFactory().create("descriptions_enabled"), + PersistentDataKeyType.BOOLEAN, + true + ); + /** * Instantiate a new command handler. * @@ -25,10 +36,10 @@ public class CommandToggleDescriptions extends Subcommand { return; } Player player = (Player) sender; - PlayerProfile profile = PlayerProfile.getProfile(player); - boolean currentStatus = profile.read("descriptions", true); + PlayerProfile profile = PlayerProfile.load(player); + boolean currentStatus = profile.read(descriptionsKey); currentStatus = !currentStatus; - profile.write("descriptions", currentStatus); + profile.write(descriptionsKey, currentStatus); if (currentStatus) { player.sendMessage(this.getPlugin().getLangYml().getMessage("enabled-descriptions")); } else { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/SaveHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/SaveHandler.kt deleted file mode 100644 index ccbce855..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/SaveHandler.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.willfp.ecoenchants.data - -import com.willfp.ecoenchants.EcoEnchantsPlugin -import com.willfp.ecoenchants.data.storage.PlayerProfile -import org.bukkit.Bukkit - -class SaveHandler { - companion object { - fun save(plugin: EcoEnchantsPlugin) { - if (Bukkit.getOnlinePlayers().isEmpty()) { - return - } - if (plugin.configYml.getBool("autosave.log")) { - plugin.logger.info("Auto-Saving player data!") - } - PlayerProfile.saveAll(plugin.configYml.getBool("autosave.async")) - if (plugin.configYml.getBool("autosave.log")) { - plugin.logger.info("Saved data!") - } - } - } - - class Runnable( - private val plugin: EcoEnchantsPlugin - ) : java.lang.Runnable { - override fun run() { - save(plugin) - } - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/DataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/DataHandler.kt deleted file mode 100644 index 272ea939..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/DataHandler.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.willfp.ecoenchants.data.storage - -import java.util.* - -interface DataHandler { - fun save() - - fun write(uuid: UUID, key: String, value: T) - 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/ecoenchants/data/storage/MySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/MySQLDataHandler.kt deleted file mode 100644 index fb8f4fb6..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/MySQLDataHandler.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.willfp.ecoenchants.data.storage - -import com.willfp.ecoenchants.EcoEnchantsPlugin -import org.jetbrains.exposed.dao.id.EntityID -import org.jetbrains.exposed.dao.id.UUIDTable -import org.jetbrains.exposed.sql.* -import org.jetbrains.exposed.sql.transactions.transaction -import java.util.* - -@Suppress("UNCHECKED_CAST") -class MySQLDataHandler( - plugin: EcoEnchantsPlugin -) : 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 { - /* - Optional for auto-add fields - */ - } - - SchemaUtils.create(Players) - } - } - - override fun save() { - // Do nothing - } - - override fun write(uuid: UUID, key: String, value: T) { - transaction { - Players.select { Players.id eq uuid }.firstOrNull() ?: run { - Players.insert { - it[this.id] = uuid - } - } - val column: Column = Players.columns.stream().filter { it.name == key }.findFirst().get() as Column - Players.update({ Players.id eq uuid }) { - it[column] = value - } - } - } - - 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("EcoEnchants_Players") { - override val id: Column> = uuid("uuid") - .entityId() - val descriptions = bool("descriptions") - .default(true) - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/PlayerProfile.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/PlayerProfile.kt deleted file mode 100644 index 6dc28943..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/PlayerProfile.kt +++ /dev/null @@ -1,85 +0,0 @@ -package com.willfp.ecoenchants.data.storage - -import com.willfp.ecoenchants.EcoEnchantsPlugin -import org.bukkit.OfflinePlayer -import java.util.* - -@Suppress("UNCHECKED_CAST") -class PlayerProfile private constructor( - private val data: MutableMap -) { - fun write(key: String, value: T) { - data[key] = value - } - - fun read(key: String, default: T): T { - return data[key] as T? ?: default - } - - companion object { - private val handler = EcoEnchantsPlugin.getInstance().dataHandler - private val loaded = mutableMapOf() - private val keys = mutableMapOf() - - private fun load(uuid: UUID): PlayerProfile { - 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) - Type.STRING -> data[key] = handler.read(uuid, key, "Unknown") - Type.BOOLEAN -> data[key] = handler.read(uuid, key, false) - } - } - - val profile = PlayerProfile(data) - loaded[uuid] = profile - return profile - } - - fun saveAll(async: Boolean) { - val saver = { - for ((uuid, profile) in loaded) { - for ((key, type) in keys) { - when (type) { - Type.INT -> handler.write(uuid, key, profile.read(key, 0)) - Type.DOUBLE -> handler.write(uuid, key, profile.read(key, 0.0)) - Type.STRING -> handler.write(uuid, key, profile.read(key, "Unknown Value")) - Type.BOOLEAN -> handler.write(uuid, key, profile.read(key, false)) - } - } - } - - handler.save() - } - - if (async) { - EcoEnchantsPlugin.getInstance().scheduler.runAsync(saver) - } else { - saver.invoke() - } - } - - @JvmStatic - val OfflinePlayer.profile: PlayerProfile - get() { - return load(this.uniqueId) - } - - init { - keys["descriptions"] = Type.BOOLEAN - } - } - - private enum class Type { - STRING, - DOUBLE, - BOOLEAN, - INT - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/YamlDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/YamlDataHandler.kt deleted file mode 100644 index ccde1a13..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/data/storage/YamlDataHandler.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.willfp.ecoenchants.data.storage - -import com.willfp.eco.core.config.yaml.YamlBaseConfig -import com.willfp.ecoenchants.EcoEnchantsPlugin -import java.util.* - -@Suppress("UNCHECKED_CAST") -class YamlDataHandler( - plugin: EcoEnchantsPlugin -) : DataHandler { - private val dataYml = DataYml(plugin) - - override fun save() { - dataYml.save() - } - - override fun write(uuid: UUID, key: String, value: T) { - dataYml.set("player.$uuid.$key", value) - } - - override fun read(uuid: UUID, key: String): T? { - return dataYml.get("player.$uuid.$key") as T? - } - - class DataYml( - plugin: EcoEnchantsPlugin - ) : 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 4fd8d60b..66e29fcc 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -3,18 +3,6 @@ # by Auxilor # -mysql: - enabled: false # Set to false, data.yml will be used instead. - host: localhost - port: 3306 - database: database - user: username - password: passy - -autosave: - log: true # If auto-save messages should be sent to console - async: false # If saves should be performed asynchronously. May cause bugs without MySQL - allow-on-npc: false # If enchantments should activate against NPCs. commands: diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 99227c99..68ba9b5b 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -22,12 +22,6 @@ softdepend: - Essentials - PlaceholderAPI - mcMMO -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: enchantinfo: