Load location from config to HashMap

Discussion in 'Plugin Development' started by AppleMen, Nov 24, 2015.

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

    AppleMen

    Hello,

    I made a plugin that saves a location of a block to a HashMap. This works fine.
    When the plugin disables, it saves the location to a config.yml file.

    However, when the plugin enables it should put the location from the config to my HashMap.

    Here is some code to make my situation clear:
    HashMap + onDisable():
    Code:
    public HashMap<Integer, Location> CHEST = new HashMap<>();
    
    @Override
        public void onDisable() {
           
            getConfig().set("Chestlocation", CHEST.get(0));
            saveConfig();
    
        }
    
    Config.yml
    Code:
    Chestlocation:
      ==: org.bukkit.Location
      world: world
      x: -645.0
      y: 6.0
      z: 673.0
      pitch: 0.0
      yaw: 0.0
    
    How can I load and put the location from the config.yml to my HashMap?
     
  2. Offline

    mcdorli

    1.: follow the naming conventions

    Save the key somewhere around the location like this:

    Code:
    chest:
        chestlocation:
           <locations>
        key: 0
       
    
    then get it from there and save it with the location
     
  3. Offline

    AppleMen

    Save it like so?
    Code:
    getConfig().set("Chest.Chestlocation", VOTE_CHEST.get(0));
    And how do I load it exactly? When I load the string, it has to be a location

    Could you give me an example on how to do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 24, 2015
  4. Offline

    mcdorli

    Code:
    chest:
        location:
            x: 124
            y : 73
            z: -5
           yaw: 37.5
           pitch: 41.2
           roll: 89.6
        key: 1
    
    save the locations info in the x, y, z etc. spaces, with getConfig().set("chest.location.x", chest.getLocation().getX), etc, then save the key to the key slot, then just get all the veriables and create a new location with them

    I won't spoonfeed.
     
  5. Offline

    AppleMen

    I got it, thank you!
     
  6. Offline

    EvilWitchdoctor

    Just a note, locations in minecraft do not have roll, just yaw and pitch. This is because player's heads cannot tilt to the side (although I believe this may be possible with armorstands and certain other entities). Save yourself a config line there :)
     
  7. Offline

    AppleMen

    Good note It stays 0 for now. Removed it from the lines
     
  8. Offline

    mcdorli

    I was certain, that this is the case, but I didn't know, if notch implemented itfor later or not. And yes, armor stand's head can be rotated on the Z axis.
     
Thread Status:
Not open for further replies.

Share This Page