@@ -628,23 +628,24 @@ public static MessageEvent showAchievement(String id) {
628
628
private static class ReflectionHelper {
629
629
630
630
private static final String version ;
631
- private static Class <?> craftPlayer ;
632
631
private static Constructor <?> chatComponentText ;
632
+
633
633
private static Class <?> packetPlayOutChat ;
634
634
private static Field packetPlayOutChatComponent ;
635
635
private static Field packetPlayOutChatMessageType ;
636
636
private static Field packetPlayOutChatUuid ;
637
- private static Class <?> packetPlayOutTitle ;
638
- private static Class <?> iChatBaseComponent ;
639
- private static Class <?> titleAction ;
637
+ private static Object enumChatMessageTypeMessage ;
638
+ private static Object enumChatMessageTypeActionbar ;
639
+
640
+ private static Constructor <?> titlePacketConstructor ;
641
+ private static Constructor <?> titleTimesPacketConstructor ;
642
+ private static Object enumActionTitle ;
643
+ private static Object enumActionSubtitle ;
644
+
640
645
private static Field connection ;
641
646
private static MethodHandle GET_HANDLE ;
642
647
private static MethodHandle SEND_PACKET ;
643
648
private static MethodHandle STRING_TO_CHAT ;
644
- private static Object enumActionTitle ;
645
- private static Object enumActionSubtitle ;
646
- private static Object enumChatMessage ;
647
- private static Object enumActionbarMessage ;
648
649
private static boolean SETUP ;
649
650
private static int MAJOR_VER = -1 ;
650
651
@@ -655,14 +656,14 @@ private static class ReflectionHelper {
655
656
try {
656
657
MAJOR_VER = Integer .parseInt (version .split ("_" )[1 ]);
657
658
658
- craftPlayer = getClass ("{obc}.entity.CraftPlayer" );
659
+ final Class <?> craftPlayer = getClass ("{obc}.entity.CraftPlayer" );
659
660
Method getHandle = craftPlayer .getMethod ("getHandle" );
660
661
connection = getHandle .getReturnType ().getField ("playerConnection" );
661
662
Method sendPacket = connection .getType ().getMethod ("sendPacket" , getClass ("{nms}.Packet" ));
662
663
663
664
chatComponentText = getClass ("{nms}.ChatComponentText" ).getConstructor (String .class );
664
665
665
- iChatBaseComponent = getClass ("{nms}.IChatBaseComponent" );
666
+ final Class <?> iChatBaseComponent = getClass ("{nms}.IChatBaseComponent" );
666
667
667
668
Method stringToChat ;
668
669
@@ -680,18 +681,21 @@ private static class ReflectionHelper {
680
681
packetPlayOutChatComponent = getField (packetPlayOutChat , "a" );
681
682
packetPlayOutChatMessageType = getField (packetPlayOutChat , "b" );
682
683
packetPlayOutChatUuid = MAJOR_VER >= 16 ? getField (packetPlayOutChat , "c" ) : null ;
683
- packetPlayOutTitle = getClass ("{nms}.PacketPlayOutTitle" );
684
684
685
- titleAction = getClass ("{nms}.PacketPlayOutTitle$EnumTitleAction" );
685
+ Class <?> packetPlayOutTitle = getClass ("{nms}.PacketPlayOutTitle" );
686
+ Class <?> titleAction = getClass ("{nms}.PacketPlayOutTitle$EnumTitleAction" );
687
+
688
+ titlePacketConstructor = packetPlayOutTitle .getConstructor (titleAction , iChatBaseComponent );
689
+ titleTimesPacketConstructor = packetPlayOutTitle .getConstructor (int .class , int .class , int .class );
686
690
687
691
enumActionTitle = titleAction .getField ("TITLE" ).get (null );
688
692
enumActionSubtitle = titleAction .getField ("SUBTITLE" ).get (null );
689
693
690
694
if (MAJOR_VER >= 12 ) {
691
695
Method getChatMessageType = getClass ("{nms}.ChatMessageType" ).getMethod ("a" , byte .class );
692
696
693
- enumChatMessage = getChatMessageType .invoke (null , (byte ) 1 );
694
- enumActionbarMessage = getChatMessageType .invoke (null , (byte ) 2 );
697
+ enumChatMessageTypeMessage = getChatMessageType .invoke (null , (byte ) 1 );
698
+ enumChatMessageTypeActionbar = getChatMessageType .invoke (null , (byte ) 2 );
695
699
}
696
700
697
701
SETUP = true ;
@@ -746,7 +750,7 @@ static Object createTitlePacket(String message) {
746
750
assertIsSetup ();
747
751
748
752
try {
749
- return packetPlayOutTitle . getConstructor ( titleAction , iChatBaseComponent ) .newInstance (enumActionTitle , fromJson (message ));
753
+ return titlePacketConstructor .newInstance (enumActionTitle , fromJson (message ));
750
754
} catch (Exception e ) {
751
755
e .printStackTrace ();
752
756
return null ;
@@ -757,7 +761,7 @@ static Object createTitleTimesPacket(int fadeIn, int stay, int fadeOut) {
757
761
assertIsSetup ();
758
762
759
763
try {
760
- return packetPlayOutTitle . getConstructor ( int . class , int . class , int . class ) .newInstance (fadeIn , stay , fadeOut );
764
+ return titleTimesPacketConstructor .newInstance (fadeIn , stay , fadeOut );
761
765
} catch (Exception e ) {
762
766
e .printStackTrace ();
763
767
return null ;
@@ -768,7 +772,7 @@ static Object createSubtitlePacket(String message) {
768
772
assertIsSetup ();
769
773
770
774
try {
771
- return packetPlayOutTitle . getConstructor ( titleAction , iChatBaseComponent ) .newInstance (enumActionSubtitle , fromJson (message ));
775
+ return titlePacketConstructor .newInstance (enumActionSubtitle , fromJson (message ));
772
776
} catch (Exception e ) {
773
777
e .printStackTrace ();
774
778
return null ;
@@ -785,10 +789,10 @@ private static void setType(Object chatPacket, byte type) {
785
789
786
790
switch (type ) {
787
791
case 1 :
788
- setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessage );
792
+ setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessageTypeMessage );
789
793
break ;
790
794
case 2 :
791
- setFieldValue (packetPlayOutChatMessageType , chatPacket , enumActionbarMessage );
795
+ setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessageTypeActionbar );
792
796
break ;
793
797
default :
794
798
throw new IllegalArgumentException ("type must be 1 or 2" );
0 commit comments