Skip to content

Commit 4b220c0

Browse files
committed
patch
1 parent 5dc8b4d commit 4b220c0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/main/java/net/estinet/gFeatures/ClioteSky/ClioteSky.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,20 @@ public static byte[] stringToBytes(String str) {
110110
private ClioteSkyServiceGrpc.ClioteSkyServiceBlockingStub blockingStub;
111111
private ClioteSkyServiceGrpc.ClioteSkyServiceStub asyncStub;
112112
public boolean continueEventLoop = true;
113-
public boolean offline = false;
113+
private boolean offline = false, slowCheck = true;
114114

115-
private String authToken;
115+
private String authToken = "";
116116

117117
public ClioteSky(String host, int port) {
118118
//this(ManagedChannelBuilder.forAddress(host, port));
119119

120+
initConnection(host, port);
121+
}
122+
123+
private void initConnection(String host, int port) {
120124
if(!checkTLS) {
121125
// 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;
127127
// Install the all-trusting host verifier
128128
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
129129
try {
@@ -171,10 +171,14 @@ public void startEventLoop() {
171171
int speedupCount = 0;
172172

173173
while (continueEventLoop) {
174+
174175
Iterator<ClioteSkyRPC.ClioteMessage> iterator;
175176

176177
try {
177178
iterator = blockingStub.request(ClioteSkyRPC.Token.newBuilder().setToken(authToken).build());
179+
180+
slowCheck = false; //the server is online
181+
178182
while (iterator.hasNext()) {
179183
speedup = true;
180184
speedupCount = 0;
@@ -207,6 +211,12 @@ public void startEventLoop() {
207211
if (e.getStatus().getDescription().equals("invalid authentication token")) {
208212
start();
209213
}
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));
210220
}
211221

212222
if (speedupCount < 20) {
@@ -216,6 +226,9 @@ public void startEventLoop() {
216226
}
217227

218228
try {
229+
if(slowCheck) {
230+
Thread.sleep(2000);
231+
}
219232
if (speedup) {
220233
Thread.sleep(200);
221234
} else {

0 commit comments

Comments
 (0)