Solved Custom Event which extends BlockGrowEvent

Discussion in 'Plugin Development' started by wand555, Mar 9, 2020.

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

    wand555

    Hello, I'm trying to add a new custom event. All the tutorials and resources (including the official one) say that the custom event has to extend from Event. After that you need to include your other methods, bla bla bla...
    What I'm curious about, is whether you can extend it BlockGrowEvent or not. My goal is to add more methods to that event to get more information overall.
    Lets say my custom event is named "DetailedBlockGrowEvent". It extends BlockGrowEvent and therefore needs to pass variables to the BlockGrowEvent constructor, basically calling a new instance of it. Now when I call my event I can use
    Code:
    Bukkit.getServer().getPluginManager().callEvent(new DetailedBlockGrowEvent(event.getBlock(), event.getNewState()));
    as the tutorial says. But obviously I want to trigger this event, when a normal BlockGrowEvent should trigger. Initially I thought I can just call my custom event on the BlockGrowEvent, but that gets me stuck in a loop. My Listener listens if a BlockGrowEvent is called and then calls my custom event, which again in its constructor, creates a new instance of the BlockGrowEvent and etc.
    Now I'm wondering if there's any way to create custom events that extend something that extend "Event" ?
    (Here: DetailedBlockGrowEvent extends BlockGrowEvent and BlockGrowEvent extends Event)
    Maybe there's a way I can listen to BlockGrowEvent, call DetailedBlockGrowEvent and cancel (something "stronger" than setCancelled, something that actually stops the event) the
    original BlockGrowEvent.
    EDIT: Stupidity makes solving problems hard.
    Solution:
    I need to override getHandlers() and create getHandlerList(). I think that way internally it uses my "custom" handlers and stops creating new instances.
     
    Last edited: Mar 9, 2020
Thread Status:
Not open for further replies.

Share This Page