Skip to content

Commit

Permalink
支持在游戏内使用服务器表情符号
Browse files Browse the repository at this point in the history
  • Loading branch information
Xujiayao committed Oct 28, 2021
1 parent 6f62b26 commit 1adc6e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.10.37'
id 'fabric-loom' version '0.10.43'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -4,9 +4,9 @@ org.gradle.jvmargs=-Xmx4G
# check these on https://fabricmc.net/use
minecraft_version=1.17.1
yarn_mappings=1.17.1+build.63
loader_version=0.12.2
loader_version=0.12.3
# Mod Properties
mod_version=1.17-1.10.4
mod_version=1.17-1.10.5
maven_group=top.xujiayao
archives_base_name=MCDiscordChat
# Dependencies
Expand Down
Expand Up @@ -2,9 +2,11 @@

import kong.unirest.Unirest;
import kong.unirest.json.JSONObject;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.utils.MarkdownSanitizer;
import net.minecraft.text.Text;
import net.minecraft.util.Pair;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import top.xujiayao.mcdiscordchat.Main;
import top.xujiayao.mcdiscordchat.events.PlayerAdvancementCallback;
Expand All @@ -15,6 +17,7 @@
import top.xujiayao.mcdiscordchat.utils.MarkdownParser;
import top.xujiayao.mcdiscordchat.utils.Utils;

import java.util.List;
import java.util.Optional;

/**
Expand All @@ -24,6 +27,21 @@ public class MinecraftEventListener {
public void init() {
ServerChatCallback.EVENT.register((playerEntity, rawMessage, message) -> {
if (!Main.stop) {
try {
if (StringUtils.countMatches(rawMessage, ":") >= 2) {
String[] emoteNames = StringUtils.substringsBetween(rawMessage, ":", ":");
for (String emoteName : emoteNames) {
List<Emote> emotes = Main.jda.getEmotesByName(emoteName, true);
if (!emotes.isEmpty()) {
rawMessage = StringUtils.replaceFirst(rawMessage, ":" + emoteName + ":", "<:" + emoteName + ":" + emotes.get(0).getId() + ">");
}
}
}
} catch (Exception e) {
e.printStackTrace();
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
}

Pair<String, String> convertedPair = Utils.convertMentionsFromNames(rawMessage);

if (Main.config.generic.bannedMinecraft.contains(playerEntity.getEntityName())) {
Expand Down
2 changes: 1 addition & 1 deletion update/version.json
@@ -1 +1 @@
{"version":"1.17-1.10.4"}
{"version":"1.17-1.10.5"}

0 comments on commit 1adc6e0

Please sign in to comment.