修复bug

This commit is contained in:
Xujiayao 2022-03-03 20:17:46 +08:00
parent 76b958b4d6
commit 6a341d14d3
4 changed files with 43 additions and 26 deletions

View file

@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx4G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.18.1
yarn_mappings=1.18.1+build.22
loader_version=0.13.1
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.1
loader_version=0.13.3
# Mod Properties
mod_version=1.18-1.11.4
@ -13,4 +13,4 @@ maven_group=top.xujiayao
archives_base_name=MCDiscordChat
# Dependencies
fabric_version=0.46.4+1.18
fabric_version=0.47.8+1.18.2

View file

@ -33,28 +33,32 @@ public class Main implements DedicatedServerModInitializer {
public static boolean stop = false;
public static Timer msptMonitorTimer;
public static Timer consoleLogTimer;
public static Timer consoleLogTimer1;
public static Timer consoleLogTimer2;
@Override
public void onInitializeServer() {
ConfigManager.initConfig();
try {
if (Main.config.generic.membersIntents) {
jda = JDABuilder.createDefault(Main.config.generic.botToken)
if (config.generic.membersIntents) {
jda = JDABuilder.createDefault(config.generic.botToken)
.setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.addEventListeners(new DiscordEventListener())
.build();
} else {
jda = JDABuilder.createDefault(Main.config.generic.botToken)
jda = JDABuilder.createDefault(config.generic.botToken)
.addEventListeners(new DiscordEventListener())
.build();
}
jda.awaitReady();
textChannel = jda.getTextChannelById(Main.config.generic.channelId);
consoleLogTextChannel = jda.getTextChannelById(Main.config.generic.consoleLogChannelId);
textChannel = jda.getTextChannelById(config.generic.channelId);
if (!config.generic.consoleLogChannelId.isEmpty()) {
consoleLogTextChannel = jda.getTextChannelById(config.generic.consoleLogChannelId);
}
} catch (Exception e) {
e.printStackTrace();
jda = null;
@ -62,12 +66,12 @@ public class Main implements DedicatedServerModInitializer {
}
if (jda != null) {
if (!Main.config.generic.botListeningStatus.isEmpty()) {
jda.getPresence().setActivity(Activity.listening(Main.config.generic.botListeningStatus));
if (!config.generic.botListeningStatus.isEmpty()) {
jda.getPresence().setActivity(Activity.listening(config.generic.botListeningStatus));
}
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
textChannel.sendMessage(Main.texts.serverStarted()).queue();
textChannel.sendMessage(texts.serverStarted()).queue();
Utils.checkUpdate(false);
if (config.generic.announceHighMSPT) {
@ -78,14 +82,15 @@ public class Main implements DedicatedServerModInitializer {
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
stop = true;
textChannel.sendMessage(Main.texts.serverStopped()).queue();
textChannel.sendMessage(texts.serverStopped()).queue();
if (config.generic.announceHighMSPT) {
msptMonitorTimer.cancel();
}
if (!config.generic.consoleLogChannelId.isEmpty()) {
consoleLogTimer.cancel();
consoleLogTimer1.cancel();
consoleLogTimer2.cancel();
}
try {

View file

@ -30,7 +30,7 @@ import java.util.TimerTask;
import static top.xujiayao.mcdiscordchat.Main.config;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTextChannel;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTimer;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTimer1;
import static top.xujiayao.mcdiscordchat.Main.textChannel;
/**
@ -130,10 +130,15 @@ public class DiscordEventListener extends ListenerAdapter {
}
textChannel = Main.jda.getTextChannelById(Main.config.generic.channelId);
consoleLogTextChannel = Main.jda.getTextChannelById(Main.config.generic.consoleLogChannelId);
if (!config.generic.consoleLogChannelId.isEmpty()) {
consoleLogTextChannel = Main.jda.getTextChannelById(Main.config.generic.consoleLogChannelId);
}
if (config.generic.announceHighMSPT) {
Main.msptMonitorTimer.cancel();
if (Main.msptMonitorTimer != null) {
Main.msptMonitorTimer.cancel();
}
Main.msptMonitorTimer = new Timer();
Utils.monitorMSPT();
} else {
@ -141,16 +146,21 @@ public class DiscordEventListener extends ListenerAdapter {
}
if (!config.generic.consoleLogChannelId.isEmpty()) {
Main.consoleLogTimer.cancel();
Main.consoleLogTimer = new Timer();
consoleLogTimer.schedule(new TimerTask() {
if (Main.consoleLogTimer1 != null) {
Main.consoleLogTimer1.cancel();
Main.consoleLogTimer2.cancel();
}
Main.consoleLogTimer1 = new Timer();
Main.consoleLogTimer2 = new Timer();
consoleLogTimer1.schedule(new TimerTask() {
@Override
public void run() {
MinecraftEventListener.consoleLogSentTimes = 0;
}
}, 0, 30000);
} else {
Main.consoleLogTimer.cancel();
Main.consoleLogTimer1.cancel();
Main.consoleLogTimer2.cancel();
}
Main.textChannel.sendMessage("**" + (config.generic.switchLanguageFromChinToEng ? "Successfully loaded the configuration file!" : "配置文件加载成功!") + "**").queue();

View file

@ -36,7 +36,8 @@ import java.util.TimerTask;
import static top.xujiayao.mcdiscordchat.Main.client;
import static top.xujiayao.mcdiscordchat.Main.config;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTextChannel;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTimer;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTimer1;
import static top.xujiayao.mcdiscordchat.Main.consoleLogTimer2;
import static top.xujiayao.mcdiscordchat.Main.textChannel;
/**
@ -180,8 +181,9 @@ public class MinecraftEventListener {
});
if (!config.generic.consoleLogChannelId.isEmpty()) {
consoleLogTimer = new Timer();
consoleLogTimer.schedule(new TimerTask() {
consoleLogTimer1 = new Timer();
consoleLogTimer2 = new Timer();
consoleLogTimer1.schedule(new TimerTask() {
@Override
public void run() {
consoleLogSentTimes = 0;
@ -203,7 +205,7 @@ public class MinecraftEventListener {
.replace("%message%", message)).queue();
if (consoleLogSentTimes == 10) {
new Timer().schedule(new TimerTask() {
consoleLogTimer2.schedule(new TimerTask() {
@Override
public void run() {
consoleLogSentTimes = 0;