How to make your plugin reload

Discussion in 'Plugin Development' started by mattibijnens, Jan 26, 2014.

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

    mattibijnens

    Hi guys, I was trying some things out on how to make a command to reload my plugin, but I can't figure it out, Please help :D
     
  2. Offline

    sgavster

    Well you could reload your config..
    reloadConfig();
     
  3. Offline

    mattibijnens

    Yeah but It is not for the config, I am just trying a lot of thins with the plugin so I need to restart my server a lot but I don't want to restart the whole server every time =)
     
  4. Offline

    ItsLeoFTW

    Say you have a main command, let's call it "myplugin". You can use THIS code to set up arguments, and make the argument by the name of "reload" reload the configuration.
    Code:java
    1. if (alias.equalsIgnoreCase("myplugin")){
    2. if (args.length == 0){ //no arguments
    3. sender.sendMessage(ChatColor.BLUE + "No arguments supplied!");
    4. } else {
    5. if (args[0].equalsIgnoreCase("reload")){
    6. reloadConfig();
    7. sender.sendMessage(ChatColor.BLUE + "Config reloaded!");
    8. }

    Make sure to register the command in plugin.yml and your main class!
    What to put in your main class:
    Code:java
    1. getCommand("myplugin").setExecutor(new MyPluginCmd());
    2.  

    Also, make sure to put the onCommand boolean before you do the actual alias & arguments code.

    EDIT: Wait... OH. Assuming you are using NetBeans, paste this code into the "build.xml" file:
    Code:
    <target name="-post-jar">
            <copy file="${dist.jar}" todir="PLUGINS FOLDER PATH HERE" failonerror="true"/>
        </target>
     
  5. Offline

    ItsLeandro

    Why would you need to reload a plugin? It would only make sense when having a Config.
     
  6. Offline

    FunnyGopher

    ItsLeandro Not necessarily. When I'm developing plugins, when I export a plugin to my server's plugin folder, I have to reload the server to see the changes.

    mattibijnens What I had to do was make a separate plugin for this purpose only. I then gave this plugin the functionality to enable and disable any plugin I pass the command. If you disable the plugin from within the plugin itself, the plugin won't be able to enable itself because the plugin is disabled. This is just from my own experiences.

    The only other way I see it is if you create an async task to enable the plugin after a short delay, but async tasks recommend you don't use Bukkit functions inside of them.
     
  7. Offline

    ItsLeandro

    FunnyGopher
    You would need to reload the server anyways when trying out your changes. You can't just replace & reload it with a commnd.
     
    stuntguy3000 likes this.
  8. Offline

    FunnyGopher

    ItsLeandro With the plugin I made for my server, it's possible. I just type /reload <PluginName> and it disables and re-enables the plugin, without touching any of the other plugins. This is handy to have, because if people are on the server using another plugin, and all of a sudden the server reloads, the plugin those people were using would reload as well. Those people could possibly lose items or whatnot. With it, you are able to reload specific plugins.
     
  9. Offline

    ItsLeandro

    FunnyGopher
    Good luck than,
    But I still think it won't be possible :oops:
     
  10. Offline

    EnderPilot105

    You can just do Bukkit.reload()
     
  11. Offline

    FunnyGopher

    ItsLeandro Lol, dude, it's possible. I have it working on my server. :) I just recently edited it to be able to control it through button presses too! So now players can enable and disable plugins they want to try out by just pressing a button next to the corresponding plugin sign! I think it's awesome.

    EnderPilot105 You can do Bukkit.reload(), but it doesn't do what he wants. He wants to reload a specific plugin. Bukkit.reload() reloads the whole server. I didn't even know there was a Bukkit.reload() though. I guess it makes sense. :)
     
  12. Offline

    ItsLeandro

  13. Offline

    EnderPilot105

    You can despatch command /reload 'plugin'

    Something like bukkit. Get server. Dispatchcommand(' 'reload theplugin'' ) :
    FunnyGopher
     
Thread Status:
Not open for further replies.

Share This Page