Compare commits
2 commits
b3615770dc
...
0ddf042311
Author | SHA1 | Date | |
---|---|---|---|
0ddf042311 | |||
4764a8947e |
2 changed files with 66 additions and 6 deletions
|
@ -374,6 +374,8 @@ public class CorePlugin extends PositionPlugin.Listener {
|
|||
|
||||
@Override
|
||||
public void positionChange (Vector3i position) {
|
||||
if (bot.position.isGoingDownFromHeightLimit) return;
|
||||
|
||||
from = Vector3i.from(
|
||||
(int) (fromSize.getX() + Math.floor((double) bot.position.position.getX() / 16) * 16),
|
||||
MathUtilities.clamp(fromSize.getY(), bot.world.minY, bot.world.maxY),
|
||||
|
|
|
@ -30,6 +30,8 @@ public class PositionPlugin extends Bot.Listener {
|
|||
|
||||
public Vector3i position = Vector3i.from(0, 0, 0);
|
||||
|
||||
public boolean isGoingDownFromHeightLimit = false; // cool variable name
|
||||
|
||||
private final Map<Integer, PlayerEntry> entityIdMap = new HashMap<>();
|
||||
private final Map<Integer, Vector3f> positionMap = new HashMap<>();
|
||||
private final Map<Integer, Rotation> rotationMap = new HashMap<>();
|
||||
|
@ -40,12 +42,23 @@ public class PositionPlugin extends Bot.Listener {
|
|||
bot.addListener(this);
|
||||
|
||||
// notchian clients also does this, sends the position packet every second
|
||||
bot.executor.scheduleAtFixedRate(() -> bot.session.send(new ServerboundMovePlayerPosPacket(
|
||||
false,
|
||||
position.getX(),
|
||||
position.getY(),
|
||||
position.getZ()
|
||||
)), 0, 1, TimeUnit.SECONDS);
|
||||
bot.executor.scheduleAtFixedRate(() -> {
|
||||
if (isGoingDownFromHeightLimit) return;
|
||||
|
||||
bot.session.send(new ServerboundMovePlayerPosPacket(
|
||||
false,
|
||||
position.getX(),
|
||||
position.getY(),
|
||||
position.getZ()
|
||||
));
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
|
||||
bot.tick.addListener(new TickPlugin.Listener() {
|
||||
@Override
|
||||
public void onTick() {
|
||||
handleHeightLimit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,6 +158,51 @@ public class PositionPlugin extends Bot.Listener {
|
|||
for (Listener listener : listeners) listener.playerMoved(player, position, rotation);
|
||||
}
|
||||
|
||||
// for now this is used in CorePlugin when placing the command block
|
||||
private void handleHeightLimit () {
|
||||
final int y = position.getY();
|
||||
final int maxY = bot.world.maxY;
|
||||
|
||||
if (y < maxY) {
|
||||
if (isGoingDownFromHeightLimit) {
|
||||
isGoingDownFromHeightLimit = false;
|
||||
|
||||
for (Listener listener : listeners) { listener.positionChange(position); }
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
isGoingDownFromHeightLimit = true;
|
||||
|
||||
final Vector3i newPosition = Vector3i.from(
|
||||
position.getX(),
|
||||
position.getY() - 2,
|
||||
position.getZ()
|
||||
);
|
||||
|
||||
position = newPosition;
|
||||
|
||||
if (position.getY() > maxY + 500) {
|
||||
String command = "/";
|
||||
|
||||
if (bot.serverPluginsManager.hasPlugin(ServerPluginsManagerPlugin.ESSENTIALS)) command += "essentials:";
|
||||
|
||||
command += String.format("tp %s %s %s", position.getX(), maxY - 1, position.getZ());
|
||||
|
||||
bot.chat.send(command);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bot.session.send(new ServerboundMovePlayerPosPacket(
|
||||
false,
|
||||
newPosition.getX(),
|
||||
newPosition.getY(),
|
||||
newPosition.getZ()
|
||||
));
|
||||
}
|
||||
|
||||
public Vector3f getPlayerPosition (String playerName) {
|
||||
int entityId = -1;
|
||||
for (Map.Entry<Integer, PlayerEntry> entry : entityIdMap.entrySet()) {
|
||||
|
|
Loading…
Reference in a new issue