From db46e7c0369b6f053ace06f76b8748c49a62e6ac Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Sun, 25 Jan 2015 23:09:25 -0600 Subject: [PATCH] Fix the error when either of the command handlers are null, fixes #40 These errors only happen when the plugin didn't load successfully, you'll need to check further up in the console/server log to see what actually caused this error. --- src/main/java/com/graywolf336/jail/JailMain.java | 16 +++++++++++----- .../java/com/graywolf336/jail/enums/Lang.java | 2 ++ src/main/resources/en.yml | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/JailMain.java b/src/main/java/com/graywolf336/jail/JailMain.java index ecd33de..ee688d5 100644 --- a/src/main/java/com/graywolf336/jail/JailMain.java +++ b/src/main/java/com/graywolf336/jail/JailMain.java @@ -11,6 +11,7 @@ import com.graywolf336.jail.beans.Jail; import com.graywolf336.jail.beans.Prisoner; import com.graywolf336.jail.command.CommandHandler; import com.graywolf336.jail.command.JailHandler; +import com.graywolf336.jail.enums.Lang; import com.graywolf336.jail.enums.Settings; import com.graywolf336.jail.legacy.LegacyManager; import com.graywolf336.jail.listeners.BlockListener; @@ -171,11 +172,16 @@ public class JailMain extends JavaPlugin { * Send the command off to the CommandHandler class, that way this main class doesn't get clogged up. */ public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) { - jh.parseCommand(jm, sender, args); - }else { - cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args); - } + if(jh == null || cmdHand == null) { + sender.sendMessage(Lang.PLUGINNOTLOADED.get()); + getServer().getConsoleSender().sendMessage(Lang.PLUGINNOTLOADED.get()); + }else { + if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) { + jh.parseCommand(jm, sender, args); + }else { + cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args); + } + } return true;//Always return true here, that way we can handle the help and command usage ourself. } diff --git a/src/main/java/com/graywolf336/jail/enums/Lang.java b/src/main/java/com/graywolf336/jail/enums/Lang.java index 1ff0e98..c8d9983 100644 --- a/src/main/java/com/graywolf336/jail/enums/Lang.java +++ b/src/main/java/com/graywolf336/jail/enums/Lang.java @@ -163,6 +163,8 @@ public enum Lang { PLAYERNOTONLINE("general"), /** The message sent to the sender when the plugin data has been reloaded. */ PLUGINRELOADED("general"), + /** The message sent to the sender of a command when the plugin didn't start correct. */ + PLUGINNOTLOADED("general"), /** The message sent whenever the prisoners are cleared from jail(s). */ PRISONERSCLEARED("general"), /** The format we should use when entering a record into flatfile or showing it. */ diff --git a/src/main/resources/en.yml b/src/main/resources/en.yml index 979ada6..4dd951d 100644 --- a/src/main/resources/en.yml +++ b/src/main/resources/en.yml @@ -32,6 +32,7 @@ language: numberformatincorrect: '&cNumber format is incorrect.' playercontextrequired: '&cA player context is required for this.' playernotonline: '&cThat player is not online!' + pluginnotloaded: '&cThe plugin did not load correctly, tell the administrator to check the console for errors.' pluginreloaded: '&9Jail data successfully reloaded.' prisonerscleared: '&cAll the prisoners from %0% have been cleared.' recordentry: '&7[%0%]: &9%1% &fjailed by &9%2% &ffor &9%3% &fminutes with a reason of &9%4%&f. [%5%]'