fix: the previous commit actually broke everything that uses the global plugins

this is why you should test your code on production THEN commit and push your changes
This commit is contained in:
ChomeNS
2025-04-01 19:51:50 +07:00
parent 58e722ba06
commit 1d7190dd44
15 changed files with 61 additions and 54 deletions

View File

@@ -69,11 +69,6 @@ public class Bot extends SessionAdapter {
public final ExecutorService executorService = Main.executorService;
public final ScheduledExecutorService executor = Main.executor;
public ConsolePlugin console = Main.console;
public DatabasePlugin database = Main.database;
public DiscordPlugin discord = Main.discord;
public IRCPlugin irc = Main.irc;
public LoggerPlugin logger;
public TickPlugin tick;
public ChatPlugin chat;

View File

@@ -196,15 +196,17 @@ public class Main {
final boolean ircEnabled = config.irc.enabled;
final boolean discordEnabled = config.discord.enabled;
if (ircEnabled) irc.quit(stoppingMessage);
final boolean[] stoppedDiscord = new boolean[copiedList.size()];
int botIndex = 0;
for (Bot bot : copiedList) {
try {
if (discordEnabled) {
final String channelId = bot.discord.servers.get(bot.getServerString(true));
final String channelId = Main.discord.servers.get(bot.getServerString(true));
final MessageCreateAction messageAction = bot.discord.sendMessageInstantly(stoppingMessage, channelId, false);
final MessageCreateAction messageAction = Main.discord.sendMessageInstantly(stoppingMessage, channelId, false);
final int finalBotIndex = botIndex;
messageAction.queue(
@@ -213,8 +215,6 @@ public class Main {
);
}
if (ircEnabled) bot.irc.quit(stoppingMessage);
bot.stop();
} catch (Exception ignored) { }

View File

@@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot.command.contexts;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.data.player.PlayerEntry;
import me.chayapak1.chomens_bot.util.ComponentUtilities;
@@ -38,7 +39,7 @@ public class IRCCommandContext extends CommandContext {
@Override
public void sendOutput (Component component) {
bot.irc.sendMessage(bot, ComponentUtilities.stringifyAnsi(component));
Main.irc.sendMessage(bot, ComponentUtilities.stringifyAnsi(component));
}
@Override

View File

@@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot.commands;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
@@ -44,22 +45,26 @@ public class ConsoleCommand extends Command {
final String server = context.getString(true, true);
for (Bot eachBot : bot.bots) {
if (server.equalsIgnoreCase("all")) {
eachBot.console.consoleServer = "all";
if (server.equalsIgnoreCase("all")) {
Main.console.consoleServer = "all";
return Component.text(
"Set the console server to all servers"
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
continue;
}
try {
// servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess
Main.console.consoleServer = servers.stream()
.filter(eachServer -> eachServer.toLowerCase().contains(server))
.findFirst()
.orElse("all");
try {
// servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess
eachBot.console.consoleServer = servers.stream()
.filter(eachServer -> eachServer.toLowerCase().contains(server))
.findFirst()
.orElse("all");
} catch (ArrayIndexOutOfBoundsException e) {
throw new CommandException(Component.text("Invalid server: " + server));
}
return Component.translatable(
"Set the console server to %s",
Component.text(Main.console.consoleServer)
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
} catch (ArrayIndexOutOfBoundsException e) {
throw new CommandException(Component.text("Invalid server: " + server));
}
}
case "logtoconsole" -> {

View File

@@ -2,6 +2,7 @@ package me.chayapak1.chomens_bot.commands;
import com.fasterxml.jackson.databind.JsonNode;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
@@ -31,10 +32,10 @@ public class FindAltsCommand extends Command {
public Component execute (CommandContext context) throws Exception {
final Bot bot = context.bot;
if (bot.database == null)
if (Main.database == null)
throw new CommandException(Component.text("Database is not enabled in the bot's config"));
bot.database.checkOverloaded();
Main.database.checkOverloaded();
final String flag = context.getString(false, true);

View File

@@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot.commands;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
@@ -27,8 +28,8 @@ public class GrepLogCommand extends Command {
public Component execute (CommandContext context) throws CommandException {
final Bot bot = context.bot;
if (bot.discord == null || bot.discord.jda == null) {
throw new CommandException(Component.text("The bot's Discord integration has to be enabled to use the command."));
if (Main.discord == null || Main.discord.jda == null) {
throw new CommandException(Component.text("The bot's Discord integration has to be enabled to use this command."));
}
boolean ignoreCase = false;

View File

@@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot.commands;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
@@ -38,10 +39,10 @@ public class MailCommand extends Command {
public Component execute (CommandContext context) throws CommandException {
final Bot bot = context.bot;
if (bot.database == null)
if (Main.database == null)
throw new CommandException(Component.text("Database is not enabled in the bot's config"));
bot.database.checkOverloaded();
Main.database.checkOverloaded();
final PlayerEntry sender = context.sender;

View File

@@ -3,6 +3,7 @@ package me.chayapak1.chomens_bot.commands;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
@@ -36,10 +37,10 @@ public class SeenCommand extends Command {
public Component execute (CommandContext context) throws CommandException {
final Bot bot = context.bot;
if (bot.database == null)
if (Main.database == null)
throw new CommandException(Component.text("Database is not enabled in the bot's config"));
bot.database.checkOverloaded();
Main.database.checkOverloaded();
final String player = context.getString(true, true);

View File

@@ -2,6 +2,7 @@ package me.chayapak1.chomens_bot.plugins;
import com.google.common.hash.Hashing;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.data.player.PlayerEntry;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@@ -71,7 +72,7 @@ public class FormatCheckerPlugin implements ChatPlugin.Listener, PlayersPlugin.L
if (
((prefix instanceof TextComponent text) && text.content().equals(bot.username + " Console")) || // ohio
(bot.discord != null && prefix.equals(bot.discord.messagePrefix))
(Main.discord != null && prefix.equals(Main.discord.messagePrefix))
) return false;
if (!(prefix instanceof TranslatableComponent translatablePrefix)) return true;

View File

@@ -1,6 +1,7 @@
package me.chayapak1.chomens_bot.plugins;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.Main;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
import me.chayapak1.chomens_bot.util.ColorUtilities;
@@ -88,8 +89,8 @@ public class GrepLogPlugin {
if (matches == 0) throw new CommandException(Component.text("No matches has been found"));
final String channelId = bot.discord.servers.get(bot.getServerString(true));
final TextChannel logChannel = bot.discord.jda.getTextChannelById(channelId);
final String channelId = Main.discord.servers.get(bot.getServerString(true));
final TextChannel logChannel = Main.discord.jda.getTextChannelById(channelId);
if (logChannel == null) return;

View File

@@ -90,7 +90,7 @@ public class IPFilterPlugin implements PlayersPlugin.Listener, CorePlugin.Listen
public void add (String ip, String reason) {
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(INSERT_FILTER);
final PreparedStatement statement = Main.database.connection.prepareStatement(INSERT_FILTER);
statement.setString(1, ip);
statement.setString(2, reason);
@@ -115,7 +115,7 @@ public class IPFilterPlugin implements PlayersPlugin.Listener, CorePlugin.Listen
public void remove (String ip) {
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(REMOVE_FILTER);
final PreparedStatement statement = Main.database.connection.prepareStatement(REMOVE_FILTER);
statement.setString(1, ip);
@@ -129,7 +129,7 @@ public class IPFilterPlugin implements PlayersPlugin.Listener, CorePlugin.Listen
public void clear () {
try {
bot.database.update(CLEAR_FILTER);
Main.database.update(CLEAR_FILTER);
list();
} catch (SQLException e) {

View File

@@ -75,7 +75,7 @@ public class MailPlugin implements PlayersPlugin.Listener {
public void send (Mail mail) {
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(INSERT_MAIL);
final PreparedStatement statement = Main.database.connection.prepareStatement(INSERT_MAIL);
statement.setString(1, mail.sentBy());
statement.setString(2, mail.sentTo());
@@ -91,7 +91,7 @@ public class MailPlugin implements PlayersPlugin.Listener {
public void clear (String sentTo) {
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(REMOVE_MAIL);
final PreparedStatement statement = Main.database.connection.prepareStatement(REMOVE_MAIL);
statement.setString(1, sentTo);
@@ -104,7 +104,7 @@ public class MailPlugin implements PlayersPlugin.Listener {
public List<Mail> list () {
final List<Mail> output = new ArrayList<>();
try (ResultSet result = bot.database.query(LIST_MAILS)) {
try (ResultSet result = Main.database.query(LIST_MAILS)) {
if (result == null) return output;
while (result.next()) {

View File

@@ -137,7 +137,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
public void add (String playerName, String reason, boolean regex, boolean ignoreCase) {
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(INSERT_FILTER);
final PreparedStatement statement = Main.database.connection.prepareStatement(INSERT_FILTER);
statement.setString(1, playerName);
statement.setString(2, reason);
@@ -166,7 +166,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
bot.filterManager.remove(playerName);
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(REMOVE_FILTER);
final PreparedStatement statement = Main.database.connection.prepareStatement(REMOVE_FILTER);
statement.setString(1, playerName);
@@ -182,7 +182,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
for (FilteredPlayer player : localList) bot.filterManager.remove(player.playerName);
try {
bot.database.update(CLEAR_FILTER);
Main.database.update(CLEAR_FILTER);
list();
} catch (SQLException e) {

View File

@@ -52,10 +52,10 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
}
public JsonNode getPlayerData (String username) {
if (bot.database == null || bot.database.connection == null) return null;
if (Main.database == null || Main.database.connection == null) return null;
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(GET_DATA);
final PreparedStatement statement = Main.database.connection.prepareStatement(GET_DATA);
statement.setString(1, username);
@@ -75,10 +75,10 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
}
public String getPlayerIP (String username) {
if (bot.database == null || bot.database.connection == null) return null;
if (Main.database == null || Main.database.connection == null) return null;
try {
final PreparedStatement statement = bot.database.connection.prepareStatement(GET_IP);
final PreparedStatement statement = Main.database.connection.prepareStatement(GET_IP);
// this may be dangerous but the server address is configured only in the config
// so this should still be safe
@@ -107,11 +107,11 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
PreparedStatement statement;
if (allServer) {
statement = bot.database.connection.prepareStatement(FIND_ALTS_ALL_SERVERS);
statement = Main.database.connection.prepareStatement(FIND_ALTS_ALL_SERVERS);
statement.setString(1, ip);
} else {
statement = bot.database.connection.prepareStatement(FIND_ALTS_SINGLE_SERVER);
statement = Main.database.connection.prepareStatement(FIND_ALTS_SINGLE_SERVER);
statement.setString(1, bot.getServerString(true));
statement.setString(2, ip);
@@ -137,7 +137,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
public void playerJoined (PlayerEntry target) {
DatabasePlugin.executorService.submit(() -> {
try {
final PreparedStatement insertPlayerStatement = bot.database.connection.prepareStatement(INSERT_PLAYER);
final PreparedStatement insertPlayerStatement = Main.database.connection.prepareStatement(INSERT_PLAYER);
insertPlayerStatement.setString(1, target.profile.getName());
@@ -161,7 +161,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
if (output == null) return null;
try {
final PreparedStatement updatePlayerStatement = bot.database.connection.prepareStatement(UPDATE_PLAYER);
final PreparedStatement updatePlayerStatement = Main.database.connection.prepareStatement(UPDATE_PLAYER);
updatePlayerStatement.setString(1, "$.ips");
updatePlayerStatement.setString(2, "$.ips");
@@ -190,7 +190,7 @@ public class PlayersDatabasePlugin implements PlayersPlugin.Listener {
public void playerLeft (PlayerEntry target) {
DatabasePlugin.executorService.submit(() -> {
try {
final PreparedStatement updatePlayerStatement = bot.database.connection.prepareStatement(UPDATE_PLAYER);
final PreparedStatement updatePlayerStatement = Main.database.connection.prepareStatement(UPDATE_PLAYER);
updatePlayerStatement.setString(1, "$.lastSeen");
updatePlayerStatement.setString(2, "$.lastSeen");