add connecting message

This commit is contained in:
Chayapak 2023-04-25 13:11:39 +07:00
parent 189aee90f9
commit a9b40c0ceb
13 changed files with 78 additions and 40 deletions

View file

@ -4,10 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="gex">
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="make trusted broadcast log in console">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/DiscordPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/LoggerPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/TrustedPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/MusicPlayerPlugin.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -99,13 +101,6 @@
<option name="presentableId" value="Default" />
<updated>1680245437032</updated>
</task>
<task id="LOCAL-00071" summary="forgor that i used displayname">
<created>1681638788599</created>
<option name="number" value="00071" />
<option name="presentableId" value="LOCAL-00071" />
<option name="project" value="LOCAL" />
<updated>1681638788599</updated>
</task>
<task id="LOCAL-00072" summary="i forgor to remove the code i copied from my chipmunkbot fork">
<created>1681692239505</created>
<option name="number" value="00072" />
@ -442,7 +437,14 @@
<option name="project" value="LOCAL" />
<updated>1682401544374</updated>
</task>
<option name="localTasksCounter" value="120" />
<task id="LOCAL-00120" summary="make trusted broadcast log in console">
<created>1682401966540</created>
<option name="number" value="00120" />
<option name="presentableId" value="LOCAL-00120" />
<option name="project" value="LOCAL" />
<updated>1682401966540</updated>
</task>
<option name="localTasksCounter" value="121" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -457,7 +459,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="change a bit mabe" />
<MESSAGE value="improve reconnect i guess" />
<MESSAGE value="make better console logging like the old js chomens bot" />
<MESSAGE value="fart !!!!" />
@ -482,7 +483,8 @@
<MESSAGE value="fix chomens bot crsah exploit 2023 working" />
<MESSAGE value="i forgor 1 thing lmfao" />
<MESSAGE value="gex" />
<option name="LAST_COMMIT_MESSAGE" value="gex" />
<MESSAGE value="make trusted broadcast log in console" />
<option name="LAST_COMMIT_MESSAGE" value="make trusted broadcast log in console" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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