From 9eefc938162e08cb849d887a2bbd8dfce6f86e5c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 13 Jan 2022 10:46:26 +0000 Subject: [PATCH] Fixed terrible performance from gainsoundkey --- .../kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt index 18c2432..26eaa02 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/EcoSkillsPlayer.kt @@ -16,7 +16,7 @@ import org.bukkit.entity.Entity import org.bukkit.entity.Player import org.bukkit.entity.Projectile import org.bukkit.entity.Tameable -import java.util.* +import java.util.UUID import kotlin.math.abs private val expMultiplierCache = mutableMapOf() @@ -179,16 +179,18 @@ fun OfflinePlayer.setStatLevel(stat: Stat, level: Int) { } } +private val gainSoundKey = PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true); + fun OfflinePlayer.hasGainSoundEnabled(): Boolean { - return PlayerProfile.load(this).read(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true)) + return PlayerProfile.load(this).read(gainSoundKey) } fun OfflinePlayer.setGainSoundEnabled(enabled: Boolean) { - PlayerProfile.load(this).write(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true), enabled) + PlayerProfile.load(this).write(gainSoundKey, enabled) } fun OfflinePlayer.toggleGainSoundEnabled() { - PlayerProfile.load(this).write(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true), !hasGainSoundEnabled()) + PlayerProfile.load(this).write(gainSoundKey, !hasGainSoundEnabled()) } fun Entity.tryAsPlayer(): Player? {