diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt index eaff779..22025eb 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterHandlers.kt @@ -2,6 +2,7 @@ package com.willfp.boosters import com.willfp.boosters.boosters.Booster import com.willfp.boosters.boosters.Boosters +import com.willfp.eco.core.data.PlayerProfile import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.Server @@ -22,12 +23,9 @@ var Server.activeBooster: Booster? val OfflinePlayer.boosters: List get() { val found = mutableListOf() - val section = plugin.dataYml.getSubsectionOrNull("${this.uniqueId}") - - for (key in (section?.getKeys(false) ?: emptyList())) { - val booster = Boosters.getById(key) ?: continue - val amount = section?.getIntOrNull(key) ?: continue + for (booster in Boosters.values()) { + val amount = PlayerProfile.load(this).read(booster.dataKey) for (i in 0 until amount) { found.add(booster) } @@ -37,12 +35,12 @@ val OfflinePlayer.boosters: List } fun OfflinePlayer.getAmountOfBooster(booster: Booster): Int { - return plugin.dataYml.getIntOrNull("${this.uniqueId}.${booster.id}") ?: 0 + return PlayerProfile.load(this).read(booster.dataKey) } fun OfflinePlayer.setAmountOfBooster(booster: Booster, amount: Int) { - plugin.dataYml.set("${this.uniqueId}.${booster.id}", amount) + PlayerProfile.load(this).write(booster.dataKey, amount) } fun Player.activateBooster(booster: Booster): Boolean { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt index ad33905..deb0c96 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoostersPlugin.kt @@ -2,21 +2,12 @@ package com.willfp.boosters import com.willfp.boosters.boosters.Boosters import com.willfp.boosters.commands.CommandBoosters -import com.willfp.boosters.config.DataYml -import com.willfp.boosters.data.SaveHandler -import com.willfp.boosters.data.SaveHandler.Companion.save import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.PluginCommand import org.bukkit.event.Listener -import java.io.IOException class BoostersPlugin : EcoPlugin() { - val dataYml: DataYml = DataYml(this) - override fun handleReload() { - save(this) - scheduler.runTimer(SaveHandler.Runnable(this), 10000, 20000) - for (booster in Boosters.values()) { this.eventManager.unregisterListener(booster) this.eventManager.registerListener(booster) @@ -24,11 +15,6 @@ class BoostersPlugin : EcoPlugin() { } override fun handleDisable() { - try { - dataYml.save() - } catch (e: IOException) { - e.printStackTrace() - } } override fun loadListeners(): List { @@ -44,7 +30,7 @@ class BoostersPlugin : EcoPlugin() { } override fun getMinimumEcoVersion(): String { - return "6.7.0" + return "6.12.0" } init { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt index b3063aa..4a0e1a9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/boosters/Booster.kt @@ -1,16 +1,24 @@ package com.willfp.boosters.boosters import com.willfp.boosters.BoostersPlugin +import com.willfp.eco.core.data.keys.PersistentDataKey +import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.util.StringUtils import org.bukkit.entity.Player import org.bukkit.event.Listener abstract class Booster( - protected val plugin: BoostersPlugin, + private val plugin: BoostersPlugin, val id: String ): Listener { abstract val duration: Int + val dataKey = PersistentDataKey( + plugin.namespacedKeyFactory.create("boosters_$id"), + PersistentDataKeyType.INT, + 0 + ) + init { register() } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/DataYml.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/DataYml.kt deleted file mode 100644 index 5752bfe..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/config/DataYml.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.willfp.boosters.config - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.config.yaml.YamlBaseConfig - -class DataYml( - plugin: EcoPlugin -): YamlBaseConfig( - "data", - false, - plugin -) \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/data/SaveHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/data/SaveHandler.kt deleted file mode 100644 index 273c4cd..0000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/data/SaveHandler.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.willfp.boosters.data - -import com.willfp.boosters.BoostersPlugin -import org.bukkit.Bukkit - -class SaveHandler { - companion object { - fun save(plugin: BoostersPlugin) { - if (Bukkit.getOnlinePlayers().isEmpty()) { - return - } - if (plugin.configYml.getBool("log-autosaves")) { - plugin.logger.info("Auto-Saving player data!") - } - plugin.dataYml.save() - if (plugin.configYml.getBool("log-autosaves")) { - plugin.logger.info("Saved data!") - } - } - } - - class Runnable( - private val plugin: BoostersPlugin - ) : java.lang.Runnable { - override fun run() { - save(plugin) - } - } -} \ 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 577edeb..0000000 --- a/eco-core/core-plugin/src/main/resources/data.yml +++ /dev/null @@ -1 +0,0 @@ -# Don't edit this file - it's for internal storage only \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1e40e36..f760949 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.0.2 +version = 1.1.0 plugin-name = Boosters \ No newline at end of file