diff --git a/src/main/java/net/pingex/discordbot/CommandDispatcher.java b/src/main/java/net/pingex/discordbot/CommandDispatcher.java index 5fe120e..6ca2563 100644 --- a/src/main/java/net/pingex/discordbot/CommandDispatcher.java +++ b/src/main/java/net/pingex/discordbot/CommandDispatcher.java @@ -9,7 +9,8 @@ import sx.blah.discord.util.MissingPermissionsException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.*; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -32,12 +33,12 @@ class CommandDispatcher /** * Contains all available commands, built using `rebuildCommandList()` */ - private HashMap commandList; + private Map commandList; /** * Contains all the shorthanded commands */ - private HashMap shortList; + private Map shortList; /** * Thread pool used to invoke commands @@ -147,9 +148,13 @@ class CommandDispatcher { String ans = (String) commandList.get(finalFullCommand).invoke(finalParsedArray); if(ans != null) event.getMessage().getChannel().sendMessage("```\n" + ans + "\n```"); - } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) + } catch (IllegalArgumentException | IllegalAccessException e) { logger.severe("Couldn't call target method (" + e.getClass().getName() + "): " + e.getMessage()); + } catch (InvocationTargetException e) + { + logger.severe("An error occurred inside the target command: " + e.getCause().getMessage()); + e.getCause().printStackTrace(); } catch (MissingPermissionsException | HTTP429Exception | DiscordException e) { logger.warning("Couldn't reply to command (" + e.getClass().getName() + "): " + e.getMessage()); @@ -183,8 +188,8 @@ class CommandDispatcher logger.info("Rebuilding command list..."); ArrayList registry = ModulesRegistry.getRegistry(); - commandList = new HashMap<>(); - shortList = new HashMap<>(); + commandList = new TreeMap<>(); + shortList = new TreeMap<>(); for(AbstractModule i : registry) if(i.getClass().isAnnotationPresent(Controllable.class)) @@ -237,22 +242,20 @@ class CommandDispatcher } /** - * Gets the command list (cloned to avoid modifications) - * @return The current cloned command list + * Gets the command list + * @return The current command list */ - @SuppressWarnings("unchecked") - public HashMap getCommandList() + public Map getCommandList() { - return (HashMap) commandList.clone(); + return commandList; } /** - * Gets the shorthands list (cloned to avoid edits) - * @return The current cloned short list + * Gets the shorthands list + * @return The current short list */ - @SuppressWarnings("unchecked") - public HashMap getShortList() + public Map getShortList() { - return (HashMap) shortList.clone(); + return shortList; } }