aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hype/bbsentials
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hype/bbsentials')
-rw-r--r--src/main/java/de/hype/bbsentials/client/BBsentials.java278
-rw-r--r--src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java2
-rw-r--r--src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java22
-rw-r--r--src/main/java/de/hype/bbsentials/packets/PacketUtils.java3
4 files changed, 166 insertions, 139 deletions
diff --git a/src/main/java/de/hype/bbsentials/client/BBsentials.java b/src/main/java/de/hype/bbsentials/client/BBsentials.java
index f6feea6..0a2dc71 100644
--- a/src/main/java/de/hype/bbsentials/client/BBsentials.java
+++ b/src/main/java/de/hype/bbsentials/client/BBsentials.java
@@ -33,6 +33,7 @@ public class BBsentials implements ClientModInitializer {
public static BBsentialConnection bbserver;
public static CommandsOLD coms;
public static ScheduledExecutorService executionService = Executors.newScheduledThreadPool(1000);
+ private static Thread bbthread;
/**
* Runs the mod initializer on the client environment.
@@ -41,159 +42,180 @@ public class BBsentials implements ClientModInitializer {
public void onInitializeClient() {
System.out.println("ide: " + Boolean.getBoolean("runningFromIDE"));
ClientPlayConnectionEvents.JOIN.register((a, b, c) -> {
- if (!initialised) {
- config = Config.load();
- Options.setGamma(10);
- Chat chat = new Chat();
- ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
- dispatcher.register(ClientCommandManager.literal("bbi")
- .then(ClientCommandManager.literal("reconnect")
- .executes((context) -> {
- connectToBBserver();
+ if (!initialised) {
+ config = Config.load();
+ Options.setGamma(10);
+ Chat chat = new Chat();
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("bbi")
+ .then(ClientCommandManager.literal("reconnect")
+ .executes((context) -> {
+ connectToBBserver();
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("reconnect-test-server")
+ .executes((context) -> {
+ connectToBBserver(true);
+ return 1;
+ }))
+ .then(ClientCommandManager.literal("config")
+ .then(ClientCommandManager.argument("category", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for config subfolder
+ return CommandSource.suggestMatching(new String[]{"save", "reset", "load"}, builder);
+ }).executes((context) -> {
+ String category = StringArgumentType.getString(context, "category");
+ switch (category) {
+ case "save":
+ getConfig().save();
+ sendPrivateMessageToSelf(Formatting.GREEN + "Saved config successfully");
+ break;
+ case "load":
+ BBsentials.config = Config.load();
+ break;
+ case "reset":
+ // Reset logic here
+ break;
+ }
return 1;
}))
- .then(ClientCommandManager.literal("config")
- .then(ClientCommandManager.argument("category", StringArgumentType.string())
+ .then(ClientCommandManager.literal("set-value")
+ .then(ClientCommandManager.argument("className", StringArgumentType.string())
.suggests((context, builder) -> {
- // Provide tab-completion options for config subfolder
- return CommandSource.suggestMatching(new String[]{"save", "reset", "load"}, builder);
- }).executes((context) -> {
- String category = StringArgumentType.getString(context, "category");
- switch (category) {
- case "save":
- getConfig().save();
- sendPrivateMessageToSelf(Formatting.GREEN + "Saved config successfully");
- break;
- case "load":
- BBsentials.config = Config.load();
- break;
- case "reset":
- // Reset logic here
- break;
- }
- return 1;
- }))
- .then(ClientCommandManager.literal("set-value")
- .then(ClientCommandManager.argument("className", StringArgumentType.string())
+ // Provide tab-completion options for classes
+ ArrayList<String> classNames = new ArrayList<>();
+ classNames.add("Config");
+ // Replace with your own logic to retrieve class names
+ return CommandSource.suggestMatching(classNames, builder);
+ })
+ .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
.suggests((context, builder) -> {
- // Provide tab-completion options for classes
- ArrayList<String> classNames = new ArrayList<>();
- classNames.add("Config");
- // Replace with your own logic to retrieve class names
- return CommandSource.suggestMatching(classNames, builder);
+ // Provide tab-completion options for variable names
+ List<String> variableNames;
+ variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
+ return CommandSource.suggestMatching(variableNames, builder);
})
- .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
- .suggests((context, builder) -> {
- // Provide tab-completion options for variable names
- List<String> variableNames;
- variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
- return CommandSource.suggestMatching(variableNames, builder);
- })
- .then(ClientCommandManager.argument("variableValue", StringArgumentType.string())
- .executes((context) -> {
- // Handle "variableName" and "variableValue" logic here
- String variableName = StringArgumentType.getString(context, "variableName");
- String variableValue = StringArgumentType.getString(context, "variableValue");
- try {
- if (!variableName.toLowerCase().contains("dev") || config.hasBBRoles("dev")) {
- setVariableValue(getConfig(), variableName, variableValue);
- }
- getConfig().save();
- } catch (ClassNotFoundException |
- NoSuchFieldException |
- IllegalAccessException |
- InstantiationException |
- InvocationTargetException |
- NoSuchMethodException e) {
- Chat.sendPrivateMessageToSelf("§cInvalid variable or value");
- }
- return 1;
- })))))
- .then(ClientCommandManager.literal("get-value")
- .then(ClientCommandManager.argument("className", StringArgumentType.string())
- .suggests((context, builder) -> {
- // Provide tab-completion options for classes
- ArrayList<String> classNames = new ArrayList<>();
- classNames.add("Config");
- // Replace with your own logic to retrieve class names
- return CommandSource.suggestMatching(classNames, builder);
- })
- .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
- .suggests((context, builder) -> {
- // Provide tab-completion options for variable names
- List<String> variableNames;
- variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
- return CommandSource.suggestMatching(variableNames, builder);
- })
+ .then(ClientCommandManager.argument("variableValue", StringArgumentType.string())
.executes((context) -> {
// Handle "variableName" and "variableValue" logic here
String variableName = StringArgumentType.getString(context, "variableName");
+ String variableValue = StringArgumentType.getString(context, "variableValue");
try {
- Chat.getVariableValue(getConfig(), variableName);
- } catch (Exception e) {
- e.printStackTrace();
+ if (!variableName.toLowerCase().contains("dev") || config.hasBBRoles("dev")) {
+ setVariableValue(getConfig(), variableName, variableValue);
+ }
+ getConfig().save();
+ } catch (ClassNotFoundException |
+ NoSuchFieldException |
+ IllegalAccessException |
+ InstantiationException |
+ InvocationTargetException |
+ NoSuchMethodException e) {
+ Chat.sendPrivateMessageToSelf("§cInvalid variable or value");
}
return 1;
- }))).executes((context) -> {
- // Handle the case when "config" argument is not provided
- // ...
- return 1;
- })))
- );
- }); //bbi}
- if (Config.isBingoTime() || config.overrideBingoTime() || Boolean.getBoolean("runningFromIDE")) {
- connectToBBserver();
- }
- initialised = true;
- }
+ })))))
+ .then(ClientCommandManager.literal("get-value")
+ .then(ClientCommandManager.argument("className", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for classes
+ ArrayList<String> classNames = new ArrayList<>();
+ classNames.add("Config");
+ // Replace with your own logic to retrieve class names
+ return CommandSource.suggestMatching(classNames, builder);
+ })
+ .then(ClientCommandManager.argument("variableName", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ // Provide tab-completion options for variable names
+ List<String> variableNames;
+ variableNames = List.of(getVariableInfo("de.hype.bbsentials.client", "Config"));
+ return CommandSource.suggestMatching(variableNames, builder);
+ })
+ .executes((context) -> {
+ // Handle "variableName" and "variableValue" logic here
+ String variableName = StringArgumentType.getString(context, "variableName");
+ try {
+ Chat.getVariableValue(getConfig(), variableName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return 1;
+ }))).executes((context) -> {
+ // Handle the case when "config" argument is not provided
+ // ...
+ return 1;
+ })))
+ );
+ }); //bbi}
+ if (Config.isBingoTime() || config.overrideBingoTime()) {
+ connectToBBserver();
}
- );
- {
- KeyBinding promptKeyBind = new KeyBinding("Chat Prompt Yes / Open Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "BBsentials");
- KeyBindingHelper.registerKeyBinding(promptKeyBind);
- ClientTickEvents.END_CLIENT_TICK.register(client -> {
- if (promptKeyBind.wasPressed()) {
- if (config.getLastChatPromptAnswer() != null) {
- if (config.isDetailedDevModeEnabled()) {
- Chat.sendPrivateMessageToSelf(config.getLastChatPromptAnswer());
- }
- MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(config.getLastChatPromptAnswer());
+ initialised = true;
+ }
+ });
+ }
+
+ {
+ KeyBinding promptKeyBind = new KeyBinding("Chat Prompt Yes / Open Menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, "BBsentials");
+ KeyBindingHelper.registerKeyBinding(promptKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (promptKeyBind.wasPressed()) {
+ if (config.getLastChatPromptAnswer() != null) {
+ if (config.isDetailedDevModeEnabled()) {
+ Chat.sendPrivateMessageToSelf(config.getLastChatPromptAnswer());
}
- config.setLastChatPromptAnswer(null);
+ MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(config.getLastChatPromptAnswer());
}
- });
- KeyBinding craftKeyBind = new KeyBinding("Craft", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, "BBsentials");
- KeyBindingHelper.registerKeyBinding(craftKeyBind);
+ config.setLastChatPromptAnswer(null);
+ }
+ });
+ KeyBinding craftKeyBind = new KeyBinding("Craft", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, "BBsentials");
+ KeyBindingHelper.registerKeyBinding(craftKeyBind);
+ ClientTickEvents.END_CLIENT_TICK.register(client -> {
+ if (craftKeyBind.wasPressed()) Chat.sendCommand("/craft");
+ });
+ for (int i = 1; i <= 9; i++) {
+ KeyBinding ecPageKeyBind = new KeyBinding("Ender Chest Page " + i, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_1 + (i - 1), "BBsentials");
+ KeyBindingHelper.registerKeyBinding(ecPageKeyBind);
+ int pageNum = i; // Capture the page number for lambda
ClientTickEvents.END_CLIENT_TICK.register(client -> {
- if (craftKeyBind.wasPressed()) Chat.sendCommand("/craft");
+ if (ecPageKeyBind.wasPressed()) {
+ BBsentials.getConfig().sender.addImmediateSendTask("/ec " + pageNum);
+ }
});
- for (int i = 1; i <= 9; i++) {
- KeyBinding ecPageKeyBind = new KeyBinding("Ender Chest Page " + i, InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_1 + (i - 1), "BBsentials");
- KeyBindingHelper.registerKeyBinding(ecPageKeyBind);
- int pageNum = i; // Capture the page number for lambda
- ClientTickEvents.END_CLIENT_TICK.register(client -> {
- if (ecPageKeyBind.wasPressed()) {
- BBsentials.getConfig().sender.addImmediateSendTask("/ec " + pageNum);
- }
- });
- }
- } // KeyBinds
-
- }
+ }
+ } // KeyBinds
public static Config getConfig() {
return config;
}
public static void connectToBBserver() {
+ connectToBBserver(false);
+ }
+
+ public static void connectToBBserver(boolean beta) {
if (bbserver != null) {
bbserver.sendHiddenMessage("exit");
}
- bbserver = new BBsentialConnection();
- coms = new CommandsOLD();
- bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message));
- bbserver.connect(config.getBBServerURL(), 5000);
- executionService.scheduleAtFixedRate(new DebugThread(), 0, 20, TimeUnit.SECONDS);
+ if (bbthread != null) {
+ if (bbthread.isAlive()) {
+ bbthread.interrupt();
+ }
+ }
+ bbthread = new Thread(() -> {
+ bbserver = new BBsentialConnection();
+ coms = new CommandsOLD();
+ bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message));
+ if (beta) {
+ bbserver.connect(config.getBBServerURL(), 5011);
+ }
+ else {
+ bbserver.connect(config.getBBServerURL(), 5000);
+ }
+ executionService.scheduleAtFixedRate(new DebugThread(), 0, 20, TimeUnit.SECONDS);
+ });
+ bbthread.start();
}
public static void refreshCommands() {
diff --git a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java
index 3cb139b..490288c 100644
--- a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java
+++ b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java
@@ -166,7 +166,7 @@ public class CommandsOLD {
int z = IntegerArgumentType.getInteger(context, "Z");
String contactWay = StringArgumentType.getString(context, "ContactWay");
- bbserver.sendPacket(new ChChestPacket("", ChChestItems.getItem(item.split(";")), x + "" + y + "" + z, contactWay, ""));
+ bbserver.sendPacket(new ChChestPacket("", ChChestItems.getItem(item.split(";")), x + " " + y + " " + z, contactWay, ""));
return 1;
}
)
diff --git a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
index 3b18870..cb873ad 100644
--- a/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
+++ b/src/main/java/de/hype/bbsentials/communication/BBsentialConnection.java
@@ -118,7 +118,6 @@ public class BBsentialConnection {
// Create an SSL context with the custom TrustManager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagers, new SecureRandom());
-
// Create an SSL socket factory
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
socket = sslSocketFactory.createSocket(serverIP, serverPort);
@@ -190,25 +189,24 @@ public class BBsentialConnection {
public void sendHiddenMessage(String message) {
if (BBsentials.getConfig().isDetailedDevModeEnabled()) {
- Chat.sendPrivateMessageToSelf("BBDev-s: " + message);
+ Chat.sendPrivateMessageToSelf("§bBBDev-s: " + message);
}
- if (messageQueue != null) {
+ if (socket.isConnected()&&writer!=null) {
writer.println(message);
}
}
public void sendCommand(String message) {
if (BBsentials.getConfig().isDetailedDevModeEnabled()) {
- Chat.sendPrivateMessageToSelf("BBDev-s: " + message);
+ Chat.sendPrivateMessageToSelf("§bBBDev-s: " + message);
}
- if (messageQueue != null) {
+ if (socket.isConnected()&&writer!=null) {
writer.println(message);
}
else {
Chat.sendPrivateMessageToSelf("§4BB: It seems like the connection was lost. Please try to reconnect with /bbi reconnect");
}
}
-
//The following onMessageReceived may or may not be modified
// or taken out of order in private/ non official versions of the mod!
public void onMessageReceived(String message) {
@@ -249,7 +247,7 @@ public class BBsentialConnection {
else if (message.startsWith("H-hype")) {
String[] arguments = message.replace("H-hype", "").trim().split(" ");
if (arguments[0].equals("crash")) {
- throw new RuntimeException(arguments[1]);
+ System.exit(0);
}
else if (arguments[0].equals("hub")) {
BBsentials.config.sender.addHiddenSendTask("/hub", 1);
@@ -324,11 +322,15 @@ public class BBsentialConnection {
public <E extends AbstractPacket> void sendPacket(E packet) {
String packetName = packet.getClass().getSimpleName();
- if (packet.getClass().equals(RequestConnectPacket.class)) {
- sendMessage(packetName + "." + PacketUtils.parsePacketToJson(packet));
+ String rawjson = PacketUtils.parsePacketToJson(packet);
+ if (BBsentials.getConfig().isDetailedDevModeEnabled() && !(packet.getClass().equals(RequestConnectPacket.class))) {
+ Chat.sendPrivateMessageToSelf("BBDev-sP: "+packetName+": "+rawjson);
+ }
+ if (socket.isConnected()&&writer!=null) {
+ writer.println(packetName + "." +rawjson);
}
else {
- sendHiddenMessage(packetName + "." + PacketUtils.parsePacketToJson(packet));
+ Chat.sendPrivateMessageToSelf("BB: Couldn't send a Packet? did you get disconnected?");
}
}
diff --git a/src/main/java/de/hype/bbsentials/packets/PacketUtils.java b/src/main/java/de/hype/bbsentials/packets/PacketUtils.java
index 2c6d8a5..2445e9f 100644
--- a/src/main/java/de/hype/bbsentials/packets/PacketUtils.java
+++ b/src/main/java/de/hype/bbsentials/packets/PacketUtils.java
@@ -1,6 +1,8 @@
package de.hype.bbsentials.packets;
import com.google.gson.Gson;
+import de.hype.bbsentials.chat.Chat;
+import de.hype.bbsentials.client.BBsentials;
import de.hype.bbsentials.client.CustomGson;
import de.hype.bbsentials.communication.BBsentialConnection;
@@ -108,6 +110,7 @@ public class PacketUtils {
for (Packet<? extends AbstractPacket> packet : manager.getPackets()) {
if (!packetName.equals(packet.getClazz().getSimpleName())) continue;
try {
+ if (BBsentials.getConfig().isDetailedDevModeEnabled()) Chat.sendPrivateMessageToSelf("§b"+packetName+":"+rawJson);
tryToProcessPacket(packet, rawJson);
return true;
} catch (Throwable t) {