From ecd65f611f1800f650594064d900c88e8d14251d Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 30 Aug 2024 09:56:10 +0800 Subject: [PATCH] =?UTF-8?q?flags.json=20=E6=96=B0=E5=A2=9E=20custom=5Ftext?= =?UTF-8?q?=20=E9=85=8D=E7=BD=AE=EF=BC=8C=E4=BE=BF=E4=BA=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0/=E8=87=AA=E5=AE=9A=E4=B9=89=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../java/cn/lunadeer/dominion/dtos/Flag.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 22478d9c..341186bf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.4.0-beta" +version = "2.4.1-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java b/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java index 35ab27f8..9458a69a 100644 --- a/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java +++ b/core/src/main/java/cn/lunadeer/dominion/dtos/Flag.java @@ -85,10 +85,15 @@ public enum Flag { private Boolean default_value; private Boolean enable; private final Boolean dominion_only; + private Boolean custom_text = false; + private final String default_display_name; + private final String default_description; Flag(String flagName, String displayName, String desc, boolean defaultValue, boolean dominion_only, boolean enable) { this.flag_name = flagName; + this.default_display_name = displayName; this.display_name = displayName; + this.default_description = desc; this.description = desc; this.default_value = defaultValue; this.dominion_only = dominion_only; @@ -221,6 +226,7 @@ public static JSONObject serializeToJson(Flag flag) { json.put("description", flag.getDescription()); json.put("default_value", flag.getDefaultValue()); json.put("enable", flag.getEnable()); + json.put("custom_text", flag.custom_text); return json; } @@ -238,13 +244,19 @@ public static void deserializeFromJson(JSONObject jsonObject) { try { JSONObject flagJson = (JSONObject) jsonObject.get(flag.getFlagName()); if (flagJson != null) { - flag.setDisplayName((String) flagJson.get("display_name")); - flag.setDescription((String) flagJson.get("description")); - flag.setDefaultValue((Boolean) flagJson.get("default_value")); - flag.setEnable((Boolean) flagJson.get("enable")); + flag.custom_text = (Boolean) flagJson.getOrDefault("custom_text", false); + flag.setDefaultValue((Boolean) flagJson.getOrDefault("default_value", flag.getDefaultValue())); + flag.setEnable((Boolean) flagJson.getOrDefault("enable", flag.getEnable())); + if (flag.custom_text) { // 如果使用自定义文本 则从配置文件中读取 + flag.setDisplayName((String) flagJson.getOrDefault("display_name", flag.getDisplayName())); + flag.setDescription((String) flagJson.getOrDefault("description", flag.getDescription())); + } else { // 否则设置为默认文本 + flag.setDisplayName(flag.default_display_name); + flag.setDescription(flag.default_description); + } } } catch (Exception e) { - XLogger.warn("读取权限 %s 配置失败:%s,已跳过", flag.getFlagName(), e.getMessage()); + XLogger.warn("读取权限 %s 配置失败:%s,已跳过,使用默认配置", flag.getFlagName(), e.getMessage()); } } }