From 177d8020eeac4d7d89b398ec029ae07b4c9aa631 Mon Sep 17 00:00:00 2001 From: RitzKid76 Date: Mon, 14 Apr 2025 12:22:31 -0400 Subject: [PATCH 1/2] override getInt to prevent default data saving --- .../chatguard/util/config/ConfigUtil.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java b/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java index 4c9d6f1..544e05a 100644 --- a/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java +++ b/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java @@ -69,6 +69,36 @@ public void load() { } } + // copied private method out of Configuration + private static Integer castInt(Object o) { + if (o == null) { + return null; + } else if (o instanceof Byte) { + return Integer.valueOf((Byte)o); + } else if (o instanceof Integer) { + return (Integer)o; + } else if (o instanceof Double) { + return (int)((double)o); + } else if (o instanceof Float) { + return (int)(float)o; + } else { + return o instanceof Long ? (int)(long)o : null; + } + } + + /** + * The super inplementation will save the default value if one doesnt exist at the storage location. This override does not. + */ + @Override + public int getInt(String path, int def) { + Integer o = castInt(this.getProperty(path)); + if (o == null) { + return def; + } else { + return o; + } + } + /** * Creates the parent directories for the configuration file if they do not exist. *

From 7021fc1123fee2379e2c4b709d974a5f7491c652 Mon Sep 17 00:00:00 2001 From: RitzKid76 Date: Mon, 14 Apr 2025 12:32:42 -0400 Subject: [PATCH 2/2] style changes does the same thing. i just like it being my style B) --- .../chatguard/util/config/ConfigUtil.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java b/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java index 544e05a..a2a102d 100644 --- a/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java +++ b/src/main/java/io/github/aleksandarharalanov/chatguard/util/config/ConfigUtil.java @@ -92,11 +92,11 @@ private static Integer castInt(Object o) { @Override public int getInt(String path, int def) { Integer o = castInt(this.getProperty(path)); - if (o == null) { + + if (o == null) return def; - } else { - return o; - } + + return o; } /** @@ -173,4 +173,4 @@ public void saveAndLog() { pluginName, configFile.getName(), e.getMessage())); } } -} \ No newline at end of file +}