|
| 1 | +package fr.maxlego08.essentials.commands.commands.deathmessage; |
| 2 | + |
| 3 | +import fr.maxlego08.essentials.api.EssentialsPlugin; |
| 4 | +import fr.maxlego08.essentials.api.commands.CommandResultType; |
| 5 | +import fr.maxlego08.essentials.api.commands.Permission; |
| 6 | +import fr.maxlego08.essentials.api.messages.Message; |
| 7 | +import fr.maxlego08.essentials.api.user.Option; |
| 8 | +import fr.maxlego08.essentials.api.user.User; |
| 9 | +import fr.maxlego08.essentials.module.modules.DeathMessageModule; |
| 10 | +import fr.maxlego08.essentials.zutils.utils.commands.VCommand; |
| 11 | +import org.bukkit.command.CommandSender; |
| 12 | +import org.bukkit.entity.Player; |
| 13 | + |
| 14 | +public class CommandDeathMessageToggle extends VCommand { |
| 15 | + |
| 16 | + public CommandDeathMessageToggle(EssentialsPlugin plugin) { |
| 17 | + super(plugin); |
| 18 | + this.setModule(DeathMessageModule.class); |
| 19 | + this.setPermission(Permission.ESSENTIALS_DEATH_MESSAGE_TOGGLE); |
| 20 | + this.setDescription(Message.DESCRIPTION_DEATH_MESSAGE_TOGGLE); |
| 21 | + this.addOptionalArg("player"); |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + protected CommandResultType perform(EssentialsPlugin plugin) { |
| 26 | + |
| 27 | + Player player = this.argAsPlayer(0, this.player); |
| 28 | + |
| 29 | + if (player == null) { |
| 30 | + return CommandResultType.SYNTAX_ERROR; |
| 31 | + } |
| 32 | + |
| 33 | + if (player.equals(this.player) || !hasPermission(sender, Permission.ESSENTIALS_DEATH_MESSAGE_TOGGLE_OTHER)) { |
| 34 | + toggleDeathMessage(player, this.user, sender); |
| 35 | + } else { |
| 36 | + User otherUser = getUser(player); |
| 37 | + if (otherUser == null) return CommandResultType.SYNTAX_ERROR; |
| 38 | + toggleDeathMessage(player, otherUser, sender); |
| 39 | + } |
| 40 | + |
| 41 | + return CommandResultType.SUCCESS; |
| 42 | + } |
| 43 | + |
| 44 | + private void toggleDeathMessage(Player player, User user, CommandSender sender) { |
| 45 | + user.setOption(Option.DEATH_MESSAGE_DISABLE, !user.getOption(Option.DEATH_MESSAGE_DISABLE)); |
| 46 | + boolean isDeathMessageDisable = user.getOption(Option.DEATH_MESSAGE_DISABLE); |
| 47 | + |
| 48 | + Message messageKey = isDeathMessageDisable ? Message.COMMAND_DEATH_MESSAGE_TOGGLE_DISABLE : Message.COMMAND_DEATH_MESSAGE_TOGGLE_ENABLE; |
| 49 | + message(sender, messageKey, "%player%", user == this.user ? Message.YOU.getMessageAsString() : player.getName()); |
| 50 | + } |
| 51 | +} |
0 commit comments