add stuff and fix stuff yet again
MORE STUFF YUP
This commit is contained in:
@@ -7,11 +7,15 @@ import com.github.steveice10.packetlib.event.session.*;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.chayapak1.chomensbot_mabe.plugins.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Bot {
|
||||
private final ArrayList<SessionListener>listeners = new ArrayList<>();
|
||||
@@ -19,25 +23,35 @@ public class Bot {
|
||||
@Getter private final String host;
|
||||
@Getter private final int port;
|
||||
@Getter private final String username;
|
||||
@Getter private final List<Bot> allBots;
|
||||
|
||||
@Getter private final Session session;
|
||||
@Getter private Session session;
|
||||
|
||||
@Getter private final int reconnectDelay;
|
||||
|
||||
@Getter private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
@Getter private final ChatPlugin chat = new ChatPlugin(this);
|
||||
@Getter private final LoggerPlugin logger = new LoggerPlugin(this);
|
||||
@Getter @Setter private LoggerPlugin logger; // in ConsolePlugin
|
||||
@Getter private final SelfCarePlugin selfCare = new SelfCarePlugin(this);
|
||||
@Getter private final ConsolePlugin console = new ConsolePlugin(this);
|
||||
@Getter @Setter private ConsolePlugin console;
|
||||
@Getter private final PositionPlugin position = new PositionPlugin(this);
|
||||
@Getter private final CorePlugin core = new CorePlugin(this);
|
||||
@Getter private final CommandHandlerPlugin commandHandler = new CommandHandlerPlugin();
|
||||
@Getter private final ChatCommandHandlerPlugin chatCommandHandler = new ChatCommandHandlerPlugin(this);
|
||||
@Getter private final HashingPlugin hashing = new HashingPlugin(this);
|
||||
|
||||
public Bot (String host, int port, String username) {
|
||||
public Bot (String host, int port, int reconnectDelay, String username, List<Bot> allBots) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.reconnectDelay = reconnectDelay;
|
||||
this.username = username;
|
||||
this.allBots = allBots;
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
public void reconnect () {
|
||||
Session session = new TcpClientSession(host, port, new MinecraftProtocol(username), null);
|
||||
this.session = session;
|
||||
|
||||
@@ -46,12 +60,12 @@ public class Bot {
|
||||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
for (SessionListener listener : listeners) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
listener.connected(new ConnectedEvent(session));
|
||||
}
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
for (SessionListener listener : listeners) {
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
listener.connected(new ConnectedEvent(session));
|
||||
}
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,6 +101,12 @@ public class Bot {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.disconnected(disconnectedEvent);
|
||||
}
|
||||
|
||||
if (reconnectDelay < 0) return; // to disable reconnecting
|
||||
|
||||
Runnable task = () -> reconnect();
|
||||
|
||||
executor.schedule(task, reconnectDelay(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user