[SOLVED] Cancelling Tree Pop Event

Discussion in 'Plugin Development' started by Scizzr, Jul 18, 2012.

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

    Scizzr

    So I went through the Block events (BlockPhysicsEvent and such), and haven't been able to find one that cancels a tree (sapling) popping when WorldEdit sets the block under it to AIR. Any help would be appreciated.

    Thanks! :)
     
  2. LeavesDecayEvent, that should do it, you should look better next time:p
    greetz blackwolf12333
     
  3. Offline

    Njol

    Try BlockPhysicsEvent
     
  4. Offline

    Scizzr

    Tried it. Didn't work.

    Didn't work.

    Thanks though, guys!
     
  5. You first need to see if it actually triggers, don't jump to conditions if you're not sure.
    Code:
    @EventHandler
    public void test(BlockPhysicsEvent event)
    {
        System.out.print("BlockPhysicsEvent :: " + event.getBlock());
    }
     
  6. Offline

    Scizzr

    I've got this setup in the plugin I'm working on:
    Code:
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled=true)
        public void onBlockPhysics(final BlockPhysicsEvent e) {
            if (HelperMgr.isHelper(e.getBlock())) {
                e.setCancelled(true);
            }
        }
    Basically when I plant a tree, it adds it to a list. When the physics event fires, it checks if that block is in the list. I can cancel everything else other than trees. Not sure why not though.

    Thanks.
     
  7. Maybe it doesn't trigger ? I suggested that code for a reason... if you're just gonna ignore it and still do it your way, I can't help you.
     
  8. Offline

    Scizzr

    No, I didn't mean to make it sound like I was ignoring you. I just tested some different code that I made and found out the problem. Long story short, I wasn't checking the right block.

    Aside from that note, I can't get it to cancel a second time after the air is still there. So I can cancel it initially, but the next time it fires, the sapling pops. This is weird.

    Thanks man.

    Edit: This is a list of what does NOT cancel the tree popping the second time (when whatever event fires):
    BlockPhysicsEvent
    BlockFadeEvent
    BlockFromToEvent
    LeavesDecayEvent
     
  9. So let me get this streight... the BlockPhysicsEvent triggers, you're able to cancel it (confirm with a debug message ?) but sometimes it still makes the sapling pop even if you cancel it ?
     
  10. Offline

    Scizzr

    Yes, the first time it would have popped is from a BlockPhysicsEvent that I can cancel (with a message). After this cancellation and a few second delay (the other event I can't seem to target), it pops anyways.

    Thanks.

    Another update. None of these work to cancel the mystery event:
    Code:
    BlockBreakEvent
    BlockBurnEvent
    BlockCanBuildEvent
    BlockDamageEvent
    BlockDispenseEvent
    BlockFadeEvent
    BlockFormEvent
    BlockFromToEvent
    BlockGrowEvent
    BlockIgniteEvent
    BlockPhysicsEvent
    BlockPlaceEvent
    BlockSpreadEvent
    
    I cancelled every single event from all of these and none of them do what I need.

    Is it possible I found a problem with Bukkit?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  11. Offline

    nisovin

    You really want a sapling floating in the air?
     
  12. Offline

    Scizzr

    The thing is, I need it to be there for an extended duration. If someone WorldEdit's it, part of my plugin replaces it. This leads to an infinite sapling loop. Understand?

    Alright guys, this seems to work well enough. Posting the code for anyone that might want it.
    Code:
        @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled=true)
        public void onBlock(final ItemSpawnEvent e) {
            if (HelperMgr.isHelper(e.getLocation().getBlock())) {
                Item it = e.getEntity();
                if (it.getItemStack().getType() == Material.SAPLING) {
                    e.setCancelled(true);
                }
            }
        }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page