1212import com .google .gson .Gson ;
1313import com .google .gson .JsonObject ;
1414import net .minecraft .ChatFormatting ;
15- import net .minecraft .client .Minecraft ;
1615//? if >= 1.20.2 {
16+ import net .minecraft .client .Minecraft ;
1717import net .minecraft .network .RegistryFriendlyByteBuf ;
18- //?} else {
18+ //?} else {
1919/*import net.minecraft.network.FriendlyByteBuf;
20- */ //?}
20+ *///?}
2121import net .minecraft .network .chat .Component ;
2222import net .minecraft .network .chat .MutableComponent ;
2323import net .minecraft .resources .Identifier ;
2424import net .minecraft .world .entity .player .Player ;
2525
26- public record ConfigStatusToClientPacket (String config ) implements Packet <ConfigStatusToClientPacket >
26+ import java .util .UUID ;
27+
28+ public record ConfigStatusToClientPacket (String config , UUID playerId ) implements Packet <ConfigStatusToClientPacket >
2729{
2830 private static final Gson GSON = new Gson ();
2931 public static final Identifier ID = Structurify .makeId ("config_status_to_client_packet" );
@@ -32,7 +34,8 @@ public record ConfigStatusToClientPacket(String config) implements Packet<Config
3234 public static void sendToClient (StructurifyConfig config , Player player ) {
3335 MessageHandler .DEFAULT_CHANNEL .sendToPlayer (
3436 new ConfigStatusToClientPacket (
35- GSON .toJson (StructurifyConfigSerializer .save (config ))
37+ GSON .toJson (StructurifyConfigSerializer .save (config )),
38+ player .getUUID ()
3639 ),
3740 player
3841 );
@@ -51,43 +54,57 @@ public Identifier id() {
5154 }
5255
5356 @ Override
54- public Runnable handle (final ConfigStatusToClientPacket packet ) {
57+ public Runnable handle (
58+ final ConfigStatusToClientPacket packet
59+ ) {
5560 return () -> {
5661 JsonObject serverConfigJson ;
57- Player player = Minecraft .getInstance ().player ;
62+ var player = Minecraft .getInstance ().level . getPlayerByUUID ( packet . playerId ) ;
5863
5964 try {
6065 serverConfigJson = GSON .fromJson (packet .config (), JsonObject .class );
6166 } catch (Throwable e ) {
6267 Structurify .getLogger ().error ("Failed to read config status from server." , e );
6368
64- if (player != null ) {
65- VersionedPlayer .sendSystemMessage (player , Component .literal ("Failed to check the Structurify config status." ));
66- }
69+ VersionedPlayer .sendSystemMessage (
70+ player ,
71+ Component .literal ("Failed to check the Structurify config status." )
72+ );
6773
6874 return ;
6975 }
7076
71- if (player != null ) {
72- VersionedPlayer .sendSystemMessage (player , describeConfigStatus (Structurify .getConfig (), serverConfigJson ));
73- }
77+ VersionedPlayer .sendSystemMessage (
78+ player ,
79+ describeConfigStatus (
80+ Structurify .getConfig (),
81+ serverConfigJson
82+ )
83+ );
7484 };
7585 }
7686
7787 //? if >= 1.20.2 {
7888 public ConfigStatusToClientPacket decode (final RegistryFriendlyByteBuf buf ) {
79- return new ConfigStatusToClientPacket (buf .readUtf ());
89+ return new ConfigStatusToClientPacket (buf .readUtf (), buf . readUUID () );
8090 }
8191
82- public void encode (final ConfigStatusToClientPacket packet , final RegistryFriendlyByteBuf buf ) {
92+ public void encode (
93+ final ConfigStatusToClientPacket packet ,
94+ final RegistryFriendlyByteBuf buf
95+ ) {
8396 buf .writeUtf (packet .config ());
97+ buf .writeUUID (packet .playerId ());
8498 }
8599 //?} else {
86100 /*public ConfigStatusToClientPacket decode(final FriendlyByteBuf buf) {
87101 return new ConfigStatusToClientPacket(buf.readUtf());
88102 }
89103
90- public void encode(final ConfigStatusToClientPacket packet, final FriendlyByteBuf buf) {
104+ public void encode(
105+ final ConfigStatusToClientPacket packet,
106+ final FriendlyByteBuf buf
107+ ) {
91108 buf.writeUtf(packet.config());
92109 }
93110
@@ -105,30 +122,24 @@ private static Component describeConfigStatus(
105122 String localHash = StructurifyConfigSerializer .computeConfigHash (localConfig );
106123 String serverHash = StructurifyConfigSerializer .hashConfigJson (serverConfigJson );
107124
108- String localVersion = PlatformHooks .PLATFORM_HELPER .getModVersion ();
109- String serverVersion = serverConfigJson .has (
110- StructurifyConfigSerializer .CONFIG_VERSION_PROPERTY
111- )
112- ? serverConfigJson .get (
113- StructurifyConfigSerializer .CONFIG_VERSION_PROPERTY
114- ).getAsString ()
115- :"unknown" ;
116-
117125 boolean isSynchronized = localHash .equals (serverHash );
118126
119127 MutableComponent message = isSynchronized
120128 ? Component .literal ("Structurify config is synchronized with the server." )
121129 .withStyle (ChatFormatting .GREEN )
122- :Component .literal ("Structurify config differs from the server." )
130+ : Component .literal ("Structurify config differs from the server." )
123131 .withStyle (ChatFormatting .RED );
124132
133+ String localHashShort = localHash .substring (0 , Math .min (16 , localHash .length ()));
134+ String serverHashShort = serverHash .substring (0 , Math .min (16 , serverHash .length ()));
135+
125136 message .append (
126- Component .literal ("\n Local version: " + localVersion )
137+ Component .literal ("\n Local version: " + localHashShort )
127138 .withStyle (ChatFormatting .GRAY )
128139 );
129140
130141 message .append (
131- Component .literal ("\n Server version: " + serverVersion )
142+ Component .literal ("\n Server version: " + serverHashShort )
132143 .withStyle (ChatFormatting .GRAY )
133144 );
134145
0 commit comments