From f18f6b8d61c46292508a2a6c1f0243b73882e9a0 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 22:31:02 +0800 Subject: [PATCH 1/9] Revert GUI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3fd704affc0fb2d8367d0cc6dcd93e4e6e944c65. Revert "[skip ci] TODOs" This reverts commit 4d3e723c2bf178acb731e24af71cb57eabf8101f. Revert "Fix slf4j" This reverts commit 5893f61dd3446892e0a6b070ac1a2ae5f13b0448. Revert "gui->wrapper,实现纯控制台模式" This reverts commit 406746e45535f78561dbbf990acfc6ab0a13823c. Revert "多语言测试通过,添加两个超链接" This reverts commit efef398c79663ac6e7aa17ecdba2b71f09100ef1. Revert "zh" This reverts commit cb842c34b4564c2a07af731c8f27a1b2e9d0e01e. Revert "修复versions不见" This reverts commit b20866f77a23abe3103e540ae03999e13848e2c1. Revert "version检测" This reverts commit 7a78b7297070ee1062f55ab3ff9b6ed2e0a82d9f. Revert "使用shadow" This reverts commit 35e4fda621d4e0cb2d03d230639252b9564b0fb2. --- build.gradle | 1 - wrapper/build.gradle | 33 +-- .../xujiayao/discord_mc_chat/wrapper/GUI.form | 137 --------- .../xujiayao/discord_mc_chat/wrapper/GUI.java | 264 ------------------ .../discord_mc_chat/wrapper/Main.java | 69 ----- wrapper/src/main/resources/icon.svg | 27 -- .../src/main/resources/lang/lang.properties | 9 - .../main/resources/lang/lang_en_US.properties | 9 - .../main/resources/lang/lang_zh_CN.properties | 9 - 9 files changed, 2 insertions(+), 556 deletions(-) delete mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form delete mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java delete mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java delete mode 100644 wrapper/src/main/resources/icon.svg delete mode 100644 wrapper/src/main/resources/lang/lang.properties delete mode 100644 wrapper/src/main/resources/lang/lang_en_US.properties delete mode 100644 wrapper/src/main/resources/lang/lang_zh_CN.properties diff --git a/build.gradle b/build.gradle index 0bda37f6..7e820af2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { id "fabric-loom" version "1.7-SNAPSHOT" apply false id "com.replaymod.preprocess" version "88169fcb" - id "com.gradleup.shadow" version "8.3.3" apply false } preprocess { diff --git a/wrapper/build.gradle b/wrapper/build.gradle index d691a4f8..9333d872 100644 --- a/wrapper/build.gradle +++ b/wrapper/build.gradle @@ -2,7 +2,6 @@ import groovy.json.JsonBuilder import groovy.json.JsonSlurper apply plugin: "fabric-loom" -apply plugin: "com.gradleup.shadow" java { sourceCompatibility = JavaVersion.VERSION_21 @@ -16,13 +15,6 @@ base { archivesName = archives_base_name } -repositories { - maven { - name = "IntelliJ Release" - url = "https://www.jetbrains.com/intellij-repository/releases" - } -} - dependencies { minecraft("com.mojang:minecraft:${minecraft_version}") mappings(loom.officialMojangMappings()) @@ -35,8 +27,7 @@ dependencies { } include("net.sf.trove4j:core:3.1.0") include("org.apache.commons:commons-collections4:4.4") - shadow(implementation("org.slf4j:slf4j-api:2.0.13")) // 1.x is Incompatible with Quilt (#164) - shadow(implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1")) // TODO Any better way? + include("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") @@ -47,11 +38,7 @@ dependencies { include("net.fellbaum:jemoji:1.3.4") // File size of 1.4.x is too big - shadow(implementation("com.google.code.gson:gson:2.11.0")) - - shadow(implementation("com.jetbrains.intellij.java:java-gui-forms-rt:242.22855.106")) - shadow(implementation("com.formdev:flatlaf:3.5.2")) - shadow(implementation("com.formdev:flatlaf-extras:3.5.2")) + include("com.google.code.gson:gson:2.11.0") } def fabric_subprojects = parent.subprojects.findAll({ @@ -61,10 +48,7 @@ def fabric_subprojects = parent.subprojects.findAll({ remapJar { outputs.upToDateWhen { false } - inputFile.set shadowJar.archiveFile - dependsOn { - shadowJar fabric_subprojects.collect { it.tasks.remapJar } @@ -91,7 +75,6 @@ remapJar { copy { from "build/libs" into "../build" - exclude "*wrapper*" } } } @@ -120,16 +103,4 @@ processResources { writer.flush() writer.close() } -} - -jar { - manifest { - attributes "Main-Class": "com.xujiayao.discord_mc_chat.wrapper.Main" - } -} - -shadowJar { - archiveClassifier = "wrapper" - configurations = [project.configurations.shadow] - // FlatLaf does not support minimization and relocation } \ No newline at end of file diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form deleted file mode 100644 index 8c349da1..00000000 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form +++ /dev/null @@ -1,137 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java deleted file mode 100644 index 692abeec..00000000 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java +++ /dev/null @@ -1,264 +0,0 @@ -package com.xujiayao.discord_mc_chat.wrapper; - -import com.formdev.flatlaf.extras.FlatSVGIcon; -import com.formdev.flatlaf.extras.FlatSVGUtils; -import com.intellij.uiDesigner.core.GridConstraints; -import com.intellij.uiDesigner.core.GridLayoutManager; -import com.intellij.uiDesigner.core.Spacer; - -import javax.swing.*; -import javax.swing.plaf.FontUIResource; -import javax.swing.text.StyleContext; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.lang.reflect.Method; -import java.net.URI; -import java.text.MessageFormat; -import java.util.Locale; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - -import static com.xujiayao.discord_mc_chat.wrapper.Main.LOGGER; -import static com.xujiayao.discord_mc_chat.wrapper.Main.VERSION; - -/** - * @author Xujiayao - */ -public class GUI extends JFrame { - - private JPanel contentPane; - private JLabel versionLabel; - private JButton button; - private JLabel iconLabel; - private JLabel docsLabel; - private JLabel discordLabel; - - public GUI() { - ResourceBundle bundle = PropertyResourceBundle.getBundle("lang/lang"); - - setTitle(bundle.getString("title")); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setContentPane(contentPane); - - setIconImages(FlatSVGUtils.createWindowIconImages("/icon.svg")); - - iconLabel.setIcon(new FlatSVGIcon("icon.svg", 50, 50)); - - String pattern = bundle.getString("version"); - versionLabel.setText(MessageFormat.format(pattern, VERSION)); - - docsLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); - discordLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); - - docsLabel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - Desktop.getDesktop().browse(new URI("https://blog.xujiayao.com/posts/4ba0a17a/")); - } catch (Exception ex) { - LOGGER.error("Exception", ex); - } - } - }); - - discordLabel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - try { - Desktop.getDesktop().browse(new URI("https://discord.gg/kbXkV6k2XU")); - } catch (Exception ex) { - LOGGER.error("Exception", ex); - } - } - }); - - setPreferredSize(new Dimension(500, 400)); - pack(); - - setLocationRelativeTo(null); - setResizable(false); - - button.addActionListener(e -> dispose()); - } - - { -// GUI initializer generated by IntelliJ IDEA GUI Designer -// >>> IMPORTANT!! <<< -// DO NOT EDIT OR ADD ANY CODE HERE! - $$$setupUI$$$(); - } - - /** - * Method generated by IntelliJ IDEA GUI Designer - * >>> IMPORTANT!! <<< - * DO NOT edit this method OR call it in your code! - * - * @noinspection ALL - */ - private void $$$setupUI$$$() { - contentPane = new JPanel(); - contentPane.setLayout(new GridLayoutManager(13, 3, new Insets(10, 10, 10, 10), -1, -1)); - versionLabel = new JLabel(); - Font versionLabelFont = this.$$$getFont$$$(null, -1, 12, versionLabel.getFont()); - if (versionLabelFont != null) versionLabel.setFont(versionLabelFont); - this.$$$loadLabelText$$$(versionLabel, this.$$$getMessageFromBundle$$$("lang/lang", "version")); - contentPane.add(versionLabel, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(248, 22), null, 0, false)); - final JSeparator separator1 = new JSeparator(); - separator1.setOrientation(0); - contentPane.add(separator1, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label1 = new JLabel(); - Font label1Font = this.$$$getFont$$$(null, -1, 12, label1.getFont()); - if (label1Font != null) label1.setFont(label1Font); - this.$$$loadLabelText$$$(label1, this.$$$getMessageFromBundle$$$("lang/lang", "description1")); - contentPane.add(label1, new GridConstraints(3, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - final JSeparator separator2 = new JSeparator(); - separator2.setOrientation(0); - contentPane.add(separator2, new GridConstraints(11, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - button = new JButton(); - Font buttonFont = this.$$$getFont$$$(null, -1, 12, button.getFont()); - if (buttonFont != null) button.setFont(buttonFont); - button.setHorizontalAlignment(0); - this.$$$loadButtonText$$$(button, this.$$$getMessageFromBundle$$$("lang/lang", "buttonText")); - contentPane.add(button, new GridConstraints(12, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label2 = new JLabel(); - Font label2Font = this.$$$getFont$$$(null, Font.BOLD, 20, label2.getFont()); - if (label2Font != null) label2.setFont(label2Font); - this.$$$loadLabelText$$$(label2, this.$$$getMessageFromBundle$$$("lang/lang", "welcome")); - contentPane.add(label2, new GridConstraints(0, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - final JLabel label3 = new JLabel(); - Font label3Font = this.$$$getFont$$$(null, -1, 12, label3.getFont()); - if (label3Font != null) label3.setFont(label3Font); - this.$$$loadLabelText$$$(label3, this.$$$getMessageFromBundle$$$("lang/lang", "author")); - contentPane.add(label3, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); - iconLabel = new JLabel(); - contentPane.add(iconLabel, new GridConstraints(0, 0, 2, 1, GridConstraints.ANCHOR_SOUTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(50, 50), new Dimension(50, 50), new Dimension(50, 50), 0, false)); - final JLabel label4 = new JLabel(); - Font label4Font = this.$$$getFont$$$(null, -1, 12, label4.getFont()); - if (label4Font != null) label4.setFont(label4Font); - label4.setOpaque(false); - this.$$$loadLabelText$$$(label4, this.$$$getMessageFromBundle$$$("lang/lang", "description2")); - contentPane.add(label4, new GridConstraints(5, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - docsLabel = new JLabel(); - Font docsLabelFont = this.$$$getFont$$$(null, -1, 12, docsLabel.getFont()); - if (docsLabelFont != null) docsLabel.setFont(docsLabelFont); - this.$$$loadLabelText$$$(docsLabel, this.$$$getMessageFromBundle$$$("lang/lang", "description3")); - docsLabel.setToolTipText("https://blog.xujiayao.com/posts/4ba0a17a/"); - contentPane.add(docsLabel, new GridConstraints(7, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - final Spacer spacer1 = new Spacer(); - contentPane.add(spacer1, new GridConstraints(8, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); - final Spacer spacer2 = new Spacer(); - contentPane.add(spacer2, new GridConstraints(6, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); - final Spacer spacer3 = new Spacer(); - contentPane.add(spacer3, new GridConstraints(4, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); - final Spacer spacer4 = new Spacer(); - contentPane.add(spacer4, new GridConstraints(10, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); - discordLabel = new JLabel(); - Font discordLabelFont = this.$$$getFont$$$(null, -1, 12, discordLabel.getFont()); - if (discordLabelFont != null) discordLabel.setFont(discordLabelFont); - this.$$$loadLabelText$$$(discordLabel, this.$$$getMessageFromBundle$$$("lang/lang", "description4")); - discordLabel.setToolTipText("https://discord.gg/kbXkV6k2XU"); - contentPane.add(discordLabel, new GridConstraints(9, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); - } - - /** - * @noinspection ALL - */ - private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { - if (currentFont == null) return null; - String resultName; - if (fontName == null) { - resultName = currentFont.getName(); - } else { - Font testFont = new Font(fontName, Font.PLAIN, 10); - if (testFont.canDisplay('a') && testFont.canDisplay('1')) { - resultName = fontName; - } else { - resultName = currentFont.getName(); - } - } - Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); - boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); - Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); - return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); - } - - private static Method $$$cachedGetBundleMethod$$$ = null; - - private String $$$getMessageFromBundle$$$(String path, String key) { - ResourceBundle bundle; - try { - Class thisClass = this.getClass(); - if ($$$cachedGetBundleMethod$$$ == null) { - Class dynamicBundleClass = thisClass.getClassLoader().loadClass("com.intellij.DynamicBundle"); - $$$cachedGetBundleMethod$$$ = dynamicBundleClass.getMethod("getBundle", String.class, Class.class); - } - bundle = (ResourceBundle) $$$cachedGetBundleMethod$$$.invoke(null, path, thisClass); - } catch (Exception e) { - bundle = ResourceBundle.getBundle(path); - } - return bundle.getString(key); - } - - /** - * @noinspection ALL - */ - private void $$$loadLabelText$$$(JLabel component, String text) { - StringBuffer result = new StringBuffer(); - boolean haveMnemonic = false; - char mnemonic = '\0'; - int mnemonicIndex = -1; - for (int i = 0; i < text.length(); i++) { - if (text.charAt(i) == '&') { - i++; - if (i == text.length()) break; - if (!haveMnemonic && text.charAt(i) != '&') { - haveMnemonic = true; - mnemonic = text.charAt(i); - mnemonicIndex = result.length(); - } - } - result.append(text.charAt(i)); - } - component.setText(result.toString()); - if (haveMnemonic) { - component.setDisplayedMnemonic(mnemonic); - component.setDisplayedMnemonicIndex(mnemonicIndex); - } - } - - /** - * @noinspection ALL - */ - private void $$$loadButtonText$$$(AbstractButton component, String text) { - StringBuffer result = new StringBuffer(); - boolean haveMnemonic = false; - char mnemonic = '\0'; - int mnemonicIndex = -1; - for (int i = 0; i < text.length(); i++) { - if (text.charAt(i) == '&') { - i++; - if (i == text.length()) break; - if (!haveMnemonic && text.charAt(i) != '&') { - haveMnemonic = true; - mnemonic = text.charAt(i); - mnemonicIndex = result.length(); - } - } - result.append(text.charAt(i)); - } - component.setText(result.toString()); - if (haveMnemonic) { - component.setMnemonic(mnemonic); - component.setDisplayedMnemonicIndex(mnemonicIndex); - } - } - - /** - * @noinspection ALL - */ - public JComponent $$$getRootComponent$$$() { - return contentPane; - } - -} 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 deleted file mode 100644 index 9375c5c5..00000000 --- a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java +++ /dev/null @@ -1,69 +0,0 @@ -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("-----------------------------------------"); - } - } -} -// TODO icon size? \ No newline at end of file diff --git a/wrapper/src/main/resources/icon.svg b/wrapper/src/main/resources/icon.svg deleted file mode 100644 index f3bd7127..00000000 --- a/wrapper/src/main/resources/icon.svg +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - diff --git a/wrapper/src/main/resources/lang/lang.properties b/wrapper/src/main/resources/lang/lang.properties deleted file mode 100644 index cb1b3012..00000000 --- a/wrapper/src/main/resources/lang/lang.properties +++ /dev/null @@ -1,9 +0,0 @@ -title=Welcome - Discord-MC-Chat (DMCC) -welcome=Welcome to Discord-MC-Chat (DMCC)! -version=Version: {0} -author=By Xujiayao -description1=Oops! You are attempting to run Discord-MC-Chat directly! -description2=Note:

Discord-MC-Chat is a Fabric Minecraft mod. Please place the JAR file in the "mods" folder of your Minecraft server and run it through the Fabric mod loader, instead of opening it directly. -description3=Please follow Discord-MC-Chat Docs to configure Discord-MC-Chat. -description4=If you need more help, you can ask me questions in the DMCC Discord Server. -buttonText=&Close \ No newline at end of file diff --git a/wrapper/src/main/resources/lang/lang_en_US.properties b/wrapper/src/main/resources/lang/lang_en_US.properties deleted file mode 100644 index cb1b3012..00000000 --- a/wrapper/src/main/resources/lang/lang_en_US.properties +++ /dev/null @@ -1,9 +0,0 @@ -title=Welcome - Discord-MC-Chat (DMCC) -welcome=Welcome to Discord-MC-Chat (DMCC)! -version=Version: {0} -author=By Xujiayao -description1=Oops! You are attempting to run Discord-MC-Chat directly! -description2=Note:

Discord-MC-Chat is a Fabric Minecraft mod. Please place the JAR file in the "mods" folder of your Minecraft server and run it through the Fabric mod loader, instead of opening it directly. -description3=Please follow Discord-MC-Chat Docs to configure Discord-MC-Chat. -description4=If you need more help, you can ask me questions in the DMCC Discord Server. -buttonText=&Close \ 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 deleted file mode 100644 index fc43fe3d..00000000 --- a/wrapper/src/main/resources/lang/lang_zh_CN.properties +++ /dev/null @@ -1,9 +0,0 @@ -title=欢迎 - Discord-MC-Chat (DMCC) -welcome=欢迎使用 Discord-MC-Chat (DMCC)! -version=版本:{0} -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 服务器 向我提问。 -buttonText=&关闭 \ No newline at end of file From ea68e6a04e03dda54c9de5e9b89156e3c0973792 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 22:35:06 +0800 Subject: [PATCH 2/9] =?UTF-8?q?Revert=20"=E5=85=BC=E5=AE=B9=E6=89=80?= =?UTF-8?q?=E6=9C=89=E4=BD=BF=E7=94=A8GameProfile=E4=B8=AD=E7=9A=84texture?= =?UTF-8?q?s=E8=BF=9B=E8=A1=8C=E5=AE=9E=E6=97=B6=E7=9A=AE=E8=82=A4?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E7=9A=84=E6=A8=A1=E7=BB=84=20/=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit bf495edd420ee8c7940d9d546a6b56667612833b. --- .../com/xujiayao/discord_mc_chat/Config.java | 4 ++- .../minecraft/MinecraftEventListener.java | 33 ++----------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/xujiayao/discord_mc_chat/Config.java b/src/main/java/com/xujiayao/discord_mc_chat/Config.java index 3e8b1a0b..871ebcec 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/Config.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/Config.java @@ -34,7 +34,9 @@ public static class Generic { public String consoleLogChannelId = ""; public String updateNotificationChannelId = ""; - public String avatarApi = "https://mc-heads.net/avatar/{player_uuid}.png"; + public boolean useUuidInsteadOfName = true; + + public String avatarApi = "https://mc-heads.net/avatar/%player%.png"; public boolean broadcastPlayerCommandExecution = true; public boolean broadcastSlashCommandExecution = true; diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index cd8487df..ea35067b 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -31,10 +31,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; -import java.nio.charset.StandardCharsets; -import java.util.Base64; import java.util.List; -import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ExecutorService; @@ -173,7 +170,7 @@ public static void init() { } if (CONFIG.generic.broadcastChatMessages) { - sendDiscordMessage(contentToDiscord, Objects.requireNonNull(player.getDisplayName()).getString(), getAvatarUrl(player)); + sendDiscordMessage(contentToDiscord, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString()))); if (CONFIG.multiServer.enable) { MULTI_SERVER.sendMessage(false, true, false, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.formatChatMessages ? contentToMinecraft : message); } @@ -217,7 +214,7 @@ public static void init() { //$$ SERVER.sendMessage(message); //#endif - sendDiscordMessage(MarkdownSanitizer.escape(command), Objects.requireNonNull(player.getDisplayName()).getString(), getAvatarUrl(player)); + sendDiscordMessage(MarkdownSanitizer.escape(command), Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString()))); if (CONFIG.multiServer.enable) { MULTI_SERVER.sendMessage(false, true, false, player.getDisplayName().getString(), MarkdownSanitizer.escape(command)); } @@ -356,30 +353,4 @@ private static void sendDiscordMessage(String content, String username, String a executor.shutdown(); } } - - // {player_name} conflicts with nickname-changing mods - // TODO Move to Placeholder class - private static String getAvatarUrl(Player player) { - String hash = "null"; - if (CONFIG.generic.avatarApi.contains("{player_textures}")) { - try { - //#if MC > 12001 - String textures = player.getGameProfile().getProperties().get("textures").iterator().next().value(); - //#else - //$$ String textures = player.getGameProfile().getProperties().get("textures").iterator().next().getValue(); - //#endif - - JsonObject json = new Gson().fromJson(new String(Base64.getDecoder().decode(textures), StandardCharsets.UTF_8), JsonObject.class); - String url = json.getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString(); - - hash = url.replace("http://textures.minecraft.net/texture/", ""); - } catch (NoSuchElementException ignored) { - } - } - - return CONFIG.generic.avatarApi - .replace("{player_uuid}", player.getUUID().toString()) - .replace("{player_name}", player.getName().getString()) - .replace("{player_textures}", hash); - } } From 4cdb51f38985713e622647420f8ab3b3f0d98bf9 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 22:35:31 +0800 Subject: [PATCH 3/9] Revert excludedCommands regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3dd2575c6e69b8dad4a1b322bc159694ed7dafca. Revert "修改正则表达式,同时新增默认排除 /teammsg 和 /tm" This reverts commit 144f85458275053b67c200bbac8e347f75571630. --- src/main/java/com/xujiayao/discord_mc_chat/Config.java | 2 +- .../discord_mc_chat/minecraft/MinecraftEventListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xujiayao/discord_mc_chat/Config.java b/src/main/java/com/xujiayao/discord_mc_chat/Config.java index 871ebcec..e5a831f4 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/Config.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/Config.java @@ -66,7 +66,7 @@ public static class Generic { public boolean shutdownImmediately = false; - public List excludedCommands = List.of("\\/msg ([^@].*)", "\\/tell ([^@].*)", "\\/tellraw ([^@].*)", "\\/w ([^@].*)", "\\/teammsg (.*)", "\\/tm (.*)"); + public List excludedCommands = List.of("/msg", "/tell", "/tellraw", "/w"); public List adminsIds = new ArrayList<>(); } diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index ea35067b..ad6a2831 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -186,7 +186,7 @@ public static void init() { MinecraftEvents.PLAYER_COMMAND.register((player, command) -> { if (CONFIG.generic.broadcastPlayerCommandExecution) { for (String excludedCommand : CONFIG.generic.excludedCommands) { - if (command.matches(excludedCommand)) { + if (command.startsWith(excludedCommand + " ")) { return; } } From 739dd04513abb17d8f22da8a84ed81689e2fa131 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 22:49:12 +0800 Subject: [PATCH 4/9] Fix revert --- .../discord_mc_chat/minecraft/MinecraftEventListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index ad6a2831..b8d7cdca 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -353,4 +353,9 @@ private static void sendDiscordMessage(String content, String username, String a executor.shutdown(); } } + + // TODO reverted + private static String getAvatarUrl(Player player) { + return CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : Objects.requireNonNull(player.getDisplayName()).getString())); + } } From a44833e8202e0dcecbdff69603a1bf90aff04ad2 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 23:03:38 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=B7=BB=E5=8A=A01.21.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +++- gradle.properties | 6 +++--- settings.gradle | 3 ++- versions/1.21.1/gradle.properties | 4 ++-- versions/1.21.3/gradle.properties | 9 +++++++++ versions/mainProject | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 versions/1.21.3/gradle.properties diff --git a/build.gradle b/build.gradle index 7e820af2..2078ceb9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.7-SNAPSHOT" apply false + id "fabric-loom" version "1.8-SNAPSHOT" apply false id "com.replaymod.preprocess" version "88169fcb" } @@ -16,6 +16,7 @@ preprocess { def mc1202 = createNode("1.20.2", 1_20_02, "mojang") def mc1204 = createNode("1.20.4", 1_20_04, "mojang") def mc1211 = createNode("1.21.1", 1_21_01, "mojang") + def mc1213 = createNode("1.21.3", 1_21_03, "mojang") mc1152.link(mc1165, file("versions/mapping-1.15.2-1.16.5.txt")) mc1165.link(mc1171, null) @@ -28,6 +29,7 @@ preprocess { mc1201.link(mc1202, file("versions/mapping-1.20.1-1.20.2.txt")) mc1202.link(mc1204, null) mc1204.link(mc1211, null) + mc1211.link(mc1213, null) } project.afterEvaluate { diff --git a/gradle.properties b/gradle.properties index 61db264c..b22f12d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ archives_base_name=Discord-MC-Chat # Wrapper Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.1 -loader_version=0.16.4 -fabric_version=0.103.0+1.21.1 \ No newline at end of file +minecraft_version=1.21.3 +loader_version=0.16.7 +fabric_version=0.107.0+1.21.3 \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index bafcb8bb..f0d3f4d5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -35,7 +35,8 @@ def versions = Arrays.asList( "1.20.1", "1.20.2", "1.20.4", - "1.21.1" + "1.21.1", + "1.21.3" ) for (String version : versions) { include(":$version") diff --git a/versions/1.21.1/gradle.properties b/versions/1.21.1/gradle.properties index 268f44e1..67846cfb 100644 --- a/versions/1.21.1/gradle.properties +++ b/versions/1.21.1/gradle.properties @@ -3,7 +3,7 @@ minecraft_version=1.21.1 # Fabric Mod Metadata -minecraft_dependency=~1.20.5,~1.21 +minecraft_dependency=~1.20.5,1.21,1.21.1 # Dependencies -fabric_version=0.103.0+1.21.1 \ No newline at end of file +fabric_version=0.107.0+1.21.1 \ No newline at end of file diff --git a/versions/1.21.3/gradle.properties b/versions/1.21.3/gradle.properties new file mode 100644 index 00000000..ad9ef5e1 --- /dev/null +++ b/versions/1.21.3/gradle.properties @@ -0,0 +1,9 @@ +# Fabric Properties +# check these on https://fabricmc.net/develop +minecraft_version=1.21.3 + +# Fabric Mod Metadata +minecraft_dependency=~1.21.2 + +# Dependencies +fabric_version=0.107.0+1.21.3 \ No newline at end of file diff --git a/versions/mainProject b/versions/mainProject index 87967a79..49340f5a 100644 --- a/versions/mainProject +++ b/versions/mainProject @@ -1 +1 @@ -1.21.1 \ No newline at end of file +1.21.3 \ No newline at end of file From 913e5d0d95f46a7546068036f2295f5d817f73cc Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Mon, 28 Oct 2024 23:57:38 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=85=BC=E5=AE=B91.21.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #258 --- build.gradle | 2 +- .../discord_mc_chat/minecraft/MinecraftEventListener.java | 2 +- versions/mapping-1.21.1-1.21.3.txt | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 versions/mapping-1.21.1-1.21.3.txt diff --git a/build.gradle b/build.gradle index 2078ceb9..d4beff73 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ preprocess { mc1201.link(mc1202, file("versions/mapping-1.20.1-1.20.2.txt")) mc1202.link(mc1204, null) mc1204.link(mc1211, null) - mc1211.link(mc1213, null) + mc1211.link(mc1213, file("versions/mapping-1.21.1-1.21.3.txt")) } project.afterEvaluate { diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index b8d7cdca..c36764d2 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -238,7 +238,7 @@ public static void init() { if (CONFIG.generic.announceAdvancements && isDone && display.shouldAnnounceChat() - && player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) { + && player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) { String message = "null"; switch (display.getType()) { diff --git a/versions/mapping-1.21.1-1.21.3.txt b/versions/mapping-1.21.1-1.21.3.txt new file mode 100644 index 00000000..854affd8 --- /dev/null +++ b/versions/mapping-1.21.1-1.21.3.txt @@ -0,0 +1 @@ +net.minecraft.server.level.ServerPlayer level() serverLevel() \ No newline at end of file From fd7ac1807137b4bfc1a0cd42208de164ea0532e2 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Tue, 29 Oct 2024 11:36:24 +0800 Subject: [PATCH 7/9] TODO --- .../discord_mc_chat/minecraft/MinecraftEventListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index c36764d2..3d52b2ab 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -355,6 +355,7 @@ private static void sendDiscordMessage(String content, String username, String a } // TODO reverted + // TODO Commit cafa9c4 private static String getAvatarUrl(Player player) { return CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : Objects.requireNonNull(player.getDisplayName()).getString())); } From 7ea983f8e7b37a2d99ce14c2d7665564705e919c Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Tue, 29 Oct 2024 12:04:13 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B02.3.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug.yml | 3 ++ CHANGELOG.md | 51 ++++++++++++++++------------------ README.md | 2 ++ README_CN.md | 2 ++ gradle.properties | 2 +- update/version.json | 4 +-- update/versions.json | 31 +++++++++------------ 7 files changed, 47 insertions(+), 48 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 53c58475..afcba699 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -25,6 +25,8 @@ body: If a version is not listed below, it is not supported by DMCC. multiple: false options: + - "1.21.3" + - "1.21.2" - "1.21.1" - "1.21" - "1.20.6" @@ -60,6 +62,7 @@ body: multiple: false options: - "Latest Build (GitHub Actions)" + - "2.3.5" - "2.3.4" - "2.3.4-compat" - "2.3.3" diff --git a/CHANGELOG.md b/CHANGELOG.md index 891d739e..b0d82f1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,50 +1,46 @@ # Changelog 更新日志 -## Discord-MC-Chat 2.3.4 for Minecraft 1.19.4+ - 2024/7/11 +## Discord-MC-Chat 2.3.5 for Minecraft 1.14.4+ - 2024/10/29 DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU -DMCC will support the [Placeholder API]() in the next release. +DMCC now supports switching to Brazilian Portuguese. Note that DMCC no longer releases Active and Compat versions separately. -`botPlayingStatus` and `botListeningStatus` have been renamed to `botPlayingActivity` and `botListeningActivity`. Please modify them before restarting the server to avoid losing any existing changes. - -In addition, the check for updates feature has been fixed. You will be able to receive update notifications for future new versions when using version 2.3.4. +As this is a minor release, new features that involve modifying the config file will not be released in this version. DMCC Discord 服务器现已公开!通过以下链接加入:https://discord.gg/kbXkV6k2XU -DMCC 将在下一个版本中支持 [Placeholder API]()。 - -`botPlayingStatus` 和 `botListeningStatus` 已被重命名为 `botPlayingActivity` 和 `botListeningActivity`。请在重新启动服务器之前进行修改,以免丢失现有的更改。 +DMCC 现在支持切换到巴西葡萄牙语。留意现在 DMCC 不再分开发布 Active 和 Compat 版本。 -此外,检查更新的功能已经修复。在使用 2.3.4 版本时,你将能够接收到未来新版本的更新推送。 +由于这是一个次要版本,涉及到修改配置文件的新功能暂时不会发布。 ## New Features 新特性 -- Add the ability to display server status in the bot's Discord online status (#95) - 添加在机器人的 Discord 在线状态中显示服务器状态的功能 +- Brazilian Portuguese translation (#243) + 巴西葡萄牙语翻译 -## Changes 更改 +- Supports broadcasting messages sent using the /tellraw @a command (#132 and #250) + 支持广播使用 /tellraw @a 命令发送的消息 -- Improved detection logic for dynamic-created DMCC Webhooks (#233) - 改进 DMCC Webhook 动态创建的检测逻辑 +- Restore /say command broadcast feature in versions 1.18.2 and below (#197) + 恢复在 1.18.2 及更早版本中广播 /say 命令的功能 -- Fix number of players in bot activity does not decrease when player leaves the game (#235) - 修复机器人活动状态中的玩家数量在玩家离开游戏时不会减少 +- Throws exception when Webhook fails to send (#249) + 在 Webhook 发送失败时抛出异常 -- Fix DMCC update notifications never being sent (#231, #234 and #239) - 修复 DMCC 更新通知从未发送 +- Compatible with Minecraft 1.21.2 and 1.21.3 (#258) + 兼容 Minecraft 1.21.2 和 1.21.3 版本 -- Fix exception when the world/stats folder does not exist (#38) - 修复 world/stats 文件夹不存在时报错 +## Changes 更改 -- No longer delays checking for updates by an hour (#52) - 不再延迟一小时开始检查更新 +- Changed the way DMCC handles the /say command (#197) + 更改 DMCC 处理 /say 命令的方式 -- Fix exception when /stats command message exceeds 2000 characters (#212) - 修复 /stats 命令消息超过 2000 个字符时报错 +- Webhook check only displays an error message when Guild permission is insufficient + Webhook 检查在 Guild 权限不足时仅显示错误消息 -- Rename botPlayingStatus and botListeningStatus -> botPlayingActivity and botListeningActivity (#95) - 重命名 botPlayingStatus 和 botListeningStatus -> botPlayingActivity 和 botListeningActivity +- No longer release Active and Compat versions separately + 不再分开发布 Active 和 Compat 版本 ## Removed 移除 @@ -53,7 +49,8 @@ N/A ## Contributors 贡献者 - @Xujiayao +- @rodrigoaddor ## Detailed Information 详细信息 -https://github.com/Xujiayao/Discord-MC-Chat/compare/2.3.3...2.3.4 \ No newline at end of file +https://github.com/Xujiayao/Discord-MC-Chat/compare/2.3.4...2.3.5 \ No newline at end of file diff --git a/README.md b/README.md index 319f2c48..2f1eabbd 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ For translation contributions, language files are located in the `/wrapper/src/m - Broadcast player command execution - Players who execute commands can also see the commands themselves - Exclude broadcasts for execution of specific commands + - Support broadcasting messages sent using /tellraw and /say command - Send all console log messages to Discord - Discord Commands available - Use Discord to manage channels that can execute DMCC commands @@ -150,6 +151,7 @@ Languages currently available: | `ko_kr` | 한국어(대한민국) | | `no_no` | Norsk Bokmål (Norge) | | `pl_pl` | Polski (Polska) | +| `pt_br` | Português (Brasil) | | `ru_ru` | Русский (Россия) | | `zh_cn` | 简体中文(中国大陆) | | `zh_hk` | 繁體中文(香港特別行政區) | diff --git a/README_CN.md b/README_CN.md index f60b35d7..34ecacae 100644 --- a/README_CN.md +++ b/README_CN.md @@ -85,6 +85,7 @@ DMCC Discord 服务器现已公开!通过以下链接加入:https://discord. - 可广播玩家指令执行 - 执行指令的玩家也可以看到自己执行的指令 - 可排除执行特定指令的广播 + - 支持广播使用 /tellraw 和 /say 命令发送的消息 - 可将所有控制台日志消息发送到 Discord - 可使用 Discord 命令 - 可使用 Discord 管理可执行 DMCC 命令的频道 @@ -150,6 +151,7 @@ DMCC Discord 服务器现已公开!通过以下链接加入:https://discord. | `ko_kr` | 한국어(대한민국) | | `no_no` | Norsk Bokmål (Norge) | | `pl_pl` | Polski (Polska) | +| `pt_br` | Português (Brasil) | | `ru_ru` | Русский (Россия) | | `zh_cn` | 简体中文(中国大陆) | | `zh_hk` | 繁體中文(香港特別行政區) | diff --git a/gradle.properties b/gradle.properties index b22f12d7..89de133e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G org.gradle.parallel=true # Mod Properties -mod_version=2.3.4 +mod_version=2.3.5 maven_group=com.xujiayao.discord_mc_chat archives_base_name=Discord-MC-Chat diff --git a/update/version.json b/update/version.json index e9e88b04..2004159e 100644 --- a/update/version.json +++ b/update/version.json @@ -1,4 +1,4 @@ { - "version": "2.3.4", - "changelog": "\n\n> DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU\n> \n> DMCC will support the [Placeholder API]() in the next release.\n> \n> `botPlayingStatus` and `botListeningStatus` have been renamed to `botPlayingActivity` and `botListeningActivity`. Please modify them before restarting the server to avoid losing any existing changes.\n> \n> In addition, the check for updates feature has been fixed. You will be able to receive update notifications for future new versions when using version 2.3.4." + "version": "2.3.5", + "changelog": "\n\n> DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU\n> \n> DMCC now supports switching to Brazilian Portuguese. Note that DMCC no longer releases Active and Compat versions separately.\n> \n> As this is a minor release, new features that involve modifying the config file will not be released in this version." } \ No newline at end of file diff --git a/update/versions.json b/update/versions.json index 10c5d55a..6ae35f5f 100644 --- a/update/versions.json +++ b/update/versions.json @@ -1,23 +1,8 @@ { "versions": [ { - "version": "2.3.4", - "changelog": "\n\n> DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU\n> \n> DMCC will support the [Placeholder API]() in the next release.\n> \n> `botPlayingStatus` and `botListeningStatus` have been renamed to `botPlayingActivity` and `botListeningActivity`. Please modify them before restarting the server to avoid losing any existing changes.\n> \n> In addition, the check for updates feature has been fixed. You will be able to receive update notifications for future new versions when using version 2.3.4.", - "minecraft_dependency": [ - "~1.19.4", - "1.20", - "1.20.1", - "1.20.2", - "1.20.3", - "1.20.4", - "~1.20.5", - "~1.21" - ] - }, - { - "notes": "To be removed", - "version": "2.3.4-compat", - "changelog": "\n\n> DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU\n> \n> DMCC will support the [Placeholder API]() in the next release.\n> \n> `botPlayingStatus` and `botListeningStatus` have been renamed to `botPlayingActivity` and `botListeningActivity`. Please modify them before restarting the server to avoid losing any existing changes.\n> \n> In addition, the check for updates feature has been fixed. You will be able to receive update notifications for future new versions when using version 2.3.4.", + "version": "2.3.5", + "changelog": "\n\n> DMCC Discord Server is now public! Join now through: https://discord.gg/kbXkV6k2XU\n> \n> DMCC now supports switching to Brazilian Portuguese. Note that DMCC no longer releases Active and Compat versions separately.\n> \n> As this is a minor release, new features that involve modifying the config file will not be released in this version.", "minecraft_dependency": [ "~1.14.4", "~1.15.2", @@ -27,7 +12,17 @@ "1.19", "1.19.1", "1.19.2", - "1.19.3" + "1.19.3", + "~1.19.4", + "1.20", + "1.20.1", + "1.20.2", + "1.20.3", + "1.20.4", + "~1.20.5", + "1.21", + "1.21.1", + "~1.21.2" ] } ] From 95a5581a309d22f7d964fcf087d73e06a1d1c413 Mon Sep 17 00:00:00 2001 From: Xujiayao Date: Tue, 29 Oct 2024 12:48:08 +0800 Subject: [PATCH 9/9] Revert --- build.gradle | 1 + .../minecraft/MinecraftEventListener.java | 35 ++- wrapper/build.gradle | 33 ++- .../xujiayao/discord_mc_chat/wrapper/GUI.form | 137 +++++++++ .../xujiayao/discord_mc_chat/wrapper/GUI.java | 264 ++++++++++++++++++ .../discord_mc_chat/wrapper/Main.java | 69 +++++ wrapper/src/main/resources/icon.svg | 27 ++ .../src/main/resources/lang/lang.properties | 9 + .../main/resources/lang/lang_en_US.properties | 9 + .../main/resources/lang/lang_zh_CN.properties | 9 + 10 files changed, 585 insertions(+), 8 deletions(-) create mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form create mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java create mode 100644 wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java create mode 100644 wrapper/src/main/resources/icon.svg create mode 100644 wrapper/src/main/resources/lang/lang.properties create mode 100644 wrapper/src/main/resources/lang/lang_en_US.properties create mode 100644 wrapper/src/main/resources/lang/lang_zh_CN.properties diff --git a/build.gradle b/build.gradle index d4beff73..540404c6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id "fabric-loom" version "1.8-SNAPSHOT" apply false id "com.replaymod.preprocess" version "88169fcb" + id "com.gradleup.shadow" version "8.3.3" apply false } preprocess { diff --git a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java index 3d52b2ab..b702f6d7 100644 --- a/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java +++ b/src/main/java/com/xujiayao/discord_mc_chat/minecraft/MinecraftEventListener.java @@ -31,7 +31,10 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.List; +import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ExecutorService; @@ -170,7 +173,7 @@ public static void init() { } if (CONFIG.generic.broadcastChatMessages) { - sendDiscordMessage(contentToDiscord, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString()))); + sendDiscordMessage(contentToDiscord, Objects.requireNonNull(player.getDisplayName()).getString(), getAvatarUrl(player)); if (CONFIG.multiServer.enable) { MULTI_SERVER.sendMessage(false, true, false, Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.formatChatMessages ? contentToMinecraft : message); } @@ -186,7 +189,7 @@ public static void init() { MinecraftEvents.PLAYER_COMMAND.register((player, command) -> { if (CONFIG.generic.broadcastPlayerCommandExecution) { for (String excludedCommand : CONFIG.generic.excludedCommands) { - if (command.startsWith(excludedCommand + " ")) { + if (command.matches(excludedCommand)) { return; } } @@ -214,7 +217,7 @@ public static void init() { //$$ SERVER.sendMessage(message); //#endif - sendDiscordMessage(MarkdownSanitizer.escape(command), Objects.requireNonNull(player.getDisplayName()).getString(), CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : player.getDisplayName().getString()))); + sendDiscordMessage(MarkdownSanitizer.escape(command), Objects.requireNonNull(player.getDisplayName()).getString(), getAvatarUrl(player)); if (CONFIG.multiServer.enable) { MULTI_SERVER.sendMessage(false, true, false, player.getDisplayName().getString(), MarkdownSanitizer.escape(command)); } @@ -354,9 +357,29 @@ private static void sendDiscordMessage(String content, String username, String a } } - // TODO reverted - // TODO Commit cafa9c4 + // {player_name} conflicts with nickname-changing mods + // TODO Move to Placeholder class private static String getAvatarUrl(Player player) { - return CONFIG.generic.avatarApi.replace("%player%", (CONFIG.generic.useUuidInsteadOfName ? player.getUUID().toString() : Objects.requireNonNull(player.getDisplayName()).getString())); + String hash = "null"; + if (CONFIG.generic.avatarApi.contains("{player_textures}")) { + try { + //#if MC > 12001 + String textures = player.getGameProfile().getProperties().get("textures").iterator().next().value(); + //#else + //$$ String textures = player.getGameProfile().getProperties().get("textures").iterator().next().getValue(); + //#endif + + JsonObject json = new Gson().fromJson(new String(Base64.getDecoder().decode(textures), StandardCharsets.UTF_8), JsonObject.class); + String url = json.getAsJsonObject("textures").getAsJsonObject("SKIN").get("url").getAsString(); + + hash = url.replace("http://textures.minecraft.net/texture/", ""); + } catch (NoSuchElementException ignored) { + } + } + + return CONFIG.generic.avatarApi + .replace("{player_uuid}", player.getUUID().toString()) + .replace("{player_name}", player.getName().getString()) + .replace("{player_textures}", hash); } } diff --git a/wrapper/build.gradle b/wrapper/build.gradle index 9333d872..d691a4f8 100644 --- a/wrapper/build.gradle +++ b/wrapper/build.gradle @@ -2,6 +2,7 @@ import groovy.json.JsonBuilder import groovy.json.JsonSlurper apply plugin: "fabric-loom" +apply plugin: "com.gradleup.shadow" java { sourceCompatibility = JavaVersion.VERSION_21 @@ -15,6 +16,13 @@ base { archivesName = archives_base_name } +repositories { + maven { + name = "IntelliJ Release" + url = "https://www.jetbrains.com/intellij-repository/releases" + } +} + dependencies { minecraft("com.mojang:minecraft:${minecraft_version}") mappings(loom.officialMojangMappings()) @@ -27,7 +35,8 @@ 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) + shadow(implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1")) // TODO Any better way? 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") @@ -38,7 +47,11 @@ dependencies { include("net.fellbaum:jemoji:1.3.4") // File size of 1.4.x is too big - include("com.google.code.gson:gson:2.11.0") + shadow(implementation("com.google.code.gson:gson:2.11.0")) + + shadow(implementation("com.jetbrains.intellij.java:java-gui-forms-rt:242.22855.106")) + shadow(implementation("com.formdev:flatlaf:3.5.2")) + shadow(implementation("com.formdev:flatlaf-extras:3.5.2")) } def fabric_subprojects = parent.subprojects.findAll({ @@ -48,7 +61,10 @@ def fabric_subprojects = parent.subprojects.findAll({ remapJar { outputs.upToDateWhen { false } + inputFile.set shadowJar.archiveFile + dependsOn { + shadowJar fabric_subprojects.collect { it.tasks.remapJar } @@ -75,6 +91,7 @@ remapJar { copy { from "build/libs" into "../build" + exclude "*wrapper*" } } } @@ -103,4 +120,16 @@ processResources { writer.flush() writer.close() } +} + +jar { + manifest { + attributes "Main-Class": "com.xujiayao.discord_mc_chat.wrapper.Main" + } +} + +shadowJar { + archiveClassifier = "wrapper" + configurations = [project.configurations.shadow] + // FlatLaf does not support minimization and relocation } \ No newline at end of file diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form new file mode 100644 index 00000000..8c349da1 --- /dev/null +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form @@ -0,0 +1,137 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java new file mode 100644 index 00000000..692abeec --- /dev/null +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.java @@ -0,0 +1,264 @@ +package com.xujiayao.discord_mc_chat.wrapper; + +import com.formdev.flatlaf.extras.FlatSVGIcon; +import com.formdev.flatlaf.extras.FlatSVGUtils; +import com.intellij.uiDesigner.core.GridConstraints; +import com.intellij.uiDesigner.core.GridLayoutManager; +import com.intellij.uiDesigner.core.Spacer; + +import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import javax.swing.text.StyleContext; +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.lang.reflect.Method; +import java.net.URI; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +import static com.xujiayao.discord_mc_chat.wrapper.Main.LOGGER; +import static com.xujiayao.discord_mc_chat.wrapper.Main.VERSION; + +/** + * @author Xujiayao + */ +public class GUI extends JFrame { + + private JPanel contentPane; + private JLabel versionLabel; + private JButton button; + private JLabel iconLabel; + private JLabel docsLabel; + private JLabel discordLabel; + + public GUI() { + ResourceBundle bundle = PropertyResourceBundle.getBundle("lang/lang"); + + setTitle(bundle.getString("title")); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setContentPane(contentPane); + + setIconImages(FlatSVGUtils.createWindowIconImages("/icon.svg")); + + iconLabel.setIcon(new FlatSVGIcon("icon.svg", 50, 50)); + + String pattern = bundle.getString("version"); + versionLabel.setText(MessageFormat.format(pattern, VERSION)); + + docsLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); + discordLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); + + docsLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + Desktop.getDesktop().browse(new URI("https://blog.xujiayao.com/posts/4ba0a17a/")); + } catch (Exception ex) { + LOGGER.error("Exception", ex); + } + } + }); + + discordLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + Desktop.getDesktop().browse(new URI("https://discord.gg/kbXkV6k2XU")); + } catch (Exception ex) { + LOGGER.error("Exception", ex); + } + } + }); + + setPreferredSize(new Dimension(500, 400)); + pack(); + + setLocationRelativeTo(null); + setResizable(false); + + button.addActionListener(e -> dispose()); + } + + { +// GUI initializer generated by IntelliJ IDEA GUI Designer +// >>> IMPORTANT!! <<< +// DO NOT EDIT OR ADD ANY CODE HERE! + $$$setupUI$$$(); + } + + /** + * Method generated by IntelliJ IDEA GUI Designer + * >>> IMPORTANT!! <<< + * DO NOT edit this method OR call it in your code! + * + * @noinspection ALL + */ + private void $$$setupUI$$$() { + contentPane = new JPanel(); + contentPane.setLayout(new GridLayoutManager(13, 3, new Insets(10, 10, 10, 10), -1, -1)); + versionLabel = new JLabel(); + Font versionLabelFont = this.$$$getFont$$$(null, -1, 12, versionLabel.getFont()); + if (versionLabelFont != null) versionLabel.setFont(versionLabelFont); + this.$$$loadLabelText$$$(versionLabel, this.$$$getMessageFromBundle$$$("lang/lang", "version")); + contentPane.add(versionLabel, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(248, 22), null, 0, false)); + final JSeparator separator1 = new JSeparator(); + separator1.setOrientation(0); + contentPane.add(separator1, new GridConstraints(2, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label1 = new JLabel(); + Font label1Font = this.$$$getFont$$$(null, -1, 12, label1.getFont()); + if (label1Font != null) label1.setFont(label1Font); + this.$$$loadLabelText$$$(label1, this.$$$getMessageFromBundle$$$("lang/lang", "description1")); + contentPane.add(label1, new GridConstraints(3, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final JSeparator separator2 = new JSeparator(); + separator2.setOrientation(0); + contentPane.add(separator2, new GridConstraints(11, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + button = new JButton(); + Font buttonFont = this.$$$getFont$$$(null, -1, 12, button.getFont()); + if (buttonFont != null) button.setFont(buttonFont); + button.setHorizontalAlignment(0); + this.$$$loadButtonText$$$(button, this.$$$getMessageFromBundle$$$("lang/lang", "buttonText")); + contentPane.add(button, new GridConstraints(12, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label2 = new JLabel(); + Font label2Font = this.$$$getFont$$$(null, Font.BOLD, 20, label2.getFont()); + if (label2Font != null) label2.setFont(label2Font); + this.$$$loadLabelText$$$(label2, this.$$$getMessageFromBundle$$$("lang/lang", "welcome")); + contentPane.add(label2, new GridConstraints(0, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + final JLabel label3 = new JLabel(); + Font label3Font = this.$$$getFont$$$(null, -1, 12, label3.getFont()); + if (label3Font != null) label3.setFont(label3Font); + this.$$$loadLabelText$$$(label3, this.$$$getMessageFromBundle$$$("lang/lang", "author")); + contentPane.add(label3, new GridConstraints(1, 2, 1, 1, GridConstraints.ANCHOR_EAST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); + iconLabel = new JLabel(); + contentPane.add(iconLabel, new GridConstraints(0, 0, 2, 1, GridConstraints.ANCHOR_SOUTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, new Dimension(50, 50), new Dimension(50, 50), new Dimension(50, 50), 0, false)); + final JLabel label4 = new JLabel(); + Font label4Font = this.$$$getFont$$$(null, -1, 12, label4.getFont()); + if (label4Font != null) label4.setFont(label4Font); + label4.setOpaque(false); + this.$$$loadLabelText$$$(label4, this.$$$getMessageFromBundle$$$("lang/lang", "description2")); + contentPane.add(label4, new GridConstraints(5, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + docsLabel = new JLabel(); + Font docsLabelFont = this.$$$getFont$$$(null, -1, 12, docsLabel.getFont()); + if (docsLabelFont != null) docsLabel.setFont(docsLabelFont); + this.$$$loadLabelText$$$(docsLabel, this.$$$getMessageFromBundle$$$("lang/lang", "description3")); + docsLabel.setToolTipText("https://blog.xujiayao.com/posts/4ba0a17a/"); + contentPane.add(docsLabel, new GridConstraints(7, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + final Spacer spacer1 = new Spacer(); + contentPane.add(spacer1, new GridConstraints(8, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + final Spacer spacer2 = new Spacer(); + contentPane.add(spacer2, new GridConstraints(6, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + final Spacer spacer3 = new Spacer(); + contentPane.add(spacer3, new GridConstraints(4, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + final Spacer spacer4 = new Spacer(); + contentPane.add(spacer4, new GridConstraints(10, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); + discordLabel = new JLabel(); + Font discordLabelFont = this.$$$getFont$$$(null, -1, 12, discordLabel.getFont()); + if (discordLabelFont != null) discordLabel.setFont(discordLabelFont); + this.$$$loadLabelText$$$(discordLabel, this.$$$getMessageFromBundle$$$("lang/lang", "description4")); + discordLabel.setToolTipText("https://discord.gg/kbXkV6k2XU"); + contentPane.add(discordLabel, new GridConstraints(9, 0, 1, 3, GridConstraints.ANCHOR_NORTHWEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false)); + } + + /** + * @noinspection ALL + */ + private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) { + if (currentFont == null) return null; + String resultName; + if (fontName == null) { + resultName = currentFont.getName(); + } else { + Font testFont = new Font(fontName, Font.PLAIN, 10); + if (testFont.canDisplay('a') && testFont.canDisplay('1')) { + resultName = fontName; + } else { + resultName = currentFont.getName(); + } + } + Font font = new Font(resultName, style >= 0 ? style : currentFont.getStyle(), size >= 0 ? size : currentFont.getSize()); + boolean isMac = System.getProperty("os.name", "").toLowerCase(Locale.ENGLISH).startsWith("mac"); + Font fontWithFallback = isMac ? new Font(font.getFamily(), font.getStyle(), font.getSize()) : new StyleContext().getFont(font.getFamily(), font.getStyle(), font.getSize()); + return fontWithFallback instanceof FontUIResource ? fontWithFallback : new FontUIResource(fontWithFallback); + } + + private static Method $$$cachedGetBundleMethod$$$ = null; + + private String $$$getMessageFromBundle$$$(String path, String key) { + ResourceBundle bundle; + try { + Class thisClass = this.getClass(); + if ($$$cachedGetBundleMethod$$$ == null) { + Class dynamicBundleClass = thisClass.getClassLoader().loadClass("com.intellij.DynamicBundle"); + $$$cachedGetBundleMethod$$$ = dynamicBundleClass.getMethod("getBundle", String.class, Class.class); + } + bundle = (ResourceBundle) $$$cachedGetBundleMethod$$$.invoke(null, path, thisClass); + } catch (Exception e) { + bundle = ResourceBundle.getBundle(path); + } + return bundle.getString(key); + } + + /** + * @noinspection ALL + */ + private void $$$loadLabelText$$$(JLabel component, String text) { + StringBuffer result = new StringBuffer(); + boolean haveMnemonic = false; + char mnemonic = '\0'; + int mnemonicIndex = -1; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '&') { + i++; + if (i == text.length()) break; + if (!haveMnemonic && text.charAt(i) != '&') { + haveMnemonic = true; + mnemonic = text.charAt(i); + mnemonicIndex = result.length(); + } + } + result.append(text.charAt(i)); + } + component.setText(result.toString()); + if (haveMnemonic) { + component.setDisplayedMnemonic(mnemonic); + component.setDisplayedMnemonicIndex(mnemonicIndex); + } + } + + /** + * @noinspection ALL + */ + private void $$$loadButtonText$$$(AbstractButton component, String text) { + StringBuffer result = new StringBuffer(); + boolean haveMnemonic = false; + char mnemonic = '\0'; + int mnemonicIndex = -1; + for (int i = 0; i < text.length(); i++) { + if (text.charAt(i) == '&') { + i++; + if (i == text.length()) break; + if (!haveMnemonic && text.charAt(i) != '&') { + haveMnemonic = true; + mnemonic = text.charAt(i); + mnemonicIndex = result.length(); + } + } + result.append(text.charAt(i)); + } + component.setText(result.toString()); + if (haveMnemonic) { + component.setMnemonic(mnemonic); + component.setDisplayedMnemonicIndex(mnemonicIndex); + } + } + + /** + * @noinspection ALL + */ + public JComponent $$$getRootComponent$$$() { + return contentPane; + } + +} 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 00000000..9375c5c5 --- /dev/null +++ b/wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/Main.java @@ -0,0 +1,69 @@ +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("-----------------------------------------"); + } + } +} +// TODO icon size? \ No newline at end of file diff --git a/wrapper/src/main/resources/icon.svg b/wrapper/src/main/resources/icon.svg new file mode 100644 index 00000000..f3bd7127 --- /dev/null +++ b/wrapper/src/main/resources/icon.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/wrapper/src/main/resources/lang/lang.properties b/wrapper/src/main/resources/lang/lang.properties new file mode 100644 index 00000000..cb1b3012 --- /dev/null +++ b/wrapper/src/main/resources/lang/lang.properties @@ -0,0 +1,9 @@ +title=Welcome - Discord-MC-Chat (DMCC) +welcome=Welcome to Discord-MC-Chat (DMCC)! +version=Version: {0} +author=By Xujiayao +description1=Oops! You are attempting to run Discord-MC-Chat directly! +description2=Note:

Discord-MC-Chat is a Fabric Minecraft mod. Please place the JAR file in the "mods" folder of your Minecraft server and run it through the Fabric mod loader, instead of opening it directly. +description3=Please follow Discord-MC-Chat Docs to configure Discord-MC-Chat. +description4=If you need more help, you can ask me questions in the DMCC Discord Server. +buttonText=&Close \ No newline at end of file diff --git a/wrapper/src/main/resources/lang/lang_en_US.properties b/wrapper/src/main/resources/lang/lang_en_US.properties new file mode 100644 index 00000000..cb1b3012 --- /dev/null +++ b/wrapper/src/main/resources/lang/lang_en_US.properties @@ -0,0 +1,9 @@ +title=Welcome - Discord-MC-Chat (DMCC) +welcome=Welcome to Discord-MC-Chat (DMCC)! +version=Version: {0} +author=By Xujiayao +description1=Oops! You are attempting to run Discord-MC-Chat directly! +description2=Note:

Discord-MC-Chat is a Fabric Minecraft mod. Please place the JAR file in the "mods" folder of your Minecraft server and run it through the Fabric mod loader, instead of opening it directly. +description3=Please follow Discord-MC-Chat Docs to configure Discord-MC-Chat. +description4=If you need more help, you can ask me questions in the DMCC Discord Server. +buttonText=&Close \ 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 new file mode 100644 index 00000000..fc43fe3d --- /dev/null +++ b/wrapper/src/main/resources/lang/lang_zh_CN.properties @@ -0,0 +1,9 @@ +title=欢迎 - Discord-MC-Chat (DMCC) +welcome=欢迎使用 Discord-MC-Chat (DMCC)! +version=版本:{0} +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 服务器 向我提问。 +buttonText=&关闭 \ No newline at end of file