aboutsummaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorHacktheTime <l4bg0jb7@duck.com>2023-10-25 20:30:56 +0200
committerHacktheTime <l4bg0jb7@duck.com>2023-10-25 20:30:56 +0200
commit229c0892f283275b57ed0d45ad401413543f218c (patch)
tree6d16a30705b2c3753d6daf0bbea865b957f86131 /common/src
parent80ffe4a632c9d1cc2c7021b990939916fd0155e0 (diff)
downloadBBsentials-229c0892f283275b57ed0d45ad401413543f218c.tar.gz
BBsentials-229c0892f283275b57ed0d45ad401413543f218c.tar.bz2
BBsentials-229c0892f283275b57ed0d45ad401413543f218c.zip
added pages too the numpad config
eased up the closing of the connection to be fully internal. updatet the fabric version fixed some bugs
Diffstat (limited to 'common/src')
-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();
}
}