/* * Minecraft Forge * Copyright (c) 2016-2020. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation version 2.1 * of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package net.minecraftforge.event; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.Cancelable; /** * ServerChatEvent is fired whenever a C01PacketChatMessage is processed.
* This event is fired via {@link ForgeHooks#onServerChatEvent(NetHandlerPlayServer, String, ITextComponent)}, * which is executed by the {@link NetHandlerPlayServer#processChatMessage(CPacketChatMessage)}
*
* {@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 net.minecraftforge.eventbus.api.Event { private final String message, username; private final ServerPlayerEntity player; private ITextComponent component; public ServerChatEvent(ServerPlayerEntity player, String message, ITextComponent component) { super(); this.message = message; this.player = player; this.username = player.getGameProfile().getName(); this.component = component; } public void setComponent(ITextComponent e) { this.component = e; } public ITextComponent getComponent() { return this.component; } public String getMessage() { return this.message; } public String getUsername() { return this.username; } public ServerPlayerEntity getPlayer() { return this.player; } }