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
c9bebcf2cb
commit
4f897d11df
6 changed files with 319 additions and 315 deletions
|
|
@ -21,7 +21,8 @@ More information + Docs: [MCDiscordChat Docs | Xujiayao's Blog](https://blog.xuj
|
|||
|
||||
## Introduction
|
||||
|
||||
[MCDiscordChat](https://github.com/Xujiayao/MCDiscordChat) (abbreviated as MCDC), a practical and powerful Fabric Minecraft <> Discord chat bridge that complements and enhances BRForgers/DisFabric.
|
||||
[MCDiscordChat](https://github.com/Xujiayao/MCDiscordChat) (abbreviated as MCDC), a practical and powerful Fabric
|
||||
Minecraft <> Discord chat bridge that complements and enhances BRForgers/DisFabric.
|
||||
|
||||
A big thanks to [BRForgers/DisFabric](https://github.com/BRForgers/DisFabric) for the original source code, which was
|
||||
licensed under the Mozilla Public License 2.0 (MPL-2.0).
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ MCDiscordChat (MCDC), a practical and powerful Fabric Minecraft <> Discord chat
|
|||
|
||||
## 简介
|
||||
|
||||
[MCDiscordChat](https://github.com/Xujiayao/MCDiscordChat) (简称为 MCDC),一个实用且功能强大的 Fabric Minecraft <> Discord 跨服聊天工具,是 BRForgers/DisFabric 的功能补充和增强。
|
||||
[MCDiscordChat](https://github.com/Xujiayao/MCDiscordChat) (简称为 MCDC),一个实用且功能强大的 Fabric Minecraft <> Discord 跨服聊天工具,是
|
||||
BRForgers/DisFabric 的功能补充和增强。
|
||||
|
||||
非常感谢 [BRForgers/DisFabric](https://github.com/BRForgers/DisFabric) 的原始源代码,该项目使用 Mozilla Public License 2.0 (MPL-2.0)
|
||||
开源协议许可开源。
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
|
||||
import static top.xujiayao.mcdiscordchat.Main.config;
|
||||
import static top.xujiayao.mcdiscordchat.Main.textChannel;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
|
|
@ -34,327 +37,315 @@ public class DiscordEventListener extends ListenerAdapter {
|
|||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent e) {
|
||||
MinecraftServer server = Utils.getServer();
|
||||
MinecraftServer server = Objects.requireNonNull(Utils.getServer());
|
||||
|
||||
if (e.getAuthor() != e.getJDA().getSelfUser()
|
||||
&& e.getChannel().getId().equals(Main.config.generic.channelId)
|
||||
&& server != null) {
|
||||
if (Main.config.generic.multiServer) {
|
||||
if (e.isWebhookMessage()) {
|
||||
if (Main.config.multiServer.serverDisplayName.equals(e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] ")))) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (e.getAuthor().isBot()) {
|
||||
if (!e.getAuthor().getName().contains(Main.config.multiServer.botName)) {
|
||||
return;
|
||||
}
|
||||
if (e.getAuthor() == e.getJDA().getSelfUser()
|
||||
|| !e.getChannel().getId().equals(config.generic.channelId)) return;
|
||||
|
||||
if (Main.config.multiServer.serverDisplayName.equals(e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] ")))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getMessage().getContentDisplay().startsWith("```")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.generic.multiServer) {
|
||||
if (e.isWebhookMessage()) {
|
||||
if (config.multiServer.serverDisplayName.equals(e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] "))))
|
||||
return;
|
||||
} else {
|
||||
if (e.getAuthor().isBot()) {
|
||||
return;
|
||||
String serverDisplayName = e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] "));
|
||||
|
||||
if (!e.getAuthor().getName().contains(config.multiServer.botName)) return;
|
||||
if (config.multiServer.serverDisplayName.equals(serverDisplayName)) return;
|
||||
if (e.getMessage().getContentDisplay().startsWith("```")) return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (e.getAuthor().isBot()) return;
|
||||
}
|
||||
|
||||
if (config.generic.bannedDiscord.contains(e.getAuthor().getId())
|
||||
&& !"769470378073653269".equals(e.getAuthor().getId())
|
||||
&& !config.generic.superAdminsIds.contains(e.getAuthor().getId())
|
||||
&& !config.generic.adminsIds.contains(e.getAuthor().getId())) return;
|
||||
|
||||
if ("!info".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder infoString = new StringBuilder("```\n=============== " + (config.generic.switchLanguageFromChinToEng ? "Server Status" : "运行状态") + " ===============\n\n");
|
||||
|
||||
List<ServerPlayerEntity> onlinePlayers = server.getPlayerManager().getPlayerList();
|
||||
infoString.append(config.generic.switchLanguageFromChinToEng ? "Online players" : "在线玩家").append(" (").append(onlinePlayers.size()).append(")").append(config.generic.switchLanguageFromChinToEng ? ":" : ":");
|
||||
|
||||
if (onlinePlayers.isEmpty()) {
|
||||
infoString.append("\n").append(config.generic.switchLanguageFromChinToEng ? "No players online!" : "当前没有在线玩家!");
|
||||
} else {
|
||||
for (ServerPlayerEntity player : onlinePlayers) {
|
||||
infoString.append("\n[").append(player.pingMilliseconds).append("ms] ").append(player.getEntityName());
|
||||
}
|
||||
}
|
||||
|
||||
if (Main.config.generic.bannedDiscord.contains(e.getAuthor().getId())
|
||||
&& !"769470378073653269".equals(e.getAuthor().getId())
|
||||
&& !Main.config.generic.superAdminsIds.contains(e.getAuthor().getId())
|
||||
&& !Main.config.generic.adminsIds.contains(e.getAuthor().getId())) {
|
||||
return;
|
||||
}
|
||||
infoString.append("\n\n").append(config.generic.switchLanguageFromChinToEng ? "Server TPS:\n" : "服务器 TPS:\n");
|
||||
double serverTickTime = MathHelper.average(server.lastTickLengths) * 1.0E-6D;
|
||||
infoString.append(Math.min(1000.0 / serverTickTime, 20));
|
||||
|
||||
if ("!info".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder infoString = new StringBuilder("```\n=============== " + (Main.config.generic.switchLanguageFromChinToEng ? "Server Status" : "运行状态") + " ===============\n\n");
|
||||
infoString.append("\n\n").append(config.generic.switchLanguageFromChinToEng ? "Server MSPT:\n" : "服务器 MSPT:\n");
|
||||
infoString.append(MathHelper.average(server.lastTickLengths) * 1.0E-6D);
|
||||
|
||||
List<ServerPlayerEntity> onlinePlayers = server.getPlayerManager().getPlayerList();
|
||||
infoString.append(Main.config.generic.switchLanguageFromChinToEng ? "Online players" : "在线玩家").append(" (").append(onlinePlayers.size()).append(")").append(Main.config.generic.switchLanguageFromChinToEng ? ":" : ":");
|
||||
infoString.append("\n\n")
|
||||
.append(config.generic.switchLanguageFromChinToEng ? "Server used memory:" : "服务器已用内存:")
|
||||
.append("\n")
|
||||
.append((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024)
|
||||
.append(" MB / ")
|
||||
.append(Runtime.getRuntime().totalMemory() / 1024 / 1024)
|
||||
.append(" MB");
|
||||
|
||||
if (onlinePlayers.isEmpty()) {
|
||||
infoString.append("\n").append(Main.config.generic.switchLanguageFromChinToEng ? "No players online!" : "当前没有在线玩家!");
|
||||
} else {
|
||||
for (ServerPlayerEntity player : onlinePlayers) {
|
||||
infoString.append("\n[").append(player.pingMilliseconds).append("ms] ").append(player.getEntityName());
|
||||
}
|
||||
}
|
||||
infoString.append("\n```");
|
||||
textChannel.sendMessage(infoString.toString()).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!scoreboard ")) {
|
||||
textChannel.sendMessage(Scoreboard.getScoreboard(e.getMessage().getContentRaw())).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!console ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!console ", "");
|
||||
|
||||
infoString.append("\n\n").append(Main.config.generic.switchLanguageFromChinToEng ? "Server TPS:\n" : "服务器 TPS:\n");
|
||||
double serverTickTime = MathHelper.average(server.lastTickLengths) * 1.0E-6D;
|
||||
infoString.append(Math.min(1000.0 / serverTickTime, 20));
|
||||
|
||||
infoString.append("\n\n").append(Main.config.generic.switchLanguageFromChinToEng ? "Server MSPT:\n" : "服务器 MSPT:\n");
|
||||
infoString.append(MathHelper.average(server.lastTickLengths) * 1.0E-6D);
|
||||
|
||||
infoString.append("\n\n")
|
||||
.append(Main.config.generic.switchLanguageFromChinToEng ? "Server used memory:" : "服务器已用内存:")
|
||||
.append("\n")
|
||||
.append((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024)
|
||||
.append(" MB / ")
|
||||
.append(Runtime.getRuntime().totalMemory() / 1024 / 1024)
|
||||
.append(" MB");
|
||||
|
||||
infoString.append("\n```");
|
||||
e.getChannel().sendMessage(infoString.toString()).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!scoreboard ")) {
|
||||
e.getChannel().sendMessage(Scoreboard.getScoreboard(e.getMessage().getContentRaw())).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!console ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!console ", "");
|
||||
|
||||
if (command.startsWith("stop") || command.startsWith("/stop")) {
|
||||
server.stop(true);
|
||||
return;
|
||||
}
|
||||
|
||||
server.getCommandManager().execute(getDiscordCommandSource(), command);
|
||||
} else {
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!reload".equals(e.getMessage().getContentRaw())) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
try {
|
||||
ConfigManager.loadConfig();
|
||||
ConfigManager.updateConfig();
|
||||
Utils.reloadTextsConfig();
|
||||
|
||||
if (Main.config.generic.botListeningStatus.isEmpty()) {
|
||||
Main.jda.getPresence().setActivity(null);
|
||||
} else {
|
||||
Main.jda.getPresence().setActivity(Activity.listening(Main.config.generic.botListeningStatus));
|
||||
}
|
||||
|
||||
if (Main.config.generic.announceHighMSPT) {
|
||||
Main.msptMonitorTimer.cancel();
|
||||
Main.msptMonitorTimer = new Timer();
|
||||
Utils.monitorMSPT();
|
||||
} else {
|
||||
Main.msptMonitorTimer.cancel();
|
||||
}
|
||||
|
||||
Main.textChannel.sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "Successfully loaded the configuration file!" : "配置文件加载成功!") + "**").queue();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(ex) + "\n```").queue();
|
||||
Main.textChannel.sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "Failed to load the configuration file!" : "配置文件加载失败!") + "**").queue();
|
||||
}
|
||||
} else {
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!help".equals(e.getMessage().getContentRaw())) {
|
||||
String help = Main.config.generic.switchLanguageFromChinToEng
|
||||
?
|
||||
"```\n" +
|
||||
"=============== Help ===============\n" +
|
||||
"\n" +
|
||||
"!info: Query server running status\n" +
|
||||
"!scoreboard <type> <id>: Query the player scoreboard for this statistic\n" +
|
||||
"!ban <type> <id/name>: Add or remove a Discord user or Minecraft player from the blacklist (admins only)\n" +
|
||||
"!blacklist: Query blacklist\n" +
|
||||
"!console <command>: Executes command in the server console (admins only)\n" +
|
||||
"!reload: Reload MCDiscordChat configuration file (admins only)\n" +
|
||||
"!admin <id>: Add or remove a Discord user from the list of MCDiscordChat admins (super admins only)\n" +
|
||||
"!adminlist: Query admin list\n" +
|
||||
"!update: Check for update\n" +
|
||||
"!stop: Stop the server (admins only)\n" +
|
||||
"```\n"
|
||||
:
|
||||
"```\n" +
|
||||
"=============== 帮助 ===============\n" +
|
||||
"\n" +
|
||||
"!info: 查询服务器运行状态\n" +
|
||||
"!scoreboard <type> <id>: 查询该统计信息的玩家排行榜\n" +
|
||||
"!ban <type> <id/name>: 将一名 Discord 用户或 Minecraft 玩家从黑名单中添加或移除(仅限管理员)\n" +
|
||||
"!blacklist: 列出黑名单\n" +
|
||||
"!console <command>: 在服务器控制台中执行指令(仅限管理员)\n" +
|
||||
"!reload: 重新加载 MCDiscordChat 配置文件(仅限管理员)\n" +
|
||||
"!admin <id>: 将一名 Discord 用户从 MCDiscordChat 普通管理员名单中添加或移除(仅限超级管理员)\n" +
|
||||
"!adminlist: 列出管理员名单\n" +
|
||||
"!update: 检查更新\n" +
|
||||
"!stop: 停止服务器(仅限管理员)\n" +
|
||||
"```\n";
|
||||
|
||||
e.getChannel().sendMessage(help).queue();
|
||||
} else if ("!blacklist".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder bannedList = new StringBuilder("```\n=============== " + (Main.config.generic.switchLanguageFromChinToEng ? "Blacklist" : "黑名单") + " ===============\n\nDiscord:");
|
||||
|
||||
if (Main.config.generic.bannedDiscord.size() == 0) {
|
||||
bannedList.append("\n").append(Main.config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String id : Main.config.generic.bannedDiscord) {
|
||||
bannedList.append("\n").append(id);
|
||||
}
|
||||
|
||||
bannedList.append("\n\nMinecraft:");
|
||||
|
||||
if (Main.config.generic.bannedMinecraft.size() == 0) {
|
||||
bannedList.append("\n").append(Main.config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String name : Main.config.generic.bannedMinecraft) {
|
||||
bannedList.append("\n").append(name);
|
||||
}
|
||||
|
||||
bannedList.append("```");
|
||||
e.getChannel().sendMessage(bannedList.toString()).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!ban ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!ban ", "");
|
||||
|
||||
if (command.startsWith("discord ")) {
|
||||
command = command.replace("discord ", "");
|
||||
|
||||
if (Main.config.generic.bannedDiscord.contains(command)) {
|
||||
Main.config.generic.bannedDiscord.remove(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command + " has been removed from the blacklist!" : "已将 " + command + " 移出黑名单!") + "**").queue();
|
||||
} else {
|
||||
Main.config.generic.bannedDiscord.add(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command + " has been added to the blacklist!" : "已将 " + command + " 添加至黑名单!") + "**").queue();
|
||||
}
|
||||
} else if (command.startsWith("minecraft ")) {
|
||||
command = command.replace("minecraft ", "");
|
||||
|
||||
if (Main.config.generic.bannedMinecraft.contains(command)) {
|
||||
Main.config.generic.bannedMinecraft.remove(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command.replace("_", "\\_") + " has been removed from the blacklist!" : "**已将 " + command.replace("_", "\\_") + " 移出黑名单!**") + "**").queue();
|
||||
} else {
|
||||
Main.config.generic.bannedMinecraft.add(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command.replace("_", "\\_") + " has been added to the blacklist!" : "**已将 " + command.replace("_", "\\_") + " 添加至黑名单!**") + "**").queue();
|
||||
}
|
||||
}
|
||||
|
||||
ConfigManager.updateConfig();
|
||||
} else {
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!admin ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), true)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!admin ", "");
|
||||
|
||||
if (Main.config.generic.adminsIds.contains(command)) {
|
||||
Main.config.generic.adminsIds.remove(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command + " has been removed from the admin list!" : "已将 " + command + " 移出 MCDiscordChat 普通管理员名单!") + "**").queue();
|
||||
} else {
|
||||
Main.config.generic.adminsIds.add(command);
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? command + " has been added to the admin list!" : "已将 " + command + " 添加至 MCDiscordChat 普通管理员名单!") + "**").queue();
|
||||
}
|
||||
|
||||
ConfigManager.updateConfig();
|
||||
} else {
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!adminlist".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder adminList = new StringBuilder("```\n=============== " + (Main.config.generic.switchLanguageFromChinToEng ? "Admin List" : "管理员名单") + " ===============\n\n" + (Main.config.generic.switchLanguageFromChinToEng ? "Super admins:" : "超级管理员:"));
|
||||
|
||||
if (Main.config.generic.superAdminsIds.size() == 0) {
|
||||
adminList.append("\n").append(Main.config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String id : Main.config.generic.superAdminsIds) {
|
||||
adminList.append("\n").append(id);
|
||||
}
|
||||
|
||||
adminList.append("\n\n").append(Main.config.generic.switchLanguageFromChinToEng ? "Admins:" : "普通管理员:");
|
||||
|
||||
if (Main.config.generic.adminsIds.size() == 0) {
|
||||
adminList.append("\n").append(Main.config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String name : Main.config.generic.adminsIds) {
|
||||
adminList.append("\n").append(name);
|
||||
}
|
||||
|
||||
adminList.append("```");
|
||||
e.getChannel().sendMessage(adminList.toString()).queue();
|
||||
} else if ("!update".equals(e.getMessage().getContentRaw())) {
|
||||
Utils.checkUpdate(true);
|
||||
} else if ("!stop".equals(e.getMessage().getContentRaw())) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
if (command.startsWith("stop") || command.startsWith("/stop")) {
|
||||
server.stop(true);
|
||||
return;
|
||||
} else {
|
||||
e.getChannel().sendMessage("**" + (Main.config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
|
||||
server.getCommandManager().execute(getDiscordCommandSource(), command);
|
||||
} else {
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!reload".equals(e.getMessage().getContentRaw())) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
try {
|
||||
ConfigManager.loadConfig();
|
||||
ConfigManager.updateConfig();
|
||||
Utils.reloadTextsConfig();
|
||||
|
||||
if (config.generic.botListeningStatus.isEmpty()) {
|
||||
Main.jda.getPresence().setActivity(null);
|
||||
} else {
|
||||
Main.jda.getPresence().setActivity(Activity.listening(config.generic.botListeningStatus));
|
||||
}
|
||||
|
||||
if (config.generic.announceHighMSPT) {
|
||||
Main.msptMonitorTimer.cancel();
|
||||
Main.msptMonitorTimer = new Timer();
|
||||
Utils.monitorMSPT();
|
||||
} else {
|
||||
Main.msptMonitorTimer.cancel();
|
||||
}
|
||||
|
||||
Main.textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "Successfully loaded the configuration file!" : "配置文件加载成功!") + "**").queue();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(ex) + "\n```").queue();
|
||||
Main.textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "Failed to load the configuration file!" : "配置文件加载失败!") + "**").queue();
|
||||
}
|
||||
} else {
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!help".equals(e.getMessage().getContentRaw())) {
|
||||
String help = config.generic.switchLanguageFromChinToEng ? """
|
||||
```
|
||||
=============== Help ===============
|
||||
|
||||
!info: Query server running status
|
||||
!scoreboard <type> <id>: Query the player scoreboard for this statistic
|
||||
!ban <type> <id/name>: Add or remove a Discord user or Minecraft player from the blacklist (admins only)
|
||||
!blacklist: Query blacklist
|
||||
!console <command>: Executes command in the server console (admins only)
|
||||
!reload: Reload MCDiscordChat configuration file (admins only)
|
||||
!admin <id>: Add or remove a Discord user from the list of MCDiscordChat admins (super admins only)
|
||||
!adminlist: Query admin list
|
||||
!update: Check for update
|
||||
!stop: Stop the server (admins only)
|
||||
```
|
||||
""" : """
|
||||
```
|
||||
=============== 帮助 ===============
|
||||
|
||||
!info: 查询服务器运行状态
|
||||
!scoreboard <type> <id>: 查询该统计信息的玩家排行榜
|
||||
!ban <type> <id/name>: 将一名 Discord 用户或 Minecraft 玩家从黑名单中添加或移除(仅限管理员)
|
||||
!blacklist: 列出黑名单
|
||||
!console <command>: 在服务器控制台中执行指令(仅限管理员)
|
||||
!reload: 重新加载 MCDiscordChat 配置文件(仅限管理员)
|
||||
!admin <id>: 将一名 Discord 用户从 MCDiscordChat 普通管理员名单中添加或移除(仅限超级管理员)
|
||||
!adminlist: 列出管理员名单
|
||||
!update: 检查更新
|
||||
!stop: 停止服务器(仅限管理员)
|
||||
```
|
||||
""";
|
||||
|
||||
textChannel.sendMessage(help).queue();
|
||||
} else if ("!blacklist".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder bannedList = new StringBuilder("```\n=============== " + (config.generic.switchLanguageFromChinToEng ? "Blacklist" : "黑名单") + " ===============\n\nDiscord:");
|
||||
|
||||
if (config.generic.bannedDiscord.size() == 0) {
|
||||
bannedList.append("\n").append(config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder(e.getMessage().getContentDisplay()
|
||||
.replace("§", Main.config.generic.removeVanillaFormattingFromDiscord ? "&" : "§")
|
||||
.replace("\n", Main.config.generic.removeLineBreakFromDiscord ? " " : "\n")
|
||||
+ ((!e.getMessage().getEmbeds().isEmpty()) ? " <embed>" : ""));
|
||||
for (String id : config.generic.bannedDiscord) {
|
||||
bannedList.append("\n").append(id);
|
||||
}
|
||||
|
||||
if (!e.getMessage().getAttachments().isEmpty()) {
|
||||
for (Message.Attachment attachment : e.getMessage().getAttachments()) {
|
||||
if (attachment.isImage()) {
|
||||
message.append(" <image>");
|
||||
} else if (attachment.isSpoiler()) {
|
||||
message.append(" <spoiler>");
|
||||
} else if (attachment.isVideo()) {
|
||||
message.append(" <video>");
|
||||
bannedList.append("\n\nMinecraft:");
|
||||
|
||||
if (config.generic.bannedMinecraft.size() == 0) {
|
||||
bannedList.append("\n").append(config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String name : config.generic.bannedMinecraft) {
|
||||
bannedList.append("\n").append(name);
|
||||
}
|
||||
|
||||
bannedList.append("```");
|
||||
textChannel.sendMessage(bannedList.toString()).queue();
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!ban ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!ban ", "");
|
||||
|
||||
if (command.startsWith("discord ")) {
|
||||
command = command.replace("discord ", "");
|
||||
|
||||
if (config.generic.bannedDiscord.contains(command)) {
|
||||
config.generic.bannedDiscord.remove(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command + " has been removed from the blacklist!" : "已将 " + command + " 移出黑名单!") + "**").queue();
|
||||
} else {
|
||||
message.append(" <file>");
|
||||
config.generic.bannedDiscord.add(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command + " has been added to the blacklist!" : "已将 " + command + " 添加至黑名单!") + "**").queue();
|
||||
}
|
||||
} else if (command.startsWith("minecraft ")) {
|
||||
command = command.replace("minecraft ", "");
|
||||
|
||||
if (config.generic.bannedMinecraft.contains(command)) {
|
||||
config.generic.bannedMinecraft.remove(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command.replace("_", "\\_") + " has been removed from the blacklist!" : "**已将 " + command.replace("_", "\\_") + " 移出黑名单!**") + "**").queue();
|
||||
} else {
|
||||
config.generic.bannedMinecraft.add(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command.replace("_", "\\_") + " has been added to the blacklist!" : "**已将 " + command.replace("_", "\\_") + " 添加至黑名单!**") + "**").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LiteralText blueColoredText;
|
||||
LiteralText roleColoredText;
|
||||
LiteralText colorlessText;
|
||||
|
||||
if (e.isWebhookMessage() || e.getAuthor().isBot()) {
|
||||
blueColoredText = new LiteralText(Main.texts.blueColoredText()
|
||||
.replace("%servername%", e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] ")))
|
||||
.replace("%message%", EmojiParser.parseToAliases(message.toString())));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.BLUE)));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withBold(true));
|
||||
|
||||
roleColoredText = new LiteralText(Main.texts.roleColoredText()
|
||||
.replace("%name%", e.getAuthor().getName().substring(e.getAuthor().getName().indexOf("] ") + 2))
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
roleColoredText.setStyle(roleColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.GRAY)));
|
||||
|
||||
colorlessText = new LiteralText(Main.texts.colorlessText()
|
||||
.replace("%name%", e.getAuthor().getName().substring(e.getAuthor().getName().indexOf("] ") + 2))
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
ConfigManager.updateConfig();
|
||||
} else {
|
||||
blueColoredText = new LiteralText(Main.texts.blueColoredText()
|
||||
.replace("%servername%", "Discord")
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", EmojiParser.parseToAliases(message.toString())));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.BLUE)));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withBold(true));
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if (e.getMessage().getContentRaw().startsWith("!admin ")) {
|
||||
if (hasPermission(e.getAuthor().getId(), true)) {
|
||||
String command = e.getMessage().getContentRaw().replace("!admin ", "");
|
||||
|
||||
roleColoredText = new LiteralText(Main.texts.roleColoredText()
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
roleColoredText.setStyle(roleColoredText.getStyle().withColor(TextColor.fromRgb(Objects.requireNonNull(e.getMember()).getColorRaw())));
|
||||
if (config.generic.adminsIds.contains(command)) {
|
||||
config.generic.adminsIds.remove(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command + " has been removed from the admin list!" : "已将 " + command + " 移出 MCDiscordChat 普通管理员名单!") + "**").queue();
|
||||
} else {
|
||||
config.generic.adminsIds.add(command);
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? command + " has been added to the admin list!" : "已将 " + command + " 添加至 MCDiscordChat 普通管理员名单!") + "**").queue();
|
||||
}
|
||||
|
||||
colorlessText = new LiteralText(Main.texts.colorlessText()
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
ConfigManager.updateConfig();
|
||||
} else {
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
} else if ("!adminlist".equals(e.getMessage().getContentRaw())) {
|
||||
StringBuilder adminList = new StringBuilder("```\n=============== " + (config.generic.switchLanguageFromChinToEng ? "Admin List" : "管理员名单") + " ===============\n\n" + (config.generic.switchLanguageFromChinToEng ? "Super admins:" : "超级管理员:"));
|
||||
|
||||
if (config.generic.superAdminsIds.size() == 0) {
|
||||
adminList.append("\n").append(config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
colorlessText.setStyle(colorlessText.getStyle().withColor(TextColor.fromFormatting(Formatting.GRAY)));
|
||||
for (String id : config.generic.superAdminsIds) {
|
||||
adminList.append("\n").append(id);
|
||||
}
|
||||
|
||||
server.getPlayerManager().getPlayerList().forEach(
|
||||
serverPlayerEntity -> serverPlayerEntity.sendMessage(new LiteralText("").append(blueColoredText).append(roleColoredText).append(colorlessText), false));
|
||||
adminList.append("\n\n").append(config.generic.switchLanguageFromChinToEng ? "Admins:" : "普通管理员:");
|
||||
|
||||
if (config.generic.adminsIds.size() == 0) {
|
||||
adminList.append("\n").append(config.generic.switchLanguageFromChinToEng ? "List is empty!" : "列表为空!");
|
||||
}
|
||||
|
||||
for (String name : config.generic.adminsIds) {
|
||||
adminList.append("\n").append(name);
|
||||
}
|
||||
|
||||
adminList.append("```");
|
||||
textChannel.sendMessage(adminList.toString()).queue();
|
||||
} else if ("!update".equals(e.getMessage().getContentRaw())) {
|
||||
Utils.checkUpdate(true);
|
||||
} else if ("!stop".equals(e.getMessage().getContentRaw())) {
|
||||
if (hasPermission(e.getAuthor().getId(), false)) {
|
||||
server.stop(true);
|
||||
return;
|
||||
} else {
|
||||
textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "You do not have permission to use this command!" : "你没有权限使用此命令!") + "**").queue();
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder(e.getMessage().getContentDisplay()
|
||||
.replace("§", config.generic.removeVanillaFormattingFromDiscord ? "&" : "§")
|
||||
.replace("\n", config.generic.removeLineBreakFromDiscord ? " " : "\n")
|
||||
+ ((!e.getMessage().getEmbeds().isEmpty()) ? " <embed>" : ""));
|
||||
|
||||
if (!e.getMessage().getAttachments().isEmpty()) {
|
||||
for (Message.Attachment attachment : e.getMessage().getAttachments()) {
|
||||
if (attachment.isImage()) {
|
||||
message.append(" <image>");
|
||||
} else if (attachment.isSpoiler()) {
|
||||
message.append(" <spoiler>");
|
||||
} else if (attachment.isVideo()) {
|
||||
message.append(" <video>");
|
||||
} else {
|
||||
message.append(" <file>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LiteralText blueColoredText;
|
||||
LiteralText roleColoredText;
|
||||
LiteralText colorlessText;
|
||||
|
||||
if (e.isWebhookMessage() || e.getAuthor().isBot()) {
|
||||
blueColoredText = new LiteralText(Main.texts.blueColoredText()
|
||||
.replace("%servername%", e.getAuthor().getName().substring(1, e.getAuthor().getName().indexOf("] ")))
|
||||
.replace("%message%", EmojiParser.parseToAliases(message.toString())));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.BLUE)));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withBold(true));
|
||||
|
||||
roleColoredText = new LiteralText(Main.texts.roleColoredText()
|
||||
.replace("%name%", e.getAuthor().getName().substring(e.getAuthor().getName().indexOf("] ") + 2))
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
roleColoredText.setStyle(roleColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.GRAY)));
|
||||
|
||||
colorlessText = new LiteralText(Main.texts.colorlessText()
|
||||
.replace("%name%", e.getAuthor().getName().substring(e.getAuthor().getName().indexOf("] ") + 2))
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
} else {
|
||||
blueColoredText = new LiteralText(Main.texts.blueColoredText()
|
||||
.replace("%servername%", "Discord")
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", EmojiParser.parseToAliases(message.toString())));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withColor(TextColor.fromFormatting(Formatting.BLUE)));
|
||||
blueColoredText.setStyle(blueColoredText.getStyle().withBold(true));
|
||||
|
||||
roleColoredText = new LiteralText(Main.texts.roleColoredText()
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
roleColoredText.setStyle(roleColoredText.getStyle().withColor(TextColor.fromRgb(Objects.requireNonNull(e.getMember()).getColorRaw())));
|
||||
|
||||
colorlessText = new LiteralText(Main.texts.colorlessText()
|
||||
.replace("%name%", Objects.requireNonNull(e.getMember()).getEffectiveName())
|
||||
.replace("%message%", MarkdownParser.parseMarkdown(EmojiParser.parseToAliases(message.toString()))));
|
||||
}
|
||||
|
||||
colorlessText.setStyle(colorlessText.getStyle().withColor(TextColor.fromFormatting(Formatting.GRAY)));
|
||||
|
||||
server.getPlayerManager().getPlayerList().forEach(
|
||||
serverPlayerEntity -> serverPlayerEntity.sendMessage(new LiteralText("").append(blueColoredText).append(roleColoredText).append(colorlessText), false));
|
||||
}
|
||||
|
||||
private boolean hasPermission(String id, boolean onlySuperAdmin) {
|
||||
if (onlySuperAdmin) {
|
||||
return Main.config.generic.superAdminsIds.contains(id)
|
||||
return config.generic.superAdminsIds.contains(id)
|
||||
|| "769470378073653269".equals(id);
|
||||
} else {
|
||||
return Main.config.generic.superAdminsIds.contains(id)
|
||||
|| Main.config.generic.adminsIds.contains(id)
|
||||
return config.generic.superAdminsIds.contains(id)
|
||||
|| config.generic.adminsIds.contains(id)
|
||||
|| "769470378073653269".equals(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import java.util.List;
|
|||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static top.xujiayao.mcdiscordchat.Main.config;
|
||||
import static top.xujiayao.mcdiscordchat.Main.textChannel;
|
||||
|
||||
/**
|
||||
* @author Xujiayao
|
||||
*/
|
||||
|
|
@ -49,18 +52,18 @@ public class MinecraftEventListener {
|
|||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
|
||||
Pair<String, String> convertedPair = Utils.convertMentionsFromNames(rawMessage);
|
||||
|
||||
if (Main.config.generic.bannedMinecraft.contains(playerEntity.getEntityName())) {
|
||||
if (config.generic.bannedMinecraft.contains(playerEntity.getEntityName())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("username", (Main.config.generic.multiServer ? "[" + Main.config.multiServer.serverDisplayName + "] " + playerEntity.getEntityName() : playerEntity.getEntityName()));
|
||||
body.put("avatar_url", Main.config.generic.avatarAPI.replace("%player%", (Main.config.generic.useUUIDInsteadNickname ? playerEntity.getUuid().toString() : playerEntity.getEntityName())));
|
||||
body.put("username", (config.generic.multiServer ? "[" + config.multiServer.serverDisplayName + "] " + playerEntity.getEntityName() : playerEntity.getEntityName()));
|
||||
body.put("avatar_url", config.generic.avatarAPI.replace("%player%", (config.generic.useUUIDInsteadNickname ? playerEntity.getUuid().toString() : playerEntity.getEntityName())));
|
||||
|
||||
JSONObject allowedMentions = new JSONObject();
|
||||
allowedMentions.put("parse", new String[]{"users", "roles"});
|
||||
|
|
@ -69,13 +72,13 @@ public class MinecraftEventListener {
|
|||
body.put("content", convertedPair.getLeft().replace("_", "\\_"));
|
||||
|
||||
try {
|
||||
Unirest.post(Main.config.generic.webhookURL).header("Content-Type", "application/json").body(body).asJsonAsync();
|
||||
Unirest.post(config.generic.webhookURL).header("Content-Type", "application/json").body(body).asJsonAsync();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
|
||||
if (Main.config.generic.modifyChatMessages) {
|
||||
if (config.generic.modifyChatMessages) {
|
||||
String jsonString = Text.Serializer.toJson(message);
|
||||
JSONObject newComponent = new JSONObject(jsonString);
|
||||
|
||||
|
|
@ -95,7 +98,7 @@ public class MinecraftEventListener {
|
|||
});
|
||||
|
||||
CommandExecutionCallback.EVENT.register((command, source) -> {
|
||||
if (!Main.stop && Main.config.generic.broadcastCommandExecution) {
|
||||
if (!Main.stop && config.generic.broadcastCommandExecution) {
|
||||
try {
|
||||
String temp = command;
|
||||
|
||||
|
|
@ -103,11 +106,11 @@ public class MinecraftEventListener {
|
|||
temp = temp.substring(0, temp.indexOf(" "));
|
||||
}
|
||||
|
||||
if (Main.config.generic.excludedCommands.contains(temp)) {
|
||||
if (config.generic.excludedCommands.contains(temp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Main.config.generic.bannedMinecraft.contains(source.getPlayer().getEntityName())) {
|
||||
if (config.generic.bannedMinecraft.contains(source.getPlayer().getEntityName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -120,8 +123,8 @@ public class MinecraftEventListener {
|
|||
lastPlayer = source.getPlayer().getEntityName();
|
||||
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("username", (Main.config.generic.multiServer ? "[" + Main.config.multiServer.serverDisplayName + "] " + source.getPlayer().getEntityName() : source.getPlayer().getEntityName()));
|
||||
body.put("avatar_url", Main.config.generic.avatarAPI.replace("%player%", (Main.config.generic.useUUIDInsteadNickname ? source.getPlayer().getUuid().toString() : source.getPlayer().getEntityName())));
|
||||
body.put("username", (config.generic.multiServer ? "[" + config.multiServer.serverDisplayName + "] " + source.getPlayer().getEntityName() : source.getPlayer().getEntityName()));
|
||||
body.put("avatar_url", config.generic.avatarAPI.replace("%player%", (config.generic.useUUIDInsteadNickname ? source.getPlayer().getUuid().toString() : source.getPlayer().getEntityName())));
|
||||
|
||||
JSONObject allowedMentions = new JSONObject();
|
||||
allowedMentions.put("parse", new String[]{"users", "roles"});
|
||||
|
|
@ -129,10 +132,10 @@ public class MinecraftEventListener {
|
|||
body.put("allowed_mentions", allowedMentions);
|
||||
body.put("content", command.replace("_", "\\_"));
|
||||
|
||||
Unirest.post(Main.config.generic.webhookURL).header("Content-Type", "application/json").body(body).asJsonAsync();
|
||||
Unirest.post(config.generic.webhookURL).header("Content-Type", "application/json").body(body).asJsonAsync();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -144,28 +147,28 @@ public class MinecraftEventListener {
|
|||
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();
|
||||
textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Main.textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
textChannel.sendMessage("```\n" + ExceptionUtils.getStackTrace(e) + "\n```").queue();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
PlayerAdvancementCallback.EVENT.register((playerEntity, advancement) -> {
|
||||
if (Main.config.generic.announceAdvancements && advancement.getDisplay() != null
|
||||
if (config.generic.announceAdvancements && advancement.getDisplay() != null
|
||||
&& advancement.getDisplay().shouldAnnounceToChat()
|
||||
&& playerEntity.getAdvancementTracker().getProgress(advancement).isDone() && !Main.stop) {
|
||||
switch (advancement.getDisplay().getFrame()) {
|
||||
case GOAL -> Main.textChannel.sendMessage(Main.texts.advancementGoal()
|
||||
case GOAL -> textChannel.sendMessage(Main.texts.advancementGoal()
|
||||
.replace("%playername%", MarkdownSanitizer.escape(playerEntity.getEntityName()))
|
||||
.replace("%advancement%", advancement.getDisplay().getTitle().getString())).queue();
|
||||
case TASK -> Main.textChannel.sendMessage(Main.texts.advancementTask()
|
||||
case TASK -> textChannel.sendMessage(Main.texts.advancementTask()
|
||||
.replace("%playername%", MarkdownSanitizer.escape(playerEntity.getEntityName()))
|
||||
.replace("%advancement%", advancement.getDisplay().getTitle().getString())).queue();
|
||||
case CHALLENGE -> Main.textChannel.sendMessage(Main.texts.advancementChallenge()
|
||||
case CHALLENGE -> textChannel.sendMessage(Main.texts.advancementChallenge()
|
||||
.replace("%playername%", MarkdownSanitizer.escape(playerEntity.getEntityName()))
|
||||
.replace("%advancement%", advancement.getDisplay().getTitle().getString())).queue();
|
||||
}
|
||||
|
|
@ -173,23 +176,23 @@ public class MinecraftEventListener {
|
|||
});
|
||||
|
||||
PlayerDeathCallback.EVENT.register((playerEntity, damageSource) -> {
|
||||
if (Main.config.generic.announceDeaths && !Main.stop) {
|
||||
Main.textChannel.sendMessage(Main.texts.deathMessage()
|
||||
if (config.generic.announceDeaths && !Main.stop) {
|
||||
textChannel.sendMessage(Main.texts.deathMessage()
|
||||
.replace("%deathmessage%", MarkdownSanitizer.escape(damageSource.getDeathMessage(playerEntity).getString()))
|
||||
.replace("%playername%", MarkdownSanitizer.escape(playerEntity.getEntityName()))).queue();
|
||||
}
|
||||
});
|
||||
|
||||
PlayerJoinCallback.EVENT.register((connection, playerEntity) -> {
|
||||
if (Main.config.generic.announcePlayers && !Main.stop) {
|
||||
Main.textChannel.sendMessage(Main.texts.joinServer().replace("%playername%",
|
||||
if (config.generic.announcePlayers && !Main.stop) {
|
||||
textChannel.sendMessage(Main.texts.joinServer().replace("%playername%",
|
||||
MarkdownSanitizer.escape(playerEntity.getEntityName()))).queue();
|
||||
}
|
||||
});
|
||||
|
||||
PlayerLeaveCallback.EVENT.register(playerEntity -> {
|
||||
if (Main.config.generic.announcePlayers && !Main.stop) {
|
||||
Main.textChannel.sendMessage(Main.texts.leftServer().replace("%playername%",
|
||||
if (config.generic.announcePlayers && !Main.stop) {
|
||||
textChannel.sendMessage(Main.texts.leftServer().replace("%playername%",
|
||||
MarkdownSanitizer.escape(playerEntity.getEntityName()))).queue();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class MarkdownParser {
|
||||
|
||||
private MarkdownParser() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static String parseMarkdown(String message) {
|
||||
String translated = message;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ import java.util.Map;
|
|||
*/
|
||||
public class Scoreboard {
|
||||
|
||||
private Scoreboard() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static StringBuilder getScoreboard(String message) {
|
||||
StringBuilder output = null;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue