aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hype/bbsentials/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hype/bbsentials/client')
-rw-r--r--src/main/java/de/hype/bbsentials/client/BBsentials.java174
-rw-r--r--src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java308
-rw-r--r--src/main/java/de/hype/bbsentials/client/Config.java266
3 files changed, 748 insertions, 0 deletions
diff --git a/src/main/java/de/hype/bbsentials/client/BBsentials.java b/src/main/java/de/hype/bbsentials/client/BBsentials.java
new file mode 100644
index 0000000..596d194
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/client/BBsentials.java
@@ -0,0 +1,174 @@
+package de.hype.bbsentials.client;
+
+import com.mojang.brigadier.arguments.StringArgumentType;
+import de.hype.bbsentials.api.Options;
+import de.hype.bbsentials.chat.Chat;
+import de.hype.bbsentials.client.Commands.CommandsOLD;
+import de.hype.bbsentials.communication.BBsentialConnection;
+import net.fabricmc.api.ClientModInitializer;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
+import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
+import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
+import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.option.KeyBinding;
+import net.minecraft.client.util.InputUtil;
+import net.minecraft.command.CommandSource;
+import net.minecraft.util.Formatting;
+import org.lwjgl.glfw.GLFW;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static de.hype.bbsentials.chat.Chat.*;
+
+public class BBsentials implements ClientModInitializer {
+ private boolean initialised = false;
+ public static Config config;
+ public static BBsentialConnection bbserver;
+ public static CommandsOLD coms;
+
+ /**
+ * Runs the mod initializer on the client environment.
+ */
+ @Override
+ public void onInitializeClient() {
+ ClientPlayConnectionEvents.JOIN.register((a, b, c) -> {
+ if (!initialised) {
+ config = Config.load();
+ Options.setGamma(10);
+ Chat chat = new Chat();
+ if (Config.isBingoTime() || config.overrideBingoTime()) {
+ connectToBBserver();
+ }
+ 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());}
+ MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(config.getLastChatPromptAnswer());
+ }
+ config.setLastChatPromptAnswer(null);
+ }
+ });
+ }
+
+ public static Config getConfig() {
+ return config;
+ }
+
+ public static void connectToBBserver() {
+ if (bbserver != null) {
+ bbserver.sendHiddenMessage("exit");
+ }
+ bbserver = new BBsentialConnection();
+ bbserver.setMessageReceivedCallback(message -> bbserver.onMessageReceived(message));
+ bbserver.connect(config.getBBServerURL(), 5000);
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("bbi")
+ .then(ClientCommandManager.literal("reconnect")
+ .executes((context) -> {
+ connectToBBserver();
+ 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("set-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 {
+ if (!variableName.contains("dev")||config.bbsentialsRoles.contains("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);
+ }).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}
+ }
+
+ public static void refreshCommands() {
+ coms = new CommandsOLD();
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java
new file mode 100644
index 0000000..bdb7478
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/client/Commands/CommandsOLD.java
@@ -0,0 +1,308 @@
+package de.hype.bbsentials.client.Commands;
+
+import com.mojang.brigadier.arguments.IntegerArgumentType;
+import com.mojang.brigadier.arguments.StringArgumentType;
+import de.hype.bbsentials.client.BBsentials;
+import de.hype.bbsentials.communication.BBsentialConnection;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
+import net.minecraft.command.CommandSource;
+
+import static de.hype.bbsentials.client.BBsentials.*;
+
+public class CommandsOLD {
+ public CommandsOLD() {
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("warp").then(ClientCommandManager.argument("destination", StringArgumentType.string()).suggests((context, builder) -> {
+ // Provide tab-completion options for menu subfolder
+ return CommandSource.suggestMatching(new String[]{"desert", "hub", "dhub", "nether", "isle", "wizard", "portal", "mines", "forge", "ch", "crystals", "nucleus", "end", "drag", "void", "castle", "howl", "park", "jungle", "nest", "arachne", "spider", "deep", "barn", "home", "kuurda", "wasteland", "dragontail", "scarleton", "smold", "garden", "da", "crypt", "museum", "trapper", "dungeon_hub"}, builder);
+ }).executes((context) -> {
+ // Handle "variableName" and "variableValue" logic here
+ String destination = StringArgumentType.getString(context, "destination");
+ getConfig().sender.addSendTask("/warp " + destination, 0);
+ return 1;
+ })));
+ }); //warp test
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("creport")
+ .then(ClientCommandManager.argument("Player_Name", StringArgumentType.string())
+ .executes((context) -> {
+ String playerName = StringArgumentType.getString(context, "Player_Name");
+ getConfig().sender.addSendTask("/creport " + playerName, 0);
+ getConfig().addReported(playerName);
+ return 1;
+ })));
+ });//creport helper → no double report during same launch
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("hp").then(ClientCommandManager.literal("accept").then(ClientCommandManager.argument("player", StringArgumentType.string()).executes((context) -> {
+ String player = StringArgumentType.getString(context, "player");
+ getConfig().sender.addImmediateSendTask("/party accept " + player);
+ return 1;
+ }))).then(ClientCommandManager.literal("chat").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party chat");
+ return 1;
+ })).then(ClientCommandManager.literal("demote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> {
+ // Provide tab-completion options for menu subfolder
+ return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder);
+ }).executes((context) -> {
+ String player = StringArgumentType.getString(context, "player");
+ getConfig().sender.addImmediateSendTask("/party demote " + player);
+ return 1;
+ }))).then(ClientCommandManager.literal("disband").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party disband");
+ return 1;
+ })).then(ClientCommandManager.literal("kick").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> {
+ // Provide tab-completion options for menu subfolder
+ return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder);
+ }).executes((context) -> {
+ String player = StringArgumentType.getString(context, "player");
+ getConfig().sender.addImmediateSendTask("/party kick " + player);
+ return 1;
+ }))).then(ClientCommandManager.literal("kickoffline").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party kickoffline");
+ return 1;
+ })).then(ClientCommandManager.literal("leave").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party leave");
+ return 1;
+ })).then(ClientCommandManager.literal("list").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party list");
+ return 1;
+ })).then(ClientCommandManager.literal("mute").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party mute");
+ return 1;
+ })).then(ClientCommandManager.literal("poll").then(ClientCommandManager.argument("question/answer/answer/answer", StringArgumentType.greedyString()).executes((context) -> {
+ String questionAndAnswers = StringArgumentType.getString(context, "question answer answer (answer)");
+ getConfig().sender.addImmediateSendTask("/party poll " + questionAndAnswers);
+ return 1;
+ }))).then(ClientCommandManager.literal("private").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party private");
+ return 1;
+ })).then(ClientCommandManager.literal("promote").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> {
+ // Provide tab-completion options for menu subfolder
+ return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder);
+ }).executes((context) -> {
+ String player = StringArgumentType.getString(context, "player");
+ getConfig().sender.addImmediateSendTask("/party promote " + player);
+ return 1;
+ }))).then(ClientCommandManager.literal("setting").then(ClientCommandManager.literal("allinvite")).executes((context) -> {
+ String setting = StringArgumentType.getString(context, "setting");
+ getConfig().sender.addImmediateSendTask("/party setting " + setting);
+ return 1;
+ })
+
+ ).then(ClientCommandManager.literal("transfer").then(ClientCommandManager.argument("player", StringArgumentType.string()).suggests((context, builder) -> {
+ // Provide tab-completion options for menu subfolder
+ return CommandSource.suggestMatching(getConfig().getPlayersInParty(), builder);
+ }).executes((context) -> {
+ String player = StringArgumentType.getString(context, "player");
+ getConfig().sender.addImmediateSendTask("/party transfer " + player);
+ return 1;
+ }))).then(ClientCommandManager.literal("warp").executes((context) -> {
+ getConfig().sender.addImmediateSendTask("/party warp");
+ return 1;
+ })).executes(context -> {
+ getConfig().sender.addImmediateSendTask("/p");
+ return 1;
+ }));
+ }); //party test
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("goblinraid")
+ .executes((context) -> {
+ bbserver.sendMessage("?dwevent goblinraid");
+ return 1;
+ })
+ );
+ });/*goblinraid*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("2xpowder")
+ .executes((context) -> {
+ bbserver.sendMessage("?dwevent 2xpowder");
+ return 1;
+ })
+ );
+ });/*2xpowder*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bettertogether")
+ .executes((context) -> {
+ bbserver.sendMessage("?dwevent bettertogether");
+ return 1;
+ })
+ );
+ });/*b2g*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("raffle")
+ .executes((context) -> {
+ bbserver.sendMessage("?dwevent raffle");
+ return 1;
+ })
+ );
+ });/*raffle*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("gonewiththewind")
+ .executes((context) -> {
+ bbserver.sendMessage("?dwevent gonewiththewind");
+ return 1;
+ })
+ );
+ });/*gonewiththewind*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(ClientCommandManager.literal("chchest")
+ .then(ClientCommandManager.argument("Item", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ return CommandSource.suggestMatching(new String[]{"PrehistoricEgg", "Pickonimbus2000", "ElectronTransmitter", "FTX3070", "RobotronReflector", "ControlSwitch", "SyntheticHeart", "SuperliteMotor", "BlueGoblinEgg", "YellowGoblinEgg", "FlawlessAmberGemstone", "FlawlessJadeGemstone", "FlawlessSapphireGemstone", "FlawlessRubyGemstone", "FlawlessAmethystGemstone", "JungleHeart", "FlawlessTopazGemstone", "FlawlessJasperGemstone"}, builder);
+ })
+ .then(ClientCommandManager.argument("X", IntegerArgumentType.integer())
+ .then(ClientCommandManager.argument("Y", IntegerArgumentType.integer())
+ .then(ClientCommandManager.argument("Z", IntegerArgumentType.integer())
+ .then(ClientCommandManager.argument("ContactWay", StringArgumentType.greedyString())
+ .suggests(((context, builder) -> {
+ return CommandSource.suggestMatching(new String[]{"/msg " + getConfig().getUsername() + " bb:party me", "/p join " + config.getUsername()}, builder);
+ }))
+ .executes((context) -> {
+ String destination = StringArgumentType.getString(context, "Item");
+ int x = IntegerArgumentType.getInteger(context, "X");
+ int y = IntegerArgumentType.getInteger(context, "Y");
+ int z = IntegerArgumentType.getInteger(context, "Z");
+ String contactWay = StringArgumentType.getString(context, "ContactWay");
+
+ String combinedString = "?chchest " + destination + " " + x + " " + y + " " + z + " " + contactWay;
+ bbserver.sendMessage(combinedString);
+ return 1;
+ }
+ )
+ )
+ )
+ )
+ )
+ )
+ );
+ }); /*chchest*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bbserver")
+ .then(ClientCommandManager.argument("Message", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "Message");
+ if (message.equals("bb:reconnect")) {
+ BBsentials.connectToBBserver();
+ } else {
+ BBsentials.bbserver.sendMessage(message);
+ }
+ return 1;
+ })
+ )
+ );
+ });/*BBserver*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bc")
+ .then(ClientCommandManager.argument("Message to Bingo Chat", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "Message to Bingo Chat");
+ sendCommand("?bingochat " + message);
+ return 1;
+ })
+ )
+ );
+ });/*BincoChatShort*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bingochat")
+ .then(ClientCommandManager.argument("Message to Bingo Chat", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "Message to Bingo Chat");
+ sendCommand("?bingochat " + message);
+ return 1;
+ })
+ )
+ );
+ });/*BingoChatLong*/
+ if (getConfig().bbsentialsRoles != null) {
+ if (getConfig().bbsentialsRoles.contains("mod")) {
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bannounce")
+ .then(ClientCommandManager.argument("message", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "message");
+ sendCommand("?announce " + message);
+ return 1;
+ })
+ )
+ );
+ });/*bAnnounce*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bmute")
+ .then(ClientCommandManager.argument("message", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "message");
+ sendCommand("?mute " + message);
+ return 1;
+ })
+ )
+ );
+ });/*bmute*/
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("bban")
+ .then(ClientCommandManager.argument("message", StringArgumentType.greedyString())
+ .executes((context) -> {
+ String message = StringArgumentType.getString(context, "message");
+ sendCommand("?bban " + message);
+ return 1;
+ })
+ )
+ );
+ });/*bmute*/
+ }
+ if (getConfig().bbsentialsRoles.contains("splasher")) {
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
+ dispatcher.register(
+ ClientCommandManager.literal("splashAnnounce")
+ .then(ClientCommandManager.argument("Hub", IntegerArgumentType.integer(1, 28))
+ .then(ClientCommandManager.argument("location", StringArgumentType.string())
+ .suggests((context, builder) -> {
+ return CommandSource.suggestMatching(new String[]{"kat","bea","guild-house"}, builder);
+ })
+ .then(ClientCommandManager.argument("extramessage", StringArgumentType.greedyString())
+ .executes((context) -> {
+ int hub_Number = IntegerArgumentType.getInteger(context, "Hub");
+ String extramessage = StringArgumentType.getString(context, "extramessage");
+ String location = StringArgumentType.getString(context, "location");
+ sendCommand("?splash " + hub_Number + " " + location+" "+extramessage);
+ return 1;
+ })
+ )
+ .executes((context) -> {
+ int hub_Number = IntegerArgumentType.getInteger(context, "Hub");
+ String message = "";
+ String location = "bea";
+ sendCommand("?splash " + hub_Number + " "+location+" " + message);
+ return 1;
+ })
+ )
+ .executes((context) -> {
+ int hub_Number = IntegerArgumentType.getInteger(context, "Hub");
+ String message = "";
+ String location = StringArgumentType.getString(context, "location");
+ sendCommand("?splash " + hub_Number + " "+location+" " + message);
+ return 1;
+ })
+ )
+ );
+ });/*SplashAnnounce*/
+ } else {
+ }
+ }
+ }
+ public void sendCommand(String message){
+ BBsentials.bbserver.sendCommand(message);
+ }
+}
+//TODO \ No newline at end of file
diff --git a/src/main/java/de/hype/bbsentials/client/Config.java b/src/main/java/de/hype/bbsentials/client/Config.java
new file mode 100644
index 0000000..35ba61f
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/client/Config.java
@@ -0,0 +1,266 @@
+package de.hype.bbsentials.client;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import de.hype.bbsentials.chat.Chat;
+import de.hype.bbsentials.chat.Sender;
+import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.client.MinecraftClient;
+
+import java.io.*;
+import java.lang.reflect.Field;
+import java.net.Socket;
+import java.time.LocalDate;
+import java.util.ArrayList;
+
+public class Config implements Serializable {
+ // Helper class for sending chat messages
+ public transient final Sender sender = new Sender();
+
+ public transient boolean highlightitem = false;
+ public transient String lastChatPromptAnswer = null;
+
+ // Automatically set, no need for config
+ private transient String username;
+ private boolean overrideBingoTime = false;
+
+ // Set in-game
+ private transient boolean isLeader;
+ private transient String alreadyReported = "";
+ private String bbServerURL = "static.204.177.34.188.clients.your-server.de";
+ public String bbsentialsRoles = "";
+ public static ArrayList<String> partyMembers = new ArrayList<>();
+
+ // Set via load / default
+ private String bbsentialsCommandPrefix = ".";
+ private String apiKey = "";
+ private boolean leaveDungeonAutomatically;
+ private boolean allowBBinviteMe = true;
+ private boolean leaveKuudraAutomatically;
+ private boolean devMode = false;
+ private boolean detailedDevMode = false;
+ private boolean acceptReparty;
+ private String nickname;
+ private String getNotifForParty;
+
+ // Set default attribute values
+ private void setDefaults() {
+ username = MinecraftClient.getInstance().player.getName().getString();
+ leaveKuudraAutomatically = true;
+ leaveDungeonAutomatically = true;
+ acceptReparty = true;
+ if (username.equals("Hype_the_Time")) {
+ nickname = "Hype";
+ getNotifForParty = "nick";
+ }
+ else {
+ nickname = "";
+ getNotifForParty = "none";
+ }
+ }
+
+ // Method to send the config to a server using sockets
+ public void sendConfig(Config config, String host, int port) {
+ Socket socket = null;
+ ObjectOutputStream objectOutputStream = null;
+ try {
+ socket = new Socket(host, port);
+ objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
+ objectOutputStream.writeObject(config);
+ objectOutputStream.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ if (objectOutputStream != null) {
+ objectOutputStream.close();
+ }
+ if (socket != null) {
+ socket.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // Method to replace the current config with a new one
+ public void replaceConfig(Config newConfig) {
+ try {
+ // Get the class of the current config
+ Class<? extends Config> currentClass = this.getClass();
+
+ // Get the fields of the current config class
+ Field[] currentFields = currentClass.getDeclaredFields();
+
+ // Iterate through the fields
+ for (Field field : currentFields) {
+ // Exclude the socket field from being updated
+ if (field.getName().equals("serverSocket") || field.getName().equals("clientSocket")) {
+ continue;
+ }
+
+ // Make the field accessible to modify its value
+ field.setAccessible(true);
+
+ // Get the corresponding field from the new config class
+ Field newField = newConfig.getClass().getDeclaredField(field.getName());
+
+ // Make the new field accessible to read its value
+ newField.setAccessible(true);
+
+ // Get the current value of the field
+ Object currentValue = field.get(this);
+
+ // Get the new value of the field
+ Object newValue = newField.get(newConfig);
+
+ // Update the field only if it is defined or explicitly overridden
+ if (newValue != null || currentValue == null) {
+ field.set(this, newValue);
+ }
+ }
+ } catch (IllegalAccessException | NoSuchFieldException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // Gson object for serialization
+ private final transient Gson GSON = new GsonBuilder().setPrettyPrinting().create();
+ // File object for storing the config
+ private final transient File CONFIG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "BBsential_settings.json");
+
+ // Constructor
+ public Config() {
+ setDefaults();
+ }
+
+ // Load the config from file
+ public static Config load() {
+ Config settings;
+ File CONFIG_FILE = new File(FabricLoader.getInstance().getConfigDir().toFile(), "BBsential_settings.json");
+ Gson GSON = new GsonBuilder().setPrettyPrinting().create();
+ if (CONFIG_FILE.exists()) {
+ try (FileReader reader = new FileReader(CONFIG_FILE)) {
+ settings = GSON.fromJson(reader, Config.class);
+ } catch (IOException e) {
+ e.printStackTrace();
+ settings = new Config(); // Use default values if loading fails
+ }
+ }
+ else {
+ settings = new Config(); // Use default values if the file doesn't exist
+ settings.username = MinecraftClient.getInstance().player.getName().getString();
+ }
+ if (!settings.bbsentialsRoles.contains("dev")) {
+ settings.detailedDevMode = false;
+ settings.devMode = false;
+ }
+ return settings;
+ }
+
+ // Save the config to file
+ public void save() {
+ try (FileWriter writer = new FileWriter(CONFIG_FILE)) {
+ GSON.toJson(this, writer);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ // Getter methods for various config attributes
+ public String getUsername() {
+ return username;
+ }
+
+ public boolean isLeader() {
+ return isLeader;
+ }
+
+ public void setIsLeader(boolean value) {
+ isLeader = value;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public String getNotifForParty() {
+ return getNotifForParty;
+ }
+
+ public boolean isLeaveDungeonAutomatically() {
+ return leaveDungeonAutomatically;
+ }
+
+ public boolean isLeaveKuudraAutomatically() {
+ return leaveKuudraAutomatically;
+ }
+
+ public boolean isDevModeEnabled() {
+ return devMode;
+ }
+
+ public boolean isDetailedDevModeEnabled() {
+ return detailedDevMode;
+ }
+
+ public String[] getPlayersInParty() {
+ return partyMembers.toArray(new String[0]);
+ }
+
+ public boolean messageFromAlreadyReported(String message) {
+ return alreadyReported.contains(Chat.getPlayerNameFromMessage(message));
+ }
+
+ public void addReported(String playerName) {
+ alreadyReported = alreadyReported + " , " + playerName;
+ }
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ public String getBBServerURL() {
+ return bbServerURL;
+ }
+
+ public String getCommandPrefix(String type) {
+ if (type.equals("BBsentials")) {
+ System.out.println("Registered command with: " + bbsentialsCommandPrefix);
+ return bbsentialsCommandPrefix;
+ }
+ else {
+ return "/";
+ }
+ }
+
+ public static boolean isBingoTime() {
+ LocalDate currentDate = LocalDate.now();
+ LocalDate lastDayOfMonth = currentDate.withDayOfMonth(currentDate.lengthOfMonth());
+ LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1);
+ Boolean isBefore = currentDate.isAfter(lastDayOfMonth.minusDays(4));
+ Boolean isInRange = currentDate.isBefore(firstDayOfMonth.plusDays(15));
+ return isBefore || isInRange;
+ }
+
+ public boolean overrideBingoTime() {
+ return overrideBingoTime;
+ }
+
+ public boolean isHighlightitem() {
+ return highlightitem;
+ }
+
+ public String getLastChatPromptAnswer() {
+ return lastChatPromptAnswer;
+ }
+
+ public boolean allowBBinviteMe() {
+ return allowBBinviteMe;
+ }
+
+ public void setLastChatPromptAnswer(String lastChatPromptAnswer) {
+ this.lastChatPromptAnswer = lastChatPromptAnswer;
+ }
+}