Solved Cancelling pistonextend event.

Discussion in 'Plugin Development' started by kukelekuuk00, Jan 17, 2013.

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

    kukelekuuk00

    Hello,

    I have a little snippet of code.
    Code:java
    1. @EventHandler(priority = EventPriority.HIGHEST)
    2. public void ReedPistonExtend(BlockPistonExtendEvent event) {
    3. if (event.isCancelled()) return;
    4. for (Block block : event.getBlocks()) {
    5. if (block.getTypeId() == 83) {
    6. event.setCancelled(true);
    7. break;
    8. }
    9. }


    This is supposed to cancel whenever it moves a SugarCane block.
    But no matter what I try, the piston moves and destroys the sugarcane and I can't figure it out.

    Any idea what I did wrong?

    Thanks in advance,

    ~kukelekuuk00
     
  2. Offline

    caseif

    e.getExtendLocation().getBlock();
     
  3. Offline

    kukelekuuk00


    That would only block it if the reed is directly in front of it, wouldn't it?
    Because I need to check for more blocks.

    Let me illustrate using text.
    [] = stone
    [- = piston
    :: = reed

    ::[][][][-
    []::[][-
    ::[-

    It needs to block it in all these kind of situations.

    Edit: your getExtendLocation function is nowhere to be found in the javadocs.
     
  4. Offline

    fireblast709

    debug your code
     
  5. Offline

    kukelekuuk00

    You are completely right, I debugged my code and I found the issue in no time.
    (The problem was that reeds don't show up in event.getBlocks())

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page