88import CoflCore .classes .Sound ;
99import CoflCore .commands .CommandType ;
1010import CoflCore .commands .JsonStringCommand ;
11+ import CoflCore .commands .models .ChatMessageData ;
1112import CoflCore .commands .models .FlipData ;
13+ import CoflCore .commands .models .SoundData ;
1214import CoflCore .events .*;
1315import com .coflnet .gui .RenderUtils ;
1416import com .coflnet .gui .cofl .CoflBinGUI ;
1719import com .google .gson .GsonBuilder ;
1820import com .google .gson .JsonObject ;
1921import com .google .gson .reflect .TypeToken ;
22+ import com .mojang .brigadier .CommandDispatcher ;
2023import com .mojang .brigadier .arguments .StringArgumentType ;
24+ import com .mojang .brigadier .context .CommandContext ;
25+ import com .mojang .brigadier .exceptions .CommandSyntaxException ;
2126import net .fabricmc .api .ClientModInitializer ;
2227import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
2328import net .fabricmc .fabric .api .client .command .v2 .ClientCommandRegistrationCallback ;
29+ import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
2430import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientLifecycleEvents ;
2531import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientTickEvents ;
2632import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
3238import net .minecraft .client .gui .screen .ingame .GenericContainerScreen ;
3339import net .minecraft .client .option .KeyBinding ;
3440import net .minecraft .client .util .InputUtil ;
41+ import net .minecraft .command .CommandSource ;
42+ import net .minecraft .entity .player .PlayerEntity ;
3543import net .minecraft .item .Items ;
44+ import net .minecraft .server .MinecraftServer ;
45+ import net .minecraft .server .command .CommandManager ;
46+ import net .minecraft .server .command .ServerCommandSource ;
47+ import net .minecraft .server .world .ServerWorld ;
48+ import net .minecraft .text .ClickEvent ;
3649import net .minecraft .text .Text ;
3750import org .greenrobot .eventbus .EventBus ;
3851import org .greenrobot .eventbus .Subscribe ;
4356import java .util .ArrayList ;
4457import java .util .Arrays ;
4558import java .util .List ;
59+ import java .util .Objects ;
4660import java .util .concurrent .ExecutorService ;
4761import java .util .concurrent .Executors ;
4862import java .util .concurrent .LinkedBlockingQueue ;
@@ -63,7 +77,7 @@ public class CoflModClient implements ClientModInitializer {
6377 private static LocalDateTime lastBatchStart = LocalDateTime .now ();
6478
6579 private String username = "" ;
66- private static String flipId = "" ;
80+ public static FlipData flip = null ;
6781 private static Gson gson = new GsonBuilder ().excludeFieldsWithoutExposeAnnotation ().create ();
6882 @ Override
6983 public void onInitializeClient () {
@@ -86,7 +100,6 @@ public void onInitializeClient() {
86100
87101 ClientTickEvents .END_CLIENT_TICK .register (client -> {
88102 if (bestflipsKeyBinding .wasPressed ()) {
89- System .out .println ("Anz Flips: " +CoflCore .flipHandler .fds .CurrentFlips ());
90103 onOpenBestFlip (username , true );
91104 }
92105 });
@@ -102,9 +115,9 @@ public void onInitializeClient() {
102115 dispatcher .register (ClientCommandManager .literal ("cofl" )
103116 .then (ClientCommandManager .argument ("args" , StringArgumentType .greedyString ()).executes (context -> {
104117 String [] args = context .getArgument ("args" , String .class ).split (" " );
105- if (args [0 ].compareToIgnoreCase ("openauctiongui" ) == 0 ){
106- flipId = args [1 ];
107- } else flipId = "" ;
118+ // if (args[0].compareToIgnoreCase("openauctiongui") == 0){
119+ // flipId = args[1];
120+ // } else flipId = "";
108121 CoflSkyCommand .processCommand (args ,username );
109122 return 1 ;
110123 })));
@@ -121,7 +134,7 @@ public void onInitializeClient() {
121134 ) {
122135 if (!(client .currentScreen instanceof CoflBinGUI || client .currentScreen instanceof TfmBinGUI )) {
123136 switch (CoflCore .config .purchaseOverlay ) {
124- case COFL : client .setScreen (new CoflBinGUI (gcs , flipId ));break ;
137+ case COFL : client .setScreen (new CoflBinGUI (gcs , flip ));break ;
125138 case TFM : client .setScreen (new TfmBinGUI (gcs ));break ;
126139 case null : default : break ;
127140 }
@@ -173,12 +186,26 @@ public void onCountdownReceive(OnCountdownReceive event){
173186
174187 @ Subscribe
175188 public void onOpenAuctionGUI (OnOpenAuctionGUI event ){
176- MinecraftClient .getInstance ().setScreen (new BookScreen ());
189+ flip = event .flip ;
190+ MinecraftClient .getInstance ().getNetworkHandler ().sendChatMessage (event .openAuctionCommand );
177191 }
178192
179193 @ Subscribe
180- public void onFlipMessage (OnFlipReceive event ){
181- System .out .println ("FLIP RECEIVED" );
194+ public void onFlipReceive (OnFlipReceive event ){
195+ Flip f = event .FlipData ;
196+ EventBus .getDefault ().post (new OnChatMessageReceive (f .getMessages ()));
197+ CoflCore .flipHandler .fds .Insert (new FlipData (
198+ Arrays .stream (f .getMessages ())
199+ .map (cm -> new ChatMessageData (cm .getText (), cm .getOnClick (), cm .getHover ()))
200+ .toArray (ChatMessageData []::new ),
201+ f .getId (),
202+ f .getWorth (),
203+ new SoundData (
204+ f .getSound ().getSoundName (),
205+ f .getSound ().getSoundPitch () == null ? 0 : f .getSound ().getSoundPitch ()
206+ ),
207+ f .getRender ()
208+ ));
182209 }
183210
184211 @ Subscribe
@@ -194,7 +221,7 @@ public static Flip jsonObjToFlip(JsonObject jsonObj){
194221 ChatMessage [] chatMessages = Arrays .stream (chatMessagesObj ).map (jsonObject -> new ChatMessage (
195222 jsonObject .get ("text" ).getAsString (),
196223 jsonObject .get ("onClick" ).getAsString (),
197- "" // jsonObject.get("hover").getAsString()
224+ jsonObject . get ( "hover" ). isJsonNull () ? null : jsonObject .get ("hover" ).getAsString ()
198225 )).toArray (ChatMessage []::new );
199226
200227 String id = gson .fromJson (jsonObj .get ("id" ), String .class );
0 commit comments