mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2025-12-31 12:56:31 +00:00
Merge pull request #29
Added /skills togglesound command for per=player toggling sound of skill xp gain
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<String>) {
|
||||
|
||||
@@ -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<String>) {
|
||||
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"))
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user