diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 868d391..690b2e2 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -75,6 +75,8 @@ public class TBMCChatAPI { continue; TBMCCommandBase c = cmd.newInstance(); c.plugin = plugin; + if (!CheckForNulls(plugin, c)) + continue; commands.put(c.GetCommandPath(), c); } catch (InstantiationException e) { TBMCCoreAPI.SendException("An error occured while registering command " + cmd.getName(), e); @@ -110,6 +112,8 @@ public class TBMCChatAPI { else c = thecmdclass.newInstance(); c.plugin = plugin; + if (!CheckForNulls(plugin, c)) + return; commands.put(c.GetCommandPath(), c); } catch (Exception e) { TBMCCoreAPI.SendException("An error occured while registering command " + thecmdclass.getSimpleName(), e); @@ -133,6 +137,8 @@ public class TBMCChatAPI { * The command to add */ public static void AddCommand(JavaPlugin plugin, TBMCCommandBase cmd) { + if (!CheckForNulls(plugin, cmd)) + return; plugin.getLogger().info("Registering command /" + cmd.GetCommandPath() + " for " + plugin.getName()); try { cmd.plugin = plugin; @@ -141,4 +147,17 @@ public class TBMCChatAPI { TBMCCoreAPI.SendException("An error occured while registering command " + cmd.GetCommandPath(), e); } } + + private static boolean CheckForNulls(JavaPlugin plugin, TBMCCommandBase cmd) { + if (cmd == null) { + TBMCCoreAPI.SendException("An error occured while registering a command for plugin " + plugin.getName(), + new Exception("The command is null!")); + return false; + } else if (cmd.GetCommandPath() == null) { + TBMCCoreAPI.SendException("An error occured while registering command " + cmd.getClass().getSimpleName() + + " for plugin " + plugin.getName(), new Exception("The command path is null!")); + return false; + } + return true; + } } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java index 9ca7c99..33d7773 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCCommandBase.java @@ -3,6 +3,13 @@ package buttondevteam.lib.chat; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; +/** + * Extend this class to create new TBMCCommand and use {@link TBMCChatAPI#AddCommand(org.bukkit.plugin.java.JavaPlugin, TBMCCommandBase)} to add it. Note: The command path (command name + * and subcommand arguments) will be the class name by default, removing any "command" from it. To change it (especially for subcommands), override {@link #GetCommandPath()}. + * + * @author Norbi + * + */ public abstract class TBMCCommandBase { public TBMCCommandBase() {