2012-10-28 06:58:23 -04:00
|
|
|
package net.minecraftforge.event;
|
|
|
|
|
|
2014-11-25 19:56:35 -08:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
2012-12-12 21:58:35 -08:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-12-21 00:10:35 -08:00
|
|
|
import net.minecraft.util.ChatComponentTranslation;
|
2016-03-01 04:58:03 -08:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2012-10-28 06:58:23 -04:00
|
|
|
|
2014-07-06 16:07:49 -04:00
|
|
|
/**
|
|
|
|
|
* ServerChatEvent is fired whenever a C01PacketChatMessage is processed. <br>
|
2015-05-25 12:02:47 -07:00
|
|
|
* This event is fired via {@link ForgeHooks#onServerChatEvent(net.minecraft.network.NetHandlerPlayServer, String, ChatComponentTranslation)},
|
2014-07-06 16:07:49 -04:00
|
|
|
* which is executed by the NetHandlerPlayServer#processChatMessage(net.minecraft.network.play.client.C01PacketChatMessage)<br>
|
|
|
|
|
* <br>
|
|
|
|
|
* {@link #username} contains the username of the player sending the chat message.<br>
|
|
|
|
|
* {@link #message} contains the message being sent.<br>
|
|
|
|
|
* {@link #player} the instance of EntityPlayerMP for the player sending the chat message.<br>
|
|
|
|
|
* {@link #component} contains the instance of ChatComponentTranslation for the sent message.<br>
|
|
|
|
|
* <br>
|
|
|
|
|
* This event is {@link Cancelable}. <br>
|
|
|
|
|
* If this event is canceled, the chat message is never distributed to all clients.<br>
|
|
|
|
|
* <br>
|
|
|
|
|
* This event does not have a result. {@link HasResult}<br>
|
|
|
|
|
* <br>
|
|
|
|
|
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
|
|
|
|
**/
|
2012-10-28 06:58:23 -04:00
|
|
|
@Cancelable
|
2013-02-15 03:22:59 -08:00
|
|
|
public class ServerChatEvent extends Event
|
|
|
|
|
{
|
2012-10-28 06:58:23 -04:00
|
|
|
public final String message, username;
|
|
|
|
|
public final EntityPlayerMP player;
|
2015-05-25 12:02:47 -07:00
|
|
|
@Deprecated //Use methods below
|
2013-12-21 00:10:35 -08:00
|
|
|
public ChatComponentTranslation component;
|
|
|
|
|
public ServerChatEvent(EntityPlayerMP player, String message, ChatComponentTranslation component)
|
2012-10-28 06:58:23 -04:00
|
|
|
{
|
|
|
|
|
super();
|
|
|
|
|
this.message = message;
|
|
|
|
|
this.player = player;
|
2014-02-05 00:05:37 -08:00
|
|
|
this.username = player.getGameProfile().getName();
|
2013-06-30 05:50:11 -07:00
|
|
|
this.component = component;
|
2012-10-28 06:58:23 -04:00
|
|
|
}
|
2015-05-25 12:02:47 -07:00
|
|
|
|
2016-03-01 04:58:03 -08:00
|
|
|
public void setComponent(ITextComponent e)
|
2015-05-25 12:02:47 -07:00
|
|
|
{
|
|
|
|
|
if (e instanceof ChatComponentTranslation)
|
|
|
|
|
this.component = (ChatComponentTranslation)e;
|
|
|
|
|
else
|
|
|
|
|
this.component = new ChatComponentTranslation("%s", e);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-01 04:58:03 -08:00
|
|
|
public ITextComponent getComponent()
|
2015-05-25 12:02:47 -07:00
|
|
|
{
|
|
|
|
|
return this.component;
|
|
|
|
|
}
|
2012-10-28 06:58:23 -04:00
|
|
|
}
|