Handling reloads

Discussion in 'Plugin Development' started by TerroDoor, Apr 4, 2020.

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

    TerroDoor

    so I noticed array lists don’t save on reloads/restarts.

    What’s the best way of saving these lists And retrieving?

    If I save the list to a config and get it back on the onEnable, does my list automatically add the players from the config list back into the array?


    Sent from my iPhone using Tapatalk
     
  2. Offline

    timtower Administrator Administrator Moderator

    @TerroDoor Bukkit does nothing automatically.
    If you want to have those players in the list again then you need to put them there.
     
  3. Offline

    TerroDoor

    I see, google searches haven’t helped me much for what I’m exactly trying to understand.

    So if the onDisable loops all players inside of array and saves it, should it be deleted after it reloads to free up memory?

    And secondly with adding the array back to each player will I need to get each player uuid from the list and assign it back accordingly? If so, would a for each loop work?


    Sent from my iPhone using Tapatalk
     
  4. Offline

    timtower Administrator Administrator Moderator

    If it is static: YES
    If not static: No needed, class gets unloaded, list gets cleared.
    A for each loop will do fine.
     
  5. Offline

    TerroDoor

    Thanks @timtower, with the static and non static modifiers, I’m unsure how this would be used in the config list, if I put all the players in the list into the config and save it, then how will it be deleted after I’ve grabbed the list back in the onEnable?

    sorry if this sounds confusing, my theory is there will always (most likely) be a player that contains this list as it’s a spawn protection list, so stacking up multiple uuids is not what I want, after the players get grabbed from the list after reload, how do I clear it for the next onDisable?


    Sent from my iPhone using Tapatalk
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    TerroDoor

    Public void onDisable() {

    For (Player pl : Bukit.getOnlinePlayers()) {

    If (util.myarray.contains(pl.UUID){

    This.getConfig.set(“templist”, pl.UUID);

    }
    }

    Sorry for the rough copy I’m not with my laptop, is this the right way to go?


    Sent from my iPhone using Tapatalk
     
  8. Offline

    timtower Administrator Administrator Moderator

    @TerroDoor What kind of data structure do you have?
    Because I have no idea what those things are.
     
  9. Offline

    TerroDoor

    Sorry for the mess, I ended up finding a YouTube video showing me exactly what I was looking for. Although since this is a array holding all protected players, I need to also save the cube location (spawn cube).. when I reload my server I stay in my array but as soon as I move it doesn’t detect my cube and instantly removes me due to my Boolean check method. Is there a way of saving a list of blocks being my cube and get it back on reload?


    Sent from my iPhone using Tapatalk
     
  10. Offline

    timtower Administrator Administrator Moderator

    @TerroDoor Same method as you are doing for the players.
     
  11. Offline

    TerroDoor

    But it’s a Location and I put it into a location array but I am stuck with setting/getting the location object into a config

    It’s a Cuboid location too I’m im more confused

    Sent from my iPhone using Tapatalk
     
  12. Offline

    timtower Administrator Administrator Moderator

    @TerroDoor Post your variable declarations please.
     
  13. Offline

    TerroDoor

    @timtower

    Code:
    
    public ArrayList<String> cubelist = new ArrayList<String>();
    
    //util class list
    
    
    Code:
    
    public class Cube {
    public Main pl;
    public Cube(Main ins) {
    pl = ins;
    }
    
    World world;
    double minx;
    double maxx;
    double miny;
    double maxy;
    double minz;
    double maxz;
    
     public void setCube(Location loc, int size) {
     world = loc.getWorld();
     this.minx = loc.getBlockX() - 5;
     this.maxx = loc.getBlockX() + 5;
     this.miny = loc.getBlockY() - 1;
     this.maxy = loc.getBlockY() + 5;
     this.minz = loc.getBlockZ() - 5;
     this.maxz = loc.getBlockZ() + 5;
    
     for (double x = minx; x <= maxx; x++) {
     for (double y = miny; y <= maxy; y++) {
     for (double z = minz; z <= maxz; z++) {
    
     Location area = new Location(world, x, y, z);
     
     String blockcoords = "world " + world.getName() + ".x " + x + ".y " + y + ".z " + z;
     
     if (y == miny) {
     area.getBlock().setType(Material.GLASS);
     
     }
     
     pl.util.cubelist.add(blockcoords);
     pl.getConfig().set("cubeloc.coords", blockcoords);
     pl.saveConfig();
     }
     }
     }
     return;
     }
    return;
    }
    
    Main class:

    Code:
    public void onEnable() {
    util.registerCommands();
    util.registerListeners();
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();
    
    for (String arealoc : this.getConfig().getStringList("cubeloc.coords")) {
    
    util.cubelist.add(arealoc);
    
    }
    @timtower ive realised something in my cube class todo with my varibles. the Boolean check doesn't know where the min and maxs are after a reload, im guessing.
    so how would I reconstruct this if im going on the right path

    Code:
    public boolean isInSpawn(Player p) {
    Location loc = p.getLocation();
    
    if (loc.getBlockX() >= minx && loc.getBlockX() <= maxx &&
    loc.getBlockY() >= miny && loc.getBlockY() <= maxy &&
    loc.getBlockZ() >= minz && loc.getBlockZ() <= maxz) {
    return true;
    }
    
    //MY CLASS VARIABLES
    World world;
    double minx;
    double maxx;
    double miny;
    double maxy;
    double minz;
    double maxz;
    
    
    So, where do I grab the min/max from?
     
    Last edited: Apr 5, 2020
  14. Offline

    timtower Administrator Administrator Moderator

    @TerroDoor You store the size as well and use setCube
     
  15. Offline

    TerroDoor

    @timtower sorry I don't understand

    Bump
    I know after I reload my server it doesn’t remember where my cuboid location is, and it’s because the min and max are unknown how do I fix this


    Sent from my iPhone using Tapatalk

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 5, 2020
Thread Status:
Not open for further replies.

Share This Page