Making more advanced effect

For an advanced effect, you can use functions to do this.

public class SayHelloEffect implements CustomEffect {

    @Override
    public @NotNull CustomEffectData effectData() {
        return new CustomEffectData("sayhelloeffect", "Say hello effect!", 0, false, true);
    }

    // Called when effect ended with no problems by itself
    @Override
    public void effectEnd(AppliedEffectData data) {
        data.getOfflinePlayer().getPlayer().sendMessage("Goodbye!");
    }

    // Called when effect is interrupted for some reason 
    // (Like player death, milk or plugin)
    @Override
    public void effectInterrupted(AppliedEffectData data, EffectInterruptionReason reason) {
        data.getOfflinePlayer()
            .getPlayer().sendMessage("Effect has been interrupted because of " + reason.toString());
    }

    @Override
    public void secondPassed(AppliedEffectData data) {
        data.getOfflinePlayer().getPlayer().sendMessage(String.valueOf(data.getDuration()));
    }
}

Don't forget to register it and you are good to go.

Last updated