aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/de
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/de')
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java37
-rw-r--r--common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java36
2 files changed, 35 insertions, 38 deletions
diff --git a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java
index 173d8d0..00112ed 100644
--- a/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java
+++ b/common/src/main/java/de/hype/bbsentials/common/client/BBsentials.java
@@ -43,30 +43,23 @@ public class BBsentials {
}
public static void connectToBBserver(boolean beta) {
- if (bbthread != null) {
- try {
- bbthread.interrupt();
- connection.messageReceiverThread.interrupt();
- connection.messageSenderThread.interrupt();
- } catch (Exception ignored) {
- }
- }
- connection = null;
- if (connection != null) {
- connection.close();
- }
- bbthread = new Thread(() -> {
- connection = new BBsentialConnection();
- coms = new Commands();
- connection.setMessageReceivedCallback(message -> executionService.execute(() -> connection.onMessageReceived(message)));
- if (beta) {
- connection.connect(config.getBBServerURL(), 5011);
- }
- else {
- connection.connect(config.getBBServerURL(), 5000);
+ executionService.execute(() -> {
+ if (connection != null) {
+ connection.close();
}
+ bbthread = new Thread(() -> {
+ connection = new BBsentialConnection();
+ coms = new Commands();
+ if (beta) {
+ connection.connect(config.getBBServerURL(), 5011);
+ }
+ else {
+ connection.connect(config.getBBServerURL(), 5000);
+ }
+ connection.setMessageReceivedCallback(message -> executionService.execute(() -> connection.onMessageReceived(message)));
+ });
+ bbthread.start();
});
- bbthread.start();
}
/**
diff --git a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java b/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java
index 23eda94..0bc1978 100644
--- a/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java
+++ b/common/src/main/java/de/hype/bbsentials/common/communication/BBsentialConnection.java
@@ -148,14 +148,14 @@ public class BBsentialConnection {
if (messageReceivedCallback != null) {
messageReceivedCallback.onMessageReceived(message);
}
- else {
- Chat.sendPrivateMessageToSelfError("BB: It seemed like you disconnected. Reconnecting...");
- BBsentials.connectToBBserver();
- try {
- Thread.sleep(1000 * 10);
- } catch (Exception ignored) {
- }
- }
+// else {
+// Chat.sendPrivateMessageToSelfError("BB: It seemed like you disconnected. Reconnecting...");
+// BBsentials.connectToBBserver();
+// try {
+// Thread.sleep(1000 * 10);
+// } catch (Exception ignored) {
+// }
+// }
}
}
} catch (IOException e) {
@@ -172,9 +172,7 @@ public class BBsentialConnection {
if (BBsentials.config.isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelfDebug("BBs: "+message);
writer.println(message);
}
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (NullPointerException ignored) {
+ } catch (InterruptedException | NullPointerException ignored) {
}
});
messageSenderThread.start();
@@ -255,8 +253,8 @@ public class BBsentialConnection {
public <E extends AbstractPacket> void sendPacket(E packet) {
String packetName = packet.getClass().getSimpleName();
String rawjson = PacketUtils.parsePacketToJson(packet);
- if (socket.isConnected() && writer != null) {
- if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class) && BBsentials.config.devSecurity)) {
+ if (isConnected() && writer != null) {
+ if (BBsentials.getConfig().isDetailedDevModeEnabled() && !((packet.getClass().equals(RequestConnectPacket.class) && !BBsentials.config.useMojangAuth) && BBsentials.config.devSecurity)) {
Chat.sendPrivateMessageToSelfDebug("BBDev-sP: " + packetName + ": " + rawjson);
}
writer.println(packetName + "." + rawjson);
@@ -561,10 +559,16 @@ public class BBsentialConnection {
public void close() {
try {
+ Thread.currentThread().interrupt();
+ messageReceiverThread.interrupt();
+ messageSenderThread.interrupt();
+ messageQueue.clear();
socket.close();
- reader = null;
- writer = null;
- } catch (IOException ignored) {
+ writer.close();
+ reader.close();
+ } catch (Exception e) {
+ Chat.sendPrivateMessageToSelfError(e.getMessage());
+ e.printStackTrace();
}
}