crwdns118183:0crwdne118183:0
crwdns118185:0:javadoc:crwdnd118185:0:javadoc:crwdnd118185:0:javadoc:crwdnd118185:0:javadoc:crwdne118185:0
crwdns118187:0crwdne118187:0
crwdns118189:0:javadoc:crwdne118189:0
crwdns118191:0:javadoc:crwdne118191: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;
}
}
crwdns118193:0crwdne118193:0
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.EventContext;
import org.spongepowered.api.event.cause.EventContextKeys;
import org.spongepowered.api.Sponge;
PluginContainer plugin = ...;
EventContext eventContext = EventContext.builder().add(EventContextKeys.PLUGIN, plugin).build();
PlayerMutationEvent event = new PlayerMutationEvent(victim, PlayerMutationEvent.Mutation.ROTTED_SOCKS,
Cause.of(eventContext, plugin));
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
// Mutation code
}
crwdns118195:0crwdne118195:0
crwdns118197:0crwdne118197: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 cannot combust here, this is a non-smoking area!"));
}
}