refactor: make listeners an interface
(except the one in Bot, which extends MCProtocolLib's SessionAdaptor, not sure how exactly make them complement)
This commit is contained in:
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// 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 Bot.Listener {
|
||||
public class PositionPlugin extends Bot.Listener implements TickPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
@@ -37,8 +37,6 @@ public class PositionPlugin extends Bot.Listener {
|
||||
public PositionPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.addListener(this);
|
||||
|
||||
// notchian clients also does this, sends the position packet every second
|
||||
bot.executor.scheduleAtFixedRate(() -> {
|
||||
if (!bot.loggedIn || isGoingDownFromHeightLimit) return;
|
||||
@@ -52,12 +50,13 @@ public class PositionPlugin extends Bot.Listener {
|
||||
));
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
|
||||
bot.tick.addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void onTick() {
|
||||
handleHeightLimit();
|
||||
}
|
||||
});
|
||||
bot.addListener(this);
|
||||
bot.tick.addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
handleHeightLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,8 +266,8 @@ public class PositionPlugin extends Bot.Listener {
|
||||
public void addListener (Listener listener) { listeners.add(listener); }
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class Listener {
|
||||
public void positionChange (Vector3d position) {}
|
||||
public void playerMoved (PlayerEntry player, Vector3d position, Rotation rotation) {}
|
||||
public interface Listener {
|
||||
default void positionChange (Vector3d position) {}
|
||||
default void playerMoved (PlayerEntry player, Vector3d position, Rotation rotation) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user