[Solved] Changing blocktype cancels event

Discussion in 'Plugin Development' started by LucasEmanuel, May 13, 2012.

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

    LucasEmanuel

    Sorry about the heading, didn't know what to write.

    Well my problem is that when i try to change a blocks type inside a BlockPlaceEvent listener it removes the block and gives it back to the player.

    The purpose of changing the blocktype is that i want to remove it without it dropping to the floor.
    So i just use "block.setType(Material.AIR);". But whenever it tries to change the block, it dissapears and returns to the player who placed it.

    Source, you can find the row where it changes the block at line 71:
    https://sourceforge.net/p/letsplayb.../letsplay/letsplay/LetsPlayBlockListener.java

    If i change it to stone instead of air it works perfectly, but thats not fixing the problem that its still there.

    I have now fixed it. Dont know what caused the event to crash or cancel must been some sort of glitch.

    I had to manually cancel the event and then remove the block from the placing players inventory in order to get it to work as intended.

    Code:
    // Cancel the event, this will return the block to the players inventory
    event.setCancelled(true);
     
    // Remove the block from the players inventory
    event.getPlayer().getInventory().remove(block.getType());
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
Thread Status:
Not open for further replies.

Share This Page