crwdns129151:0crwdne129151:0

crwdns129153:0:javadoc:crwdnd129153:0:javadoc:crwdnd129153:0:javadoc:crwdnd129153:0:javadoc:crwdne129153:0

crwdns129155:0crwdne129155:0

crwdns129157:0crwdne129157:0

crwdns129159:0:javadoc:crwdne129159:0

import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.entity.living.humanoid.player.TargetPlayerEvent;
import org.spongepowered.api.event.impl.AbstractEvent;

public class PlayerMutationEvent extends AbstractEvent implements TargetPlayerEvent, Cancellable {

    public enum Mutation {
        COMPULSIVE_POETRY,
        ROTTED_SOCKS,
        SPONTANEOUS_COMBUSTION;
    };

    private final Cause cause;
    private final Player victim;
    private final Mutation mutation;
    private boolean cancelled = false;

    public PlayerMutationEvent(Player victim, Mutation mutation, Cause cause) {
        this.victim = victim;
        this.mutation = mutation;
        this.cause = cause;
    }

    public Mutation getMutation() {
        return this.mutation;
    }

    @Override
    public boolean isCancelled() {
        return this.cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }

    @Override
    public Cause getCause() {
        return this.cause;
    }

    @Override
    public Player getTargetEntity() {
        return this.victim;
    }

}

crwdns129161:0crwdne129161:0

import org.spongepowered.api.Sponge;

PlayerMutationEvent event = new PlayerMutationEvent(victim, PlayerMutationEvent.Mutation.ROTTED_SOCKS,
        Cause.source(flardSource).build());
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
    // Mutation code
}

crwdns129163:0crwdne129163:0

crwdns129165:0crwdne129165:0

import org.spongepowered.api.event.Listener;
import org.spongepowered.api.text.Text;

@Listener
public void onPrivateMessage(PlayerMutationEvent event) {
    if(event.getMutation() == PlayerMutationEvent.Mutation.SPONTANEOUS_COMBUSTION) {
        event.setCancelled(true);
        event.getTargetEntity().sendMessage(Text.of("You can not combust here, this is a non-smoking area!"));
    }
}