DeadlyDisasters
  • ⚙️Custom Disasters
    • How To Make A Custom Disaster
    • Skeleton Body
    • Core Body
    • Actions
      • Disaster Action
        • Disaster Modifiers
      • Broadcast Action
      • Fill Action
      • Summon Action
      • Particle Action
      • Sound Action
    • Custom Items
    • Custom Entities
    • Catalog Body
    • Publishing Your Disaster!
    • Resources
  • 👋Community
    • Discord
    • Challenge Packs (Coming Soon)
  • 🔌Developers
    • API
      • Creating Disasters
      • Listening For Disasters
      • Custom Items
      • Custom Entities (Coming Soon)
      • Extra Features
    • Source
Powered by GitBook
On this page
  1. Developers
  2. API

Listening For Disasters

Using the API you can listen for when a disaster starts and access the variables, level, location, attached player, or cancel it. There are two types of disasters as earlier specified destruction disasters and weather disasters, each has its own event. This is how you can listen for a destruction disaster and cancel it if it's a sinkhole:

@EventHandler
public void onDisasterStart(DestructionDisasterEvent e) {
    if (e.getDisaster() instanceof Sinkhole)
        e.setCancelled(true);
}

Here is an example of canceling any weather disaster that is over level 3:

@EventHandler
public void onWeatherDisasterStart(WeatherDisasterEvent e) {
    if (e.getLevel() > 3)
        e.setCancelled(true);
}

You can cast the disaster from the event to then access and modify its variables like this:

@EventHandler
public void onDisasterStart(DestructionDisasterEvent e) {
    if (e.getDisaster() instanceof Earthquake) {
        Earthquake earthquake = (Earthquake) e.getDisaster();
        earthquake.setWidth(10);
    }
}

You can also check the type of disaster with an enum like this:

@EventHandler
public void onWeatherDisasterStart(WeatherDisasterEvent e) {
    if (e.getDisaster().getType() == Disaster.ACIDSTORM || e.getDisaster().getType() == Disaster.BLIZZARD || e.getDisaster().getType() == Disaster.SOULSTORM)
        e.setCancelled(true);
}

If you need any help or you're having problems you can join the discord to get fast support, if you have any ideas or suggestions you can also leave them there.

PreviousCreating DisastersNextCustom Items

Last updated 2 years ago

🔌
Join the Deadly Disasters Discord Server!Discord
Logo