44import ml .peya .mc .exception .*;
55import net .minecraft .client .*;
66import net .minecraft .crash .*;
7+ import net .minecraft .event .*;
78import net .minecraft .util .*;
89import net .minecraftforge .client .*;
910import net .minecraftforge .client .event .*;
1314import net .minecraftforge .fml .common .eventhandler .*;
1415import net .minecraftforge .fml .relauncher .*;
1516
17+ import javax .swing .text .*;
18+ import java .awt .*;
19+ import java .awt .datatransfer .*;
20+ import java .util .*;
1621import java .util .logging .*;
22+ import java .util .regex .*;
1723
1824@ Mod (modid = PeyangRawChatViewer .MOD_ID ,
1925 name = PeyangRawChatViewer .MOD_NAME ,
@@ -43,6 +49,7 @@ public void preInit(FMLPreInitializationEvent e)
4349 public void init (FMLInitializationEvent e )
4450 {
4551 ClientCommandHandler .instance .registerCommand (new ToggleCommands ());
52+ ClientCommandHandler .instance .registerCommand (new PeyangDraftCopyUrl ());
4653 logger = Logger .getLogger (MOD_ID );
4754 MinecraftForge .EVENT_BUS .register (this );
4855 }
@@ -61,8 +68,21 @@ public void chatReceive(ClientChatReceivedEvent e)
6168 IChatComponent chatComponent = e .message ;
6269 //logger.info(e.message.getFormattedText());
6370 logger .info (IChatComponent .Serializer .componentToJson (chatComponent ));
64- String json = IChatComponent .Serializer .componentToJson (chatComponent ).replace ("§" , "[Section]" );
65- Minecraft .getMinecraft ().thePlayer .addChatMessage (new ChatComponentText (getRawPrefix () + EnumChatFormatting .WHITE + " " + json ));
71+ String json = IChatComponent .Serializer .componentToJson (chatComponent );
72+ json = json .replace ("§" , "[Section]" );
73+ ChatComponentText response = new ChatComponentText (getRawPrefix () + EnumChatFormatting .WHITE + " " + json );
74+ ChatStyle style = response .getChatStyle ();
75+
76+ IChatComponent hoverTxt = new ChatComponentText (EnumChatFormatting .YELLOW + "Click to send !" );
77+ HoverEvent hoverEvt = new HoverEvent (HoverEvent .Action .SHOW_TEXT , hoverTxt );
78+
79+ ClickEvent clickEvt = new ClickEvent (ClickEvent .Action .RUN_COMMAND , "/zzzpeyangdraftcopysandopenurl " + String .join (" " , splitByLength (json )));
80+ style .setChatHoverEvent (hoverEvt );
81+ style .setChatClickEvent (clickEvt );
82+
83+ response .setChatStyle (style );
84+
85+ Minecraft .getMinecraft ().thePlayer .addChatMessage (response );
6686 }
6787
6888 public static String getRawPrefix ()
@@ -71,4 +91,13 @@ public static String getRawPrefix()
7191 EnumChatFormatting .BLUE + "RAWCHAT" +
7292 EnumChatFormatting .AQUA + "]" ;
7393 }
94+
95+ public static ArrayList <String > splitByLength (String str )
96+ {
97+ Matcher matcher = Pattern .compile (".{1,30}" ).matcher (str );
98+ ArrayList <String > response = new ArrayList <>();
99+ while (matcher .find ())
100+ response .add (str .substring (matcher .start (), matcher .end ()));
101+ return response ;
102+ }
74103}
0 commit comments