fixed command verbose

This commit is contained in:
Indyuce 2021-08-25 16:21:00 +02:00
parent 00ca007ecc
commit 60038e08d7

View File

@ -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<CommandType, VerboseValue> values = new HashMap<>();
private final Map<CommandType, VerboseValue> 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
}
}