From 71e26039df38648d9ca3ec81f25eec9d1744e84f Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 11 Feb 2022 17:59:07 +0000 Subject: [PATCH] Added support for SQL --- .../com/willfp/boosters/BoosterUtils.kt | 44 ++++++++++++++++++- .../com/willfp/boosters/BoostersPlugin.kt | 2 + .../core-plugin/src/main/resources/config.yml | 5 +++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt index 346e239..2e69307 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/BoosterUtils.kt @@ -5,21 +5,61 @@ package com.willfp.boosters import com.willfp.boosters.boosters.ActivatedBooster import com.willfp.boosters.boosters.Booster import com.willfp.boosters.boosters.Boosters +import com.willfp.eco.core.data.keys.PersistentDataKey +import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.eco.core.data.profile import org.bukkit.Bukkit import org.bukkit.OfflinePlayer import org.bukkit.Sound import org.bukkit.entity.Player +import java.util.* private var active: ActivatedBooster? = null private val plugin = BoostersPlugin.instance +private var usingSql: Boolean = false var activeBooster: ActivatedBooster? get() { - return active + if (usingSql) { + val key = Bukkit.getServer().profile.read(boosterKey) + + return if (key.isEmpty()) { + null + } else { + val booster = key.split("::") + val id = booster[0] + val uuid = UUID.fromString(booster[1]) + ActivatedBooster( + Boosters.getByID(id) ?: return null, + uuid + ) + } + } else { + return active + } } set(value) { - active = value + if (usingSql) { + if (value == null) { + Bukkit.getServer().profile.write(boosterKey, "") + } else { + Bukkit.getServer().profile.write(boosterKey, "${value.booster.id}::${value.player}") + } + } else { + active = value + } + } + +private val boosterKey = PersistentDataKey( + plugin.namespacedKeyFactory.create("active_booster"), + PersistentDataKeyType.STRING, + "" +) + +var useSQL: Boolean + get() = usingSql + set(value) { + usingSql = value } val OfflinePlayer.boosters: List 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 9d09e87..c10ae56 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 @@ -16,6 +16,8 @@ class BoostersPlugin : LibReforgePlugin(0, 14269, "&e") { val boostersYml = BoostersYml(this) override fun handleEnableAdditional() { + useSQL = configYml.getBool("use-sql") + PlaceholderManager.registerPlaceholder( PlaceholderEntry( this, diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 88c72a3..3af98ce 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -3,6 +3,11 @@ # by Auxilor # +# Will synchronize active booster over all servers in a network. +# SQL Settings are in /plugins/eco/config.yml +# If false, boosters will be server-specific. +use-sql: false + gui: title: Boosters rows: 3