Save A list of locations to the config?

Discussion in 'Plugin Development' started by VortexGmer, May 22, 2015.

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

    VortexGmer

    How do I do this?
    Basically what I'm doing is saving the location of a block placed if it is an electric furnace by checking the display name and whatnot.
    How do I save the location to a config file so it ends up like this:
    EFurnaces:
    - 1:
    x:
    y:
    z:
    world:
    - 2:
    so on and so forth
    And get the locations everytime on player interact event on a furnace to check if it is the right location and open a different inventory.
    basically:
    Code:
    public void onInteract(PlayerInteractEvent e){
        if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
            if(e.getBlock.getType() == Material.FURNACE){
                /*Get the location and see if it is one of the
                Locations in the config file and if it is do stuff*/
            }
        }
    }
     
  2. Offline

    FisheyLP

    Much simpler: use metadatas.
    Set the metadata:
    Code:
    block.setMetadata("electricFurnace", new FixedMetadataValue(this, true));
    If it contains the metadata:
    Code:
    block.hasMetadata("electricFurnace)
     
  3. Offline

    Konato_K

    @FisheyLP You need to keep in mind that metadata is lost after a restart
     
  4. Offline

    Zombie_Striker

    To get what you want, you need to use the following code
    Code:
    gerConfig().set("ElectricFurnance.1.x", Location#getX());
    gerConfig().set("ElectricFurnance.1.y", Location#getY());
    gerConfig().set("ElectricFurnance.1.z", Location#getZ());
    this.saveConfig();
    
     
  5. Offline

    ZackBlazes

    Yes, that will be for saving the locations. For getting them, I would recommend using the following within your event.
    Code:
    int x = getConfig().getString("ElectricFurnace.1.x");
    int y = getConfig().getString("ElectricFurnace.1.y");
    int z = getConfig().getString("ElectricFurnace.1.z");
    World world = getConfig().getString("ElectricFurnace.1.world");
    Location furnaceLocation = new Location(x, y, z, world);
    if(e.getClickedBlock().getLocation() == furnaceLocation) {
      //DO STUFF
    }
     
  6. Offline

    FisheyLP

    @Konato_K No it isnt. I tested the metadata on an entity, restarted the server and it was still there
     
  7. Offline

    I Al Istannen

    @FisheyLP ReSTART or ReLOAD? I did a reload, metadata stayed. I did a restart ("/stop", and start again) and metadata gone.
     
  8. Offline

    VortexGmer

    yes, But It will only do that to ElectricFurnace.1
    so when I place more than one How will it DO ElectricFurnace.2?
    And when I destroy?
    MetaData seems like a good option, If only I could save them to the config or somehow keep them through the restart!
     
  9. Offline

    bwfcwalshy Retired Staff

    @VortexGmer You could get the amount of furnaces on enable, assign that to a variable. Then do variable++ when they place it, when setting the location get the variable.
     
  10. Offline

    VortexGmer

  11. Offline

    Corndogoz

    so basicly you have an integer like int i=0 then when a user places the furnace, u do getConfig().set(String.valueOf(i), Location) then do int++ so ur never overwriting it
     
  12. Offline

    VortexGmer

    oh ok!

    Yes but it would be a painfull process, I would need to do something like getting the int of furnaces anf looping through while it isnt 0 and then for each location check if the furnace is there...

    I found another way!
    Code:
    Furnace f = (Furnace) e.getBlock();
                    if(f.getInventory().getName() == ChatColor.AQUA + "Electric Furnace"){
                        e.setCancelled(true);
                        //do stuff!
                    }
    Thing is, I don't know how to open a custom furnace inventory and save stuff when it is closed, I basically only want batteries to power it but it smelts twice as fast and all, I don't know how to cancel the default recipes and make it a custom furnace with only this, I was thinking to make a custom furnace inventory but How do i make it a burning furnace when it starts smelting and do the things in the background and when you open it you can see the process of the smelting

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

Share This Page