Updated to eco 6.12.1

This commit is contained in:
Auxilor
2021-11-02 09:18:36 +00:00
parent fbf6755c04
commit 4757549f23
7 changed files with 16 additions and 66 deletions

View File

@@ -2,6 +2,7 @@ package com.willfp.boosters
import com.willfp.boosters.boosters.Booster import com.willfp.boosters.boosters.Booster
import com.willfp.boosters.boosters.Boosters import com.willfp.boosters.boosters.Boosters
import com.willfp.eco.core.data.PlayerProfile
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer import org.bukkit.OfflinePlayer
import org.bukkit.Server import org.bukkit.Server
@@ -22,12 +23,9 @@ var Server.activeBooster: Booster?
val OfflinePlayer.boosters: List<Booster> val OfflinePlayer.boosters: List<Booster>
get() { get() {
val found = mutableListOf<Booster>() val found = mutableListOf<Booster>()
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) { for (i in 0 until amount) {
found.add(booster) found.add(booster)
} }
@@ -37,12 +35,12 @@ val OfflinePlayer.boosters: List<Booster>
} }
fun OfflinePlayer.getAmountOfBooster(booster: Booster): Int { 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) { 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 { fun Player.activateBooster(booster: Booster): Boolean {

View File

@@ -2,21 +2,12 @@ package com.willfp.boosters
import com.willfp.boosters.boosters.Boosters import com.willfp.boosters.boosters.Boosters
import com.willfp.boosters.commands.CommandBoosters 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.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand import com.willfp.eco.core.command.impl.PluginCommand
import org.bukkit.event.Listener import org.bukkit.event.Listener
import java.io.IOException
class BoostersPlugin : EcoPlugin() { class BoostersPlugin : EcoPlugin() {
val dataYml: DataYml = DataYml(this)
override fun handleReload() { override fun handleReload() {
save(this)
scheduler.runTimer(SaveHandler.Runnable(this), 10000, 20000)
for (booster in Boosters.values()) { for (booster in Boosters.values()) {
this.eventManager.unregisterListener(booster) this.eventManager.unregisterListener(booster)
this.eventManager.registerListener(booster) this.eventManager.registerListener(booster)
@@ -24,11 +15,6 @@ class BoostersPlugin : EcoPlugin() {
} }
override fun handleDisable() { override fun handleDisable() {
try {
dataYml.save()
} catch (e: IOException) {
e.printStackTrace()
}
} }
override fun loadListeners(): List<Listener> { override fun loadListeners(): List<Listener> {
@@ -44,7 +30,7 @@ class BoostersPlugin : EcoPlugin() {
} }
override fun getMinimumEcoVersion(): String { override fun getMinimumEcoVersion(): String {
return "6.7.0" return "6.12.0"
} }
init { init {

View File

@@ -1,16 +1,24 @@
package com.willfp.boosters.boosters package com.willfp.boosters.boosters
import com.willfp.boosters.BoostersPlugin 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 com.willfp.eco.util.StringUtils
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.event.Listener import org.bukkit.event.Listener
abstract class Booster( abstract class Booster(
protected val plugin: BoostersPlugin, private val plugin: BoostersPlugin,
val id: String val id: String
): Listener { ): Listener {
abstract val duration: Int abstract val duration: Int
val dataKey = PersistentDataKey<Int>(
plugin.namespacedKeyFactory.create("boosters_$id"),
PersistentDataKeyType.INT,
0
)
init { init {
register() register()
} }

View File

@@ -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
)

View File

@@ -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)
}
}
}

View File

@@ -1 +0,0 @@
# Don't edit this file - it's for internal storage only

View File

@@ -1,2 +1,2 @@
version = 1.0.2 version = 1.1.0
plugin-name = Boosters plugin-name = Boosters