SendBlockChange issues

Discussion in 'Plugin Development' started by RegalMachine, Jul 13, 2014.

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

    RegalMachine

    Code:java
    1. private Map<Player, ArrayList<Location>> borderBlocks = new HashMap<Player, ArrayList<Location>>();
    2.  
    3. @SuppressWarnings("deprecation")
    4. @EventHandler
    5. public void onDistrictEnter(RegionEnteredEvent e){
    6. Player p = e.getPlayer();
    7. ProtectedRegion region = e.getRegion();
    8. if(DistrictBag.districts.containsKey(UUID.fromString(region.getId()))){
    9. //get the blocks at the top level of the world and at the borders of the region.
    10. World world = p.getWorld();
    11. if(!DistrictBag.getDistrict(region.getId()).getOwner().getPlayer().getUniqueId().toString().equalsIgnoreCase(p.getUniqueId().toString())){
    12. return;
    13. }
    14. if(!borderBlocks.containsKey(p)){
    15. borderBlocks.put(p, new ArrayList<Location>());
    16. }
    17. for(int x = region.getMinimumPoint().getBlockX(); x<= region.getMaximumPoint().getBlockX(); x++){
    18. borderBlocks.get(p).add(world.getHighestBlockAt(new Location(world, x, 0, region.getMinimumPoint().getBlockZ())).getLocation());
    19. borderBlocks.get(p).add(world.getHighestBlockAt(new Location(world, x, 0, region.getMaximumPoint().getBlockZ())).getLocation());
    20. }
    21. for(int z = region.getMinimumPoint().getBlockZ(); z<= region.getMaximumPoint().getBlockZ(); z++){
    22. borderBlocks.get(p).add(world.getHighestBlockAt(new Location(world, region.getMinimumPoint().getBlockX(), 0, z)).getLocation());
    23. borderBlocks.get(p).add(world.getHighestBlockAt(new Location(world, region.getMaximumPoint().getBlockX(), 0, z)).getLocation());
    24. }
    25. for(Location loc: borderBlocks.get(p)){
    26. p.sendBlockChange(new Location(loc.getWorld(), loc.getX(), loc.getY()-1, loc.getZ()), Material.REDSTONE_BLOCK, (byte) 0);
    27. }
    28. }
    29. }
    30.  
    31. public void onDistrictExit(RegionLeftEvent e){
    32. Player p = e.getPlayer();
    33. ProtectedRegion region = e.getRegion();
    34. if(DistrictBag.districts.containsKey(UUID.fromString(region.getId()))){
    35. if(borderBlocks.containsKey(p)){
    36. for(Location loc: borderBlocks.get(p)){
    37. Location locc = new Location(loc.getWorld(),loc.getX(),loc.getY(),loc.getZ());
    38. p.sendBlockChange(locc, Material.GRASS, (byte) 0);
    39. }
    40. borderBlocks.remove(p);
    41. }
    42. }
    43. }


    What I am trying to accomplish here is when a player enters their "claim", it outlines it in redstone block, but only for them. That part works.

    When the player leaves their claim I want the blocks that were changed to go back to the way they were, but I am having trouble reversing the SendBlockChange.

    I have been messing around with this for a few days now, and i'm feeling defeated. Where am I going wrong?
     
  2. Offline

    tommyhoogstra

    Small snippet of mine:
    Code:java
    1. player.sendBlockChange(block.getLocation(), block.getType(), block.getData());

    You surround that with a for loop, looping through the blocks in the region.

    It sets the block back to its original content, hence block.getType() and block.getData()
     
Thread Status:
Not open for further replies.

Share This Page