mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
Add ClientChatReceivedEvent for system messages (#9284)
This commit is contained in:
1 parent
5946356f8e
commit
59ab01a559
4 files changed
+53
No files matched your search
@@ -72,10 +72,12 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.ChatTypeDecoration;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
@@ -974,6 +976,17 @@ public class ForgeHooksClient
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
private static final ChatTypeDecoration SYSTEM_CHAT_TYPE_DECORATION = new ChatTypeDecoration("forge.chatType.system", List.of(ChatTypeDecoration.Parameter.CONTENT), Style.EMPTY);
|
||||
private static final ChatType SYSTEM_CHAT_TYPE = new ChatType(SYSTEM_CHAT_TYPE_DECORATION, SYSTEM_CHAT_TYPE_DECORATION);
|
||||
private static final ChatType.Bound SYSTEM_CHAT_TYPE_BOUND = SYSTEM_CHAT_TYPE.bind(Component.literal("System"));
|
||||
|
||||
@Nullable
|
||||
public static Component onClientSystemChat(Component message, boolean overlay)
|
||||
{
|
||||
ClientChatReceivedEvent.System event = new ClientChatReceivedEvent.System(SYSTEM_CHAT_TYPE_BOUND, message, overlay);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String onClientSendMessage(String message)
|
||||
{
|
||||
|
||||
@@ -118,4 +118,33 @@ public class ClientChatReceivedEvent extends Event
|
||||
return this.playerChatMessage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a system chat message is received on the client.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the message is not displayed in the chat message window or in the overlay.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
public static class System extends ClientChatReceivedEvent
|
||||
{
|
||||
private final boolean overlay;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public System(ChatType.Bound boundChatType, Component message, boolean overlay)
|
||||
{
|
||||
super(boundChatType, message, Util.NIL_UUID);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether the message goes to the overlay}
|
||||
*/
|
||||
public boolean isOverlay()
|
||||
{
|
||||
return this.overlay;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user