fix: all null pointers in disconnect listeners (there was so much)
i didn't even know how the bot even functioned for the whole 5 months without me noticing
This commit is contained in:
@@ -387,7 +387,11 @@ public class Bot extends SessionAdapter {
|
||||
}
|
||||
|
||||
for (final SessionListener listener : listeners) {
|
||||
listener.disconnected(disconnectedEvent);
|
||||
try {
|
||||
listener.disconnected(disconnectedEvent);
|
||||
} catch (final Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,6 @@ public class Configuration {
|
||||
}
|
||||
|
||||
public static class Core {
|
||||
public int refillInterval = (60 * 5) * 1000; // 5 minutes
|
||||
public String customName = "{\"text\":\"@\"}";
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.Serv
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -45,8 +44,6 @@ public class CorePlugin
|
||||
|
||||
public volatile boolean ready = false;
|
||||
|
||||
private ScheduledFuture<?> refillTask;
|
||||
|
||||
public final Vector3i fromSize;
|
||||
public Vector3i toSize;
|
||||
|
||||
@@ -76,8 +73,6 @@ public class CorePlugin
|
||||
15
|
||||
);
|
||||
|
||||
bot.position.addListener(this);
|
||||
|
||||
if (hasRateLimit() && hasReset()) {
|
||||
bot.executor.scheduleAtFixedRate(
|
||||
() -> commandsPerSecond.set(0),
|
||||
@@ -90,6 +85,7 @@ public class CorePlugin
|
||||
bot.addListener(this);
|
||||
bot.world.addListener(this);
|
||||
bot.tick.addListener(this);
|
||||
bot.position.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -426,7 +422,9 @@ public class CorePlugin
|
||||
if (!ready) {
|
||||
ready = true;
|
||||
|
||||
refillTask = bot.executor.scheduleAtFixedRate(this::refill, 0, bot.config.core.refillInterval, TimeUnit.MILLISECONDS);
|
||||
reset();
|
||||
refill();
|
||||
|
||||
for (final Listener listener : listeners) listener.coreReady();
|
||||
}
|
||||
}
|
||||
@@ -440,10 +438,6 @@ public class CorePlugin
|
||||
@Override
|
||||
public void disconnected (final DisconnectedEvent event) {
|
||||
ready = false;
|
||||
|
||||
refillTask.cancel(false);
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
public void recalculateRelativePositions () {
|
||||
|
||||
@@ -4,7 +4,6 @@ import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.Configuration;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.ClientCommand;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
|
||||
@@ -22,14 +21,11 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.S
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private ScheduledFuture<?> checkTask;
|
||||
|
||||
public boolean visible = false;
|
||||
|
||||
private int entityId;
|
||||
@@ -154,13 +150,11 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener
|
||||
muted = false;
|
||||
prefix = false;
|
||||
|
||||
final Runnable task = () -> {
|
||||
bot.executor.scheduleAtFixedRate(() -> {
|
||||
if (!bot.loggedIn) return;
|
||||
|
||||
check();
|
||||
};
|
||||
|
||||
checkTask = bot.executor.scheduleAtFixedRate(task, 0, bot.config.selfCare.delay, TimeUnit.MILLISECONDS);
|
||||
}, 0, bot.config.selfCare.delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private void packetReceived (final ClientboundGameEventPacket packet) {
|
||||
@@ -220,9 +214,4 @@ public class SelfCarePlugin extends Bot.Listener implements ChatPlugin.Listener
|
||||
if (bot.options.useChat) bot.chat.sendCommandInstantly(command);
|
||||
else bot.core.run(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (final DisconnectedEvent event) {
|
||||
checkTask.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user