How to reload plugin (.jar)?

Discussion in 'Plugin Development' started by Staartvin, Apr 10, 2012.

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

    Staartvin

    Hello everyone (once again),

    I need to reload (.jar) my plugin with the command /fjh reload.
    This is what I have right now:

    Code:
                    else if (strings[0].equalsIgnoreCase("reload")) {
                            if(player.hasPermission("fjh.admin")) {
                                getConfig();
                                saveConfig();
                                getServer().getPluginManager().disablePlugin(plugin);
                                getServer().getPluginManager().enablePlugin(plugin);
                                player.sendMessage(ChatColor.AQUA + "[First Join Help] Plugin reloaded!");
                                System.out.print("[FIRST JOIN HELP] " + cs.getName().toUpperCase() + " HAS RELOADED FJH!");
                                  return true;
                            }
                                }

    But, it doesn't work..
    I get this error when i'm trying to perform it:

    Code:
    18:32:38 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'fjh'
    in plugin FirstJoinHelp v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    73)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
     
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
            at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManag
    er.java:397)
            at me.staartvin.FirstJoinHelp.FirstJoinHelp.onCommand(FirstJoinHelp.java
    :98)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    >

    Could you guys help me?
     
  2. Did you checked if 'plugin' isn't null?
     
  3. Offline

    Staartvin

    Code:
            public static JavaPlugin plugin;
     
  4. That still doesn't answer my question, did you checked if it's null?
     
  5. Offline

    Staartvin

    How can I check it?
     
  6. Code:
    if(plugin == null)
      System.out.println("Yes, it is.");
     
  7. Offline

    Staartvin

    Yes it is.
    So how should I change that?
     
  8. at some point you need to set a variable to it.
     
  9. Offline

    Staartvin

    Is there a way that I can reload my plugin without 'plugin'? I can't figure how to declare 'plugin' correctly..
     
  10. you'll need a reference to your main class otherwise not.
     
  11. Offline

    Father Of Time

    Ouch... Unable to perform null checks, no understanding of class casting... With all due respect, I think you need to pick yourself up an "introduction to java" book...

    To answer your question:

    Code:
        YouPluginName plugin = Bukkit.getServer().getPluginManager().getPlugin("YourPluginName");
        plugin.Reload();
    I wrote this freehand in notepad, but basically you want to get your plugin from bukkit, then take that plugin and call the Reload function within it, which will force your plug-in to reload (I think, I've never done it).
     
  12. Offline

    Staartvin


    I'm familiar with Java (not at it's greatest) , but not with Bukkit.
    Of course I know what null means and such, but I'm kind of shy towards Bukkit. They have a lot of new stuff I need to learn.

    Thank you for the help anyway, I fixed it myself. :)
    I still have one question closed before this thread can be closed, which is:

    How to make default line in the config like this:

    # This is a comment line

     
  13. Code:
    getConfig().options().header("This is a comment");
    You can only add a header comment, not a comment inside the lines (you could using a pre-done file as a resource but the comments will be lost after reload anyway).
     
  14. Offline

    Staartvin

    Ok, that's dissapointing then... Thanks for the help!
     
  15. Offline

    Father Of Time

    If the code is in he main class I think you can simply do this inside your onCommand function when the command is executed:

    Code:
        this.reload();
    But this will only work within the your plug-ins main class, as it extends the JavaPlugin class.

    Edit: Opps, a little late on this one... A phone call came in at work half way through typing this. Oh well, glad to see you resolved your issue.

    Take care!
     
    Benlewis9000 likes this.
  16. Offline

    Staartvin

    Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page