diff options
author | hackthetime <l4bg0jb7@duck.com> | 2023-11-08 10:35:08 +0100 |
---|---|---|
committer | hackthetime <l4bg0jb7@duck.com> | 2023-11-08 10:35:08 +0100 |
commit | c41eb7f730e7586a69dce21691083f4637c0e595 (patch) | |
tree | 45564770e7140e10be8f96c74850dbea06a3c3c5 /common | |
parent | 208ee28028e4a772a573a75f2aef6780304b3f53 (diff) | |
download | BBsentials-c41eb7f730e7586a69dce21691083f4637c0e595.tar.gz BBsentials-c41eb7f730e7586a69dce21691083f4637c0e595.tar.bz2 BBsentials-c41eb7f730e7586a69dce21691083f4637c0e595.zip |
found a solution to solve the bug that crashed the mod when initialising the config at startup. No automatically loads the config at start by using a different source for the username. getUsername did not change.
Diffstat (limited to 'common')
3 files changed, 51 insertions, 67 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 2c9a603..20fb7ef 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 @@ -18,7 +18,6 @@ public class BBsentials { public static SplashStatusUpdateListener splashStatusUpdateListener; public static Thread bbthread; public static Chat chat = new Chat(); - private static boolean initialised = false; public static Config getConfig() { return config; @@ -67,20 +66,14 @@ public class BBsentials { public static void onServerSwap() { splashLobby = false; - if (!initialised) { - config = Config.load(); - executionService.scheduleAtFixedRate(EnvironmentCore.debug, 0, 20, TimeUnit.SECONDS); - if (config.doGammaOverride) EnvironmentCore.mcoptions.setGamma(10); - if (Config.isBingoTime() || config.overrideBingoTime()) { - connectToBBserver(); - } - initialised = true; - } } - public void manualLoad() { - initialised = true; + public static void init() { config = Config.load(); - connectToBBserver(); + executionService.scheduleAtFixedRate(EnvironmentCore.debug, 0, 20, TimeUnit.SECONDS); + if (config.doGammaOverride) EnvironmentCore.mcoptions.setGamma(10); + if (Config.isBingoTime() || config.overrideBingoTime()) { + connectToBBserver(); + } } }
\ No newline at end of file diff --git a/common/src/main/java/de/hype/bbsentials/common/client/Config.java b/common/src/main/java/de/hype/bbsentials/common/client/Config.java index e05320a..ceeafa9 100644 --- a/common/src/main/java/de/hype/bbsentials/common/client/Config.java +++ b/common/src/main/java/de/hype/bbsentials/common/client/Config.java @@ -13,25 +13,23 @@ import java.util.List; public class Config implements Serializable { //DO NOT Change any of the following unless you know what you are doing! public static int apiVersion = 1; + public static List<String> partyMembers = new ArrayList<>(); + public transient final Sender sender = new Sender(); + // 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(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); + //You can change again public boolean allowServerPartyInvite = true; public boolean devMode = false; public boolean detailedDevMode = false; public boolean devSecurity = true; - //You can change again - - // set automatically - private transient boolean isPartyLeader; public transient String overwriteActionBar = ""; - public transient String alreadyReported = ""; public String[] bbsentialsRoles = {""}; - public static List<String> partyMembers = new ArrayList<>(); public transient ToDisplayConfig toDisplayConfig = ToDisplayConfig.loadFromFile(); - public transient final Sender sender = new Sender(); public transient boolean highlightitem = false; public transient String lastChatPromptAnswer = null; - private transient String username; - // Set via load / default you may change these public boolean useNumCodes = true; public boolean overrideBingoTime = false; @@ -41,9 +39,9 @@ public class Config implements Serializable { public String bbServerURL = "localhost"; public String apiKey = ""; public boolean showBingoChat = true; - public boolean doAllChatCustomMenu=true; - public boolean doPartyChatCustomMenu=true; - public boolean doGuildChatCustomMenu=true; + public boolean doAllChatCustomMenu = true; + public boolean doPartyChatCustomMenu = true; + public boolean doGuildChatCustomMenu = true; public boolean allowBBinviteMe = true; public boolean doDesktopNotifications = false; @@ -57,27 +55,9 @@ public class Config implements Serializable { public boolean swapActionBarChat = false; public boolean swapOnlyNormal = true; public boolean swapOnlyBBsentials = false; - - // Set default attribute values - private void setDefaults() { - username = EnvironmentCore.mcUtils.getUsername(); - acceptReparty = true; - if (username.equals("Hype_the_Time")) { - nickname = "Hype"; - notifForMessagesType = "nick"; - doDesktopNotifications=true; - } //Gimmic for Developer due too things which dont make it into releases (bugs) - else { - nickname = ""; - notifForMessagesType = "none"; - } - } - - // 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(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); - + // set automatically + private transient boolean isPartyLeader; + private transient String username; // Constructor public Config() { setDefaults(); @@ -89,14 +69,12 @@ public class Config implements Serializable { File CONFIG_FILE = new File(EnvironmentCore.mcUtils.getConfigPath(), "BBsential_settings.json"); Gson GSON = new GsonBuilder().setPrettyPrinting().create(); if (CONFIG_FILE.exists()) { - try (FileReader reader = new FileReader(CONFIG_FILE)) { + try { + FileReader reader = new FileReader(CONFIG_FILE); settings = GSON.fromJson(reader, Config.class); - } catch (IOException e) { + } catch (IOException | RuntimeException e) { + System.err.println("Error loading config. Resetting it."); e.printStackTrace(); - settings = new Config(); // Use default values if loading fails - settings.save(); - } catch (IllegalStateException e) { - System.out.println("Error loading config. Resetting it."); settings = new Config(); settings.save(); } @@ -114,6 +92,30 @@ public class Config implements Serializable { return settings; } + 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; + } + + // Set default attribute values + private void setDefaults() { + username = EnvironmentCore.mcUtils.getUsername(); + acceptReparty = true; + if (username.equals("Hype_the_Time")) { + nickname = "Hype"; + notifForMessagesType = "nick"; + doDesktopNotifications = true; + } //Gimmic for Developer due too things which dont make it into releases (bugs) + else { + nickname = ""; + notifForMessagesType = "none"; + } + } + // Save the config to file public void save() { try (FileWriter writer = new FileWriter(CONFIG_FILE)) { @@ -169,16 +171,6 @@ public class Config implements Serializable { return bbServerURL; } - - 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; } @@ -187,14 +179,14 @@ public class Config implements Serializable { return lastChatPromptAnswer; } - public boolean allowBBinviteMe() { - return allowBBinviteMe; - } - public void setLastChatPromptAnswer(String lastChatPromptAnswer) { this.lastChatPromptAnswer = lastChatPromptAnswer; } + public boolean allowBBinviteMe() { + return allowBBinviteMe; + } + public boolean hasBBRoles(String roleName) { if (roleName == null) return true; if (roleName.isEmpty()) return true; 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 7d593f9..59f5bee 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 @@ -134,7 +134,6 @@ public class BBsentialConnection { // Create an SSL socket factory SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); socket = sslSocketFactory.createSocket(serverIP, serverPort); - socket.setKeepAlive(true); // Enable Keep-Alive reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); writer = new PrintWriter(socket.getOutputStream(), true); |