Disable Plugin After Exception

Discussion in 'Plugin Development' started by Beatsleigher, Apr 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Beatsleigher

    Hey guys,

    I was wondering how I can disable a plugin after an exception in onEnable() has occurred.

    This would be handy, as the plugin would spam the console with error messages (java.lang.NullPointerException) and other HashMap exceptions.

    Any help with this matter is much appreciated. :)
    Thanks in advance.
     
  2. Offline

    JasonDL13

    use a try/catch statment and in the catch get the plugin manager and disable the plugin
     
  3. Offline

    Beatsleigher

    Yes, I was going to use a Try-Catch. I wasn 't sure how to disable the plugin. Thanks :)

    Edit: Yes, I did get what you were saying, and found out how to get the PluginManager :p
     
  4. Offline

    Bammerbom

    Beatsleigher
    Bukkit.getPluginManager().disablePlugin(this);
     
  5. Offline

    Beatsleigher

    Thanks, I figured that out after he wrote the answer :)
     
  6. Offline

    amhokies

    Just a note for people reading this, you don't always pass in the 'this' keyword. The method takes an instance of your JavaPlugin extended class, so using 'this' will only work if you call the method from within your main class.
     
  7. Offline

    Beatsleigher

    I solved it this way, because I was using threads:
    Code:java
    1. PluginName name = this;
    2. PluginManager manager = Bukkit.getPluginManager();
    3.  
    4. /*In a thread*/
    5. manager.disablePlugin(name);
     
Thread Status:
Not open for further replies.

Share This Page