Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Oct 29, 2024
1 parent 7ea983f commit 95a5581
Show file tree
Hide file tree
Showing 10 changed files with 585 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
}
}
33 changes: 31 additions & 2 deletions wrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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")
Expand All @@ -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({
Expand All @@ -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
}
Expand All @@ -75,6 +91,7 @@ remapJar {
copy {
from "build/libs"
into "../build"
exclude "*wrapper*"
}
}
}
Expand Down Expand Up @@ -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
}
137 changes: 137 additions & 0 deletions wrapper/src/main/java/com/xujiayao/discord_mc_chat/wrapper/GUI.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?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.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>
<xy x="20" y="20" width="658" height="514"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="a81dc" class="javax.swing.JLabel" binding="versionLabel">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="248" height="22"/>
</grid>
</constraints>
<properties>
<font size="12"/>
<text resource-bundle="lang/lang" key="version"/>
</properties>
</component>
<component id="7f8" class="javax.swing.JSeparator">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<orientation value="0"/>
</properties>
</component>
<component id="d92a4" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<text resource-bundle="lang/lang" key="description1"/>
</properties>
</component>
<component id="f21cf" class="javax.swing.JSeparator">
<constraints>
<grid row="11" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<orientation value="0"/>
</properties>
</component>
<component id="2943f" class="javax.swing.JButton" binding="button">
<constraints>
<grid row="12" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<horizontalAlignment value="0"/>
<text resource-bundle="lang/lang" key="buttonText"/>
</properties>
</component>
<component id="d9f15" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="20" style="1"/>
<text resource-bundle="lang/lang" key="welcome"/>
</properties>
</component>
<component id="deecd" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<text resource-bundle="lang/lang" key="author"/>
</properties>
</component>
<component id="ed076" class="javax.swing.JLabel" binding="iconLabel">
<constraints>
<grid row="0" column="0" row-span="2" col-span="1" vsize-policy="0" hsize-policy="0" anchor="10" fill="0" indent="0" use-parent-layout="false">
<minimum-size width="50" height="50"/>
<preferred-size width="50" height="50"/>
<maximum-size width="50" height="50"/>
</grid>
</constraints>
<properties/>
</component>
<component id="3772" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<opaque value="false"/>
<text resource-bundle="lang/lang" key="description2"/>
</properties>
</component>
<component id="b2631" class="javax.swing.JLabel" binding="docsLabel">
<constraints>
<grid row="7" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<text resource-bundle="lang/lang" key="description3"/>
<toolTipText value="https://blog.xujiayao.com/posts/4ba0a17a/" noi18n="true"/>
</properties>
</component>
<vspacer id="26498">
<constraints>
<grid row="8" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="13b05">
<constraints>
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="b64a9">
<constraints>
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="b7b17">
<constraints>
<grid row="10" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="63dc0" class="javax.swing.JLabel" binding="discordLabel">
<constraints>
<grid row="9" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="12"/>
<text resource-bundle="lang/lang" key="description4"/>
<toolTipText value="https://discord.gg/kbXkV6k2XU" noi18n="true"/>
</properties>
</component>
</children>
</grid>
</form>
Loading

0 comments on commit 95a5581

Please sign in to comment.