11package org .cyberpwn .react .network ;
22
3+ import javax .swing .JLabel ;
34import org .cyberpwn .react .ui .ServerTab ;
5+ import org .cyberpwn .react .util .GList ;
46import org .cyberpwn .react .util .GMap ;
57import org .cyberpwn .react .util .JSONArray ;
68import org .cyberpwn .react .util .JSONObject ;
@@ -15,32 +17,38 @@ public class NetworkedServer
1517 private GMap <String , Double > sample ;
1618 private ServerTab tab ;
1719 private Request rx ;
20+ private RequestActions ra ;
1821 private String version ;
1922 private String versionBukkit ;
23+ private GList <String > actions ;
24+ private boolean gettingReactors ;
2025
2126 public NetworkedServer (String name , String username , String password , String address , Integer port )
2227 {
2328 this .name = name ;
2429 this .username = username ;
2530 this .password = password ;
2631 this .address = address ;
27- this .tab = null ;
32+ tab = null ;
33+ gettingReactors = true ;
34+ actions = null ;
2835 this .port = port ;
29- this .sample = new GMap <String , Double >();
30- this .rx = null ;
31- this .version = null ;
32- this .versionBukkit = null ;
36+ sample = new GMap <String , Double >();
37+ rx = null ;
38+ ra = null ;
39+ version = null ;
40+ versionBukkit = null ;
3341 }
3442
3543 public NetworkedServer (JSONObject js )
3644 {
37- this . name = js .getString ("name" );
38- this . username = js .getString ("username" );
39- this . password = js .getString ("password" );
40- this . address = js .getString ("address" );
41- this . port = js .getInt ("port" );
42- this . tab = null ;
43- this . sample = new GMap <String , Double >();
45+ name = js .getString ("name" );
46+ username = js .getString ("username" );
47+ password = js .getString ("password" );
48+ address = js .getString ("address" );
49+ port = js .getInt ("port" );
50+ tab = null ;
51+ sample = new GMap <String , Double >();
4452 }
4553
4654 public void toJson (JSONArray parent )
@@ -56,12 +64,51 @@ public void toJson(JSONArray parent)
5664 parent .put (js );
5765 }
5866
67+ public void requestActions ()
68+ {
69+ if (actions != null )
70+ {
71+ return ;
72+ }
73+
74+ gettingReactors = true ;
75+
76+ tab .pushStartedActions ();
77+
78+ if (ra != null && ra .isAlive ())
79+ {
80+ return ;
81+ }
82+
83+ ra = new RequestActions (this , new RequestActionsCallback ()
84+ {
85+ @ Override
86+ public void run ()
87+ {
88+ if (isOk ())
89+ {
90+ actions = getActions ();
91+ tab .push (actions );
92+ gettingReactors = false ;
93+ }
94+ }
95+ });
96+
97+ ra .start ();
98+ }
99+
59100 public void requestSample ()
60101 {
102+ if (gettingReactors )
103+ {
104+ return ;
105+ }
106+
61107 if (version == null || versionBukkit == null )
62108 {
63109 new RequestBasic (this , new RequestCallbackBasic ()
64110 {
111+ @ Override
65112 public void run ()
66113 {
67114 if (isOk ())
@@ -80,6 +127,7 @@ public void run()
80127
81128 rx = new Request (this , new RequestCallback ()
82129 {
130+ @ Override
83131 public void run ()
84132 {
85133 if (isOk ())
@@ -163,19 +211,42 @@ public void setTab(ServerTab tab)
163211 {
164212 this .tab = tab ;
165213 }
166-
214+
167215 public Request getRx ()
168216 {
169217 return rx ;
170218 }
171-
219+
172220 public String getVersion ()
173221 {
174222 return version ;
175223 }
176-
224+
177225 public String getVersionBukkit ()
178226 {
179227 return versionBukkit ;
180228 }
229+
230+ public void act (String action , final JLabel label )
231+ {
232+ label .setText ("Preparing..." );
233+ RequestAction ra = new RequestAction (this , new RequestActionCallback ()
234+ {
235+ @ Override
236+ public void run ()
237+ {
238+ if (isOk ())
239+ {
240+ label .setText ("Action Completed" );
241+ }
242+
243+ else
244+ {
245+ label .setText ("Failed... Check Console." );
246+ }
247+ }
248+ }, action );
249+ label .setText ("Executing..." );
250+ ra .start ();
251+ }
181252}
0 commit comments