use of org.spongepowered.api.text.channel.MessageChannel in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method callDestructEntityEventDeath.
public static DestructEntityEvent.Death callDestructEntityEventDeath(EntityLivingBase entity, DamageSource source) {
final MessageEvent.MessageFormatter formatter = new MessageEvent.MessageFormatter();
MessageChannel originalChannel;
MessageChannel channel;
Text originalMessage;
Optional<User> sourceCreator = Optional.empty();
boolean messageCancelled = false;
if (entity instanceof EntityPlayerMP) {
originalChannel = channel = ((IMixinEntityPlayerMP) entity).getDeathMessageChannel();
} else {
originalChannel = MessageChannel.TO_NONE;
channel = MessageChannel.TO_NONE;
}
if (source instanceof EntityDamageSource) {
EntityDamageSource damageSource = (EntityDamageSource) source;
IMixinEntity spongeEntity = (IMixinEntity) damageSource.getImmediateSource();
if (spongeEntity != null) {
sourceCreator = spongeEntity.getCreatorUser();
}
}
originalMessage = SpongeTexts.toText(entity.getCombatTracker().getDeathMessage());
formatter.getBody().add(new MessageEvent.DefaultBodyApplier(originalMessage));
final boolean isMainThread = Sponge.isServerAvailable() && Sponge.getServer().isMainThread();
// checks need to be made here since entities can die on the client world.
try (final StackFrame frame = isMainThread ? Sponge.getCauseStackManager().pushCauseFrame() : null) {
if (isMainThread) {
Sponge.getCauseStackManager().pushCause(source);
if (sourceCreator.isPresent()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, sourceCreator.get());
}
}
final Cause cause = isMainThread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), source);
DestructEntityEvent.Death event = SpongeEventFactory.createDestructEntityEventDeath(cause, originalChannel, Optional.of(channel), formatter, (Living) entity, entity.world.getGameRules().getBoolean("keepInventory"), messageCancelled);
SpongeImpl.postEvent(event);
Text message = event.getMessage();
if (!event.isMessageCancelled() && !message.isEmpty()) {
event.getChannel().ifPresent(eventChannel -> eventChannel.send(entity, event.getMessage()));
}
return event;
}
}
use of org.spongepowered.api.text.channel.MessageChannel in project SpongeForge by SpongePowered.
the class MixinIntegratedServerAnonInner3 method beforeFirePlayerLoggedOut.
/**
* @author Simon816
*
* PlayerQuitEvent must be fired manually just before playerLoggedOut.
*
* @see MixinPlayerList#onFirePlayerLoggedOutCall
*/
@ModifyArg(method = "run()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;playerLoggedOut(Lnet/minecraft/entity/player/EntityPlayerMP;)V"))
public EntityPlayerMP beforeFirePlayerLoggedOut(EntityPlayerMP playerIn) {
Player player = (Player) playerIn;
MessageChannel originalChannel = player.getMessageChannel();
Sponge.getCauseStackManager().pushCause(player);
ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(), player, true);
SpongeImpl.postEvent(event);
// are quitting anyway
return playerIn;
}
use of org.spongepowered.api.text.channel.MessageChannel in project NewHonor-SpongePlugin by euOnmyoji.
the class NewHonor method onClientConnectionJoin.
@Listener
public void onClientConnectionJoin(ClientConnectionEvent.Join event) {
Player p = event.getTargetEntity();
PlayerData pd = new PlayerData(p);
Task.builder().execute(() -> {
if (!pd.init()) {
logger.error("初始化玩家" + p.getName() + "," + p.getUniqueId() + ",头衔数据失败!");
}
doSomething(pd);
}).async().delayTicks(20).name("newhonor - init Player" + p.getName()).submit(this);
MessageChannel originalChannel = event.getOriginalChannel();
MessageChannel newChannel = MessageChannel.combined(p.getMessageChannel(), originalChannel, mMessage);
p.setMessageChannel(newChannel);
}
use of org.spongepowered.api.text.channel.MessageChannel in project LanternServer by LanternPowered.
the class NetworkSession method leavePlayer.
/**
* Is called when the {@link LanternPlayer} leaves the
* server and needs to be cleaned up.
*/
private void leavePlayer() {
checkState(this.player != null, "The player must first be available!");
final LanternWorld world = this.player.getWorld();
if (world != null) {
final CauseStack causeStack = CauseStack.current();
causeStack.pushCause(this.player);
// Close the open container
this.player.getContainerSession().setRawOpenContainer(causeStack, null);
final MessageChannel messageChannel = this.player.getMessageChannel();
final Text quitMessage = t("multiplayer.player.left", this.player.getName());
final ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(causeStack.getCurrentCause(), messageChannel, Optional.of(messageChannel), new MessageEvent.MessageFormatter(quitMessage), this.player, false);
Sponge.getEventManager().post(event);
if (!event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(this.player, event.getMessage()));
}
causeStack.popCause();
// Remove the proxy user from the player and save the player data
this.player.getProxyUser().setInternalUser(null);
// Destroy the player entity
this.player.remove(LanternEntity.RemoveState.DESTROYED);
// Detach the player from the world
this.player.setWorld(null);
// Release the players entity id
EntityProtocolManager.releaseEntityId(this.player.getNetworkId());
}
}
use of org.spongepowered.api.text.channel.MessageChannel in project Nucleus by NucleusPowered.
the class AFKHandler method setAfk.
public boolean setAfk(Player player, Cause cause, boolean force) {
if (!player.isOnline()) {
return false;
}
UUID uuid = player.getUniqueId();
AFKData a = data.compute(uuid, ((u, afkData) -> afkData == null ? new AFKData(u) : afkData));
if (force) {
a.isKnownAfk = false;
} else if (a.isKnownAfk) {
return false;
}
if (a.canGoAfk()) {
// Don't accident undo setting AFK, remove any activity from the list.
synchronized (lock) {
activity.remove(uuid);
}
Tuple<Text, MessageChannel> ttmc = getAFKMessage(player, true);
AFKEvents.To event = new AFKEvents.To(player, ttmc.getFirst(), ttmc.getSecond(), cause);
Sponge.getEventManager().post(event);
actionEvent(event, "command.afk.to.vanish");
a.isKnownAfk = true;
return true;
}
return false;
}
Aggregations