Solved HashMap Not Storing Locations

Discussion in 'Plugin Development' started by jthort, May 11, 2014.

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

    jthort

    I'm creating a cobblestone square 10x10, then when the player moves their head, it removes the previous square and places the new one where that player is looking. So it will create a square block following where they are looking.

    The problem is it's not restoring the previous square, I have the following hashmap and method
    Code:java
    1. HashMap<Material, Location> trailLocations = new HashMap<Material, Location>();


    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void startTrail(String planType, Player player){
    3.  
    4. restorePreviousTrail();
    5.  
    6. Location centerLocation = player.getTargetBlock(null, 30).getLocation();
    7. int tierMultiplyer = 2*(mainClass.getConfig().getInt(savedTownName + ".Buildings." + planType + ".Level"));
    8. Location startDrawLocation = new Location(centerLocation.getWorld(),
    9. centerLocation.getX()-tierMultiplyer,
    10. centerLocation.getY(),
    11. centerLocation.getZ()-tierMultiplyer
    12. );
    13. Location stopDrawLocation = new Location(centerLocation.getWorld(),
    14. centerLocation.getX()+tierMultiplyer,
    15. centerLocation.getY(),
    16. centerLocation.getZ()+tierMultiplyer
    17. );
    18. for(double x = startDrawLocation.getX(); x <= stopDrawLocation.getX(); x++){
    19. for(double z = startDrawLocation.getZ(); z <= stopDrawLocation.getZ(); z++){
    20. Location l = new Location(centerLocation.getWorld(),
    21. x,
    22. centerLocation.getY(),
    23. z
    24. );
    25. trailLocations.put(l.getBlock().getType(), l);
    26. l.getBlock().setType(Material.COBBLESTONE);
    27. }
    28. }
    29. }


    That generates the new square and restores the previous one by calling this method

    Code:java
    1. private void restorePreviousTrail(){
    2. System.out.println(trailLocations.size());
    3. for (Map.Entry<Material, Location> entry : trailLocations.entrySet()) {
    4. Location location = entry.getValue();
    5. Material material = entry.getKey();
    6. location.getBlock().setType(Material.DIAMOND_BLOCK);
    7. }
    8. trailLocations.clear();
    9. }


    Solved this cleared up my problem https://forums.bukkit.org/threads/tutorial-block-restoration.228896/
     
Thread Status:
Not open for further replies.

Share This Page