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.

Last updated