Updated to eco placeholder system

This commit is contained in:
Auxilor
2022-04-17 13:16:36 +01:00
parent 380886934f
commit a3be5f1e20
2 changed files with 39 additions and 50 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ allprojects {
} }
dependencies { dependencies {
compileOnly 'com.willfp:eco:6.33.0' compileOnly 'com.willfp:eco:6.30.0'
implementation 'com.willfp:libreforge:3.34.0' implementation 'com.willfp:libreforge:3.34.0'
compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'org.jetbrains:annotations:23.0.0'
@@ -9,8 +9,8 @@ import com.willfp.eco.core.data.ServerProfile
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.data.profile
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
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.util.ListUtils import com.willfp.eco.util.ListUtils
import com.willfp.eco.util.formatEco import com.willfp.eco.util.formatEco
import com.willfp.eco.util.savedDisplayName import com.willfp.eco.util.savedDisplayName
@@ -73,92 +73,81 @@ class BoostersPlugin : LibReforgePlugin(2036, 14269, "&e") {
override fun handleEnableAdditional() { override fun handleEnableAdditional() {
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"booster_info", "booster_info",
{ {
val booster = activeBooster val booster = activeBooster
if (booster == null) { if (booster == null) {
return@PlaceholderEntry this.langYml.getString("no-currently-active") return@PlayerlessPlaceholder this.langYml.getString("no-currently-active")
.formatEco(formatPlaceholders = false) .formatEco(formatPlaceholders = false)
} else { } else {
return@PlaceholderEntry this.langYml.getString("active-placeholder") return@PlayerlessPlaceholder this.langYml.getString("active-placeholder")
.replace("%player%", booster.player.savedDisplayName) .replace("%player%", booster.player.savedDisplayName)
.replace("%booster%", booster.booster.name) .replace("%booster%", booster.booster.name)
.formatEco(formatPlaceholders = false) .formatEco(formatPlaceholders = false)
} }
}, }
false
) )
) )
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"active", "active",
{ ) {
activeBooster?.booster?.id ?: "" activeBooster?.booster?.id ?: ""
}, }
false
)
) )
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"active_name", "active_name"
{ ) {
activeBooster?.booster?.name ?: "" activeBooster?.booster?.name ?: ""
}, }
false
)
) )
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"active_player", "active_player",
{ ) {
activeBooster?.player?.savedDisplayName ?: "" activeBooster?.player?.savedDisplayName ?: ""
}, }
false
)
) )
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"seconds_remaining", "seconds_remaining"
{ ) {
secondsLeft.toString() secondsLeft.toString()
}, }
false
)
) )
PlaceholderManager.registerPlaceholder( PlaceholderManager.registerPlaceholder(
PlaceholderEntry( PlayerlessPlaceholder(
this, this,
"time_remaining", "time_remaining"
{ ) {
if (secondsLeft <= 0) { if (secondsLeft <= 0) {
return@PlaceholderEntry "00:00:00" return@PlayerlessPlaceholder "00:00:00"
} }
// if you've seen this code on the internet, no you haven't. shush // if you've seen this code on the internet, no you haven't. shush
val seconds = secondsLeft % 3600 % 60 val seconds = secondsLeft % 3600 % 60
val minutes = floor(secondsLeft % 3600 / 60.0).toInt() val minutes = floor(secondsLeft % 3600 / 60.0).toInt()
val hours = floor(secondsLeft / 3600.0).toInt() val hours = floor(secondsLeft / 3600.0).toInt()
val hh = (if (hours < 10) "0" else "") + hours val hh = (if (hours < 10) "0" else "") + hours
val mm = (if (minutes < 10) "0" else "") + minutes val mm = (if (minutes < 10) "0" else "") + minutes
val ss = (if (seconds < 10) "0" else "") + seconds val ss = (if (seconds < 10) "0" else "") + seconds
"${hh}:${mm}:${ss}" "${hh}:${mm}:${ss}"
}, }
false
)
) )
this.registerHolderProvider { ListUtils.toSingletonList(activeBooster?.booster as Holder) } this.registerHolderProvider { ListUtils.toSingletonList(activeBooster?.booster as Holder) }