2020import net .minecraft .util .Hand ;
2121
2222import java .lang .reflect .Array ;
23+ import org .apache .commons .codec .binary .Base64 ;
2324import java .util .*;
2425
2526public class Bookchat extends Module {
@@ -32,13 +33,21 @@ public Bookchat() {
3233 private final SettingGroup sgGeneral = this .settings .getDefaultGroup ();
3334 private final Setting <String > person = sgGeneral .add (new StringSetting .Builder ().name ("Person" ).description ("Person your chatting with" ).defaultValue ("" ).build ());
3435
36+ private final Setting <Boolean > encryption = sgGeneral .add (new BoolSetting .Builder ()
37+ .name ("encryption" )
38+ .description ("Encrypt the messages in base64." )
39+ .defaultValue (false )
40+ .build ()
41+ );
42+
3543 @ EventHandler
3644 private void onchat (SendMessageEvent event ){
37- String msg = mc . player . getEntityName () + " : " + event .message ;
45+ String msg = event .message ;
3846 if (mc .player .getMainHandStack ().getItem ().equals (Items .WRITABLE_BOOK )){
3947 event .cancel ();
40- info (msg );
41- mc .player .networkHandler .sendPacket (new BookUpdateC2SPacket (mc .player .getInventory ().selectedSlot , Collections .singletonList (msg ), Optional .empty ()));
48+ info (mc .player .getEntityName () + " : " + msg );
49+ String encrypted = Base64 .encodeBase64String (msg .getBytes ());
50+ mc .player .networkHandler .sendPacket (new BookUpdateC2SPacket (mc .player .getInventory ().selectedSlot , Collections .singletonList ((encryption .get () ? encrypted : msg )), Optional .empty ()));
4251 }
4352 }
4453
@@ -56,6 +65,7 @@ private void ontick(TickEvent.Pre event){
5665 PlayerEntity playerEntity = null ;
5766
5867 if (person .get ().isEmpty ()) return ;
68+ if (mc .world .getPlayers () == null ) return ;
5969 for (PlayerEntity p : mc .world .getPlayers ()){
6070 if (p .getEntityName ().equalsIgnoreCase (person .get ())){
6171 playerEntity = p ;
@@ -65,16 +75,22 @@ private void ontick(TickEvent.Pre event){
6575 if (playerEntity == null ) return ;
6676
6777 if (playerEntity .getMainHandStack ().getItem ().equals (Items .WRITABLE_BOOK )){
78+ if (playerEntity .getMainHandStack ().getNbt ().get ("pages" ).toString () == null ) return ;
6879 String text = playerEntity .getMainHandStack ().getNbt ().get ("pages" ).toString ()
6980 .replaceAll ("\\ ]" , "" )
7081 .replaceAll ("\\ [" , "" )
7182 .replaceAll ("\" " , "" )
7283 .replaceAll ("," , " " );
7384
85+ byte [] decodedBytes = Base64 .decodeBase64 (text );
86+ String decodedString = new String (decodedBytes );
87+
7488 if (Objects .equals (lasttext , text )) return ;
7589
90+ boolean isBase64 = Base64 .isBase64 (text .getBytes ());
91+
7692 lasttext = text ;
77- info (text );
93+ info (playerEntity . getEntityName () + " : " + ( isBase64 ? decodedString : text ) );
7894 }
7995 }
8096}
0 commit comments