mc-forge/src/main/java/net/minecraftforge/event/ServerChatEvent.java

85 lines
2.3 KiB
Java
Raw Normal View History

/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event;
import java.util.Objects;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge;
2018-06-10 21:12:46 -04:00
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.ApiStatus;
Forge 1.19 * Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <curle@gemwire.uk> Co-authored-by: sciwhiz12 <arnoldnunag12@gmail.com> Signed-off-by: SizableShrimp <sizableshrimp@sizableshrimp.me>
2022-06-07 15:31:26 -05:00
/**
* This event is fired whenever a {@link ServerboundChatPacket} is received from a client
* who has submitted their chat message.
* <p>
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* If the event is cancelled, the message will not be sent to clients.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
@Cancelable
public final class ServerChatEvent extends Event
{
private final ServerPlayer player;
private final String username;
private final String rawText;
private Component message;
@ApiStatus.Internal
public ServerChatEvent(ServerPlayer player, String rawText, Component message)
{
this.player = player;
this.username = player.getGameProfile().getName();
this.rawText = rawText;
this.message = message;
}
/**
* {@return the player who initiated the chat action}
*/
public ServerPlayer getPlayer()
{
return this.player;
}
/**
* {@return the username of the player who initiated the chat action}
*/
public String getUsername()
{
return this.username;
}
/**
* {@return the original raw text of the player chat message}
*/
public String getRawText()
{
return this.rawText;
}
/**
* Set the message to be sent to the relevant clients.
*/
public void setMessage(Component message)
{
this.message = Objects.requireNonNull(message);
}
2016-03-01 20:42:36 -08:00
/**
* {@return the message that will be sent to the relevant clients, if the event is not cancelled}
*/
public Component getMessage()
{
return this.message;
}
}