Solved Getting all Y coordinates from every file

Discussion in 'Plugin Development' started by plisov, Mar 28, 2017.

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

    plisov

    I have been working on a skyblock plugin and have been doing fairly well thus far. However one of the biggest issues I have right now is that the islands sometimes spawn very close to each other. I set the island schematic at a random X and Z coordinate. I then save the XYZ coordinates in a personal player data.yml. What I want to do is create a for loop that will loop through all the data.yml files, get the X and Z coordinate thus checking if the new island that is about to be created is at least 400 blocks away from all the other X and Z coordinates. if it is, the island is placed, if not it will continue to try to find a spot until it eventually does find a spot.
    If anyone has an easier way of doing this, I'd love to hear it.
     
  2. Offline

    jobisingh

    What i would recommend is creating a list of x and y coordinates and save that to the config and just have it loop through that
     
  3. Offline

    N00BHUN73R

    @plisov
    I don't think there is really is going to be a super easy way to do this.
    I mean, if you think about it, it's not tooo hard.

    First you loop through the player configs, grab the first one.
    Then you read the file and grab the XYZ
    Then you compare it to the current XYZ you're trying to set
    If it's close, move it away, and continue to make sure there's no other islands near by.

    EDIT: You also could load all the islands on startup into a map or arraylist and that might be easier
     
  4. Offline

    plisov

    There are multiple issues with this. The loop will never stop running. If I were to do it the way you describe it, it will take the first config, get the X and Z coordinates, if they are near the ones being created it will change the ones being created and do that until it finds a number that is greater by 400 integers than the other X and Z coordinates. Wooh! Done with that config. Then it'll move on to the next player's X and Z coordinates does the same thing. But wait... those numbers are 400 integers away from the X and Z coordinates from the config it's checking right now but are not 400 integers away from the first config it checked anymore. It's going to be an ongoing cycle and will never find 2 numbers for X and Z that will satisfy the 100+ config X and Z numbers there will be. See the problem?
     
  5. Offline

    mehboss

    @plisov
    This is also a very bad idea because if there are tons of islands, loading 100+ islands every time can be hefty.

    If you have your other islands, those should also be 400 blocks away from each other.

    So basically, this is what your island pattern should be if they are spaced away 400 each time.
    [​IMG]
    Thus, your config should look something like:
    Code:
    Islands:
      island1:
        X: 400
        Z: 400
      island2:
        X: 800
        Z: 800
      island3:
        X: 1200
        Z: 1200
    
    etc...
    Just grab the most recently created island and do some math (get X & Z, add 400 to both) and create your island at the new location.
     
  6. Offline

    plisov

    I really like the idea you set forth. However I am not saving my X and Z coordinates quite like this this. Each player has their own separate file. Looks like Skyblock > users > 'playersname' > data.yml. Any idea on how I could get the latest island with how I'm doing it?
     
  7. Offline

    mehboss

    Well, every time the player makes an island (since they are seperate files), just add their most recent island location to one array that will be shared among the other players.

    E.X:
    Code:
    
    ArrayList islands = array;
    
    *** Player Creates an Island ***
    
    // Remove their previous location from the array if this is not their first island.
    
    // Get the array size if it is not empty and get the value by stating the size.
    
    #
    # The value of the size will return the last island location that was added to the array.
    #
    
    // Add 400 to the X and Z value and create the island.
    
    // Add the location of the island that was created to the array.
    
    
     
    Last edited: Mar 28, 2017
  8. Offline

    plisov

    I'm a bit new to arrays. Could I save the last X and Z coordinates in a config.yml instead and change those numbers by adding 400 to each every time an island is created? If arrays are easier please explain them. The arrays won't save will they? For example, if you reload the server or stop it and start it back up, the array will be cleared as well, right?
     
  9. Offline

    mehboss

    Don't mind the last post I made. Even though each player has their own .yml, you use it for their islands, not recent islands. You don't need to get any values from their .ymls for doing what you want. So, when a player makes an island just save the location somewhere (.yml or a config). The place you saved it will then only have one location, which would be the island location of the most recent island created on this server, regardless of the player. Yes, arrays wipe when the server restarts, you don't even need an array if you have one location though. If you still want to use one, just save the locations in the array to a .yml...


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page