From 48f5e78bd7cb3390b38143d2225cbd11953eef97 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 3 May 2023 11:41:00 +0700 Subject: [PATCH] Listener !!!!!!!!!! --- .../plugins/ChatCommandHandlerPlugin.java | 2 +- .../chomens_bot/plugins/ChatPlugin.java | 14 ++++++------- .../plugins/ClearChatUsernamePlugin.java | 2 +- .../plugins/CommandSuggestionPlugin.java | 2 +- .../chomens_bot/plugins/CorePlugin.java | 2 +- .../chomens_bot/plugins/DiscordPlugin.java | 2 +- .../chomens_bot/plugins/FilterPlugin.java | 2 +- .../chomens_bot/plugins/LoggerPlugin.java | 2 +- .../chomens_bot/plugins/PlayersPlugin.java | 20 +++++++++---------- .../chomens_bot/plugins/PositionPlugin.java | 8 ++++---- .../chomens_bot/plugins/SelfCarePlugin.java | 4 ++-- .../chomens_bot/plugins/TrustedPlugin.java | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java index 4e3ec21..77c3cdf 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatCommandHandlerPlugin.java @@ -10,7 +10,7 @@ import net.kyori.adventure.text.Component; import java.util.List; -public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener { +public class ChatCommandHandlerPlugin extends ChatPlugin.Listener { public final Bot bot; @Getter private final List prefixes; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java index e5b7b5b..ecdd359 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java @@ -35,7 +35,7 @@ public class ChatPlugin extends Bot.Listener { @Getter private final List queue = new ArrayList<>(); - private final List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); public ChatPlugin (Bot bot) { this.bot = bot; @@ -81,7 +81,7 @@ public class ChatPlugin extends Bot.Listener { PlayerMessage commandSpyMessage; commandSpyMessage = commandSpyParser.parse(component); - for (ChatListener listener : listeners) { + for (Listener listener : listeners) { listener.systemMessageReceived(component); if (playerMessage != null) listener.playerMessageReceived(playerMessage); if (commandSpyMessage != null) listener.commandSpyMessageReceived(commandSpyMessage); @@ -101,7 +101,7 @@ public class ChatPlugin extends Bot.Listener { Component.text(packet.getContent()) ); - for (ChatListener listener : listeners) { + for (Listener listener : listeners) { listener.playerMessageReceived(playerMessage); if (packet.getChatType() == 4) { // type 4 is /say @@ -145,7 +145,7 @@ public class ChatPlugin extends Bot.Listener { final PlayerMessage playerMessage = new PlayerMessage(parsed.sender(), packet.getName(), parsed.contents()); - for (ChatListener listener : listeners) { + for (Listener listener : listeners) { listener.playerMessageReceived(playerMessage); listener.systemMessageReceived(component); } @@ -164,7 +164,7 @@ public class ChatPlugin extends Bot.Listener { final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender(), packet.getName(), parsedFromMessage.contents()); - for (ChatListener listener : listeners) { + for (Listener listener : listeners) { listener.playerMessageReceived(playerMessage); listener.systemMessageReceived(component); } @@ -228,9 +228,9 @@ public class ChatPlugin extends Bot.Listener { public void tellraw (Component component) { tellraw(component, "@a"); } - public void addListener (ChatListener listener) { listeners.add(listener); } + public void addListener (Listener listener) { listeners.add(listener); } - public static class ChatListener { + public static class Listener { public void playerMessageReceived (PlayerMessage message) {} public void commandSpyMessageReceived (PlayerMessage message) {} public void systemMessageReceived (Component component) {} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java index dc55146..c666448 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ClearChatUsernamePlugin.java @@ -7,7 +7,7 @@ import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; // idea totallynotskidded™ from chipmunkbot (the js one) -public class ClearChatUsernamePlugin extends ChatPlugin.ChatListener { +public class ClearChatUsernamePlugin extends ChatPlugin.Listener { private final Bot bot; public ClearChatUsernamePlugin(Bot bot) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java index 2b6b98d..5ee8a10 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandSuggestionPlugin.java @@ -11,7 +11,7 @@ import net.kyori.adventure.text.TextComponent; import java.util.ArrayList; import java.util.List; -public class CommandSuggestionPlugin extends ChatPlugin.ChatListener { +public class CommandSuggestionPlugin extends ChatPlugin.Listener { private final Bot bot; @Getter @Setter private String id = "chomens_bot_command_suggestion"; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java index 35b8ef3..d8352be 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java @@ -32,7 +32,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -public class CorePlugin extends PositionPlugin.PositionListener { +public class CorePlugin extends PositionPlugin.Listener { private final Bot bot; @Getter private final List listeners = new ArrayList<>(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java index 5aa4ee3..d8e59c9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java @@ -77,7 +77,7 @@ public class DiscordPlugin { } }); - bot.chat().addListener(new ChatPlugin.ChatListener() { + bot.chat().addListener(new ChatPlugin.Listener() { @Override public void systemMessageReceived (Component component) { final String content = ComponentUtilities.stringifyAnsi(component); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FilterPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FilterPlugin.java index 4dd1821..c58244e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FilterPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FilterPlugin.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -public class FilterPlugin extends PlayersPlugin.PlayerListener { +public class FilterPlugin extends PlayersPlugin.Listener { private final Bot bot; @Getter private final List filteredPlayers = new ArrayList<>(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java index 83a2e74..ab4a0b0 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java @@ -11,7 +11,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -public class LoggerPlugin extends ChatPlugin.ChatListener { +public class LoggerPlugin extends ChatPlugin.Listener { private final Bot bot; private boolean addedListener = false; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java index 2ea4330..f301c96 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java @@ -22,7 +22,7 @@ public class PlayersPlugin extends Bot.Listener { private final Bot bot; @Getter private final List list = new ArrayList<>(); - private final List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); public PlayersPlugin (Bot bot) { this.bot = bot; @@ -116,7 +116,7 @@ public class PlayersPlugin extends Bot.Listener { list.add(target); // loginNames.put(target, target.profile().getIdAsString()); - if (duplicate == null) for (PlayerListener listener : listeners) { listener.playerJoined(target); } + if (duplicate == null) for (Listener listener : listeners) { listener.playerJoined(target); } /* else { for (Map.Entry entry : loginNames.entrySet()) { if ( @@ -131,7 +131,7 @@ public class PlayersPlugin extends Bot.Listener { return; } */ - else for (PlayerListener listener : listeners) { listener.playerUnVanished(target); } + else for (Listener listener : listeners) { listener.playerUnVanished(target); } // } } @@ -143,7 +143,7 @@ public class PlayersPlugin extends Bot.Listener { target.gamemode(gameMode); - for (PlayerListener listener : listeners) { listener.playerGameModeUpdated(target, gameMode); } + for (Listener listener : listeners) { listener.playerGameModeUpdated(target, gameMode); } } private void updateLatency (PlayerListEntry newEntry) { @@ -154,7 +154,7 @@ public class PlayersPlugin extends Bot.Listener { target.latency(ping); - for (PlayerListener listener : listeners) { listener.playerLatencyUpdated(target, ping); } + for (Listener listener : listeners) { listener.playerLatencyUpdated(target, ping); } } private void updateDisplayName (PlayerListEntry newEntry) { @@ -165,7 +165,7 @@ public class PlayersPlugin extends Bot.Listener { target.displayName(displayName); - for (PlayerListener listener : listeners) { listener.playerDisplayNameUpdated(target, displayName); } + for (Listener listener : listeners) { listener.playerDisplayNameUpdated(target, displayName); } } private void removePlayer (UUID uuid) { @@ -180,13 +180,13 @@ public class PlayersPlugin extends Bot.Listener { for (int i = 0; i < matches.length; i++) { if (tooltips[i] != null || !matches[i].equals(username)) continue; target.listed(false); - for (PlayerListener listener : listeners) { listener.playerVanished(target); } + for (Listener listener : listeners) { listener.playerVanished(target); } return packet; } list.remove(target); - for (PlayerListener listener : listeners) { listener.playerLeft(target); } + for (Listener listener : listeners) { listener.playerLeft(target); } return packet; }); @@ -197,9 +197,9 @@ public class PlayersPlugin extends Bot.Listener { list.clear(); } - public void addListener (PlayerListener listener) { listeners.add(listener); } + public void addListener (Listener listener) { listeners.add(listener); } - public static class PlayerListener { + public static class Listener { public void playerJoined (MutablePlayerListEntry target) {} public void playerUnVanished (MutablePlayerListEntry target) {} public void playerGameModeUpdated (MutablePlayerListEntry target, GameMode gameMode) {} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java index 4031858..a38d7da 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PositionPlugin.java @@ -25,7 +25,7 @@ import java.util.Map; public class PositionPlugin extends Bot.Listener { private final Bot bot; - private final List listeners = new ArrayList<>(); + private final List listeners = new ArrayList<>(); @Getter private Vector3i position = Vector3i.from(0, 0, 0); @@ -52,7 +52,7 @@ public class PositionPlugin extends Bot.Listener { bot.session().send(new ServerboundAcceptTeleportationPacket(packet.getTeleportId())); position = Vector3i.from(packet.getX(), packet.getY(), packet.getZ()); - for (PositionListener listener : listeners) { listener.positionChange(position); } + for (Listener listener : listeners) { listener.positionChange(position); } } public void packetReceived (ClientboundAddPlayerPacket packet) { @@ -155,9 +155,9 @@ public class PositionPlugin extends Bot.Listener { return null; } - public void addListener (PositionListener listener) { listeners.add(listener); } + public void addListener (Listener listener) { listeners.add(listener); } - public static class PositionListener { + public static class Listener { public void positionChange (Vector3i position) {} } } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java index 6300d93..b47a04e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/SelfCarePlugin.java @@ -50,7 +50,7 @@ public class SelfCarePlugin extends Bot.Listener { bot.addListener(this); - bot.chat().addListener(new ChatPlugin.ChatListener() { + bot.chat().addListener(new ChatPlugin.Listener() { @Override public void systemMessageReceived(Component component) { final String message = ComponentUtilities.stringify(component); @@ -81,7 +81,7 @@ public class SelfCarePlugin extends Bot.Listener { } }); - bot.position().addListener(new PositionPlugin.PositionListener() { + bot.position().addListener(new PositionPlugin.Listener() { @Override public void positionChange(Vector3i position) { SelfCarePlugin.this.positionChange(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java index f09b8dd..9696bad 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java @@ -9,7 +9,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.util.List; import java.util.UUID; -public class TrustedPlugin extends PlayersPlugin.PlayerListener { +public class TrustedPlugin extends PlayersPlugin.Listener { private final Bot bot; @Getter private final List list;