Detect if plugin was reloaded in onEnable()?

Discussion in 'Plugin Development' started by uyuyuy99, May 13, 2014.

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

    uyuyuy99

    I'm wondering what the simplest/best way is to tell if the plugin was either reloaded or the server was just started in the onEnable() method. I could probably think up some hackish ways of doing this, but I'm just wondering what the best way is.

    Thanks.
     
  2. Offline

    Mayoz

    Simplest way I can think of is to use PlayerCommandPreprocessEvent and then write to the config and check it when the plugin enables.

    Edit: it's PlayerCommandPreprocessEvent and I'm not sure what the event for all senders is. You could look in the JavaDoc, I'm just too lazy right now to do it myself
     
    uyuyuy99 likes this.
  3. Offline

    RawCode

    do you know about booleans?
     
  4. Offline

    AoH_Ruthless

    RawCode
    How would that help, exactly? I fail to see how you could solve the issue with booleans alone.
     
  5. Offline

    jthort

    If the onenable is called, set it to true. If the disable is called, set it to false.
     
  6. Offline

    AoH_Ruthless

    jthort
    That doesn't solve anything. A reload and a server start both run through onEnable() and onDisable(): that doesn't help distinguish a reload from a restart, unless of course I am missing something obvious here.
     
  7. Offline

    jthort

    You said you wanted to tell if it's either reloaded or started. You didn't say you wanted to specify between the two
     
  8. Offline

    AoH_Ruthless

    jthort
    I guess that was a mistake in my interpretation.
     
  9. Offline

    Garris0n

    It could technically mean that, however it wouldn't make very much sense.
     
  10. Offline

    RawCode

    ok, it will spoonfeed you.

    1) create boolean field and set it to false;
    2) set it to true inside onEnable()
    3) if it already true - server was reloaded
    4) if it already false - server was started

    was so hard?
     
  11. Offline

    uyuyuy99

    I did not ask you to spoonfeed me, and this code does not answer my question. Thank you for your help though.

    The pseudocode you just posted shows how to detect if the plugin was enabled. Of course I know how to do that; as garrison said, it wouldn't make very much sense. I need to be able to tell whether the plugin was reloaded or whether the server was just started.
     
  12. Offline

    Shevchik

    Start a separate thread on enable, make it daemon so it will shut down on JVM disable, and then on next pllugin enable check if the thread is still there - if yes than plugin was reloaded.
     
  13. Offline

    RawCode

    are you kidding? i posted exactly what you asked, care to atleast try to implement code i posted? uyuyuy99
     
  14. RawCode Surely the boolean would be reset when the server is reloaded or restarted, so it would always look like the server was restarted?
     
  15. Offline

    RawCode

    will your HDD reset of you restart windows\linux\mac or something similar?
    AdamQpzm
     
  16. RawCode No, but my HDD isn't held in RAM. Fields generally are.
     
  17. Offline

    RawCode

    AdamQpzm
    And what problem in saving that boolean to HDD?
     
  18. Offline

    jthort

  19. Offline

    rsod

    Code:
    private boolean firstTimeStart = true;
    public void onEnable(){
    if(firstTimeStart){
    // server started
    }else{
    //server reloaded
    }
    firstTimeStart = false;
    }
    
     
  20. RawCode Well for one you said that you said "exactly" how to do it. Not saying that you should tell people exactly how to do things, but you did say that you did :)

    Also, how would you make it so that the boolean is changed only when restarting but not when reloading? Neither restarting nor reloading would handle the file differently.
     
  21. Offline

    RawCode

    I reevaluated difficulty of task and come to conclusion - everage person maynot handle it.

    You may find code sample here:
    https://github.com/RawCode/UBT/blob/master/src/rc/ubt/Loader.java#L128

    Code:
    	System.out.println(System.getProperty("OLD", ""));
        	System.setProperty("OLD", "TRUE");
    
    Main concept is:
    To store data outside of classes loaded by plugin or from plugin, since classloader of plugin will be terminated.

    There are plenty of options available, including storing data on HDD, inside "native" classes (like interned strings) or currentthread, most simple way to use hashmap of system property.

    I not stated that field shoud be created inside plugin, i stated that boolean field shoud be operated inside onEnabled method@AdamQpzm
     
    uyuyuy99, Garris0n and AdamQpzm like this.
Thread Status:
Not open for further replies.

Share This Page