From 497f2e6f6b5058a907144dd08565235eefb337d0 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Tue, 1 Dec 2020 01:58:40 +0100 Subject: [PATCH] Verbose management in config.yml You can now disable some of the command results from appearing in console, etc. --- .../java/net/Indyuce/mmocore/MMOCore.java | 7 +++ .../mmocore/command/CommandVerbose.java | 53 +++++++++++++++++++ .../rpg/admin/AttributeCommandTreeNode.java | 5 +- .../rpg/admin/ClassCommandTreeNode.java | 5 +- .../rpg/admin/ExperienceCommandTreeNode.java | 9 ++-- .../rpg/admin/ForceClassCommandTreeNode.java | 5 +- .../rpg/admin/LevelCommandTreeNode.java | 9 ++-- .../rpg/admin/NoCooldownCommandTreeNode.java | 4 +- .../rpg/admin/PointsCommandTreeNode.java | 5 +- .../rpg/admin/ResetCommandTreeNode.java | 16 ++++-- .../rpg/admin/ResourceCommandTreeNode.java | 4 +- .../mmocore/manager/ConfigManager.java | 12 ++--- src/main/resources/config.yml | 30 +++++++++++ 13 files changed, 135 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 92210761..da360c8c 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -166,6 +166,13 @@ public class MMOCore extends JavaPlugin { new Metrics(this); saveDefaultConfig(); + final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1; + final int defConfigVersion = getConfig().getDefaults().getInt("config-version"); + if(configVersion != defConfigVersion) { + getLogger().warning("You may be using an outdated config.yml!"); + getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')"); + } + if (getConfig().isConfigurationSection("mysql") && getConfig().getBoolean("mysql.enabled")) dataProvider = new MySQLDataProvider(getConfig()); diff --git a/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java b/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java new file mode 100644 index 00000000..32244e5f --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/command/CommandVerbose.java @@ -0,0 +1,53 @@ +package net.Indyuce.mmocore.command; + +import net.Indyuce.mmocore.MMOCore; +import net.mmogroup.mmolib.api.util.EnumUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +public class CommandVerbose { + private final Map values = new HashMap<>(); + + 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)); + } + + public enum CommandType { + ATTRIBUTE, CLASS, EXPERIENCE, LEVEL, + NOCD, POINTS, RESET, RESOURCE + } + + enum VerboseValue { + TRUE, PLAYER, + CONSOLE, FALSE + } + + public void handle(CommandSender sender, CommandType cmd, String verbose) { + switch(values.getOrDefault(cmd, VerboseValue.TRUE)) { + 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 static void verbose(CommandSender sender, CommandType cmd, String verbose) { + MMOCore.plugin.configManager.commandVerbose.handle(sender, cmd, verbose); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java index fcbbd477..17f558dc 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/AttributeCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -62,8 +63,8 @@ public class AttributeCommandTreeNode extends CommandTreeNode { AttributeInstance instance = PlayerData.get(player).getAttributes().getInstance(attribute); instance.setBase(Math.min(attribute.getMax(), instance.getBase() + c * amount)); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + instance.getBase() - + ChatColor.YELLOW + " " + attribute.getName() + "."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.ATTRIBUTE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW + + " now has " + ChatColor.GOLD + instance.getBase() + ChatColor.YELLOW + " " + attribute.getName() + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ClassCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ClassCommandTreeNode.java index 44866502..ff6499fc 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ClassCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ClassCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Sound; @@ -59,8 +60,8 @@ public class ClassCommandTreeNode extends CommandTreeNode { data.getPlayer().playSound(data.getPlayer().getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1); } - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD - + profess.getName() + ChatColor.YELLOW + "."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.CLASS, ChatColor.GOLD + player.getName() + + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java index 3e5eaf7f..eb2a7eaf 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandTreeNode.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.command.rpg.admin; import java.util.function.BiConsumer; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -62,8 +63,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); if (args[4].equalsIgnoreCase("main")) { main.accept(data, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + data.getExperience() - + ChatColor.YELLOW + " EXP."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + + ChatColor.YELLOW + " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP."); return CommandResult.SUCCESS; } @@ -75,8 +76,8 @@ public class ExperienceCommandTreeNode extends CommandTreeNode { Profession profession = MMOCore.plugin.professionManager.get(format); this.profession.accept(data.getCollectionSkills(), profession, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD - + data.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " EXP in " + profession.getName() + "."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + + ChatColor.GOLD + data.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " EXP in " + profession.getName() + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ForceClassCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ForceClassCommandTreeNode.java index 4535f0f6..afd2d6b0 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ForceClassCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ForceClassCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -41,8 +42,8 @@ public class ForceClassCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); data.setClass(profess); - sender.sendMessage( - ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + "."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.CLASS, ChatColor.GOLD + player.getName() + + ChatColor.YELLOW + " is now a " + ChatColor.GOLD + profess.getName() + ChatColor.YELLOW + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java index 9bf890c3..342a811e 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandTreeNode.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.command.rpg.admin; import java.util.function.BiConsumer; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -63,8 +64,9 @@ public class LevelCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); if (args[4].equalsIgnoreCase("main")) { main.accept(data, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + data.getLevel() - + ChatColor.YELLOW + "."); + + CommandVerbose.verbose(sender, CommandVerbose.CommandType.LEVEL, ChatColor.GOLD + player.getName() + + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + data.getLevel() + ChatColor.YELLOW + "."); return CommandResult.SUCCESS; } @@ -76,7 +78,8 @@ public class LevelCommandTreeNode extends CommandTreeNode { Profession profession = MMOCore.plugin.professionManager.get(format); this.profession.accept(data.getCollectionSkills(), profession, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + CommandVerbose.verbose(sender, CommandVerbose.CommandType.LEVEL, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + data.getCollectionSkills().getLevel(profession) + ChatColor.YELLOW + " in " + profession.getName() + "."); return CommandResult.SUCCESS; } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java index f2505743..65b39e3d 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/NoCooldownCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -29,7 +30,8 @@ public class NoCooldownCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); data.nocd = !data.nocd; - sender.sendMessage(ChatColor.YELLOW + "NoCD " + (data.nocd ? "enabled" : "disabled") + " for " + player.getName() + "."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.NOCD, + ChatColor.YELLOW + "NoCD " + (data.nocd ? "enabled" : "disabled") + " for " + player.getName() + "."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java index 45dc2822..c2f15535 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/PointsCommandTreeNode.java @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.command.rpg.admin; import java.util.function.BiConsumer; import java.util.function.Function; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -60,8 +61,8 @@ public class PointsCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); action.accept(data, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data) - + ChatColor.YELLOW + " " + type + " points."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.POINTS, ChatColor.GOLD + player.getName() + + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data) + ChatColor.YELLOW + " " + type + " points."); return CommandResult.SUCCESS; } } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java index 9a8f2054..7697b383 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResetCommandTreeNode.java @@ -1,5 +1,6 @@ package net.Indyuce.mmocore.command.rpg.admin; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -66,7 +67,8 @@ public class ResetCommandTreeNode extends CommandTreeNode { data.unbindSkill(0); data.getQuestData().resetFinishedQuests(); data.getQuestData().start(null); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s data was succesfully reset."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s data was succesfully reset."); return CommandResult.SUCCESS; } } @@ -142,7 +144,8 @@ public class ResetCommandTreeNode extends CommandTreeNode { data.mapSkillLevels().forEach((skill, level) -> data.resetSkillLevel(skill)); while (data.hasSkillBound(0)) data.unbindSkill(0); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s skill data was succesfully reset."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s skill data was succesfully reset."); return CommandResult.SUCCESS; } } @@ -180,12 +183,14 @@ public class ResetCommandTreeNode extends CommandTreeNode { } data.giveAttributePoints(points); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attribute points spendings were successfully reset."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attribute points spendings were successfully reset."); return CommandResult.SUCCESS; } data.getAttributes().getInstances().forEach(ins -> ins.setBase(0)); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attributes were succesfully reset."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s attributes were succesfully reset."); return CommandResult.SUCCESS; } } @@ -215,7 +220,8 @@ public class ResetCommandTreeNode extends CommandTreeNode { data.getCollectionSkills().setExperience(profession, 0); data.getCollectionSkills().setLevel(profession, 0); } - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s levels were succesfully reset."); + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESET, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + "'s levels were succesfully reset."); return CommandResult.SUCCESS; } diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourceCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourceCommandTreeNode.java index 1795a069..547c1da1 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourceCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ResourceCommandTreeNode.java @@ -3,6 +3,7 @@ package net.Indyuce.mmocore.command.rpg.admin; import java.util.function.BiConsumer; import java.util.function.Function; +import net.Indyuce.mmocore.command.CommandVerbose; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -61,7 +62,8 @@ public class ResourceCommandTreeNode extends CommandTreeNode { PlayerData data = PlayerData.get(player); action.accept(data, amount); - sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data) + CommandVerbose.verbose(sender, CommandVerbose.CommandType.RESOURCE, + ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + get.apply(data) + ChatColor.YELLOW + " " + type + " points."); return CommandResult.SUCCESS; } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 77ab7feb..5f93d6f7 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.util.input.AnvilGUI; import net.Indyuce.mmocore.api.util.input.ChatInput; import net.Indyuce.mmocore.api.util.input.PlayerInput; import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType; +import net.Indyuce.mmocore.command.CommandVerbose; import net.mmogroup.mmolib.MMOLib; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; @@ -21,8 +22,8 @@ import java.text.DecimalFormatSymbols; import java.util.List; import java.util.logging.Level; -@SuppressWarnings("ALL") public class ConfigManager { + public final CommandVerbose commandVerbose = new CommandVerbose(); public boolean overrideVanillaExp, hotbarSwap; public double expPartyBuff, regenPartyBuff; @@ -33,8 +34,8 @@ public class ConfigManager { public final DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(); public final DecimalFormat decimal = new DecimalFormat("0.#", formatSymbols), decimals = new DecimalFormat("0.##", formatSymbols); - private FileConfiguration messages; - private boolean chatInput; + private final FileConfiguration messages; + private final boolean chatInput; /* * the instance must be created after the other managers since all it does @@ -42,7 +43,6 @@ public class ConfigManager { * already loaded based on the config */ public ConfigManager() { - // loadDefaultFile("recipes", "brewing.yml"); // loadDefaultFile("recipes", "furnace.yml"); @@ -91,10 +91,8 @@ public class ConfigManager { loadDefaultFile("commands.yml"); loadDefaultFile("guilds.yml"); - loadOptions(); - } + commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose")); - public void loadOptions() { messages = new ConfigFile("messages").getConfig(); hotbarSwap = MMOCore.plugin.getConfig().getBoolean("hotbar-swap"); chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d7c3a323..b4aed9a0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,15 @@ +# +# ███ ███ ███ ███ ██████ ██████ ██████ ██████ ███████ +# ████ ████ ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ +# ██ ████ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██████ █████ +# ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +# ██ ██ ██ ██ ██████ ██████ ██████ ██ ██ ███████ +# +# a Spigot Plugin by Team Requiem + +# DO NOT TOUCH +config-version: 2 + # Auto-Save feature automatically saves playerdata # (class, level, etc.) and guild data # (guild names, members, etc.) at a set interval. @@ -151,3 +163,21 @@ resource-bar-colors: stamina-whole: 'GREEN' stamina-half: 'DARK_GREEN' stamina-empty: 'WHITE' + +# Whether or not the admin commands should display +# the result of the command when ran. +# For Example: "Players Level is now 10." +# Accepted Values: +# true - Always verbose +# player - Only verbose when ran from a player +# console - Only verbose when ran from console +# false - Never verbose +command-verbose: + attribute: true + class: true + experience: true + level: true + nocd: true + points: true + reset: true + resource: true \ No newline at end of file