11package com .coflnet ;
22
33import CoflCore .CoflCore ;
4+ import CoflCore .classes .AuctionItem ;
45import CoflCore .classes .ChatMessage ;
56import CoflCore .CoflSkyCommand ;
6- import CoflCore .events .OnChatMessageReceive ;
7- import CoflCore .events .OnModChatMessage ;
8- import CoflCore .events .OnWriteToChatReceive ;
7+ import CoflCore .classes .Flip ;
8+ import CoflCore .classes .Sound ;
9+ import CoflCore .commands .CommandType ;
10+ import CoflCore .commands .JsonStringCommand ;
11+ import CoflCore .commands .models .ChatMessageData ;
12+ import CoflCore .commands .models .FlipData ;
13+ import CoflCore .commands .models .SoundData ;
14+ import CoflCore .events .*;
15+ import CoflCore .handlers .EventRegistry ;
16+ import CoflCore .network .WSClient ;
917import com .coflnet .gui .RenderUtils ;
1018import com .coflnet .gui .cofl .CoflBinGUI ;
1119import com .coflnet .gui .tfm .TfmBinGUI ;
20+ import com .google .gson .Gson ;
21+ import com .google .gson .GsonBuilder ;
22+ import com .google .gson .JsonObject ;
23+ import com .google .gson .JsonParser ;
24+ import com .google .gson .reflect .TypeToken ;
25+ import com .mojang .authlib .minecraft .client .ObjectMapper ;
1226import com .mojang .brigadier .arguments .StringArgumentType ;
1327import net .fabricmc .api .ClientModInitializer ;
1428import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
1832import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
1933import net .fabricmc .fabric .api .client .networking .v1 .ClientPlayConnectionEvents ;
2034import net .fabricmc .fabric .api .client .screen .v1 .ScreenEvents ;
35+ import net .fabricmc .fabric .api .message .v1 .ServerMessageEvents ;
2136import net .fabricmc .loader .api .FabricLoader ;
2237import net .minecraft .client .MinecraftClient ;
38+ import net .minecraft .client .gui .screen .ingame .BookScreen ;
2339import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
2440import net .minecraft .client .option .KeyBinding ;
2541import net .minecraft .client .util .InputUtil ;
2642import net .minecraft .item .Items ;
43+ import net .minecraft .text .ClickEvent ;
2744import net .minecraft .text .Text ;
45+ import org .apache .logging .log4j .core .jackson .Log4jJsonObjectMapper ;
46+ import org .greenrobot .eventbus .EventBus ;
2847import org .greenrobot .eventbus .Subscribe ;
2948import org .lwjgl .glfw .GLFW ;
49+
50+ import java .awt .event .KeyEvent ;
3051import java .nio .file .Path ;
52+ import java .time .LocalDateTime ;
53+ import java .util .ArrayList ;
54+ import java .util .concurrent .ExecutorService ;
55+ import java .util .concurrent .Executors ;
56+ import java .util .concurrent .LinkedBlockingQueue ;
57+ import java .util .regex .Pattern ;
3158
3259import static com .coflnet .Utils .ChatComponent ;
3360
3461public class CoflModClient implements ClientModInitializer {
3562 private KeyBinding bestflipsKeyBinding ;
63+
64+ public static long LastClick = System .currentTimeMillis ();
65+ public static final ExecutorService chatThreadPool = Executors .newFixedThreadPool (2 );
66+ public static final ExecutorService tickThreadPool = Executors .newFixedThreadPool (2 );
67+ public static long LastViewAuctionInvocation = Long .MIN_VALUE ;
68+ public static String LastViewAuctionUUID = null ;
69+ public static Pattern chatpattern = Pattern .compile ("a^" , 2 );
70+ private static LinkedBlockingQueue <String > chatBatch = new LinkedBlockingQueue ();
71+ private static LocalDateTime lastBatchStart = LocalDateTime .now ();
72+
73+ private String username = "" ;
74+ private static String flipId = "" ;
75+ private static Gson gson = new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ().create ();
3676 @ Override
3777 public void onInitializeClient () {
38- String username = MinecraftClient .getInstance ().getSession ().getUsername ();
78+ username = MinecraftClient .getInstance ().getSession ().getUsername ();
3979 Path configDir = FabricLoader .getInstance ().getConfigDir ();
4080 CoflCore cofl = new CoflCore ();
4181 cofl .init (configDir );
@@ -53,22 +93,26 @@ public void onInitializeClient() {
5393 ));
5494
5595 ClientTickEvents .END_CLIENT_TICK .register (client -> {
56- while (bestflipsKeyBinding .wasPressed ()) {
57- //client.player.sendMessage(Text.literal(), false );
58- CoflCore . flipHandler . fds . CurrentFlips ( );
96+ if (bestflipsKeyBinding .wasPressed ()) {
97+ System . out . println ( "Anz Flips: " + CoflCore . flipHandler . fds . CurrentFlips () );
98+ onOpenBestFlip ( username , true );
5999 }
60100 });
61101
62102 ClientPlayConnectionEvents .JOIN .register ((handler , sender , server ) -> {
63103 if (MinecraftClient .getInstance () != null && MinecraftClient .getInstance ().getCurrentServerEntry () != null && MinecraftClient .getInstance ().getCurrentServerEntry ().address .contains ("hypixel.net" )){
64104 System .out .println ("Connected to Hypixel" );
105+ username = MinecraftClient .getInstance ().getSession ().getUsername ();
65106 }
66107 });
67108
68109 ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) -> {
69110 dispatcher .register (ClientCommandManager .literal ("cofl" )
70111 .then (ClientCommandManager .argument ("args" , StringArgumentType .greedyString ()).executes (context -> {
71112 String [] args = context .getArgument ("args" , String .class ).split (" " );
113+ if (args [0 ].compareToIgnoreCase ("openauctiongui" ) == 0 ){
114+ flipId = args [1 ];
115+ } else flipId = "" ;
72116 CoflSkyCommand .processCommand (args ,username );
73117 return 1 ;
74118 })));
@@ -77,28 +121,42 @@ public void onInitializeClient() {
77121 ScreenEvents .AFTER_INIT .register ((client , screen , scaledWidth , scaledHeight ) -> {
78122 if (screen instanceof GenericContainerScreen gcs ) {
79123 System .out .println (gcs .getTitle ().getString ());
80- ScreenEvents .beforeRender (screen ).register ((screen1 , drawContext , a , b , c ) -> {
81- GenericContainerScreen gcs1 = (GenericContainerScreen ) screen1 ;
82- if (CoflCore .config .purchaseOverlay != null && gcs .getTitle () != null
83- && (gcs .getTitle ().getString ().contains ("BIN Auction View" )
84- && gcs .getScreenHandler ().getInventory ().size () == 9 * 6
85- || gcs .getTitle ().getString ().contains ("Confirm Purchase" )
86- && gcs .getScreenHandler ().getInventory ().size () == 9 * 3 )
87- ) {
88- if (!(client .currentScreen instanceof CoflBinGUI || client .currentScreen instanceof TfmBinGUI )) {
89- switch (CoflCore .config .purchaseOverlay ) {
90- case COFL : client .setScreen (new CoflBinGUI (Items .BREAD , gcs1 ));break ;
91- case TFM : client .setScreen (new TfmBinGUI (Items .BREAD ));break ;
92- case null : default : break ;
93- }
124+ if (CoflCore .config .purchaseOverlay != null && gcs .getTitle () != null
125+ && (gcs .getTitle ().getString ().contains ("BIN Auction View" )
126+ && gcs .getScreenHandler ().getInventory ().size () == 9 * 6
127+ || gcs .getTitle ().getString ().contains ("Confirm Purchase" )
128+ && gcs .getScreenHandler ().getInventory ().size () == 9 * 3 )
129+ ) {
130+ if (!(client .currentScreen instanceof CoflBinGUI || client .currentScreen instanceof TfmBinGUI )) {
131+ switch (CoflCore .config .purchaseOverlay ) {
132+ case COFL : client .setScreen (new CoflBinGUI (gcs , flipId ));break ;
133+ case TFM : client .setScreen (new TfmBinGUI (Items .BREAD ));break ;
134+ case null : default : break ;
94135 }
95136 }
96- });
137+ }
97138 }
98139 });
99-
100140 }
101141
142+ public static void onOpenBestFlip (String username , boolean isInitialKeypress ) {
143+ if (System .currentTimeMillis () - LastClick >= 300L ) {
144+ FlipData f = CoflCore .flipHandler .fds .GetHighestFlip ();
145+ System .out .println (f );
146+ if (f != null ) {
147+ CoflSkyCommand .processCommand (new String []{"openauctiongui" , f .Id , "true" }, username );
148+ LastViewAuctionUUID = f .Id ;
149+ LastViewAuctionInvocation = System .currentTimeMillis ();
150+ LastClick = System .currentTimeMillis ();
151+ String command = (new Gson ()).toJson ("/viewauction " + f .Id );
152+ CoflCore .Wrapper .SendMessage (new JsonStringCommand (CommandType .Clicked , command ));
153+ CoflSkyCommand .processCommand (new String []{"track" , "besthotkey" , f .Id , username }, username );
154+ } else if (isInitialKeypress ) {
155+ CoflSkyCommand .processCommand (new String []{"dialog" , "nobestflip" , username }, username );
156+ }
157+ }
158+ }
159+
102160 @ Subscribe
103161 public void WriteToChat (OnWriteToChatReceive command ){
104162 MinecraftClient .getInstance ().inGameHud .getChatHud ().addMessage (ChatComponent (command .ChatMessage ));
@@ -115,4 +173,40 @@ public void onChatMessage(OnChatMessageReceive event){
115173 public void onModChatMessage (OnModChatMessage event ){
116174 MinecraftClient .getInstance ().inGameHud .getChatHud ().addMessage (Text .of (event .message ));
117175 }
176+
177+ @ Subscribe
178+ public void onCountdownReceive (OnCountdownReceive event ){
179+ //MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(Text.of("COUNTDOWN RECEIVED: "+event.CountdownData.getDuration()));
180+ }
181+
182+ @ Subscribe
183+ public void onOpenAuctionGUI (OnOpenAuctionGUI event ){
184+ MinecraftClient .getInstance ().setScreen (new BookScreen ());
185+ }
186+
187+ @ Subscribe
188+ public void onFlipReceive (OnFlipReceive event ){
189+ System .out .println ("FLIP RECEIVED" );
190+ }
191+
192+ @ Subscribe
193+ public void onReceiveCommand (ReceiveCommand event ){
194+ if (event .command .getType () == CommandType .Flip ){
195+ System .out .println ("onReceiveCommand: " +event .command .getData ());
196+ // JsonObject jsonObject = JsonParser.parseString(event.command.getData()).getAsJsonObject();
197+ // EventBus.getDefault().post(new OnFlipReceive(new Flip(
198+ // new ChatMessage[]{},//jsonObject.get("messages"),
199+ // jsonObject.get("id").getAsString(),
200+ // jsonObject.get("worth").getAsInt(),
201+ // new Sound(),//jsonObject.get("sound"),
202+ // new AuctionItem(),//jsonObject.get("auction"),
203+ // jsonObject.get("render").getAsString(),
204+ // jsonObject.get("target").getAsString()
205+ // )));
206+
207+ // Flip f = new ObjectMapper(gson).readValue(event.command.getData(), Flip.class);
208+ // System.out.println("res: "+f.getId());
209+ // //EventBus.getDefault().post(new OnFlipReceive(f));
210+ }
211+ }
118212}
0 commit comments