Skip to content

Commit

Permalink
gui->wrapper,实现纯控制台模式
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Oct 22, 2024
1 parent efef398 commit 406746e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 49 deletions.
4 changes: 2 additions & 2 deletions wrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"
}
}

Expand Down
41 changes: 0 additions & 41 deletions wrapper/src/main/java/com/xujiayao/discord_mc_chat/gui/Main.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.xujiayao.discord_mc_chat.gui.GUI">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.xujiayao.discord_mc_chat.wrapper.GUI">
<grid id="27dc6" binding="contentPane" layout-manager="GridLayoutManager" row-count="13" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
});
Expand All @@ -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);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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("<html>|</html>", "");

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("<html>|</html>", ""));
LOGGER.info("");
LOGGER.info(description2.substring(0, description2.indexOf("<")));
LOGGER.info(description2.substring(description2.indexOf("<br>") + 8));
LOGGER.info("");
LOGGER.info(bundle.getString("description3").replaceAll("<html>|</html>", "").replaceAll("</font>", " (https://blog.xujiayao.com/posts/4ba0a17a/)").replaceAll("<(.*?)>", ""));
LOGGER.info("");
LOGGER.info(bundle.getString("description4").replaceAll("<html>|</html>", "").replaceAll("</font>", " (https://discord.gg/kbXkV6k2XU)").replaceAll("<(.*?)>", ""));
LOGGER.info("-----------------------------------------");
}
}
}
2 changes: 1 addition & 1 deletion wrapper/src/main/resources/lang/lang_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ author=作者:Xujiayao
description1=<html>哎呀!你正试图直接运行 Discord-MC-Chat!</html>
description2=<html>注意:<br><br>Discord-MC-Chat 是一个 Fabric Minecraft 模组。请将 JAR 文件放入 Minecraft 服务器的 "mods" 文件夹中,并通过 Fabric 模组加载器运行,而并非直接打开。</html>
description3=<html>请按照 <font color="#1B75D0">Discord-MC-Chat 文档</font> 配置 Discord-MC-Chat。</html>
description4=<html>如果你需要更多帮助,你可以在 <font color="#1B75D0">DMCC Discord Server</font> 向我提问。</html>
description4=<html>如果你需要更多帮助,你可以在 <font color="#1B75D0">DMCC Discord 服务器</font> 向我提问。</html>
buttonText=&关闭

0 comments on commit 406746e

Please sign in to comment.