@@ -628,23 +628,24 @@ public static MessageEvent showAchievement(String id) {
628628 private static class ReflectionHelper {
629629
630630 private static final String version ;
631- private static Class <?> craftPlayer ;
632631 private static Constructor <?> chatComponentText ;
632+
633633 private static Class <?> packetPlayOutChat ;
634634 private static Field packetPlayOutChatComponent ;
635635 private static Field packetPlayOutChatMessageType ;
636636 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+
640645 private static Field connection ;
641646 private static MethodHandle GET_HANDLE ;
642647 private static MethodHandle SEND_PACKET ;
643648 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 ;
648649 private static boolean SETUP ;
649650 private static int MAJOR_VER = -1 ;
650651
@@ -655,14 +656,14 @@ private static class ReflectionHelper {
655656 try {
656657 MAJOR_VER = Integer .parseInt (version .split ("_" )[1 ]);
657658
658- craftPlayer = getClass ("{obc}.entity.CraftPlayer" );
659+ final Class <?> craftPlayer = getClass ("{obc}.entity.CraftPlayer" );
659660 Method getHandle = craftPlayer .getMethod ("getHandle" );
660661 connection = getHandle .getReturnType ().getField ("playerConnection" );
661662 Method sendPacket = connection .getType ().getMethod ("sendPacket" , getClass ("{nms}.Packet" ));
662663
663664 chatComponentText = getClass ("{nms}.ChatComponentText" ).getConstructor (String .class );
664665
665- iChatBaseComponent = getClass ("{nms}.IChatBaseComponent" );
666+ final Class <?> iChatBaseComponent = getClass ("{nms}.IChatBaseComponent" );
666667
667668 Method stringToChat ;
668669
@@ -680,18 +681,21 @@ private static class ReflectionHelper {
680681 packetPlayOutChatComponent = getField (packetPlayOutChat , "a" );
681682 packetPlayOutChatMessageType = getField (packetPlayOutChat , "b" );
682683 packetPlayOutChatUuid = MAJOR_VER >= 16 ? getField (packetPlayOutChat , "c" ) : null ;
683- packetPlayOutTitle = getClass ("{nms}.PacketPlayOutTitle" );
684684
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 );
686690
687691 enumActionTitle = titleAction .getField ("TITLE" ).get (null );
688692 enumActionSubtitle = titleAction .getField ("SUBTITLE" ).get (null );
689693
690694 if (MAJOR_VER >= 12 ) {
691695 Method getChatMessageType = getClass ("{nms}.ChatMessageType" ).getMethod ("a" , byte .class );
692696
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 );
695699 }
696700
697701 SETUP = true ;
@@ -746,7 +750,7 @@ static Object createTitlePacket(String message) {
746750 assertIsSetup ();
747751
748752 try {
749- return packetPlayOutTitle . getConstructor ( titleAction , iChatBaseComponent ) .newInstance (enumActionTitle , fromJson (message ));
753+ return titlePacketConstructor .newInstance (enumActionTitle , fromJson (message ));
750754 } catch (Exception e ) {
751755 e .printStackTrace ();
752756 return null ;
@@ -757,7 +761,7 @@ static Object createTitleTimesPacket(int fadeIn, int stay, int fadeOut) {
757761 assertIsSetup ();
758762
759763 try {
760- return packetPlayOutTitle . getConstructor ( int . class , int . class , int . class ) .newInstance (fadeIn , stay , fadeOut );
764+ return titleTimesPacketConstructor .newInstance (fadeIn , stay , fadeOut );
761765 } catch (Exception e ) {
762766 e .printStackTrace ();
763767 return null ;
@@ -768,7 +772,7 @@ static Object createSubtitlePacket(String message) {
768772 assertIsSetup ();
769773
770774 try {
771- return packetPlayOutTitle . getConstructor ( titleAction , iChatBaseComponent ) .newInstance (enumActionSubtitle , fromJson (message ));
775+ return titlePacketConstructor .newInstance (enumActionSubtitle , fromJson (message ));
772776 } catch (Exception e ) {
773777 e .printStackTrace ();
774778 return null ;
@@ -785,10 +789,10 @@ private static void setType(Object chatPacket, byte type) {
785789
786790 switch (type ) {
787791 case 1 :
788- setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessage );
792+ setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessageTypeMessage );
789793 break ;
790794 case 2 :
791- setFieldValue (packetPlayOutChatMessageType , chatPacket , enumActionbarMessage );
795+ setFieldValue (packetPlayOutChatMessageType , chatPacket , enumChatMessageTypeActionbar );
792796 break ;
793797 default :
794798 throw new IllegalArgumentException ("type must be 1 or 2" );
0 commit comments