Creating Effects

How to create your own effects using the API

You can use the API to create your own effects for this plugin

Create your own effect class

public class Example extends CustomEffect {
    public Example(Plugin plugin) {
        super(plugin, "EXAMPLE", "This is an example effect", "EXAMPLE:[VALUE]");
    }

    @Override
    public void run(LivingEntity player, @Nullable LivingEntity target, String[] arguments, Event event) {
        player.sendMessage("HELLO");
    }
}

You can also call events (as long as they are called using an effect type related, ie. if you want to call BlockBreakEvent. The effect type has to be MINE) Here is an example of an effect that sends the message "BROKEN" to the player once they break a block and it also cancel them from being able to break said block

public class Example extends CustomEffect {
    public Example(Plugin plugin) {
        super(plugin, "EXAMPLE", "This is an example effect", "EXAMPLE:[VALUE]");
    }

    @Override
    public void run(LivingEntity player, @Nullable LivingEntity target, String[] arguments, Event event) {
        if (!(event instanceof BlockBreakEvent)) return;
        BlockBreakEvent breakEvent = (BlockBreakEvent) event;

        Player breaker = breakEvent.getPlayer();
        if (breaker.getUniqueId() != player.getUniqueId()) return;
        breakEvent.setCancelled(true);

        breaker.sendMessage("BROKEN");
    }
}

Registering effect

You will then need to add the following to your onEnable (Preferably with a delay) You can register multiple effects by separating them with a comma as shown below

    @Override
    public void onEnable() {
        if (getServer().getPluginManager().isPluginEnabled("EliteEnchantments")) {
            EliteEnchantmentsAPI.getAPI().registerEffects(Example.class, Potion.class);
        }
    }

Last updated