crwdns137747:0crwdne137747:0
crwdns156853:0:javadoc:crwdnd156853:0:javadoc:crwdnd156853:0:javadoc:crwdne156853:0
Tip
crwdns156855:0:javadoc:crwdne156855:0
crwdns137751:0crwdne137751:0
crwdns137753:0:javadoc:crwdne137753:0
crwdns137755:0:javadoc:crwdne137755:0
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.event.impl.AbstractEvent;
public class PlayerMutationEvent extends AbstractEvent implements Cancellable {
public enum Mutation {
COMPULSIVE_POETRY,
ROTTED_SOCKS,
SPONTANEOUS_COMBUSTION;
};
private final Cause cause;
private final ServerPlayer victim;
private final Mutation mutation;
private boolean cancelled = false;
public PlayerMutationEvent(ServerPlayer victim, Mutation mutation, Cause cause) {
this.victim = victim;
this.mutation = mutation;
this.cause = cause;
}
public ServerPlayer victim() {
return this.victim;
}
public Mutation mutation() {
return this.mutation;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@Override
public Cause cause() {
return this.cause;
}
}
crwdns137757:0crwdne137757:0
import org.spongepowered.api.event.Cause;
import org.spongepowered.api.event.EventContext;
import org.spongepowered.api.event.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.eventManager().post(event);
if (!event.isCancelled()) {
// Mutation code
}
crwdns137759:0crwdne137759:0
crwdns137761:0crwdne137761:0
import net.kyori.adventure.text.Component;
import org.spongepowered.api.event.Listener;
@Listener
public void onPrivateMessage(PlayerMutationEvent event) {
if (event.mutation() == PlayerMutationEvent.Mutation.SPONTANEOUS_COMBUSTION) {
event.setCancelled(true);
event.victim().sendMessage(Component.text("You cannot combust here, this is a non-smoking area!"));
}
}