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.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
.getPlayer()
.sendMessage("Effect has been interrupted because of " + reason.toString());
}
@Override
public void process(AppliedEffectData data) {
data.getPlayer().sendMessage(String.valueOf(data.getDuration()));
}
}
Don't forget to register it and you are good to go.