From 6dc78354f6239900e7f07a09b47dd499c57a96cc Mon Sep 17 00:00:00 2001 From: Taskeren Date: Mon, 28 Oct 2024 12:33:43 +0800 Subject: [PATCH] added an option to disable DefaultServerList, and removed ".idea" --- .gitignore | 2 + .idea/compiler.xml | 37 - .idea/gradle.xml | 18 - .idea/inspectionProfiles/GTNN_Inspections.xml | 6 - .../inspectionProfiles/profiles_settings.xml | 6 - .idea/jarRepositories.xml | 70 -- .idea/kotlinc.xml | 9 - .idea/misc.xml | 7 - .idea/modules.xml | 10 - .idea/scala_compiler.xml | 9 - .idea/uiDesigner.xml | 124 --- .idea/vcs.xml | 6 - .idea/workspace.xml | 985 ------------------ .../cn/taskeren/gtnn/client/ClientProxy.java | 12 + .../no_default_server/NoDefaultServer.java | 53 + .../taskeren/gtnn/common/config/Config.java | 4 +- 16 files changed, 69 insertions(+), 1289 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/inspectionProfiles/GTNN_Inspections.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/jarRepositories.xml delete mode 100644 .idea/kotlinc.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/scala_compiler.xml delete mode 100644 .idea/uiDesigner.xml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml create mode 100644 src/main/java/cn/taskeren/gtnn/client/no_default_server/NoDefaultServer.java diff --git a/.gitignore b/.gitignore index 776c010..47479b9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ src/main/resources/mixins.*([!.]).json *.bat *.DS_Store !gradlew.bat + +.idea diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 8bc9113..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 650a3a0..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/GTNN_Inspections.xml b/.idea/inspectionProfiles/GTNN_Inspections.xml deleted file mode 100644 index bdd52e6..0000000 --- a/.idea/inspectionProfiles/GTNN_Inspections.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 9457068..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 5e0f270..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 22dcb88..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index e653c7e..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 54227ba..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/scala_compiler.xml b/.idea/scala_compiler.xml deleted file mode 100644 index f3244af..0000000 --- a/.idea/scala_compiler.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 66c6c60..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,985 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/cn/taskeren/gtnn/client/ClientProxy.java b/src/main/java/cn/taskeren/gtnn/client/ClientProxy.java index 5134579..326ec9c 100644 --- a/src/main/java/cn/taskeren/gtnn/client/ClientProxy.java +++ b/src/main/java/cn/taskeren/gtnn/client/ClientProxy.java @@ -1,5 +1,7 @@ package cn.taskeren.gtnn.client; +import cn.taskeren.gtnn.GTNN; +import cn.taskeren.gtnn.client.no_default_server.NoDefaultServer; import cn.taskeren.gtnn.common.CommonProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -20,5 +22,15 @@ public void onInit(FMLInitializationEvent event) { @Override public void onPostInit(FMLPostInitializationEvent event) { super.onPostInit(event); + + // the list is loaded in the pre-init stage in the DefaultServerList mod, + // so we clear it at post-init stage, it should not be filled again + try { + if(NoDefaultServer.isDefaultServerListInstalled()) { + NoDefaultServer.clearDefaultServerList(); + } + } catch(Exception e) { + GTNN.logger.error("Failed to remove Default Server List!", e); + } } } diff --git a/src/main/java/cn/taskeren/gtnn/client/no_default_server/NoDefaultServer.java b/src/main/java/cn/taskeren/gtnn/client/no_default_server/NoDefaultServer.java new file mode 100644 index 0000000..1212ec9 --- /dev/null +++ b/src/main/java/cn/taskeren/gtnn/client/no_default_server/NoDefaultServer.java @@ -0,0 +1,53 @@ +package cn.taskeren.gtnn.client.no_default_server; + +import cn.taskeren.gtnn.GTNN; +import org.jetbrains.annotations.Nullable; + +import java.util.LinkedHashMap; + +public class NoDefaultServer { + + private static final String PACKAGE_DEFAULT_SERVER_LIST = "glowredman.defaultserverlist."; + + private static final String DEFAULT_SERVER_LIST_CONFIG_CLASS_NAME = PACKAGE_DEFAULT_SERVER_LIST + "Config"; + + @Nullable + private static final Class DEFAULT_SERVER_LIST_CONFIG; + + static { + Class clazz; + + try { + clazz = Class.forName(DEFAULT_SERVER_LIST_CONFIG_CLASS_NAME); + } catch(ClassNotFoundException ex) { + clazz = null; + GTNN.logger.info("DefaultServerList is not found. Yay!"); + } + + DEFAULT_SERVER_LIST_CONFIG = clazz; + } + + public static boolean isDefaultServerListInstalled() { + return DEFAULT_SERVER_LIST_CONFIG != null; + } + + public static void clearDefaultServerList() throws Exception { + if(!isDefaultServerListInstalled()) { + return; + } + + var log = GTNN.logger; + + log.debug("Attempt to get 'config' field in Config class"); + var configField = DEFAULT_SERVER_LIST_CONFIG.getDeclaredField("config"); + log.debug("Attempt to get 'config' instance in Config class"); + var configObject = configField.get(null); + log.debug("Attempt to get 'servers' field in ConfigObj class"); + var serversMapField = configObject.getClass().getDeclaredField("servers"); + log.debug("Attempt to get 'servers' instance in ConfigObj class"); + var serversMap = (LinkedHashMap) serversMapField.get(configObject); + log.debug("Nice, everything is done! Clearing list!"); + serversMap.clear(); + } + +} diff --git a/src/main/java/cn/taskeren/gtnn/common/config/Config.java b/src/main/java/cn/taskeren/gtnn/common/config/Config.java index 3cb08b9..3ada992 100644 --- a/src/main/java/cn/taskeren/gtnn/common/config/Config.java +++ b/src/main/java/cn/taskeren/gtnn/common/config/Config.java @@ -13,12 +13,12 @@ public class Config { private static final Configuration CONF; - public static boolean useRawMouseMotion; + public static boolean removeDefaultServerList; static { CONF = new Configuration(new File("config/gtnn.cfg")); - useRawMouseMotion = CONF.getBoolean("use-raw-mouse-motion", "client", true, "Whether enable Raw Mouse Motion or not. Removed, use lwjgl3ify instead."); + removeDefaultServerList = CONF.getBoolean("remove-default-server-list", "client", true, "Whether remove the Default Server List."); CONF.save(); }