self care fix ig
This commit is contained in:
parent
f5db2e02a3
commit
489d65bf76
2 changed files with 56 additions and 1 deletions
|
@ -0,0 +1,55 @@
|
|||
package land.chipmunk.chipmunkbot.plugins;
|
||||
|
||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||
import land.chipmunk.chipmunkbot.Options;
|
||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||
import lombok.Getter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class TickLoop extends SessionAdapter {
|
||||
private Client client;
|
||||
private Timer timer;
|
||||
@Getter private List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
public TickLoop (ChipmunkBot client, Options options) {
|
||||
this.client = client;
|
||||
client.session().addListener((SessionListener) this);
|
||||
|
||||
final TimerTask task = new TimerTask() {
|
||||
public void run () {
|
||||
if (((MinecraftProtocol) client.session().getPacketProtocol()).getState() != ProtocolState.GAME) return;
|
||||
|
||||
int cancel = false;
|
||||
for (Listener listener : listeners) {
|
||||
if (!listener.onTick()) cancel = true;
|
||||
}
|
||||
|
||||
if (!c)
|
||||
}
|
||||
};
|
||||
|
||||
timer = new Timer();
|
||||
timer.schedule(task, options.chat.queue.interval, options.chat.queue.interval);
|
||||
}
|
||||
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
if (client.reconnectDelay() < 0 && timer != null) {
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Listener {
|
||||
public void onTick () {}
|
||||
}
|
||||
|
||||
public void addListener (Listener listener) { listeners.add(listener); }
|
||||
public void removeListener (Listener listener) { listeners.remove(listener); }
|
||||
}
|
|
@ -48,7 +48,7 @@ public class SelfCarePlugin extends SessionAdapter {
|
|||
};
|
||||
|
||||
timer = new Timer();
|
||||
timer.schedule(task, 70, 70);
|
||||
timer.schedule(task, 75, 75);
|
||||
}
|
||||
|
||||
public void tick () {
|
||||
|
|
Loading…
Reference in a new issue