mirror of
https://github.com/System-End/Discord-MC-Chat.git
synced 2026-04-19 23:22:49 +00:00
游戏内显示玩家执行的指令 + 修改更新下载链接
This commit is contained in:
parent
a5c0e77f38
commit
f558e0e85b
6 changed files with 42 additions and 23 deletions
4
TODO.txt
4
TODO.txt
|
|
@ -1,3 +1 @@
|
|||
远程开服
|
||||
|
||||
MCDC一周年2021/12/27,到时候提前几个星期发布一个版本,在2021/12/27那天开服时像检查更新那样@everyone
|
||||
远程开服
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
plugins {
|
||||
id 'fabric-loom' version '0.10.57'
|
||||
id 'fabric-loom' version '0.10.61'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ minecraft_version=1.17.1
|
|||
yarn_mappings=1.17.1+build.64
|
||||
loader_version=0.12.5
|
||||
# Mod Properties
|
||||
mod_version=1.17-1.10.8
|
||||
mod_version=1.17-1.10.9
|
||||
maven_group=top.xujiayao
|
||||
archives_base_name=MCDiscordChat
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.42.1+1.17
|
||||
fabric_version=0.43.1+1.17
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.vdurmont.emoji.EmojiParser;
|
|||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
|
@ -33,7 +32,7 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent e) {
|
||||
MinecraftServer server = getServer();
|
||||
MinecraftServer server = Utils.getServer();
|
||||
|
||||
if (e.getAuthor() != e.getJDA().getSelfUser()
|
||||
&& e.getChannel().getId().equals(Main.config.generic.channelId)
|
||||
|
|
@ -327,19 +326,8 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
}
|
||||
|
||||
private ServerCommandSource getDiscordCommandSource() {
|
||||
ServerWorld serverWorld = Objects.requireNonNull(getServer()).getOverworld();
|
||||
ServerWorld serverWorld = Objects.requireNonNull(Utils.getServer()).getOverworld();
|
||||
|
||||
return new ServerCommandSource(new DiscordCommandOutput(), serverWorld == null ? Vec3d.ZERO : Vec3d.of(serverWorld.getSpawnPos()), Vec2f.ZERO, serverWorld, 4, "MCDiscordChat", new LiteralText("MCDiscordChat"), getServer(), null);
|
||||
}
|
||||
|
||||
private MinecraftServer getServer() {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object gameInstance = FabricLoader.getInstance().getGameInstance();
|
||||
|
||||
if (gameInstance instanceof MinecraftServer minecraftServer) {
|
||||
return minecraftServer;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new ServerCommandSource(new DiscordCommandOutput(), serverWorld == null ? Vec3d.ZERO : Vec3d.of(serverWorld.getSpawnPos()), Vec2f.ZERO, serverWorld, 4, "MCDiscordChat", new LiteralText("MCDiscordChat"), Utils.getServer(), null);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ 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.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Pair;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -18,7 +20,9 @@ import top.xujiayao.mcdiscordchat.events.ServerChatCallback;
|
|||
import top.xujiayao.mcdiscordchat.utils.MarkdownParser;
|
||||
import top.xujiayao.mcdiscordchat.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
|
@ -108,6 +112,22 @@ public class MinecraftEventListener {
|
|||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
|
||||
try {
|
||||
List<ServerPlayerEntity> list = new ArrayList<>(Objects.requireNonNull(Utils.getServer()).getPlayerManager().getPlayerList());
|
||||
list.remove(source.getPlayer());
|
||||
list.forEach(
|
||||
serverPlayerEntity -> {
|
||||
try {
|
||||
serverPlayerEntity.sendMessage(new LiteralText("<").append(source.getPlayer().getEntityName()).append("> ").append(command), false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package top.xujiayao.mcdiscordchat.utils;
|
|||
import com.google.gson.Gson;
|
||||
import kong.unirest.Unirest;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Pair;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
|
@ -28,6 +30,17 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class Utils {
|
||||
|
||||
public static MinecraftServer getServer() {
|
||||
@SuppressWarnings("deprecation")
|
||||
Object gameInstance = FabricLoader.getInstance().getGameInstance();
|
||||
|
||||
if (gameInstance instanceof MinecraftServer minecraftServer) {
|
||||
return minecraftServer;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void checkUpdate(boolean isManualCheck) {
|
||||
try {
|
||||
Version version = new Gson().fromJson(Unirest.get("https://cdn.jsdelivr.net/gh/Xujiayao/MCDiscordChat@master/update/version.json").asString().getBody(), Version.class);
|
||||
|
|
@ -37,9 +50,9 @@ public class Utils {
|
|||
StringBuilder text;
|
||||
|
||||
if (Main.config.generic.switchLanguageFromChinToEng) {
|
||||
text = new StringBuilder("**A new version is available!**\n\nMCDiscordChat **" + modJson.version + "** -> **" + version.version() + "**\n\nDownload link: https://github.com/Xujiayao/MCDiscordChat/releases\n\n");
|
||||
text = new StringBuilder("**A new version is available!**\n\nMCDiscordChat **" + modJson.version + "** -> **" + version.version() + "**\n\nDownload link: https://www.curseforge.com/minecraft/mc-mods/mcdiscordchat\n\n");
|
||||
} else {
|
||||
text = new StringBuilder("**新版本可用!**\n\nMCDiscordChat **" + modJson.version + "** -> **" + version.version() + "**\n\n下载链接:https://github.com/Xujiayao/MCDiscordChat/releases\n\n");
|
||||
text = new StringBuilder("**新版本可用!**\n\nMCDiscordChat **" + modJson.version + "** -> **" + version.version() + "**\n\n下载链接:https://www.curseforge.com/minecraft/mc-mods/mcdiscordchat\n\n");
|
||||
}
|
||||
|
||||
for (String id : Main.config.generic.superAdminsIds) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue