From 6d01e2a35ecc47424dd903c5371c83f19af4a567 Mon Sep 17 00:00:00 2001 From: cubewhy Date: Tue, 23 Jan 2024 13:23:58 +0800 Subject: [PATCH] fix set agent args --- .../org/cubewhy/celestial/game/addon/JavaAgent.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cubewhy/celestial/game/addon/JavaAgent.java b/src/main/java/org/cubewhy/celestial/game/addon/JavaAgent.java index 7832b4a7..f93acf52 100644 --- a/src/main/java/org/cubewhy/celestial/game/addon/JavaAgent.java +++ b/src/main/java/org/cubewhy/celestial/game/addon/JavaAgent.java @@ -97,7 +97,7 @@ public static List findEnabled() { if (javaAgentFolder.isDirectory()) { for (File file : Objects.requireNonNull(javaAgentFolder.listFiles())) { if (file.getName().endsWith(".jar") && file.isFile()) { - list.add(new JavaAgent(file)); + list.add(new JavaAgent(file, JavaAgent.findAgentArg(file.getName()))); } } } @@ -109,7 +109,7 @@ public static List findEnabled() { if (javaAgentFolder.isDirectory()) { for (File file : Objects.requireNonNull(javaAgentFolder.listFiles())) { if (file.getName().endsWith(".jar.disabled") && file.isFile()) { - list.add(new JavaAgent(file)); + list.add(new JavaAgent(file, JavaAgent.findAgentArg(file.getName()))); } } } @@ -140,7 +140,7 @@ public static void setArgFor(@NotNull JavaAgent agent, String arg) { */ public static void setArgFor(String name, String arg) { JsonObject ja = config.getValue("javaagents").getAsJsonObject(); - ja.addProperty(name, arg); // leave empty + ja.addProperty(name, arg); config.setValue("javaagents", ja); // dump } @@ -215,6 +215,11 @@ public boolean isEnabled() { @Override public boolean toggle() { + if (isEnabled()) { + migrate(file.getName(), file.getName() + ".disabled"); + } else { + migrate(file.getName(), file.getName().substring(0, file.getName().length() - 9)); + } return toggle0(file); } }