Creating Disasters

Starting a disaster is much easier than you would think, all you need to do is create the disaster instance and then call the start() method. Here is an example of starting a sinkhole on a player named Steve:

Player player = Bukkit.getPlayer("Steve");

Sinkhole sinkhole = new Sinkhole(1);
sinkhole.start(player.getLocation(), player);

As you may have noticed inside the new Sinkhole(1) there is a '1' this stands for the level of the disaster. There are two types of disasters in the API, DestructionDisaster and WeatherDisaster. As you may have already guessed, the WeatherDisaster type is for weather-based disasters like acidstorms, blizzards, soulstorms, meteorshowers, etc. And the DestructionDisaster type is for disasters that are not weather affiliated such as sinkholes, earthquakes, supernovas, etc. All DestructionDisaster type disasters share the same constructor for creating and starting the disaster, this is the super constructor for DestructionDisaster:

DestructionDisaster variable = new DestructionDisaster(int level);
variable.start(Location loc, @Nullable Player player);

And here are the constructors for creating and starting a WeatherDisaster:

WeatherDisaster variable = new WeatherDisaster(int level);
variable.start(World world, @Nullable Player player);

This means that all disasters have either the same syntax as the DestructionDisaster or the WeatherDisaster. The reason why Player is nullable in the start() syntax is because you do not need to define an origin player for the disaster (Except purges). Defining an origin player just lets you and other plugins keep track of what player caused the disaster. You can also start disasters with a delay before they actually start, the reason why you would do this is for the end totem pet to be able to detect the disaster before it happens and also for the listplayer command to display the disaster and how much time before it happens. All disasters that naturally occur are started like this:

DestructionDisaster variable = new DestructionDisaster(int level);
variable.createTimedStart(int delaySeconds, Vector offset, Player p);

The delaySeconds is how many seconds before the disaster starts. The offset vector is the disasters offset as a vector value. The player is not optional, if you are creating a delay for a disaster to start you must specify the player that it will start on. The offset vector is applied to the location of the player when the disaster actually occurs.

Disasters will start at the location you define in the parameter, sinkholes work best at ground level so here is a quick method to start a sinkhole below the player on solid ground:

Location loc = p.getLocation().clone();
for (int c=loc.getBlockY()-1; c > 0; c--) {
    loc.setY(c);
    if (loc.getBlock().getType().isSolid()) {
        Sinkhole s = new Sinkhole(level);
        s.start(loc, p);
        break;
    }
}

Some disasters have tools to assist in finding a location suitable for the disaster such as Tsunamis spawning where water is deep enough:

Tsunami tsunami = new Tsunami(level);
Location location = tsunami.findAvailabePool(player.getLocation());
if (location != null)
    tsunami.start(location, player);

Each disaster has its own unique variables you can manipulate such as size, damage, volume, etc. Here is an example of starting an Earthquake with a custom size:

Earthquake earthquake = new Earthquake(1);
earthquake.setWidth(20);
earthquake.setRadius(100);
earthquake.start(location, null);

Some disasters such as Geysers can be customized and do not need to be started but instead have internal features that you can use, for example, this method will create a water geyser under our player that will not do any damage:

Geyser geyser = new Geyser(1);
geyser.setDamage(0);
geyser.createWater(player.getLocation());

Here is an example of creating an acid storm with no start delay and custom damage that will not melt players armor or items:

AcidStorm storm = new AcidStorm(5);
storm.setDelay(0);
storm.setDamage(0.5);
storm.setMeltArmor(false);
storm.setMeltItems(false);
storm.start(world, null);

Here is an example of creating a meteor shower that will last 60 seconds and force the time to night, keep in mind that the time variable is in-game ticks and counts down.

MeteorShower shower = new MeteorShower(1);
shower.setTime(1200);
shower.setNight(true);
shower.start(world, null);

This example will start a plague and infect 6 additional mobs (the level of the plague is the number of mobs that will be infected).

BlackPlague plague = new BlackPlague(2);
if (plague.isMobAvailable(world)) {
    plague.start(world, null);
    plague.infectRandomMobs(6, world);
}

// You can also infect specified targets using this
BlackPlague.infect(entity);

// You can also cure an entity using this
BlackPlague.cureEntity(entity);

Last updated