From e1a840b1e1eab25fee748ea8e8ec964ae499c26c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 18 May 2023 15:48:26 +0100 Subject: [PATCH] Readded /skills togglexpgainsound --- .../ecoskills/commands/CommandSkills.kt | 1 + .../commands/CommandToggleActionBar.kt | 2 -- .../commands/CommandToggleXpGainSound.kt | 24 +++++++++++++++++++ .../ecoskills/skills/display/GainXPDisplay.kt | 22 ++++++++++++++++- .../core-plugin/src/main/resources/lang.yml | 2 ++ .../src/main/resources/paper-plugin.yml | 4 ++++ .../core-plugin/src/main/resources/plugin.yml | 4 ++++ 7 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleXpGainSound.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandSkills.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandSkills.kt index 2fe4154..0c3b6db 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandSkills.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandSkills.kt @@ -16,6 +16,7 @@ class CommandSkills(plugin: EcoPlugin) : PluginCommand( ) { init { this.addSubcommand(CommandToggleActionBar(plugin)) + .addSubcommand(CommandToggleXpGainSound(plugin)) .addSubcommand(CommandTop(plugin)) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleActionBar.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleActionBar.kt index eaa74ba..219ee82 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleActionBar.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleActionBar.kt @@ -1,5 +1,3 @@ -@file:Suppress("DEPRECATION") - package com.willfp.ecoskills.commands import com.willfp.eco.core.EcoPlugin diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleXpGainSound.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleXpGainSound.kt new file mode 100644 index 0000000..a9f739d --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleXpGainSound.kt @@ -0,0 +1,24 @@ +package com.willfp.ecoskills.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.ecoskills.skills.display.isXPGainSoundEnabled +import com.willfp.ecoskills.skills.display.toggleXPGainSound +import org.bukkit.entity.Player + +class CommandToggleXpGainSound(plugin: EcoPlugin) : Subcommand( + plugin, "togglexpgainsound", "ecoskills.command.togglexpgainsound", true +) { + + override fun onExecute(player: Player, args: List) { + when (player.isXPGainSoundEnabled) { + true -> { + player.sendMessage(plugin.langYml.getMessage("disabled-xp-gain-sound")) + } + + false -> player.sendMessage(plugin.langYml.getMessage("enabled-xp-gain-sound")) + } + + player.toggleXPGainSound() + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt index e5c50ce..5b506ca 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/display/GainXPDisplay.kt @@ -1,8 +1,12 @@ package com.willfp.ecoskills.skills.display import com.willfp.eco.core.EcoPlugin +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.sound.PlayableSound import com.willfp.eco.util.formatEco +import com.willfp.eco.util.namespacedKeyOf import com.willfp.eco.util.toNiceString import com.willfp.ecoskills.actionbar.sendCompatibleActionBarMessage import com.willfp.ecoskills.api.event.PlayerSkillXPGainEvent @@ -12,9 +16,23 @@ import com.willfp.ecoskills.api.getSkillProgress import com.willfp.ecoskills.api.getSkillXP import org.bukkit.boss.BarColor import org.bukkit.boss.BarStyle +import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener +private val xpGainSoundEnabledKey = PersistentDataKey( + namespacedKeyOf("ecoskills", "gain_sound_enabled"), + PersistentDataKeyType.BOOLEAN, + true +) + +fun Player.toggleXPGainSound() { + this.profile.write(xpGainSoundEnabledKey, !this.profile.read(xpGainSoundEnabledKey)) +} + +val Player.isXPGainSoundEnabled: Boolean + get() = this.profile.read(xpGainSoundEnabledKey) + class GainXPDisplay( private val plugin: EcoPlugin ) : Listener { @@ -35,7 +53,9 @@ class GainXPDisplay( handleActionBar(event) handleBossBar(event) - sound?.playTo(player) + if (player.isXPGainSoundEnabled) { + sound?.playTo(player) + } } } diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 1ddd2fa..e4d4c9b 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -15,6 +15,8 @@ messages: gave-stat: "Gave %player% %amount% %obj%&r!" enabled-actionbar: "&fYou have &aenabled &fthe action bar!" disabled-actionbar: "&fYou have &cdisabled &fthe action bar!" + enabled-xp-gain-sound: "&fYou have &aenabled &fXP gain sounds!" + disabled-xp-gain-sound: "&fYou have &cdisabled &fXP gain sounds!" actionbar-disabled: "&cThe action bar is disabled on this server." resetting-all-players: "&fResetting all players... (this may take a while)" reset-all-players: "&fReset all players!" diff --git a/eco-core/core-plugin/src/main/resources/paper-plugin.yml b/eco-core/core-plugin/src/main/resources/paper-plugin.yml index 506b2a9..abdd09c 100644 --- a/eco-core/core-plugin/src/main/resources/paper-plugin.yml +++ b/eco-core/core-plugin/src/main/resources/paper-plugin.yml @@ -35,6 +35,7 @@ permissions: ecoskills.command.top: true ecoskills.command.recount: true ecoskills.command.toggleactionbar: true + ecoskills.command.togglexpgainsound: true ecoskills.command.reload: description: Allows reloading the config @@ -60,6 +61,9 @@ permissions: ecoskills.command.toggleactionbar: description: Allows the use of /skills toggleactionbar. default: op + ecoskills.command.togglexpgainsound: + description: Allows the use of /skills togglexpgainsound. + default: op ecoskills.xpmultiplier.50percent: description: Gives the player 50% more skill experience diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 9e8117b..e1aae3e 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -38,6 +38,7 @@ permissions: ecoskills.command.top: true ecoskills.command.recount: true ecoskills.command.toggleactionbar: true + ecoskills.command.togglexpgainsound: true ecoskills.command.reload: description: Allows reloading the config @@ -63,6 +64,9 @@ permissions: ecoskills.command.toggleactionbar: description: Allows the use of /skills toggleactionbar. default: op + ecoskills.command.togglexpgainsound: + description: Allows the use of /skills togglexpgainsound. + default: op ecoskills.xpmultiplier.50percent: description: Gives the player 50% more skill experience