package net.minecraftforge.event; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IChatComponent; /** * ServerChatEvent is fired whenever a C01PacketChatMessage is processed.
* This event is fired via {@link ForgeHooks#onServerChatEvent(net.minecraft.network.NetHandlerPlayServer, String, ChatComponentTranslation)}, * which is executed by the NetHandlerPlayServer#processChatMessage(net.minecraft.network.play.client.C01PacketChatMessage)
*
* {@link #username} contains the username of the player sending the chat message.
* {@link #message} contains the message being sent.
* {@link #player} the instance of EntityPlayerMP for the player sending the chat message.
* {@link #component} contains the instance of ChatComponentTranslation for the sent message.
*
* This event is {@link Cancelable}.
* If this event is canceled, the chat message is never distributed to all clients.
*
* This event does not have a result. {@link HasResult}
*
* This event is fired on the {@link MinecraftForge#EVENT_BUS}. **/ @Cancelable public class ServerChatEvent extends Event { public final String message, username; public final EntityPlayerMP player; @Deprecated //Use methods below public ChatComponentTranslation component; public ServerChatEvent(EntityPlayerMP player, String message, ChatComponentTranslation component) { super(); this.message = message; this.player = player; this.username = player.getGameProfile().getName(); this.component = component; } public void setComponent(IChatComponent e) { if (e instanceof ChatComponentTranslation) this.component = (ChatComponentTranslation)e; else this.component = new ChatComponentTranslation("%s", e); } public IChatComponent getComponent() { return this.component; } }