Multiple Chest Locations

Discussion in 'Plugin Development' started by Doubtstand, Sep 13, 2015.

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

    Doubtstand

    So I'm making a plugin that gives you a chest, and when you place it the location is saved to the config. With my current code the location gets overriden by the last placed chest. Is there anyway to save multiple locations and retrieve them later? I'm using the BlockPlaceEvent.

    Is it also possible that it only saves the location if the chest placed is the same as this one:

    Code:java
    1.  
    2. ItemStack lootchest = new ItemBuilder(Material.CHEST)
    3. .name(ChatColor.RED + "Loot Chest")
    4. .lore(ChatColor.GRAY + "Place to create a loot chest")
    5. .build();
    6.  


    How I tried to save locations:
    Code:java
    1.  
    2. @EventHandler
    3. public void onBlockPlace(BlockPlaceEvent e){
    4.  
    5. Player player = e.getPlayer();
    6. ItemStack hand = player.getItemInHand();
    7. Block placed = e.getBlock();
    8.  
    9. if(hand.isSimilar(lootchest)){
    10. int x = placed.getX();
    11. int y = placed.getY();
    12. int z = placed.getZ();
    13.  
    14. FileConfiguration config = plugin.getConfig();
    15.  
    16. config.set("lootchest.World" , placed.getWorld().getName());
    17. config.set("lootchest.X" , x);
    18. config.set("lootchest.Y" , y);
    19. config.set("lootchest.Z" , z);
    20.  
    21. player.sendMessage("Lootchest placed.");
    22. }
    23. }
    24.  


    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Sep 13, 2015
  2. First question: Check for existing configuration sections, and have them be named numerically. If, say, numbers 1-10 exist, add the next chest location to be under number 11. If numbers 1-4 and 6-10 exist, add number five instead.


    Second question: Press the edit button instead of double posting

    Just check during a BlockPlaceEvent
    a. make sure the event isn't cancelled (in case of, say, spawn protection)
    b. check if the item in the player's hand is the same as the lootchest
     
    Last edited: Sep 13, 2015
  3. Report it and we can fix it fast.
     
Thread Status:
Not open for further replies.

Share This Page