Plugin doesnt last reload

Discussion in 'Plugin Development' started by XxZHALO13Xx, Aug 29, 2014.

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

    XxZHALO13Xx

    So i made a region plugin... when i reload the server the region goes away.. how do i make it stay through reloads until i do /region delete <NAME> i have the ability to delete but idk what to do about the reload.
     
  2. Offline

    SmooshCakez

    Save the regions to a config file and save/load them on disable/enable, getConfig() seems promising.
     
  3. Offline

    XxZHALO13Xx

    XxZHALO13Xx could u give me a example. im new to doing config files
     
  4. Offline

    nateracecar5

    If you store the region as a variable, when the plugin is reset the variable get's reset, since the plugin instance is no more. Do what the above says and you'll be fine.

    This comment was for explanatory purposes only.
     
  5. Offline

    XxZHALO13Xx

    SmooshCakez and how to save then delete them when needed.. tahnks

    nateracecar5

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  6. Offline

    Gamecube762

    XxZHALO13Xx
    This seems promising.

    I also suggest no to /reload, not many plugins like being reloaded and many memory leaks can occur.
     
  7. Offline

    nateracecar5

    XxZHALO13Xx What I do is I create a config.yml file in my jar, then I put in my onEnable()
    Code:java
    1. getConfig().options.copyDefaults(true);


    So if you had in your config:
    Code:java
    1. autoUpdate: true
    2. useRedstoneAsItems: false
    3. makeMobsSpinUncontrolably: true


    It would copy all of that in the config. Now don't worry, it doesn't reset the config everytime the plugin is reloaded. Now, if you want to get one of those booleans, in your code somewhere you can do:
    Code:java
    1. boolean myBool = getConfig().getBoolean("useRedstoneAsItems");

    That will get the boolean above, and set myBool to false, since useRedstoneAsItems in set to false.

    You can do that with strings, and ints too. For instance:
    Code:java
    1. String myStr = getConfig().getString("myString");
    2. int myInt = getConfig().getInt("myInt");


    You can also use those in if statements, but you can figure that out ;)

    If you want to set a variable, you can do the same above in a similar manner my doing:
    Code:java
    1. getConfig().set(true, "myBool");
    2. getConfig().set(52, "myInt");
    3. getConfig().set("Hello World!", "myStr");


    Also, make sure to ALWAYS do
    Code:java
    1. saveConfig();

    after EVERY config change. The method name is self explanatory.

    There are probably better ways of doing this, but this is how I do it with my plugins. :)

    There are also ways of creating custom config names, but I haven't learned that yet. Try googling it :D
     
Thread Status:
Not open for further replies.

Share This Page