mirror of
https://github.com/JonasunderscoreJones/YetAnotherDiscordChatLink.git
synced 2025-10-23 00:39:17 +02:00
Cleaned up code
Added delapy when stopping to ensure that the server-stopped message was sent
This commit is contained in:
parent
5bfb195326
commit
48761085c4
4 changed files with 18 additions and 13 deletions
|
@ -17,7 +17,7 @@ public class ModConfigs {
|
|||
//public static Boolean PLAYER_COMMAND_MSG;
|
||||
public static Boolean SERVER_START_STOP_MSG;
|
||||
|
||||
public static String BOT_STATUS;
|
||||
//public static String BOT_STATUS;
|
||||
|
||||
public static void registerConfigs() {
|
||||
configs = new ModConfigProvider();
|
||||
|
@ -37,7 +37,7 @@ public class ModConfigs {
|
|||
configs.addKeyValuePair(new Pair<>("bot.player_chat_msgs", true), "Should the bot send a message when a player sends a chat message");
|
||||
//configs.addKeyValuePair(new Pair<>("bot.player_command_msgs", true), "Should the bot send a message when a player sends a command");
|
||||
configs.addKeyValuePair(new Pair<>("bot.server_start_stop_msgs", true), "Should the bot send a message when the server starts or stops");
|
||||
configs.addKeyValuePair(new Pair<>("bot.status", "PlayerCount"), "What status should the bot display [None, PlayerCount, IP, Uptime]");
|
||||
//configs.addKeyValuePair(new Pair<>("bot.status", "PlayerCount"), "What status should the bot display [None, PlayerCount, IP, Uptime]");
|
||||
}
|
||||
|
||||
private static void assignConfigs() {
|
||||
|
@ -49,7 +49,7 @@ public class ModConfigs {
|
|||
PLAYER_CHAT_MSG = CONFIG.getOrDefault("bot.player_chat_msgs", true);
|
||||
//PLAYER_COMMAND_MSG = CONFIG.getOrDefault("bot.player_command_msgs", true);
|
||||
SERVER_START_STOP_MSG = CONFIG.getOrDefault("bot.server_start_stop_msgs", true);
|
||||
BOT_STATUS = CONFIG.getOrDefault("bot.status", "PlayerCount");
|
||||
//BOT_STATUS = CONFIG.getOrDefault("bot.status", "PlayerCount");
|
||||
|
||||
YetAnotherDiscordChatLink.LOGGER.info("All " + configs.getConfigsList().size() + " Configs have been set properly");
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class DiscordBot {
|
|||
}
|
||||
});
|
||||
// Set the bot status
|
||||
if (ModConfigs.BOT_STATUS.equals("Uptime")) {
|
||||
/*if (ModConfigs.BOT_STATUS.equals("Uptime")) {
|
||||
new Thread(() -> {
|
||||
while (isBotRunning) {
|
||||
botStatus(ModConfigs.BOT_STATUS);
|
||||
|
@ -58,7 +58,7 @@ public class DiscordBot {
|
|||
}).start();
|
||||
} else {
|
||||
botStatus(ModConfigs.BOT_STATUS);
|
||||
}
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Failed to start Discord bot. Check the provided discord token in the config file.");
|
||||
return;
|
||||
|
@ -104,11 +104,17 @@ public class DiscordBot {
|
|||
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
|
||||
sendToDiscord("Server is stopped!");
|
||||
//wait for 2 seconds to make sure the message is sent
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
stopBot();
|
||||
});
|
||||
}
|
||||
|
||||
public static void botStatus(String status) {
|
||||
/*public static void botStatus(String status) {
|
||||
if (!isBotRunning) {
|
||||
return;
|
||||
}
|
||||
|
@ -150,5 +156,5 @@ public class DiscordBot {
|
|||
}
|
||||
|
||||
return duration.toString();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static dev.jonasjones.yadcl.dcbot.DiscordBot.botStatus;
|
||||
//import static dev.jonasjones.yadcl.dcbot.DiscordBot.botStatus;
|
||||
import static dev.jonasjones.yadcl.dcbot.DiscordBot.sendToDiscord;
|
||||
|
||||
@Mixin(PlayerManager.class)
|
||||
|
@ -19,9 +19,9 @@ public class PlayerManagerMixin {
|
|||
public void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, ConnectedClientData clientData, CallbackInfo ci) {
|
||||
if (ModConfigs.PLAYER_JOIN_LEAVE_MSG) {
|
||||
sendToDiscord(player.getDisplayName().getString() + " joined the game");
|
||||
if (ModConfigs.BOT_STATUS.equals("PlayerCount")) {
|
||||
/*if (ModConfigs.BOT_STATUS.equals("PlayerCount")) {
|
||||
botStatus(ModConfigs.BOT_STATUS);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,9 @@ public class PlayerManagerMixin {
|
|||
public void remove(ServerPlayerEntity player, CallbackInfo ci) {
|
||||
if (ModConfigs.PLAYER_JOIN_LEAVE_MSG) {
|
||||
sendToDiscord(player.getDisplayName().getString() + " left the game");
|
||||
if (ModConfigs.BOT_STATUS.equals("PlayerCount")) {
|
||||
/*if (ModConfigs.BOT_STATUS.equals("PlayerCount")) {
|
||||
botStatus(ModConfigs.BOT_STATUS);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import static dev.jonasjones.yadcl.dcbot.DiscordBot.sendToDiscord;
|
||||
import static dev.jonasjones.yadcl.dcbot.DiscordBot.stopBot;
|
||||
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class ServerStopMixin {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue