Search in sources :

Example 1 with IMixinInitCause

use of org.spongepowered.common.interfaces.IMixinInitCause in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createServerChatEvent.

// Server events
private static ServerChatEvent createServerChatEvent(Event event) {
    MessageChannelEvent.Chat spongeEvent = (MessageChannelEvent.Chat) event;
    Optional<Player> player = spongeEvent.getCause().first(Player.class);
    if (!player.isPresent()) {
        return null;
    }
    Text spongeText = spongeEvent.getOriginalMessage();
    ITextComponent component = SpongeTexts.toComponent(spongeText);
    if (!(component instanceof TextComponentTranslation)) {
        component = new TextComponentTranslation("%s", component);
    }
    // Using toPlain here is fine, since the raw message from the client
    // can't have formatting.
    ServerChatEvent forgeEvent = new ServerChatEvent((EntityPlayerMP) player.get(), spongeEvent.getOriginalMessage().toPlain(), (TextComponentTranslation) component);
    ((IMixinInitCause) forgeEvent).initCause(spongeEvent.getCause());
    return forgeEvent;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) ITextComponent(net.minecraft.util.text.ITextComponent) IMixinInitCause(org.spongepowered.common.interfaces.IMixinInitCause) Text(org.spongepowered.api.text.Text) ServerChatEvent(net.minecraftforge.event.ServerChatEvent)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 ServerChatEvent (net.minecraftforge.event.ServerChatEvent)1 Player (org.spongepowered.api.entity.living.player.Player)1 MessageChannelEvent (org.spongepowered.api.event.message.MessageChannelEvent)1 Text (org.spongepowered.api.text.Text)1 IMixinInitCause (org.spongepowered.common.interfaces.IMixinInitCause)1