Added support for SQL
This commit is contained in:
@@ -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<Booster>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user