Skip to content

Commit 2bd300b

Browse files
SawFowlFaithcaio
authored andcommitted
Update PlayerListMixin.java
Fix for the `PlayerChatEvent.Submit` event. Now you can change messages in this event and it will work correctly.
1 parent 6f65c94 commit 2bd300b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/mixins/java/org/spongepowered/common/mixin/core/server/players/PlayerListMixin.java

100644100755
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,15 @@ public abstract class PlayerListMixin implements PlayerListBridge {
645645
boundChatType = event.target().map(SpongeAdventure::asVanilla).map(boundChatType::withTargetName).orElse(boundChatType);
646646

647647
filter = event.filter().map(f -> $$1.and((Predicate) f)).orElse($$1);
648-
if (!isTrusted && event.message() != event.originalMessage()) {
648+
if (event.message() != event.originalMessage()) {
649649
final net.minecraft.network.chat.Component customMessage = SpongeAdventure.asVanilla(event.message());
650-
// TODO does this work?
651-
var systemMessage = PlayerChatMessage.system(customMessage.getString()).withUnsignedContent(customMessage);
652-
this.shadow$broadcastChatMessage(systemMessage, filter, $$2, boundChatType);
650+
// It works!
651+
// If the message is changed, the player will be shown the standard message change notification for such situations.
652+
// The value of `isTrusted` will always be `true` when `online-mode=true`.
653+
// If `online-mode=false`, then `isTrusted` will also have a value of `false`.
654+
// When `online-mode=false`, the player is not shown a notification when the server changes the message.
655+
var modifiedMessage = new PlayerChatMessage($$0.link(), $$0.signature(), $$0.signedBody(), customMessage, $$0.filterMask());
656+
this.shadow$broadcastChatMessage(modifiedMessage, filter, $$2, boundChatType);
653657
return;
654658
}
655659
}

0 commit comments

Comments
 (0)