add connecting message
This commit is contained in:
@@ -19,7 +19,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Bot {
|
||||
private final ArrayList<SessionListener> listeners = new ArrayList<>();
|
||||
private final ArrayList<Listener> listeners = new ArrayList<>();
|
||||
|
||||
@Getter private final String host;
|
||||
@Getter private final int port;
|
||||
@@ -108,7 +108,11 @@ public class Bot {
|
||||
reconnect();
|
||||
}
|
||||
|
||||
public void reconnect () {
|
||||
private void reconnect () {
|
||||
for (Listener listener : listeners) {
|
||||
listener.connecting();
|
||||
}
|
||||
|
||||
final String _username = options.username();
|
||||
|
||||
if (_username == null) username = RandomStringUtils.randomAlphabetic(8);
|
||||
@@ -189,7 +193,11 @@ public class Bot {
|
||||
session.connect();
|
||||
}
|
||||
|
||||
public void addListener (SessionListener listener) {
|
||||
public void addListener (Listener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public static class Listener extends SessionAdapter {
|
||||
public void connecting () {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.BossBar;
|
||||
import lombok.Getter;
|
||||
@@ -13,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BossbarManagerPlugin extends SessionAdapter {
|
||||
public class BossbarManagerPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> tickTask;
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSy
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.ChomeNSCustomChatParser;
|
||||
@@ -27,7 +26,7 @@ import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ChatPlugin extends SessionAdapter {
|
||||
public class ChatPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private final List<ChatParser> chatParsers;
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
@@ -58,7 +57,7 @@ public class CorePlugin extends PositionPlugin.PositionListener {
|
||||
|
||||
bot.position().addListener(this);
|
||||
|
||||
bot.addListener(new SessionAdapter() {
|
||||
bot.addListener(new Bot.Listener() {
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
ready = false;
|
||||
|
||||
@@ -2,7 +2,6 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.Configuration;
|
||||
import land.chipmunk.chayapak.chomens_bot.Main;
|
||||
@@ -44,12 +43,31 @@ public class DiscordPlugin {
|
||||
for (Bot bot : Main.allBots) {
|
||||
String channelId = servers.get(bot.host() + ":" + bot.port());
|
||||
|
||||
bot.addListener(new SessionAdapter() {
|
||||
bot.addListener(new Bot.Listener() {
|
||||
@Override
|
||||
public void connecting() {
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Connecting to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected (ConnectedEvent event) {
|
||||
boolean channelAlreadyAddedListeners = alreadyAddedListeners.getOrDefault(channelId, false);
|
||||
|
||||
sendMessageInstantly("Successfully connected to: " + "`" + bot.host() + ":" + bot.port() + "`", channelId);
|
||||
sendMessageInstantly(
|
||||
String.format(
|
||||
"Successfully connected to: `%s:%s`",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
),
|
||||
channelId
|
||||
);
|
||||
|
||||
if (channelAlreadyAddedListeners) return;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.Logger;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
@@ -22,10 +21,27 @@ public class LoggerPlugin extends ChatPlugin.ChatListener {
|
||||
public LoggerPlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.addListener(new SessionAdapter() {
|
||||
bot.addListener(new Bot.Listener() {
|
||||
@Override
|
||||
public void connecting() {
|
||||
info(
|
||||
String.format(
|
||||
"Connecting to: %s:%s",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected (ConnectedEvent event) {
|
||||
info("Successfully connected to: " + bot.host() + ":" + bot.port());
|
||||
info(
|
||||
String.format(
|
||||
"Successfully connected to: %s:%s",
|
||||
bot.host(),
|
||||
bot.port()
|
||||
)
|
||||
);
|
||||
|
||||
if (addedListener) return;
|
||||
bot.chat().addListener(LoggerPlugin.this);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.BossBar;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.BossBarColor;
|
||||
@@ -21,7 +20,7 @@ import java.util.LinkedList;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MusicPlayerPlugin extends SessionAdapter {
|
||||
public class MusicPlayerPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> playTask;
|
||||
|
||||
@@ -7,16 +7,18 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPl
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoUpdatePacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import lombok.Getter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayersPlugin extends SessionAdapter {
|
||||
public class PlayersPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
@Getter private final List<MutablePlayerListEntry> list = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
@@ -23,7 +22,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
// some part of the code used to be in a test plugin but i thought it would be useful in the future so i moved it here
|
||||
public class PositionPlugin extends SessionAdapter {
|
||||
public class PositionPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private final List<PositionListener> listeners = new ArrayList<>();
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.Clientb
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
@@ -27,7 +26,7 @@ import net.kyori.adventure.text.Component;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfCarePlugin extends SessionAdapter {
|
||||
public class SelfCarePlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> checkTask;
|
||||
|
||||
@@ -3,7 +3,6 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundSetTimePacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.BossBar;
|
||||
@@ -16,7 +15,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TPSPlugin extends SessionAdapter {
|
||||
public class TPSPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private boolean enabled = false;
|
||||
|
||||
@@ -3,7 +3,6 @@ package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCommandSuggestionsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCommandSuggestionPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
|
||||
@@ -11,7 +10,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TabCompletePlugin extends SessionAdapter {
|
||||
public class TabCompletePlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
private int nextTransactionId = 0;
|
||||
private final Map<Integer, CompletableFuture<ClientboundCommandSuggestionsPacket>> transactions = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user