mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 02:55:17 +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
@@ -30,3 +30,12 @@
|
||||
this.m_241119_(p_251766_, component);
|
||||
}
|
||||
}
|
||||
@@ -159,6 +_,8 @@
|
||||
|
||||
public void m_240494_(Component p_240522_, boolean p_240642_) {
|
||||
if (!this.f_240348_.f_91066_.m_231833_().m_231551_() || !this.f_240348_.m_91246_(this.m_240473_(p_240522_))) {
|
||||
+ p_240522_ = net.minecraftforge.client.ForgeHooksClient.onClientSystemChat(p_240522_, p_240642_);
|
||||
+ if (p_240522_ == null) return;
|
||||
if (p_240642_) {
|
||||
this.f_240348_.f_91065_.m_93063_(p_240522_, false);
|
||||
} else {
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,5 +220,7 @@
|
||||
"forge.experimentalsettings.tooltip": "This world uses experimental settings, which could stop working at any time.",
|
||||
"forge.selectWorld.backupWarning.experimental.additional" : "This message will not show again for this world.",
|
||||
|
||||
"forge.chatType.system": "{0}",
|
||||
|
||||
"pack.forge.description": "Forge resource pack"
|
||||
}
|
||||
Reference in new issue
Block a user