Add handy way to tell you what config options you're missing, and check it through LD command
This commit is contained in:
		| @@ -462,20 +462,83 @@ public class DisguiseConfig { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         int missingConfigs = 0; |         boolean verbose = config.getBoolean("VerboseConfig"); | ||||||
|  |         boolean changed = config.getBoolean("ChangedConfig"); | ||||||
|  |  | ||||||
|         for (String key : config.getDefaultSection().getKeys(true)) { |         if (!verbose) { | ||||||
|             if (config.contains(key, true)) { |             int missingConfigs = 0; | ||||||
|  |  | ||||||
|  |             for (String key : config.getDefaultSection().getKeys(true)) { | ||||||
|  |                 if (config.contains(key, true)) { | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 missingConfigs++; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (missingConfigs > 0) { | ||||||
|  |                 DisguiseUtilities.getLogger().warning("Your config is missing " + missingConfigs + | ||||||
|  |                         " options! Please consider regenerating your config!"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (verbose || changed) { | ||||||
|  |             ArrayList<String> returns = doOutput(config, changed, verbose); | ||||||
|  |  | ||||||
|  |             if (!returns.isEmpty()) { | ||||||
|  |                 DisguiseUtilities.getLogger() | ||||||
|  |                         .info("This is not an error! Now outputting " + (verbose ? "missing " : "") + | ||||||
|  |                                 (changed ? (verbose ? "and " : "") + "changed/invalid " : "") + "config values"); | ||||||
|  |  | ||||||
|  |                 for (String v : returns) { | ||||||
|  |                     DisguiseUtilities.getLogger().info(v); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static ArrayList<String> doOutput(ConfigurationSection config, boolean informChangedUnknown, | ||||||
|  |             boolean informMissing) { | ||||||
|  |         HashMap<String, Object> configs = new HashMap<>(); | ||||||
|  |         ConfigurationSection defaultSection = config.getDefaultSection(); | ||||||
|  |         ArrayList<String> returns = new ArrayList<>(); | ||||||
|  |  | ||||||
|  |         for (String key : defaultSection.getKeys(true)) { | ||||||
|  |             if (defaultSection.isConfigurationSection(key)) { | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             missingConfigs++; |             configs.put(key, defaultSection.get(key)); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (missingConfigs > 0) { |         for (String key : config.getKeys(true)) { | ||||||
|             DisguiseUtilities.getLogger().warning( |             if (config.isConfigurationSection(key)) { | ||||||
|                     "Your config is missing " + missingConfigs + " options! Please consider regenerating your config!"); |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!configs.containsKey(key)) { | ||||||
|  |                 if (informChangedUnknown) { | ||||||
|  |                     returns.add("Unknown config option '" + key + ": " + config.get(key) + "'"); | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             if (!configs.get(key).equals(config.get(key))) { | ||||||
|  |                 if (informChangedUnknown) { | ||||||
|  |                     returns.add("Modified config: '" + key + ": " + config.get(key) + "'"); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             configs.remove(key); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (informMissing) { | ||||||
|  |             for (Entry<String, Object> entry : configs.entrySet()) { | ||||||
|  |                 returns.add("Missing '" + entry.getKey() + ": " + entry.getValue() + "'"); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return returns; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static void loadCustomDisguises() { |     static void loadCustomDisguises() { | ||||||
|   | |||||||
| @@ -252,6 +252,23 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | |||||||
|                 if (mcArray.size() > 1) { |                 if (mcArray.size() > 1) { | ||||||
|                     sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, ldItem); |                     sendMessage(sender, LibsMsg.ITEM_SERIALIZED_MC, LibsMsg.ITEM_SERIALIZED_MC_NO_COPY, ldItem); | ||||||
|                 } |                 } | ||||||
|  |             } else if (args[0].equalsIgnoreCase("config")) { | ||||||
|  |                 if (!sender.hasPermission("libsdisguises.config")) { | ||||||
|  |                     sender.sendMessage(LibsMsg.NO_PERM.get()); | ||||||
|  |                     return true; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 ArrayList<String> returns = DisguiseConfig | ||||||
|  |                         .doOutput(LibsDisguises.getInstance().getConfig(), true, true); | ||||||
|  |  | ||||||
|  |                 if (returns.isEmpty()) { | ||||||
|  |                     sender.sendMessage(LibsMsg.USING_DEFAULT_CONFIG.get()); | ||||||
|  |                     return true; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 for (String s : returns) { | ||||||
|  |                     sender.sendMessage(ChatColor.AQUA + "[LibsDisguises] " + s); | ||||||
|  |                 } | ||||||
|             } else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) { |             } else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) { | ||||||
|                 if (!sender.hasPermission("libsdisguises.metainfo")) { |                 if (!sender.hasPermission("libsdisguises.metainfo")) { | ||||||
|                     sender.sendMessage(LibsMsg.NO_PERM.get()); |                     sender.sendMessage(LibsMsg.NO_PERM.get()); | ||||||
| @@ -351,7 +368,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { | |||||||
|         String[] args = getArgs(origArgs); |         String[] args = getArgs(origArgs); | ||||||
|  |  | ||||||
|         if (args.length == 0) |         if (args.length == 0) | ||||||
|             tabs.addAll(Arrays.asList("reload", "scoreboard", "permtest", "json", "metainfo")); |             tabs.addAll(Arrays.asList("reload", "scoreboard", "permtest", "json", "metainfo", "config")); | ||||||
|  |  | ||||||
|         return filterTabs(tabs, origArgs); |         return filterTabs(tabs, origArgs); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -2,8 +2,10 @@ package me.libraryaddict.disguise.utilities.packets; | |||||||
|  |  | ||||||
| import com.comphenix.protocol.PacketType; | import com.comphenix.protocol.PacketType; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
|  | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||||
|  | import me.libraryaddict.disguise.utilities.LibsPremium; | ||||||
| import me.libraryaddict.disguise.utilities.packets.packethandlers.*; | import me.libraryaddict.disguise.utilities.packets.packethandlers.*; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| @@ -34,7 +36,12 @@ public class PacketsHandler { | |||||||
|         packetHandlers.add(new PacketHandlerEquipment(this)); |         packetHandlers.add(new PacketHandlerEquipment(this)); | ||||||
|  |  | ||||||
|         packetHandlers.add(new PacketHandlerHeadRotation()); |         packetHandlers.add(new PacketHandlerHeadRotation()); | ||||||
|         packetHandlers.add(new PacketHandlerMetadata(this)); |  | ||||||
|  |         // If not prem, if build is from jenkins, else its a custom and needs paid info | ||||||
|  |         if (!LibsPremium.isPremium() || LibsDisguises.getInstance().getBuildNo().matches("[0-9]+") || LibsPremium.getPaidInformation() != null) { | ||||||
|  |             packetHandlers.add(new PacketHandlerMetadata(this)); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         packetHandlers.add(new PacketHandlerMovement()); |         packetHandlers.add(new PacketHandlerMovement()); | ||||||
|         packetHandlers.add(new PacketHandlerSpawn(this)); |         packetHandlers.add(new PacketHandlerSpawn(this)); | ||||||
|         packetHandlers.add(new PacketHandlerVelocity()); |         packetHandlers.add(new PacketHandlerVelocity()); | ||||||
|   | |||||||
| @@ -265,11 +265,14 @@ public enum LibsMsg { | |||||||
|     LIBS_SCOREBOARD_NO_TEAM(ChatColor.RED + "Not on a scoreboard team!"), |     LIBS_SCOREBOARD_NO_TEAM(ChatColor.RED + "Not on a scoreboard team!"), | ||||||
|     LIBS_SCOREBOARD_NO_TEAM_PUSH(ChatColor.RED + "On scoreboard team '%s' and pushing is enabled!"), |     LIBS_SCOREBOARD_NO_TEAM_PUSH(ChatColor.RED + "On scoreboard team '%s' and pushing is enabled!"), | ||||||
|     LIBS_SCOREBOARD_SUCCESS(ChatColor.GOLD + |     LIBS_SCOREBOARD_SUCCESS(ChatColor.GOLD + | ||||||
|             "On scoreboard team '%s' with pushing disabled! If you're still having issues and you are disguised right now, then " + |             "On scoreboard team '%s' with pushing disabled! If you're still having issues and you are disguised right" + | ||||||
|             "you have a plugin modifying scoreboard through packets. Example of this is a plugin that modifies your name above head, or the tablist. Check their configs for pushing disabling options"), |             " now, then " + | ||||||
|  |             "you have a plugin modifying scoreboard through packets. Example of this is a plugin that modifies your " + | ||||||
|  |             "name above head, or the tablist. Check their configs for pushing disabling options"), | ||||||
|     LIBS_SCOREBOARD_DISABLED( |     LIBS_SCOREBOARD_DISABLED( | ||||||
|             "The scoreboard modification has been disabled in config, will continue the debug incase this is intended" + |             "The scoreboard modification has been disabled in config, will continue the debug incase this is intended" + | ||||||
|                     "."); |                     "."), | ||||||
|  |     USING_DEFAULT_CONFIG(ChatColor.DARK_GREEN + "Using the default config!"); | ||||||
|  |  | ||||||
|     private String string; |     private String string; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,6 +28,12 @@ Permissions: | |||||||
|   # NOT_OP = Only non operators can see this |   # NOT_OP = Only non operators can see this | ||||||
|   SeeCommands: TRUE |   SeeCommands: TRUE | ||||||
|  |  | ||||||
|  | # You can also get this information through /libsdisguises config | ||||||
|  | # Should the plugin output missing config options instead of just counting them | ||||||
|  | VerboseConfig: false | ||||||
|  | # Should the plugin output changed config options? Will also list unknown extra options | ||||||
|  | ChangedConfig: false | ||||||
|  |  | ||||||
| # Disables commands with the exception of /libsdisguises. Useful if you don't want the plugin to be used by anything | # Disables commands with the exception of /libsdisguises. Useful if you don't want the plugin to be used by anything | ||||||
| #  but a plugin | #  but a plugin | ||||||
| # Useful if you didn't purchase the plugin. | # Useful if you didn't purchase the plugin. | ||||||
|   | |||||||
| @@ -109,6 +109,8 @@ permissions: | |||||||
|       default: true |       default: true | ||||||
|     libsdisguises.scoreboardtest: |     libsdisguises.scoreboardtest: | ||||||
|       description: Test if the scoreboard is valid, this is a simple test. |       description: Test if the scoreboard is valid, this is a simple test. | ||||||
|  |     libsdisguises.config: | ||||||
|  |       description: Allows player to check Lib's Disguises config for values | ||||||
|     libsdisguises.noactionbar: |     libsdisguises.noactionbar: | ||||||
|       description: Hides the action bar even if enabled in config |       description: Hides the action bar even if enabled in config | ||||||
|       default: false |       default: false | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user