callEvent() Question

Discussion in 'Plugin Development' started by nossr50, Mar 29, 2011.

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

    nossr50

    Howdy, I send a *fake* blockBroken event around to other plugins for maximum compatibility. And I've run into one snag with CB 600.

    Now I have to have some of my own code that runs when block breaks in onBlockBreak which is fine but now when I fake the blockBroken event in onBlockDamage it causes some unwanted stuff to happen.

    How can I call this event without sending it to my own plugin or at least making it so my own plugin will ignore it?
     
    cengbrecht likes this.
  2. Offline

    Afforess

    Could create a wrapper event, like FakeBlockBrokenEvent extends BlockBrokenEvent and pass it as a block broken event. All plugins would see it as a regular event, but your plugin could use a !(event instanceof FakeBlockBrokenEvent) to make sure it didn't get the fake event.

    If you're not sure what I'm talking about, I'll post a code example.
     
    nossr50 and cengbrecht like this.
  3. Offline

    cengbrecht

    That was confusing as all heck, but I hope Nossr50 got it. :p
     
  4. Offline

    nossr50

    @Afforess Could you post the example?
     
  5. Offline

    Afforess

    Sure. (Assuming your using RB 600)

    Add this to your project as FakeBlockBreakEvent.java:
    Code:
    /*FakeBlockBreakEvent.java*/
    
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockBreakEvent;
    
    public class FakeBlockBreakEvent extends BlockBreakEvent {
    	public FakeBlockBreakEvent(Block theBlock, Player player) {
    		super(theBlock, player);
    	}
    }
    
    Then, instead of using callEvent() with BlockBreakEvent, use FakeBlockBreakEvent.

    Finally, in onBlockBreak(BlockBreakEvent event), put this check in the beginning:
    Code:
    if (event instanceof FakeBlockBreakEvent) {
    	return;
    }
    
     
    nossr50 and cengbrecht like this.
  6. Offline

    nossr50

    I can't thank you enough Afforess
     
    cengbrecht likes this.
Thread Status:
Not open for further replies.

Share This Page