From 60038e08d7138182aabd40d54433c3a262ac9c2b Mon Sep 17 00:00:00 2001 From: Indyuce Date: Wed, 25 Aug 2021 16:21:00 +0200 Subject: [PATCH] fixed command verbose --- .../mmocore/command/CommandVerbose.java | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java b/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java index 7316c96d..82c454d3 100644 --- a/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java +++ b/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java @@ -1,53 +1,67 @@ package net.Indyuce.mmocore.command; -import io.lumine.mythic.lib.api.util.EnumUtils; import net.Indyuce.mmocore.MMOCore; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; public class CommandVerbose { - private final Map values = new HashMap<>(); + private final Map values = new HashMap<>(); - public void reload(ConfigurationSection config) { - values.clear(); + public void reload(ConfigurationSection config) { + values.clear(); - for(CommandType type : CommandType.values()) - values.put(type, EnumUtils.getIfPresent(VerboseValue.class, config.getString(type.name().toLowerCase(), "true")).orElse(VerboseValue.TRUE)); - } + for (CommandType type : CommandType.values()) + try { + values.put(type, VerboseValue.valueOf(config.getString(type.name().toLowerCase(), "TRUE").toUpperCase())); + } catch (IllegalArgumentException exception) { + values.put(type, VerboseValue.TRUE); + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load command verbose action for " + type.name()); + } + } - public enum CommandType { - ATTRIBUTE, CLASS, EXPERIENCE, LEVEL, - NOCD, POINTS, RESET, RESOURCE - } + public void handle(CommandSender sender, CommandType type, String verbose) { + switch (values.getOrDefault(type, VerboseValue.FALSE)) { + case FALSE: + return; + case TRUE: + sender.sendMessage(verbose); + break; + case PLAYER: + if (sender instanceof Player) + sender.sendMessage(verbose); + break; + case CONSOLE: + if (sender instanceof ConsoleCommandSender) + sender.sendMessage(verbose); + break; + } + } - enum VerboseValue { - TRUE, PLAYER, - CONSOLE, FALSE - } + public static void verbose(CommandSender sender, CommandType cmd, String verbose) { + MMOCore.plugin.configManager.commandVerbose.handle(sender, cmd, verbose); + } - public void handle(CommandSender sender, CommandType cmd, String verbose) { - switch(values.getOrDefault(cmd, VerboseValue.FALSE)) { - case FALSE: - return; - case TRUE: - //sender.sendMessage(verbose); - break; - case PLAYER: - if(sender instanceof Player) - //sender.sendMessage(verbose); - break; - case CONSOLE: - if(!(sender instanceof Player)) - //sender.sendMessage(verbose); - break; - } - } + public enum CommandType { + ATTRIBUTE, + CLASS, + EXPERIENCE, + LEVEL, + NOCD, + POINTS, + RESET, + RESOURCE + } - public static void verbose(CommandSender sender, CommandType cmd, String verbose) { - MMOCore.plugin.configManager.commandVerbose.handle(sender, cmd, verbose); - } + private enum VerboseValue { + TRUE, + PLAYER, + CONSOLE, + FALSE + } }