11package com .coflnet ;
22
33import CoflCore .CoflCore ;
4+ import CoflCore .classes .AuctionItem ;
45import CoflCore .classes .ChatMessage ;
56import CoflCore .CoflSkyCommand ;
7+ import CoflCore .classes .Flip ;
8+ import CoflCore .classes .Sound ;
69import CoflCore .commands .CommandType ;
710import CoflCore .commands .JsonStringCommand ;
811import CoflCore .commands .models .FlipData ;
1215import com .coflnet .gui .tfm .TfmBinGUI ;
1316import com .google .gson .Gson ;
1417import com .google .gson .GsonBuilder ;
18+ import com .google .gson .JsonObject ;
19+ import com .google .gson .reflect .TypeToken ;
1520import com .mojang .brigadier .arguments .StringArgumentType ;
1621import net .fabricmc .api .ClientModInitializer ;
1722import net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager ;
2934import net .minecraft .client .util .InputUtil ;
3035import net .minecraft .item .Items ;
3136import net .minecraft .text .Text ;
37+ import org .greenrobot .eventbus .EventBus ;
3238import org .greenrobot .eventbus .Subscribe ;
3339import org .lwjgl .glfw .GLFW ;
3440
3541import java .nio .file .Path ;
3642import java .time .LocalDateTime ;
43+ import java .util .ArrayList ;
44+ import java .util .Arrays ;
45+ import java .util .List ;
3746import java .util .concurrent .ExecutorService ;
3847import java .util .concurrent .Executors ;
3948import java .util .concurrent .LinkedBlockingQueue ;
@@ -174,25 +183,26 @@ public void onFlipMessage(OnFlipReceive event){
174183
175184 @ Subscribe
176185 public void onReceiveCommand (ReceiveCommand event ){
177- if (event .command .getType () == CommandType .ChatMessage ){
178- System .out .println ("onReceiveCommand: " +event .command .getData ());
179-
180- // EventBus.getDefault().post(new OnFlipReceive((Flip)event.command.GetAs(new TypeToken<Flip>() {
181- // }).getData()));
182- // JsonObject jsonObject = JsonParser.parseString(event.command.getData()).getAsJsonObject();
183- // EventBus.getDefault().post(new OnFlipReceive(new Flip(
184- // new ChatMessage[]{},//jsonObject.get("messages"),
185- // jsonObject.get("id").getAsString(),
186- // jsonObject.get("worth").getAsInt(),
187- // new Sound(),//jsonObject.get("sound"),
188- // new AuctionItem(),//jsonObject.get("auction"),
189- // jsonObject.get("render").getAsString(),
190- // jsonObject.get("target").getAsString()
191- // )));
192-
193- // Flip f = new ObjectMapper(gson).readValue(event.command.getData(), Flip.class);
194- // System.out.println("res: "+f.getId());
195- // //EventBus.getDefault().post(new OnFlipReceive(f));
186+ if (event .command .getType () == CommandType .Flip ){
187+ JsonObject jo = gson .fromJson (event .command .getData (), JsonObject .class );
188+ EventBus .getDefault ().post (new OnFlipReceive (jsonObjToFlip (jo )));
196189 }
197190 }
191+
192+ public static Flip jsonObjToFlip (JsonObject jsonObj ){
193+ JsonObject [] chatMessagesObj = gson .fromJson (jsonObj .get ("messages" ), JsonObject [].class );
194+ ChatMessage [] chatMessages = Arrays .stream (chatMessagesObj ).map (jsonObject -> new ChatMessage (
195+ jsonObject .get ("text" ).getAsString (),
196+ jsonObject .get ("onClick" ).getAsString (),
197+ "" //jsonObject.get("hover").getAsString()
198+ )).toArray (ChatMessage []::new );
199+
200+ String id = gson .fromJson (jsonObj .get ("id" ), String .class );
201+ int worth = gson .fromJson (jsonObj .get ("worth" ), Integer .class );
202+ Sound sound = gson .fromJson (jsonObj .get ("sound" ), Sound .class );
203+ AuctionItem auction = gson .fromJson (jsonObj .get ("auction" ), AuctionItem .class );
204+ String render = gson .fromJson (jsonObj .get ("render" ), String .class );
205+ String target = gson .fromJson (jsonObj .get ("target" ), String .class );
206+ return new Flip (chatMessages , id , worth , sound , auction , render , target );
207+ }
198208}
0 commit comments