Skip to content

Custom Events

EricLangezaal edited this page Jun 19, 2021 · 2 revisions

DragonSwoopEvent

This event is called whenever a PetDragon is about to launch a living entity away due to the entity getting too close to its wings. By default such a launch will also inflict damage to the entity, which can be changed separately through regular Spigot events. It is possible to cancel this event, in which case only the launch will not happen. As this event subclasses EntityTargetLivingEntityEvent, it also has all methods that event provides.

Internally this event is also used to determine if a dragon should launch an entity. If the config.yml setting do-entity-interact is set to false this event will fire in a cancelled state. It can also be fired in a cancelled state if a PetDragon is trying to launch her owner. You are free to make the event go through in these cases, just be sure to communicate this to your users accordingly.

In the example below I cancel 50% of the launches and make the remaining ones be half as powerful, if the dragon is named "nerfed".

@EventHandler
public void onDragonSwoop(DragonSwoopEvent event){
   EnderDragon dragon = event.getEntity();
   
   if (!dragon.getName().equals("nerfed")) return;

   if (ThreadLocaleRandom.current().nextBoolean(){
      event.setCancelled(true); 
   } else {
      event.setVelocity(event.getVelocity().multiply(0.5)); // half the additional velocity this launch adds to the entity.
   }


}  
Clone this wiki locally