[Help!] BlockBreakEvent in PlayerMoveEvent

Discussion in 'Plugin Development' started by HariHD, Feb 10, 2014.

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

    HariHD

    Hey!

    I need help with something I have been stuck for a while but just got back on it trying to fix and I need a little help. I have found the easiest way thanks to @mattrick to restore blocks in an arena.
    But ...

    Code:java
    1. public List<BlockState> blocklist = new ArrayList<BlockState>();
    2.  
    3. @EventHandler
    4. public void onPlayerMove1(PlayerMoveEvent e) {
    5. final Block block = e.getTo().getBlock().getLocation().add(new Vector(0,-2,0)).getBlock();
    6.  
    7. if(changeblock == true) {
    8. if(block.getType().equals(Material.TNT)) {
    9. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    10. public void run() {
    11. blocklist.add(block.getState());//NEED HELP HERE!
    12. block.setType(Material.AIR);
    13. }
    14. },10L);
    15. }
    16. }
    17. }


    then to restore it

    Code:java
    1. for (BlockState block: blocklist) {
    2. block.update(true);
    3. }
    4. blocklist.clear();


    But for some reason it doesn't work. I have tested it and it only works if I break the block and not when its set to AIR. Does anyone know why? Help

    Thanks for your time,
    HariHD

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    HariHD

    Bump

    Anyone? Come on its been a day now and noone has helped :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  3. Quick glance: Have you tried adding Block instances to the list and calling block.getState().update() instead of storing BlockState instances?

    The problem is that BlockState could change and won't be valid if the block changes and maybe it does invalidate on other occasions as well.

    Please use a paste-format/service that displays the indentation level, e.g. bukkitdev paste, [and/or use a code formatting with your java- IDE/tool :)], you are more likely to get fast answers if it is easily readible.
     
Thread Status:
Not open for further replies.

Share This Page