🔮Powerup API

To create your own Powerup, create a new class that extends Powerup, example

public class MyPowerup extends Powerup {
    public MyPowerup(String configIdentifier, Location location, long interval) {
        super(configIdentifier, location, interval);
    }

    @Override
    protected Item respawnPowerup(Location location) {
        return null;
    }

    @Override
    protected void onPlayerPickup(Player player) {

    }
}

Now, you can create your Powerup Item and Powerup Action.

The Identifier is the name in map config and the name you will use to add the Powerup location via command.

public class MyPowerup extends Powerup {
    public MyPowerup(Location location, long interval) {
        super("MYPOWERUP", location, interval);
    }

    @Override
    protected Item respawnPowerup(Location location) {
        Item item = location.getWorld().dropItem(location, new ItemStack(Material.BLAZE_POWDER));
        item.setVelocity(new Vector(0, 0, 0));
        item.teleport(location.clone().add(.5, 0, .5));
        return item;
    }

    @Override
    protected void onPlayerPickup(Player player) {
        GamePlayer.get(player).setMana(99);
        player.sendMessage(ChatColor.RED + "Filled your mana!");
    }
}

That's it! You now have your own powerup.

Now, you need to register the Powerup Spawn and add the powerup to your games. You will need to use the new event made for this: GameArenaLoadEvent.

You will need to access the GameArena and the Map that contains the Locations for each Powerup Type, made this way to be easier for developers.

@EventHandler
public void onArenaLoad(GameArenaLoadEvent e) {
e.getGame().registerPowerupSpawn("MYPOWERUP");
e.getGame().getGameArena().getPowerups().get("MYPOWERUP").forEach(location ->
       e.getGame().getPowerups().add(new MyPowerup(location, 15000L)));
}

Spawns are automatically handled by the Game.

And it's done.

You can now add your powerups to the arena using the command.

For Developers, a quick note here, make sure all your Powerup names are in UPPER CASE, this is not a mechanic limitation, it is just to make it easier when setting up the arena and getting names from config files.

For admins who are setting up the arena it doesn't metter, you can use upper or lower case, it will convert to uppercase anyways.

Last updated