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 2572484..18c2432 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 @@ -1,6 +1,8 @@ package com.willfp.ecoskills import com.willfp.eco.core.data.PlayerProfile +import com.willfp.eco.core.data.keys.PersistentDataKey +import com.willfp.eco.core.data.keys.PersistentDataKeyType import com.willfp.ecoskills.api.PlayerSkillExpGainEvent import com.willfp.ecoskills.api.PlayerSkillLevelUpEvent import com.willfp.ecoskills.api.modifier.ModifierOperation @@ -177,6 +179,18 @@ fun OfflinePlayer.setStatLevel(stat: Stat, level: Int) { } } +fun OfflinePlayer.hasGainSoundEnabled(): Boolean { + return PlayerProfile.load(this).read(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true)) +} + +fun OfflinePlayer.setGainSoundEnabled(enabled: Boolean) { + PlayerProfile.load(this).write(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true), enabled) +} + +fun OfflinePlayer.toggleGainSoundEnabled() { + PlayerProfile.load(this).write(PersistentDataKey(plugin.namespacedKeyFactory.create("gainSound"), PersistentDataKeyType.BOOLEAN, true), !hasGainSoundEnabled()) +} + fun Entity.tryAsPlayer(): Player? { return when (this) { is Projectile -> this.shooter as? Player 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 9577b6e..84de387 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 @@ -18,6 +18,7 @@ class CommandSkills(plugin: EcoPlugin) : this.addSubcommand(CommandTop(plugin)) .addSubcommand(CommandRank(plugin)) .addSubcommand(CommandToggleActionbar(plugin)) + .addSubcommand(CommandToggleSound(plugin)) } override fun onExecute(sender: CommandSender, args: List) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleSound.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleSound.kt new file mode 100644 index 0000000..7bcb3b9 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandToggleSound.kt @@ -0,0 +1,41 @@ +package com.willfp.ecoskills.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.eco.util.PlayerUtils +import com.willfp.eco.util.StringUtils +import com.willfp.ecoskills.data.LeaderboardHandler +import com.willfp.ecoskills.getSkillLevel +import com.willfp.ecoskills.hasGainSoundEnabled +import com.willfp.ecoskills.skills.Skills +import com.willfp.ecoskills.toggleGainSoundEnabled +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + + +class CommandToggleSound(plugin: EcoPlugin) : + Subcommand( + plugin, + "togglesound", + "ecoskills.command.togglesound", + true + ) { + + override fun onExecute(sender: CommandSender, args: List) { + if (this.plugin.configYml.getBool("skills.progress.sound.enabled")) { + sender.sendMessage(this.plugin.langYml.getMessage("xp-gain-sound-disabled")) + return + } + + val player = sender as Player + player.toggleGainSoundEnabled() + + val key = when(player.hasGainSoundEnabled()) { + true -> "enabled" + else -> "disabled" + } + + player.sendMessage(this.plugin.langYml.getMessage("xp-gain-sound-$key")) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt index d67c056..597c6dd 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt @@ -6,6 +6,7 @@ import com.willfp.ecoskills.api.PlayerSkillExpGainEvent import com.willfp.ecoskills.api.PlayerSkillLevelUpEvent import com.willfp.ecoskills.getSkillLevel import com.willfp.ecoskills.getSkillProgress +import com.willfp.ecoskills.hasGainSoundEnabled import net.md_5.bungee.api.ChatMessageType import net.md_5.bungee.api.chat.TextComponent import org.bukkit.Bukkit @@ -81,7 +82,7 @@ class SkillDisplayListener( System.currentTimeMillis() + this.plugin.configYml.getInt("skills.progress.boss-bar.duration") } - if (this.plugin.configYml.getBool("skills.progress.sound.enabled")) { + if (this.plugin.configYml.getBool("skills.progress.sound.enabled") && player.hasGainSoundEnabled()) { val sound = Sound.valueOf(this.plugin.configYml.getString("skills.progress.sound.id").uppercase()) val pitch = this.plugin.configYml.getDouble("skills.progress.sound.pitch") diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 8f02189..a19f557 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -18,7 +18,10 @@ messages: gave-stat: "Gave %player% %amount% %stat%&r!" enabled-actionbar: "&fYou have &aenabled &fthe action bar!" disabled-actionbar: "&fYou have &cdisabled &fthe action bar!" - actionbar-disabled: "&cThe action bar disabled on this server." + actionbar-disabled: "&cThe action bar is disabled on this server." + enabled-xp-gain-sound: "&fYou have &aenabled &fskill XP gain sound!" + disabled-xp-gain-sound: "&fYou have &cdisabled &fskill XP gain sound!" + xp-gain-sound-disabled: "&cSkill XP gain sound is disabled on this server." line-wrap-color: "&8" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 3b912c3..59aa5d3 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -43,6 +43,7 @@ permissions: ecoskills.command.rank: true ecoskills.command.recount: true ecoskills.command.toggleactionbar: true + ecoskills.command.togglesound: true ecoskills.command.reload: description: Allows reloading the config @@ -71,6 +72,9 @@ permissions: ecoskills.command.toggleactionbar: description: Allows the use of /skills toggleactionbar. default: op + ecoskills.command.togglesound: + description: Allows the use of /skills togglesound. + default: op ecoskills.xpmultiplier.50percent: description: Gives the player 50% more skill experience