-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: notify clients immediately of team display name change
Needed to ensure command completion works and produces correct shortname FTBTeam/FTB-Mods-Issues#1457
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
common/src/main/java/dev/ftb/mods/ftbteams/net/NotifyTeamRenameMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.ftb.mods.ftbteams.net; | ||
|
||
import dev.architectury.networking.NetworkManager; | ||
import dev.ftb.mods.ftbteams.api.FTBTeamsAPI; | ||
import dev.ftb.mods.ftbteams.data.ClientTeamManagerImpl; | ||
import net.minecraft.core.UUIDUtil; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* Received on: CLIENT<br> | ||
* Sent by server when the display name property of a team is changed to make clients aware of the new shortname | ||
* for command completion purposes. | ||
* | ||
* @param teamId the unique team ID | ||
* @param newName the new display name | ||
*/ | ||
public record NotifyTeamRenameMessage(UUID teamId, String newName) implements CustomPacketPayload { | ||
public static final Type<NotifyTeamRenameMessage> TYPE = new Type<>(FTBTeamsAPI.rl("notify_team_rename")); | ||
|
||
public static final StreamCodec<FriendlyByteBuf, NotifyTeamRenameMessage> STREAM_CODEC = StreamCodec.composite( | ||
UUIDUtil.STREAM_CODEC, NotifyTeamRenameMessage::teamId, | ||
ByteBufCodecs.STRING_UTF8, NotifyTeamRenameMessage::newName, | ||
NotifyTeamRenameMessage::new | ||
); | ||
|
||
@Override | ||
public Type<NotifyTeamRenameMessage> type() { | ||
return TYPE; | ||
} | ||
|
||
public static void handle(NotifyTeamRenameMessage message, NetworkManager.PacketContext context) { | ||
context.queue(() -> { | ||
ClientTeamManagerImpl.getInstance().updateDisplayName(message.teamId, message.newName); | ||
}); | ||
} | ||
} |