1414
1515public class PlayerChatHelper {
1616
17+ static Version version ;
18+
1719 // 1.19
1820 private static Class <?> chatSenderClass ;
1921
@@ -35,6 +37,24 @@ public class PlayerChatHelper {
3537 private static Field chatTypeField ;
3638
3739 static {
40+ byte serverMajorVersion = ProtocolStringReplacer .getInstance ().getServerMajorVersion ();
41+ byte serverMinorVersion = ProtocolStringReplacer .getInstance ().getServerMinorVersion ();
42+ if (serverMajorVersion <= 18 ) {
43+ version = Version .V8_0_TO_V18_2 ;
44+ } else if (serverMajorVersion == 19 ){
45+ if (serverMinorVersion == 0 ) {
46+ version = Version .V19_0 ;
47+ } else if (serverMinorVersion <= 2 ) {
48+ version = Version .V19_1_TO_V19_2 ;
49+ } else if (serverMinorVersion == 3 ) {
50+ version = Version .V19_3 ;
51+ } else {
52+ version = Version .V19_4 ;
53+ }
54+ } else {
55+ version = Version .V19_4 ;
56+ }
57+
3858 try {
3959 messageBodyClass = MinecraftReflection .getMinecraftClass ("network.chat.SignedMessageBody" );
4060 } catch (Throwable ignored ) {}
@@ -249,7 +269,7 @@ public static WrappedChatComponent getTeamNameWrapped(Object object) {
249269 try {
250270 Object o = teamNameField .get (object );
251271 if (o == null ) {
252- return WrappedChatComponent . fromText ( "" ) ;
272+ return null ;
253273 }
254274 return WrappedChatComponent .fromHandle (o );
255275 } catch (IllegalAccessException e ) {
@@ -274,68 +294,100 @@ public static Class<?> getChatMessageTypeSubClass() {
274294 }
275295
276296 public static ChatType getChatTypeFromId (int id ) {
277- if (isLegacy ()) {
278- switch (id ) {
279- case 0 :
280- return ChatType .PLAYER_CHAT ;
281- case 1 :
282- return ChatType .SYSTEM_CHAT ;
283- case 2 :
284- return ChatType .GAME_INFO ;
285- case 3 :
286- return ChatType .SAY ;
287- case 4 :
288- return ChatType .MSG_INCOMING ;
289- case 5 :
290- return ChatType .TEAM_MSG_INCOMING ;
291- case 6 :
292- return ChatType .EMOTE ;
293- case 7 :
294- return ChatType .TELLRAW ;
295- default :
296- ProtocolStringReplacer .warn ("Not supported PlayerChatType when convert: " + id );
297- return ChatType .SYSTEM_CHAT ;
298- }
299- } else {
300- switch (id ) {
301- case 0 :
302- return ChatType .PLAYER_CHAT ;
303- case 1 :
304- return ChatType .SAY ;
305- case 2 :
306- return ChatType .MSG_INCOMING ;
307- case 3 :
308- return ChatType .MSG_OUTGOING ;
309- case 4 :
310- return ChatType .TEAM_MSG_INCOMING ;
311- case 5 :
312- return ChatType .TEAM_MSG_OUTGOING ;
313- case 6 :
314- return ChatType .EMOTE ;
315- case 7 :
316- return ChatType .TELLRAW ;
317- default :
318- ProtocolStringReplacer .warn ("Not supported PlayerChatType when convert: " + id );
319- return ChatType .SYSTEM_CHAT ;
320- }
297+ switch (version ) {
298+ case V8_0_TO_V18_2 :
299+ throw new AssertionError ();
300+ case V19_0 :
301+ switch (id ) {
302+ case 0 :
303+ return ChatType .PLAYER_CHAT ;
304+ case 1 :
305+ return ChatType .SYSTEM_CHAT ;
306+ case 2 :
307+ return ChatType .GAME_INFO ;
308+ case 3 :
309+ return ChatType .SAY ;
310+ case 4 :
311+ return ChatType .MSG_INCOMING ;
312+ case 5 :
313+ return ChatType .TEAM_MSG_INCOMING ;
314+ case 6 :
315+ return ChatType .EMOTE ;
316+ case 7 :
317+ return ChatType .TELLRAW ;
318+ default :
319+ ProtocolStringReplacer .warn ("Not supported PlayerChatType when convert: " + id );
320+ return ChatType .SYSTEM_CHAT ;
321+ }
322+ case V19_1_TO_V19_2 :
323+ switch (id ) {
324+ case 0 :
325+ return ChatType .PLAYER_CHAT ;
326+ case 1 :
327+ return ChatType .SAY ;
328+ case 2 :
329+ return ChatType .MSG_INCOMING ;
330+ case 3 :
331+ return ChatType .MSG_OUTGOING ;
332+ case 4 :
333+ return ChatType .TEAM_MSG_INCOMING ;
334+ case 5 :
335+ return ChatType .TEAM_MSG_OUTGOING ;
336+ case 6 :
337+ return ChatType .EMOTE ;
338+ case 7 :
339+ return ChatType .TELLRAW ;
340+ default :
341+ ProtocolStringReplacer .warn ("Not supported PlayerChatType when convert: " + id );
342+ return ChatType .SYSTEM_CHAT ;
343+ }
344+ case V19_3 :
345+ case V19_4 :
346+ default :
347+ switch (id ) {
348+ case 0 :
349+ return ChatType .PLAYER_CHAT ;
350+ case 1 :
351+ return ChatType .EMOTE ;
352+ case 2 :
353+ return ChatType .MSG_INCOMING ;
354+ case 3 :
355+ return ChatType .MSG_OUTGOING ;
356+ case 4 :
357+ return ChatType .SAY ;
358+ case 5 :
359+ return ChatType .TEAM_MSG_INCOMING ;
360+ case 6 :
361+ return ChatType .TEAM_MSG_OUTGOING ;
362+ case 7 :
363+ return ChatType .TELLRAW ;
364+ default :
365+ ProtocolStringReplacer .warn ("Not supported PlayerChatType when convert: " + id );
366+ return ChatType .SYSTEM_CHAT ;
367+ }
321368 }
322369 }
323370
324371 public enum ChatType {
325- PLAYER_CHAT (0 , 0 ),
326- SYSTEM_CHAT (1 , 1 ),
327- GAME_INFO (2 , -1 ),
328- SAY (3 , 2 ),
329- MSG_INCOMING (4 , 3 ),
330- MSG_OUTGOING (-1 , 4 ),
331- TEAM_MSG_INCOMING (5 , 5 ),
332- TEAM_MSG_OUTGOING (-1 , 6 ),
333- EMOTE (6 , 7 ),
334- TELLRAW (7 , 8 );
335-
336- ChatType (int legacyId , int newId ) {
337- // TODO
338- }
372+ PLAYER_CHAT (),
373+ SYSTEM_CHAT (),
374+ GAME_INFO (),
375+ SAY (),
376+ MSG_INCOMING (),
377+ MSG_OUTGOING (),
378+ TEAM_MSG_INCOMING (),
379+ TEAM_MSG_OUTGOING (),
380+ EMOTE (),
381+ TELLRAW ()
382+
383+ }
384+
385+ enum Version {
386+ V8_0_TO_V18_2 ,
387+ V19_0 ,
388+ V19_1_TO_V19_2 ,
389+ V19_3 ,
390+ V19_4
339391 }
340392
341393}
0 commit comments