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


    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:
    - 1:
    - 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.
    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


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


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


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


    Yes, that will be for saving the locations. For getting them, I would recommend using the following within your event.
    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("");
    Location furnaceLocation = new Location(x, y, z, world);
    if(e.getClickedBlock().getLocation() == furnaceLocation) {
      //DO STUFF
  6. Offline


    @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


    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


  11. Offline


    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


    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!
    Furnace f = (Furnace) e.getBlock();
                    if(f.getInventory().getName() == ChatColor.AQUA + "Electric Furnace"){
                        //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