@@ -110,20 +110,20 @@ public static byte[] stringToBytes(String str) {
110
110
private ClioteSkyServiceGrpc .ClioteSkyServiceBlockingStub blockingStub ;
111
111
private ClioteSkyServiceGrpc .ClioteSkyServiceStub asyncStub ;
112
112
public boolean continueEventLoop = true ;
113
- public boolean offline = false ;
113
+ private boolean offline = false , slowCheck = true ;
114
114
115
- private String authToken ;
115
+ private String authToken = "" ;
116
116
117
117
public ClioteSky (String host , int port ) {
118
118
//this(ManagedChannelBuilder.forAddress(host, port));
119
119
120
+ initConnection (host , port );
121
+ }
122
+
123
+ private void initConnection (String host , int port ) {
120
124
if (!checkTLS ) {
121
125
// Create all-trusting host name verifier
122
- HostnameVerifier allHostsValid = new HostnameVerifier () {
123
- public boolean verify (String hostname , SSLSession session ) {
124
- return true ;
125
- }
126
- };
126
+ HostnameVerifier allHostsValid = (hostname , session ) -> true ;
127
127
// Install the all-trusting host verifier
128
128
HttpsURLConnection .setDefaultHostnameVerifier (allHostsValid );
129
129
try {
@@ -171,10 +171,14 @@ public void startEventLoop() {
171
171
int speedupCount = 0 ;
172
172
173
173
while (continueEventLoop ) {
174
+
174
175
Iterator <ClioteSkyRPC .ClioteMessage > iterator ;
175
176
176
177
try {
177
178
iterator = blockingStub .request (ClioteSkyRPC .Token .newBuilder ().setToken (authToken ).build ());
179
+
180
+ slowCheck = false ; //the server is online
181
+
178
182
while (iterator .hasNext ()) {
179
183
speedup = true ;
180
184
speedupCount = 0 ;
@@ -207,6 +211,12 @@ public void startEventLoop() {
207
211
if (e .getStatus ().getDescription ().equals ("invalid authentication token" )) {
208
212
start ();
209
213
}
214
+ } catch (NullPointerException e ) { // if the initial connection couldn't be reached on server start
215
+ if (Listeners .debug ) {
216
+ Bukkit .getLogger ().severe ("Can't establish connection with server. Attempting again..." );
217
+ e .printStackTrace ();
218
+ }
219
+ initConnection (ClioteSky .address , Integer .parseInt (ClioteSky .port ));
210
220
}
211
221
212
222
if (speedupCount < 20 ) {
@@ -216,6 +226,9 @@ public void startEventLoop() {
216
226
}
217
227
218
228
try {
229
+ if (slowCheck ) {
230
+ Thread .sleep (2000 );
231
+ }
219
232
if (speedup ) {
220
233
Thread .sleep (200 );
221
234
} else {
0 commit comments