Added support for SQL
This commit is contained in:
@@ -5,22 +5,62 @@ package com.willfp.boosters
|
|||||||
import com.willfp.boosters.boosters.ActivatedBooster
|
import com.willfp.boosters.boosters.ActivatedBooster
|
||||||
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.keys.PersistentDataKey
|
||||||
|
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||||
import com.willfp.eco.core.data.profile
|
import com.willfp.eco.core.data.profile
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.OfflinePlayer
|
import org.bukkit.OfflinePlayer
|
||||||
import org.bukkit.Sound
|
import org.bukkit.Sound
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
private var active: ActivatedBooster? = null
|
private var active: ActivatedBooster? = null
|
||||||
private val plugin = BoostersPlugin.instance
|
private val plugin = BoostersPlugin.instance
|
||||||
|
private var usingSql: Boolean = false
|
||||||
|
|
||||||
var activeBooster: ActivatedBooster?
|
var activeBooster: ActivatedBooster?
|
||||||
get() {
|
get() {
|
||||||
|
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
|
return active
|
||||||
}
|
}
|
||||||
|
}
|
||||||
set(value) {
|
set(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
|
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>
|
val OfflinePlayer.boosters: List<Booster>
|
||||||
get() {
|
get() {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ class BoostersPlugin : LibReforgePlugin(0, 14269, "&e") {
|
|||||||
val boostersYml = BoostersYml(this)
|
val boostersYml = BoostersYml(this)
|
||||||
|
|
||||||
override fun handleEnableAdditional() {
|
override fun handleEnableAdditional() {
|
||||||
|
useSQL = configYml.getBool("use-sql")
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
PlaceholderManager.registerPlaceholder(
|
||||||
PlaceholderEntry(
|
PlaceholderEntry(
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
# by Auxilor
|
# 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:
|
gui:
|
||||||
title: Boosters
|
title: Boosters
|
||||||
rows: 3
|
rows: 3
|
||||||
|
|||||||
Reference in New Issue
Block a user