crwdns148377:0crwdne148377:0

crwdns148379:0:javadoc:crwdnd148379:0:javadoc:crwdnd148379:0:javadoc:crwdnd148379:0:javadoc:crwdne148379:0

crwdns148381:0crwdne148381:0

crwdns148383:0crwdne148383:0

crwdns148385:0:javadoc:crwdne148385: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;
    }

}

crwdns148387:0crwdne148387: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
}

crwdns148389:0crwdne148389:0

crwdns148391:0crwdne148391: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!"));
    }
}