refactor: use Executor.execute instead of submit
refactor: use mcprotocollib's packet handler executor to send the brand and the client information (even though it's for handling packets)
This commit is contained in:
@@ -1 +1 @@
|
||||
3373
|
||||
3378
|
||||
@@ -313,8 +313,8 @@ public class Bot extends SessionAdapter {
|
||||
}
|
||||
|
||||
private void packetSent (final ServerboundLoginAcknowledgedPacket ignoredPacket) {
|
||||
// doesn't work without submitting it somewhere :(
|
||||
executorService.submit(() -> {
|
||||
// doesn't work without executing
|
||||
session.getPacketHandlerExecutor().execute(() -> {
|
||||
// for voicechat
|
||||
session.send(new ServerboundCustomPayloadPacket(
|
||||
Key.key("minecraft:brand"),
|
||||
|
||||
@@ -190,6 +190,7 @@ public class Main {
|
||||
|
||||
EXECUTOR.shutdown();
|
||||
EXECUTOR_SERVICE.shutdown();
|
||||
FileLoggerUtilities.stop();
|
||||
if (database != null) database.stop();
|
||||
|
||||
final ArrayList<Bot> copiedList;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FilterCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.add(player, reason, regex, ignoreCase));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.playerFilter.add(player, reason, regex, ignoreCase));
|
||||
|
||||
if (reason.isEmpty()) {
|
||||
return Component.translatable(
|
||||
@@ -102,7 +102,7 @@ public class FilterCommand extends Command {
|
||||
|
||||
if (player == null) throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.remove(player.playerName()));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.playerFilter.remove(player.playerName()));
|
||||
|
||||
return Component.translatable(
|
||||
"commands.filter.remove.output",
|
||||
@@ -113,7 +113,7 @@ public class FilterCommand extends Command {
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(bot.playerFilter::clear);
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(bot.playerFilter::clear);
|
||||
return Component.translatable("commands.filter.clear.output").color(bot.colorPalette.defaultColor);
|
||||
}
|
||||
case "list" -> {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class FindAltsCommand extends Command {
|
||||
|
||||
final String player = context.getString(true, true);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
final PlayerEntry playerInTheServer = bot.players.getEntry(player);
|
||||
|
||||
final String ipFromUsername;
|
||||
@@ -62,8 +62,6 @@ public class FindAltsCommand extends Command {
|
||||
} else {
|
||||
context.sendOutput(handle(bot, ipFromUsername, player, allServer));
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
return null;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class IPFilterCommand extends Command {
|
||||
);
|
||||
}
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.ipFilter.add(ip, reason));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.ipFilter.add(ip, reason));
|
||||
|
||||
if (reason.isEmpty()) {
|
||||
return Component.translatable(
|
||||
@@ -77,7 +77,7 @@ public class IPFilterCommand extends Command {
|
||||
|
||||
if (targetIP == null) throw new CommandException(Component.translatable("commands.generic.error.invalid_index"));
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.ipFilter.remove(targetIP));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> bot.ipFilter.remove(targetIP));
|
||||
|
||||
return Component.translatable(
|
||||
"commands.ipfilter.remove.output",
|
||||
@@ -88,7 +88,7 @@ public class IPFilterCommand extends Command {
|
||||
case "clear" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(bot.ipFilter::clear);
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(bot.ipFilter::clear);
|
||||
return Component.translatable("commands.ipfilter.clear.output").color(bot.colorPalette.defaultColor);
|
||||
}
|
||||
case "list" -> {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MailCommand extends Command {
|
||||
final String action = context.getAction();
|
||||
|
||||
switch (action) {
|
||||
case "send" -> DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
case "send" -> DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
bot.mail.send(
|
||||
new Mail(
|
||||
@@ -79,7 +79,7 @@ public class MailCommand extends Command {
|
||||
throw new CommandException(Component.translatable("commands.mail.sendselecteditem.error.no_item_nbt"));
|
||||
}
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
bot.mail.send(
|
||||
new Mail(
|
||||
@@ -107,7 +107,7 @@ public class MailCommand extends Command {
|
||||
case "read" -> {
|
||||
context.checkOverloadArgs(1);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
final List<Mail> mails = bot.mail.list();
|
||||
|
||||
int senderMailSize = 0;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class SeenCommand extends Command {
|
||||
|
||||
if (online) return Component.join(JoinConfiguration.newlines(), onlineComponents);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
final JsonNode playerElement = bot.playersDatabase.getPlayerData(player);
|
||||
if (playerElement == null) throw new CommandException(Component.translatable(
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ServerEvalCommand extends Command {
|
||||
return Component.translatable("commands.servereval.reset", bot.colorPalette.defaultColor);
|
||||
}
|
||||
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
try {
|
||||
if (lua == null) lua = new Lua54();
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TranslateCommand extends Command {
|
||||
|
||||
final String message = context.getString(true, true);
|
||||
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
try {
|
||||
final URL url = new URI(
|
||||
String.format(
|
||||
|
||||
@@ -55,7 +55,7 @@ public class UrbanCommand extends Command {
|
||||
|
||||
final Gson gson = new Gson();
|
||||
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
try {
|
||||
final URL url = new URI(
|
||||
"https://api.urbandictionary.com/v0/define?term=" +
|
||||
|
||||
@@ -44,7 +44,7 @@ public class WikipediaCommand extends Command {
|
||||
|
||||
final Gson gson = new Gson();
|
||||
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
try {
|
||||
Component component = Component.empty();
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class EvalPlugin {
|
||||
socket.on(
|
||||
BRIDGE_PREFIX + function.name + ":" + bot.getServerString(true),
|
||||
functionArgs ->
|
||||
Main.EXECUTOR_SERVICE.submit(() -> {
|
||||
Main.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
final EvalFunction.Output output = function.execute(bot, functionArgs);
|
||||
if (output == null) return;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class IPFilterPlugin implements Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (final SQLException e) {
|
||||
@@ -108,7 +108,7 @@ public class IPFilterPlugin implements Listener {
|
||||
private void checkAllPlayers () {
|
||||
if (localList.isEmpty()) return;
|
||||
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
synchronized (bot.players.list) {
|
||||
for (final PlayerEntry entry : bot.players.list) check(entry);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class MailPlugin implements Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (final SQLException e) {
|
||||
@@ -45,7 +45,7 @@ public class MailPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onPlayerJoined (final PlayerEntry target) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
final String name = target.profile.getName();
|
||||
|
||||
int sendToTargetSize = 0;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PlayerFilterPlugin implements Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (final SQLException e) {
|
||||
@@ -127,7 +127,7 @@ public class PlayerFilterPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onPlayerJoined (final PlayerEntry target) {
|
||||
bot.executorService.submit(() -> {
|
||||
bot.executorService.execute(() -> {
|
||||
final FilteredPlayer player = getPlayer(target.profile.getName());
|
||||
|
||||
if (player == null) return;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PlayersDatabasePlugin implements Listener {
|
||||
|
||||
static {
|
||||
if (Main.database != null) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
Main.database.execute(CREATE_TABLE);
|
||||
} catch (final SQLException e) {
|
||||
@@ -138,7 +138,7 @@ public class PlayersDatabasePlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onPlayerJoined (final PlayerEntry target) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
final PreparedStatement insertPlayerStatement = Main.database.connection.prepareStatement(INSERT_PLAYER);
|
||||
|
||||
@@ -163,7 +163,7 @@ public class PlayersDatabasePlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onQueriedPlayerIP (final PlayerEntry target, final String ip) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
try {
|
||||
final PreparedStatement updatePlayerStatement = Main.database.connection.prepareStatement(UPDATE_PLAYER);
|
||||
|
||||
@@ -191,7 +191,7 @@ public class PlayersDatabasePlugin implements Listener {
|
||||
synchronized (bot.players.list) {
|
||||
final List<PlayerEntry> clonedList = new ArrayList<>(bot.players.list);
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
for (final PlayerEntry target : clonedList) {
|
||||
updateLastSeenEntry(target);
|
||||
}
|
||||
@@ -201,7 +201,7 @@ public class PlayersDatabasePlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onPlayerLeft (final PlayerEntry target) {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> updateLastSeenEntry(target));
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> updateLastSeenEntry(target));
|
||||
}
|
||||
|
||||
private void updateLastSeenEntry (final PlayerEntry target) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class PlayersPlugin implements Listener {
|
||||
public CompletableFuture<String> getPlayerIP (final PlayerEntry target, final boolean forceSeen) {
|
||||
final CompletableFuture<String> outputFuture = new CompletableFuture<>();
|
||||
|
||||
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> {
|
||||
DatabasePlugin.EXECUTOR_SERVICE.execute(() -> {
|
||||
if (!forceSeen) {
|
||||
final String databaseIP = bot.playersDatabase.getPlayerIP(target.profile.getName());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user