Added support for multiple boosters
This commit is contained in:
@@ -27,7 +27,6 @@ allprojects {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
|
||||||
maven { url 'https://jitpack.io' }
|
maven { url 'https://jitpack.io' }
|
||||||
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ 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.boosters.boosters.addActiveBooster
|
||||||
import com.willfp.eco.core.data.ServerProfile
|
import com.willfp.eco.core.data.ServerProfile
|
||||||
import com.willfp.eco.core.data.profile
|
import com.willfp.eco.core.data.profile
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
@@ -12,14 +13,12 @@ import org.bukkit.OfflinePlayer
|
|||||||
import org.bukkit.Sound
|
import org.bukkit.Sound
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
private val plugin = BoostersPlugin.instance
|
|
||||||
|
|
||||||
val OfflinePlayer.boosters: List<Booster>
|
val OfflinePlayer.boosters: List<Booster>
|
||||||
get() {
|
get() {
|
||||||
val found = mutableListOf<Booster>()
|
val found = mutableListOf<Booster>()
|
||||||
|
|
||||||
for (booster in Boosters.values()) {
|
for (booster in Boosters.values()) {
|
||||||
val amount = this.profile.read(booster.dataKey)
|
val amount = this.profile.read(booster.ownedDataKey)
|
||||||
for (i in 0 until amount) {
|
for (i in 0 until amount) {
|
||||||
found.add(booster)
|
found.add(booster)
|
||||||
}
|
}
|
||||||
@@ -29,11 +28,11 @@ val OfflinePlayer.boosters: List<Booster>
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.getAmountOfBooster(booster: Booster): Int {
|
fun OfflinePlayer.getAmountOfBooster(booster: Booster): Int {
|
||||||
return this.profile.read(booster.dataKey)
|
return this.profile.read(booster.ownedDataKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.setAmountOfBooster(booster: Booster, amount: Int) {
|
fun OfflinePlayer.setAmountOfBooster(booster: Booster, amount: Int) {
|
||||||
this.profile.write(booster.dataKey, amount)
|
this.profile.write(booster.ownedDataKey, amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OfflinePlayer.incrementBoosters(booster: Booster, amount: Int) {
|
fun OfflinePlayer.incrementBoosters(booster: Booster, amount: Int) {
|
||||||
@@ -54,11 +53,18 @@ fun Player.activateBooster(booster: Booster): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerProfile.load().write(
|
ServerProfile.load().write(
|
||||||
plugin.expiryTimeKey,
|
booster.expiryTimeKey,
|
||||||
(booster.duration.toDouble() * 50) + System.currentTimeMillis()
|
(booster.duration.toDouble() * 50) + System.currentTimeMillis()
|
||||||
)
|
)
|
||||||
|
|
||||||
plugin.activeBooster = ActivatedBooster(booster, this.uniqueId)
|
ServerProfile.load().write(
|
||||||
|
booster.activeDataKey,
|
||||||
|
this.uniqueId.toString()
|
||||||
|
)
|
||||||
|
|
||||||
|
Bukkit.getServer().addActiveBooster(
|
||||||
|
ActivatedBooster(booster, this.uniqueId)
|
||||||
|
)
|
||||||
|
|
||||||
for (player in Bukkit.getOnlinePlayers()) {
|
for (player in Bukkit.getOnlinePlayers()) {
|
||||||
player.playSound(
|
player.playSound(
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package com.willfp.boosters
|
package com.willfp.boosters
|
||||||
|
|
||||||
import com.willfp.boosters.boosters.ActivatedBooster
|
|
||||||
import com.willfp.boosters.boosters.Boosters
|
import com.willfp.boosters.boosters.Boosters
|
||||||
|
import com.willfp.boosters.boosters.activeBoosters
|
||||||
|
import com.willfp.boosters.boosters.expireBooster
|
||||||
import com.willfp.boosters.commands.CommandBoosters
|
import com.willfp.boosters.commands.CommandBoosters
|
||||||
import com.willfp.boosters.config.BoostersYml
|
import com.willfp.boosters.config.BoostersYml
|
||||||
import com.willfp.eco.core.command.impl.PluginCommand
|
import com.willfp.eco.core.command.impl.PluginCommand
|
||||||
import com.willfp.eco.core.data.ServerProfile
|
import com.willfp.eco.core.data.ServerProfile
|
||||||
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 com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||||
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
||||||
@@ -16,153 +15,29 @@ import com.willfp.eco.util.savedDisplayName
|
|||||||
import com.willfp.libreforge.LibReforgePlugin
|
import com.willfp.libreforge.LibReforgePlugin
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
import java.util.UUID
|
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
class BoostersPlugin : LibReforgePlugin(2036, 14269, "&e") {
|
class BoostersPlugin : LibReforgePlugin(2036, 14269, "&e") {
|
||||||
val boostersYml = BoostersYml(this)
|
val boostersYml = BoostersYml(this)
|
||||||
|
|
||||||
private val boosterKey = PersistentDataKey(
|
|
||||||
this.namespacedKeyFactory.create("active_booster"),
|
|
||||||
PersistentDataKeyType.STRING,
|
|
||||||
""
|
|
||||||
).server()
|
|
||||||
|
|
||||||
val expiryTimeKey = PersistentDataKey(
|
|
||||||
this.namespacedKeyFactory.create("expiry_time"),
|
|
||||||
PersistentDataKeyType.DOUBLE,
|
|
||||||
0.0
|
|
||||||
).server()
|
|
||||||
|
|
||||||
var activeBooster: ActivatedBooster?
|
|
||||||
get() {
|
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set(value) {
|
|
||||||
if (value == null) {
|
|
||||||
Bukkit.getServer().profile.write(boosterKey, "")
|
|
||||||
} else {
|
|
||||||
Bukkit.getServer().profile.write(boosterKey, "${value.booster.id}::${value.player.uniqueId}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val secondsLeft: Int
|
|
||||||
get() {
|
|
||||||
val endTime = ServerProfile.load().read(expiryTimeKey)
|
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
return if (endTime < currentTime || activeBooster == null) {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
((endTime - currentTime) / 1000).toInt()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handleEnableAdditional() {
|
override fun handleEnableAdditional() {
|
||||||
PlaceholderManager.registerPlaceholder(
|
this.registerHolderProvider { Bukkit.getServer().activeBoosters.map { it.booster } }
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"booster_info"
|
|
||||||
) {
|
|
||||||
val booster = activeBooster
|
|
||||||
|
|
||||||
if (booster == null) {
|
|
||||||
return@PlayerlessPlaceholder this.langYml.getString("no-currently-active")
|
|
||||||
.formatEco(formatPlaceholders = false)
|
|
||||||
} else {
|
|
||||||
return@PlayerlessPlaceholder this.langYml.getString("active-placeholder")
|
|
||||||
.replace("%player%", booster.player.savedDisplayName)
|
|
||||||
.replace("%booster%", booster.booster.name)
|
|
||||||
.formatEco(formatPlaceholders = false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"active",
|
|
||||||
) {
|
|
||||||
activeBooster?.booster?.id ?: ""
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"active_name"
|
|
||||||
) {
|
|
||||||
activeBooster?.booster?.name ?: ""
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"active_player",
|
|
||||||
) {
|
|
||||||
activeBooster?.player?.savedDisplayName ?: ""
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"seconds_remaining"
|
|
||||||
) {
|
|
||||||
secondsLeft.toString()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
PlaceholderManager.registerPlaceholder(
|
|
||||||
PlayerlessPlaceholder(
|
|
||||||
this,
|
|
||||||
"time_remaining"
|
|
||||||
) {
|
|
||||||
if (secondsLeft <= 0) {
|
|
||||||
return@PlayerlessPlaceholder "00:00:00"
|
|
||||||
}
|
|
||||||
|
|
||||||
// if you've seen this code on the internet, no you haven't. shush
|
|
||||||
val seconds = secondsLeft % 3600 % 60
|
|
||||||
val minutes = floor(secondsLeft % 3600 / 60.0).toInt()
|
|
||||||
val hours = floor(secondsLeft / 3600.0).toInt()
|
|
||||||
|
|
||||||
val hh = (if (hours < 10) "0" else "") + hours
|
|
||||||
val mm = (if (minutes < 10) "0" else "") + minutes
|
|
||||||
val ss = (if (seconds < 10) "0" else "") + seconds
|
|
||||||
|
|
||||||
"${hh}:${mm}:${ss}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
this.registerHolderProvider {
|
|
||||||
activeBooster.let {
|
|
||||||
if (it == null) emptyList() else listOf(it.booster)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleReloadAdditional() {
|
override fun handleReloadAdditional() {
|
||||||
this.scheduler.runTimer(1, 1) {
|
this.scheduler.runTimer(1, 1) {
|
||||||
val booster = activeBooster ?: return@runTimer
|
for (booster in Boosters.values()) {
|
||||||
val endTime = ServerProfile.load().read(expiryTimeKey)
|
if (booster.active == null) {
|
||||||
if (endTime <= System.currentTimeMillis()) {
|
continue
|
||||||
for (expiryMessage in booster.booster.expiryMessages) {
|
}
|
||||||
|
|
||||||
|
if (booster.secondsLeft <= 0) {
|
||||||
|
for (expiryMessage in booster.expiryMessages) {
|
||||||
Bukkit.broadcastMessage(expiryMessage)
|
Bukkit.broadcastMessage(expiryMessage)
|
||||||
}
|
}
|
||||||
activeBooster = null
|
|
||||||
|
Bukkit.getServer().expireBooster(booster)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,7 +55,7 @@ class BoostersPlugin : LibReforgePlugin(2036, 14269, "&e") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getMinimumEcoVersion(): String {
|
override fun getMinimumEcoVersion(): String {
|
||||||
return "6.24.0"
|
return "6.35.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
|
package com.willfp.boosters.boosters
|
||||||
|
|
||||||
|
import com.willfp.eco.core.data.ServerProfile
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.OfflinePlayer
|
||||||
|
import org.bukkit.Server
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
private val boosters = mutableSetOf<ActivatedBooster>()
|
||||||
|
|
||||||
|
fun Server.addActiveBooster(activatedBooster: ActivatedBooster) {
|
||||||
|
boosters += activatedBooster
|
||||||
|
}
|
||||||
|
|
||||||
|
val Server.activeBoosters: Set<ActivatedBooster>
|
||||||
|
get() = boosters.toSet()
|
||||||
|
|
||||||
|
fun Server.expireBooster(booster: Booster) {
|
||||||
|
boosters.removeIf { it.booster == booster }
|
||||||
|
|
||||||
|
ServerProfile.load().write(
|
||||||
|
booster.activeDataKey,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class ActivatedBooster(
|
||||||
|
val booster: Booster,
|
||||||
|
private val uuid: UUID
|
||||||
|
) {
|
||||||
|
val player: OfflinePlayer
|
||||||
|
get() = Bukkit.getOfflinePlayer(uuid)
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is ActivatedBooster) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.booster == this.booster
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return Objects.hash(this.booster)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,18 +5,22 @@ import com.willfp.boosters.getAmountOfBooster
|
|||||||
import com.willfp.eco.core.config.interfaces.Config
|
import com.willfp.eco.core.config.interfaces.Config
|
||||||
import com.willfp.eco.core.data.keys.PersistentDataKey
|
import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||||
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||||
|
import com.willfp.eco.core.data.profile
|
||||||
|
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||||
import com.willfp.eco.core.items.Items
|
import com.willfp.eco.core.items.Items
|
||||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||||
|
import com.willfp.eco.core.placeholder.PlayerlessPlaceholder
|
||||||
import com.willfp.eco.util.StringUtils
|
import com.willfp.eco.util.StringUtils
|
||||||
import com.willfp.eco.util.formatEco
|
import com.willfp.eco.util.formatEco
|
||||||
|
import com.willfp.eco.util.savedDisplayName
|
||||||
import com.willfp.libreforge.Holder
|
import com.willfp.libreforge.Holder
|
||||||
import com.willfp.libreforge.conditions.Conditions
|
import com.willfp.libreforge.conditions.Conditions
|
||||||
import com.willfp.libreforge.effects.Effects
|
import com.willfp.libreforge.effects.Effects
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.OfflinePlayer
|
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.floor
|
||||||
|
|
||||||
class Booster(
|
class Booster(
|
||||||
private val plugin: BoostersPlugin,
|
private val plugin: BoostersPlugin,
|
||||||
@@ -24,12 +28,48 @@ class Booster(
|
|||||||
) : Holder {
|
) : Holder {
|
||||||
val id = config.getString("id")
|
val id = config.getString("id")
|
||||||
|
|
||||||
val dataKey: PersistentDataKey<Int> = PersistentDataKey(
|
val ownedDataKey: PersistentDataKey<Int> = PersistentDataKey(
|
||||||
plugin.namespacedKeyFactory.create(id),
|
plugin.namespacedKeyFactory.create(id),
|
||||||
PersistentDataKeyType.INT,
|
PersistentDataKeyType.INT,
|
||||||
0
|
0
|
||||||
).player()
|
).player()
|
||||||
|
|
||||||
|
val activeDataKey: PersistentDataKey<String> = PersistentDataKey(
|
||||||
|
plugin.namespacedKeyFactory.create("${id}_active"),
|
||||||
|
PersistentDataKeyType.STRING,
|
||||||
|
""
|
||||||
|
).server()
|
||||||
|
|
||||||
|
val expiryTimeKey = PersistentDataKey(
|
||||||
|
plugin.namespacedKeyFactory.create("${id}_expiry_time"),
|
||||||
|
PersistentDataKeyType.DOUBLE,
|
||||||
|
0.0
|
||||||
|
).server()
|
||||||
|
|
||||||
|
val active: ActivatedBooster?
|
||||||
|
get() {
|
||||||
|
val activeKey = Bukkit.getServer().profile.read(activeDataKey)
|
||||||
|
|
||||||
|
if (activeKey.isEmpty()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val uuid = UUID.fromString(activeKey)
|
||||||
|
|
||||||
|
return ActivatedBooster(this, uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
val secondsLeft: Int
|
||||||
|
get() {
|
||||||
|
val endTime = Bukkit.getServer().profile.read(expiryTimeKey)
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
return if (endTime < currentTime || active == null) {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
((endTime - currentTime) / 1000).toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val name = config.getFormattedString("name")
|
val name = config.getFormattedString("name")
|
||||||
|
|
||||||
val duration = config.getInt("duration")
|
val duration = config.getInt("duration")
|
||||||
@@ -74,6 +114,64 @@ class Booster(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
Boosters.addNewBooster(this)
|
Boosters.addNewBooster(this)
|
||||||
|
PlaceholderManager.registerPlaceholder(
|
||||||
|
PlayerlessPlaceholder(
|
||||||
|
plugin,
|
||||||
|
"${id}_info"
|
||||||
|
) {
|
||||||
|
val active = this.active
|
||||||
|
|
||||||
|
if (active != null) {
|
||||||
|
plugin.langYml.getString("active-placeholder")
|
||||||
|
.replace("%player%", active.player.savedDisplayName)
|
||||||
|
.replace("%booster%", active.booster.name)
|
||||||
|
.formatEco(formatPlaceholders = false)
|
||||||
|
} else {
|
||||||
|
plugin.langYml.getString("no-currently-active")
|
||||||
|
.formatEco(formatPlaceholders = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
PlaceholderManager.registerPlaceholder(
|
||||||
|
PlayerlessPlaceholder(
|
||||||
|
plugin,
|
||||||
|
"${id}_player",
|
||||||
|
) {
|
||||||
|
active?.player?.savedDisplayName ?: ""
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
PlaceholderManager.registerPlaceholder(
|
||||||
|
PlayerlessPlaceholder(
|
||||||
|
plugin,
|
||||||
|
"${id}_seconds_remaining"
|
||||||
|
) {
|
||||||
|
secondsLeft.toString()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
PlaceholderManager.registerPlaceholder(
|
||||||
|
PlayerlessPlaceholder(
|
||||||
|
plugin,
|
||||||
|
"time_remaining"
|
||||||
|
) {
|
||||||
|
if (secondsLeft <= 0) {
|
||||||
|
return@PlayerlessPlaceholder "00:00:00"
|
||||||
|
}
|
||||||
|
|
||||||
|
// if you've seen this code on the internet, no you haven't. shush
|
||||||
|
val seconds = secondsLeft % 3600 % 60
|
||||||
|
val minutes = floor(secondsLeft % 3600 / 60.0).toInt()
|
||||||
|
val hours = floor(secondsLeft / 3600.0).toInt()
|
||||||
|
|
||||||
|
val hh = (if (hours < 10) "0" else "") + hours
|
||||||
|
val mm = (if (minutes < 10) "0" else "") + minutes
|
||||||
|
val ss = (if (seconds < 10) "0" else "") + seconds
|
||||||
|
|
||||||
|
"${hh}:${mm}:${ss}"
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
@@ -88,11 +186,3 @@ class Booster(
|
|||||||
return this.id.hashCode()
|
return this.id.hashCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ActivatedBooster(
|
|
||||||
val booster: Booster,
|
|
||||||
private val uuid: UUID
|
|
||||||
) {
|
|
||||||
val player: OfflinePlayer
|
|
||||||
get() = Bukkit.getOfflinePlayer(uuid)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.willfp.boosters.commands
|
package com.willfp.boosters.commands
|
||||||
|
|
||||||
import com.willfp.boosters.BoostersPlugin
|
import com.willfp.boosters.BoostersPlugin
|
||||||
|
import com.willfp.boosters.boosters.activeBoosters
|
||||||
|
import com.willfp.boosters.boosters.expireBooster
|
||||||
import com.willfp.eco.core.EcoPlugin
|
import com.willfp.eco.core.EcoPlugin
|
||||||
import com.willfp.eco.core.command.impl.Subcommand
|
import com.willfp.eco.core.command.impl.Subcommand
|
||||||
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
class CommandCancel(plugin: EcoPlugin) :
|
class CommandCancel(plugin: EcoPlugin) :
|
||||||
@@ -14,7 +17,9 @@ class CommandCancel(plugin: EcoPlugin) :
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||||
(plugin as BoostersPlugin).activeBooster = null
|
for (booster in Bukkit.getServer().activeBoosters) {
|
||||||
|
Bukkit.getServer().expireBooster(booster.booster)
|
||||||
|
}
|
||||||
sender.sendMessage(plugin.langYml.getMessage("cancelled"))
|
sender.sendMessage(plugin.langYml.getMessage("cancelled"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ object BoosterGUI {
|
|||||||
return SlotHandler { event, _, _ ->
|
return SlotHandler { event, _, _ ->
|
||||||
val player = event.whoClicked.tryAsPlayer() ?: return@SlotHandler
|
val player = event.whoClicked.tryAsPlayer() ?: return@SlotHandler
|
||||||
|
|
||||||
if (plugin.activeBooster != null) {
|
if (booster.active != null) {
|
||||||
player.sendMessage(plugin.langYml.getMessage("already-active"))
|
player.sendMessage(plugin.langYml.getMessage("already-active"))
|
||||||
player.playSound(
|
player.playSound(
|
||||||
player.location,
|
player.location,
|
||||||
|
|||||||
@@ -17,5 +17,5 @@ messages:
|
|||||||
cancelled: "Cancelled the active booster"
|
cancelled: "Cancelled the active booster"
|
||||||
cannot-transmit: "&cYou can't transmit here!"
|
cannot-transmit: "&cYou can't transmit here!"
|
||||||
|
|
||||||
no-currently-active: "&cThere is no booster currently active!"
|
no-currently-active: "&cNot Active!"
|
||||||
active-placeholder: "%player% &fhas activated a %booster%&f!"
|
active-placeholder: "&fThanks %player% &ffor activating %booster%&f!"
|
||||||
|
|||||||
Reference in New Issue
Block a user