From 406746e45535f78561dbbf990acfc6ab0a13823c Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Wed, 23 Oct 2024 01:28:35 +0800 Subject: [PATCH] =?UTF-8?q?gui->wrapper=EF=BC=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=BA=AF=E6=8E=A7=E5=88=B6=E5=8F=B0=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wrapper/build.gradle | 4 +- .../xujiayao/discord_mc_chat/gui/Main.java | 41 ----------- .../discord_mc_chat/{gui => wrapper}/GUI.form | 2 +- .../discord_mc_chat/{gui => wrapper}/GUI.java | 9 +-- .../discord_mc_chat/wrapper/Main.java | 68 +++++++++++++++++++ .../main/resources/lang/lang_zh_CN.properties | 2 +- 6 files changed, 77 insertions(+), 49 deletions(-) delete mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/Main.java rename wrapper/src/main/java/com/xujiayao/discord_mc_chat/{gui => wrapper}/GUI.form (99%) rename wrapper/src/main/java/com/xujiayao/discord_mc_chat/{gui => wrapper}/GUI.java (97%) create mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java diff --git a/wrapper/build.gradle b/wrapper/build.gradle index e05e248..e4fe547 100644 --- a/wrapper/build.gradle +++ b/wrapper/build.gradle @@ -35,7 +35,7 @@ dependencies { } include("net.sf.trove4j:core:3.1.0") include("org.apache.commons:commons-collections4:4.4") - include("org.slf4j:slf4j-api:2.0.13") // 1.x is Incompatible with Quilt (#164) + shadow(implementation("org.slf4j:slf4j-api:2.0.13")) // 1.x is Incompatible with Quilt (#164) include("com.neovisionaries:nv-websocket-client:2.14") include("com.fasterxml.jackson.core:jackson-core:2.17.2") include("com.fasterxml.jackson.core:jackson-databind:2.17.2") @@ -123,7 +123,7 @@ processResources { jar { manifest { - attributes "Main-Class": "com.xujiayao.discord_mc_chat.gui.Main" + attributes "Main-Class": "com.xujiayao.discord_mc_chat.wrapper.Main" } } diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/Main.java b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/Main.java deleted file mode 100644 index c3c849e..0000000 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/Main.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.xujiayao.discord_mc_chat.gui; - -import com.formdev.flatlaf.FlatIntelliJLaf; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import javax.swing.*; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.Locale; -import java.util.Objects; - -/** - * @author Xujiayao - */ -public class Main { - - public static final String VERSION; - - static { - String version = null; - try (Reader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/fabric.mod.json")))) { - version = new Gson().fromJson(reader, JsonObject.class).get("version").getAsString(); - } catch (Exception e) { - e.printStackTrace(); - } - VERSION = version; - } - - - public static void main(String[] args) { - SwingUtilities.invokeLater(() -> { - FlatIntelliJLaf.setup(); - - //Locale.setDefault(Locale.US); - - GUI gui = new GUI(); - gui.setVisible(true); - }); - } -} diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.form b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form similarity index 99% rename from wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.form rename to wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form index 5df2430..8c349da 100644 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.form +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form @@ -1,5 +1,5 @@ -
+ diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.java b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java similarity index 97% rename from wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.java rename to wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java index 4187511..692abee 100644 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/GUI.java +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java @@ -1,4 +1,4 @@ -package com.xujiayao.discord_mc_chat.gui; +package com.xujiayao.discord_mc_chat.wrapper; import com.formdev.flatlaf.extras.FlatSVGIcon; import com.formdev.flatlaf.extras.FlatSVGUtils; @@ -19,7 +19,8 @@ import java.util.PropertyResourceBundle; import java.util.ResourceBundle; -import static com.xujiayao.discord_mc_chat.gui.Main.VERSION; +import static com.xujiayao.discord_mc_chat.wrapper.Main.LOGGER; +import static com.xujiayao.discord_mc_chat.wrapper.Main.VERSION; /** * @author Xujiayao @@ -56,7 +57,7 @@ public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("https://blog.xujiayao.com/posts/4ba0a17a/")); } catch (Exception ex) { - ex.printStackTrace(); + LOGGER.error("Exception", ex); } } }); @@ -67,7 +68,7 @@ public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("https://discord.gg/kbXkV6k2XU")); } catch (Exception ex) { - ex.printStackTrace(); + LOGGER.error("Exception", ex); } } }); diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java new file mode 100644 index 0000000..e6f1e7a --- /dev/null +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java @@ -0,0 +1,68 @@ +package com.xujiayao.discord_mc_chat.wrapper; + +import com.formdev.flatlaf.FlatIntelliJLaf; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.swing.*; +import java.awt.*; +import java.io.InputStreamReader; +import java.io.Reader; +import java.text.MessageFormat; +import java.util.Objects; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +/** + * @author Xujiayao + */ +public class Main { + + public static final String VERSION; + public static final Logger LOGGER = LoggerFactory.getLogger("Discord-MC-Chat Wrapper"); + + static { + String version = null; + try (Reader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/fabric.mod.json")))) { + version = new Gson().fromJson(reader, JsonObject.class).get("version").getAsString(); + } catch (Exception e) { + LOGGER.error("Exception", e); + } + VERSION = version; + } + + + public static void main(String[] args) { + // Locale.setDefault(Locale.US); + + if (Desktop.isDesktopSupported()) { + SwingUtilities.invokeLater(() -> { + FlatIntelliJLaf.setup(); + + GUI gui = new GUI(); + gui.setVisible(true); + }); + } else { + ResourceBundle bundle = PropertyResourceBundle.getBundle("lang/lang"); + + String description2 = bundle.getString("description2").replaceAll("|", ""); + + LOGGER.info("-----------------------------------------"); + LOGGER.info(bundle.getString("welcome")); + LOGGER.info(MessageFormat.format(bundle.getString("version"), VERSION)); + LOGGER.info(bundle.getString("author")); + LOGGER.info(""); + LOGGER.info(bundle.getString("description1").replaceAll("|", "")); + LOGGER.info(""); + LOGGER.info(description2.substring(0, description2.indexOf("<"))); + LOGGER.info(description2.substring(description2.indexOf("
") + 8)); + LOGGER.info(""); + LOGGER.info(bundle.getString("description3").replaceAll("|", "").replaceAll("", " (https://blog.xujiayao.com/posts/4ba0a17a/)").replaceAll("<(.*?)>", "")); + LOGGER.info(""); + LOGGER.info(bundle.getString("description4").replaceAll("|", "").replaceAll("", " (https://discord.gg/kbXkV6k2XU)").replaceAll("<(.*?)>", "")); + LOGGER.info("-----------------------------------------"); + } + } +} \ No newline at end of file diff --git a/wrapper/src/main/resources/lang/lang_zh_CN.properties b/wrapper/src/main/resources/lang/lang_zh_CN.properties index e9eadeb..fc43fe3 100644 --- a/wrapper/src/main/resources/lang/lang_zh_CN.properties +++ b/wrapper/src/main/resources/lang/lang_zh_CN.properties @@ -5,5 +5,5 @@ author=作者:Xujiayao description1=哎呀!你正试图直接运行 Discord-MC-Chat! description2=注意:

Discord-MC-Chat 是一个 Fabric Minecraft 模组。请将 JAR 文件放入 Minecraft 服务器的 "mods" 文件夹中,并通过 Fabric 模组加载器运行,而并非直接打开。 description3=请按照 Discord-MC-Chat 文档 配置 Discord-MC-Chat。 -description4=如果你需要更多帮助,你可以在 DMCC Discord Server 向我提问。 +description4=如果你需要更多帮助,你可以在 DMCC Discord 服务器 向我提问。 buttonText=&关闭 \ No newline at end of file