Listener !!!!!!!!!!

This commit is contained in:
Chayapak 2023-05-03 11:41:00 +07:00
parent 0baa640191
commit 48f5e78bd7
12 changed files with 31 additions and 31 deletions

View file

@ -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<String> prefixes;

View file

@ -35,7 +35,7 @@ public class ChatPlugin extends Bot.Listener {
@Getter private final List<String> queue = new ArrayList<>();
private final List<ChatListener> listeners = new ArrayList<>();
private final List<Listener> 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) {}

View file

@ -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) {

View file

@ -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";

View file

@ -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<Listener> listeners = new ArrayList<>();

View file

@ -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);

View file

@ -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<FilteredPlayer> filteredPlayers = new ArrayList<>();

View file

@ -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;

View file

@ -22,7 +22,7 @@ public class PlayersPlugin extends Bot.Listener {
private final Bot bot;
@Getter private final List<MutablePlayerListEntry> list = new ArrayList<>();
private final List<PlayerListener> listeners = new ArrayList<>();
private final List<Listener> 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<MutablePlayerListEntry, String> 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) {}

View file

@ -25,7 +25,7 @@ import java.util.Map;
public class PositionPlugin extends Bot.Listener {
private final Bot bot;
private final List<PositionListener> listeners = new ArrayList<>();
private final List<Listener> 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) {}
}
}

View file

@ -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();

View file

@ -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<String> list;