2016-06-22 23:49:47 -04:00
|
|
|
/*
|
2022-04-14 03:42:00 +00:00
|
|
|
* Copyright (c) Forge Development LLC and contributors
|
2022-02-28 13:41:23 -08:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-only
|
2016-06-22 23:49:47 -04:00
|
|
|
*/
|
|
|
|
|
|
2012-10-28 06:58:23 -04:00
|
|
|
package net.minecraftforge.event;
|
|
|
|
|
|
2021-11-26 05:09:56 +08:00
|
|
|
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
2021-07-17 00:08:49 -05:00
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
|
import net.minecraft.network.chat.Component;
|
2021-11-26 05:09:56 +08:00
|
|
|
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
|
|
|
import net.minecraftforge.common.ForgeHooks;
|
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2018-06-10 21:12:46 -04:00
|
|
|
import net.minecraftforge.eventbus.api.Cancelable;
|
2022-06-07 16:03:52 -05:00
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2022-06-07 15:31:26 -05:00
|
|
|
|
2014-07-06 16:07:49 -04:00
|
|
|
/**
|
|
|
|
|
* ServerChatEvent is fired whenever a C01PacketChatMessage is processed. <br>
|
2022-06-07 15:31:26 -05:00
|
|
|
* This event is fired via {@link ForgeHooks#onServerChatEvent(ServerPlayer, String, Component)},
|
2021-11-26 05:09:56 +08:00
|
|
|
* which is executed by the {@link ServerGamePacketListenerImpl#handleChat(ServerboundChatPacket)}<br>
|
2014-07-06 16:07:49 -04:00
|
|
|
* <br>
|
2022-06-07 15:31:26 -05:00
|
|
|
* {@link #username} contains the username of the player sending the chat message, unless fired from the server, where it is null.<br>
|
2014-07-06 16:07:49 -04:00
|
|
|
* {@link #message} contains the message being sent.<br>
|
2022-06-07 15:31:26 -05:00
|
|
|
* {@link #player} the instance of ServerPlayer for the player sending the chat message, or null when fired from the server.<br>
|
|
|
|
|
* {@link #component} contains the instance of Component for the sent message.<br>
|
2014-07-06 16:07:49 -04:00
|
|
|
* <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
|
2022-06-07 16:03:52 -05:00
|
|
|
public class ServerChatEvent extends Event
|
2013-02-15 03:22:59 -08:00
|
|
|
{
|
2022-06-07 15:31:26 -05:00
|
|
|
private final String message;
|
2022-06-07 16:03:52 -05:00
|
|
|
@Nullable
|
|
|
|
|
private final String username;
|
|
|
|
|
@Nullable
|
|
|
|
|
private final ServerPlayer player;
|
2021-07-17 00:08:49 -05:00
|
|
|
private Component component;
|
2022-06-07 16:03:52 -05:00
|
|
|
|
2022-06-07 15:31:26 -05:00
|
|
|
public ServerChatEvent(@Nullable ServerPlayer player, String message, Component component)
|
2012-10-28 06:58:23 -04:00
|
|
|
{
|
|
|
|
|
super();
|
|
|
|
|
this.message = message;
|
|
|
|
|
this.player = player;
|
2022-06-07 15:31:26 -05:00
|
|
|
this.username = player != null ? player.getGameProfile().getName() : null;
|
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
|
|
|
|
2021-07-17 00:08:49 -05:00
|
|
|
public void setComponent(Component e)
|
2015-05-25 12:02:47 -07:00
|
|
|
{
|
2016-03-01 20:42:36 -08:00
|
|
|
this.component = e;
|
2015-05-25 12:02:47 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-17 00:08:49 -05:00
|
|
|
public Component getComponent()
|
2015-05-25 12:02:47 -07:00
|
|
|
{
|
|
|
|
|
return this.component;
|
|
|
|
|
}
|
2016-03-01 20:42:36 -08:00
|
|
|
|
|
|
|
|
public String getMessage() { return this.message; }
|
2022-06-07 15:31:26 -05:00
|
|
|
public @Nullable String getUsername() { return this.username; }
|
|
|
|
|
public @Nullable ServerPlayer getPlayer() { return this.player; }
|
2012-10-28 06:58:23 -04:00
|
|
|
}
|