Reload vs. Stop

Discussion in 'Plugin Development' started by aidan matzko, May 24, 2011.

Thread Status:
Not open for further replies.
  1. Hello,
    I was wondering if there is any way to tell when the plugin is disabling weither it is a reload or a full server stop. Im guessing there might be something in onDisable,or would you have to make a player listener just to find out?

    Thanks,
    Tips48
     
  2. Offline

    Shamebot

    Maybe onServerCommand ?
     
  3. Offline

    DreadKyller

    maybe, because when you enter the command won't it go through other listeners too to see if it should actually stop or reload? so you could pick it up there.
     
  4. Hmmmm.
    onServerCommand would only work for things entered server side tho, right?
     
  5. Offline

    ToastedJelly

    I didn't test, but there are strong indications that on reload the Plugins don't get recreated. So on onDisable set a boolean and if in onEnable this boolean is set, you know you just had a reload instead of a new start.
     
  6. Offline

    Shamebot

    I don't think so, when my server is running and I drop a new version of a plugin into the plugins folder and reload, the changes are applied
     
  7. Offline

    ToastedJelly

    You're right, but I've seen plugins behave differently on reloads than on restarts, so maybe this is only done when there's really a new jar available...
    well.. guess I can't get around actually testing this and checking some code...
     
  8. Offline

    DreadKyller

    @ToastedJelly : I just tested that theory by reloading 5 times, each time the plugin restarted completely and refreshed, no difference
     
  9. Offline

    ToastedJelly

    Thanks. There still needs to be some kind of difference. BigBrother has a bug atm. that it stops working after a reload, but works after a complete restart. Could also depend on the reload method. I used to use /reloadall - i think that was essentials and the messages looked different from what reload looks like now on McMyAdmin
     
  10. Offline

    DreadKyller

    maybe the onLoad only activates while server is loading, and may not activate again until the server is completely restarted. therefore on enable you can check to see if the plugin was completely reloaded (if the onLoad happens) for example:

    PHP:
    public class main extends JavaPlugin{
        private 
    boolean reloaded true;
        public 
    void onLoad(){
            
    reloaded=false;//not reload, restart
        
    }
        public 
    void onEnable(){
            if(!
    reloaded){//if was restarted or just loaded up
                
    System.out.println("Plugin Loaded")
            }
        }
        public 
    void onDisable(){
        }
    }
     
  11. Offline

    Afforess

    Once onDisable is called your plugin is done. I've watched the Server with a specialized debugging software (JUnit, if interested, costs $), and each /reload creates a new instance of each plugin. Even static plugin classes are re-created. The old instances are not garbage collected, but are never sent any information from then on (Events are not passed, etc)
     
  12. Offline

    DreadKyller

    that will not work then, I didn't know so I just tried to give a suggestion.
     
  13. Offline

    Afforess

    The solution is pretty easy. A dummy file. Create a dummy file with 1 thing inside: the system time in milliseconds. Save it. When your plugin loads, check for the file, parse the time, and compare. If they are within 2 seconds (or so...), it was a /reload command. Can all be achieved with the Java File, PrintWriter, and Scanner classes, all really basic stuff.
     
  14. Offline

    matejdro

    It's not really good solution. Some servers may use very little plugins and have restart script, so server will restart very fast. Other servers may have some plugins with long onEnable delay, so it will take more than 2 seconds to reload everything.
     
  15. Offline

    valdark

    I was having this issue with McMyAdmin as well. I found that waiting 20-30 seconds and reloading a second time got things up and running just like the server had restarted. Your just out 20-30 seconds on your plugins.
     
  16. Offline

    DreadKyller

    @valdark : still not work for my friends purpose, he has so many plugins, we actually timed it to see how long it took to reload, which ended up being 2 minuted 16 seconds...
     
  17. Offline

    valdark

    @DreadKyller
    Yikes... I can see the issue there..... I hope you find a solution. This problem has bugged me for quite a while now. It seems to be McMyAdmin specific from what I gather by discussing with some of the plugin devs.
     
  18. Offline

    Afforess

    The time delay is relative, I was just throwing out a solution. You could make it 10, even 20 min. There are no other solutions though.
     
  19. Offline

    FrozenBrain

    There is a solution. As I just updated my MessageChanger plugin I figured out how to check if the server is getting stopped:
    Code:
    public void onDisable() {
    	StackTraceElement[] st = new Throwable().getStackTrace();
    	for(int i=0;i<st.length;i++) {
    		if(st[i].getMethodName().equals("stop")) {
    			// Server stops, do some stuff here
    			return;
    		}
    	}
    }
    The code above just gets a stack trace and checks whether craftbukkit "stop" method got called or not. I don't know how reliable this is, but I guess it should work most of the time.
     
  20. Offline

    ToastedJelly

    I can't think of any use for knowing if the server stops or just restarts besides some kind of log. A plugin gets termineted no matter what, so why would it make sense to react differently to these two events?
     
  21. Offline

    DreadKyller

    @ToastedJelly : well, people are getting annoyed when a plugin is reloaded it prints the
    Code:
    Pluginname Disabled
    Pluginname Enabled
    also a lot of disable methods on the server is annoying, so this could be used to send certain messages when reloading, like onDisable "Pluginname is reloading" instead of disabled and then enabled and disabled when the server actually stops and such
     
  22. Offline

    FrozenBrain

    Because I want to kick all players with a custom message when the server stops.
     
  23. Offline

    ToastedJelly

    commandbook:

    /kickAndStop $ = /kick * $ \ /stop

    Not very convincing. I don't see the console anyway. It's even dangerous to have different code paths on reloads and restarts.
    Most likey I do a reload, because something changed - either a setting for a plugin or I have new plugins that either may collide with each other in a way or need to work together etc.

    In any case, I want a reproducible "reload" that's the same for a restart that may follow later. I don't want the reload to work only to find out later that it broke on the restart, because a plugin did something else than it does on reloads.

    I mean CommandHelper or course...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  24. Offline

    DreadKyller

    extremely good point... if a plugin does something else on reload then restart then trying to update by reloading will not work with plugin...
     
Thread Status:
Not open for further replies.

Share This Page