mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-06-02 06:22:18 +00:00
Adding more velocity handling stuff
This commit is contained in:
@@ -3,6 +3,7 @@ package dev.brighten.ac.check.impl.movement.fly;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutEntityVelocity;
|
||||
|
||||
public class FlyC extends Check {
|
||||
@@ -10,7 +11,7 @@ public class FlyC extends Check {
|
||||
super(player);
|
||||
}
|
||||
|
||||
WAction<WPacketPlayOutEntityVelocity> action = packet -> {
|
||||
if(packet.getEntityId() != player.getBukkitPlayer().getEntityId()) return;
|
||||
WAction<WPacketPlayInFlying> flyingAction = packet -> {
|
||||
boolean ground =
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import dev.brighten.ac.data.obj.NormalAction;
|
||||
import dev.brighten.ac.data.obj.TimedActionStore;
|
||||
import dev.brighten.ac.handler.EntityLocationHandler;
|
||||
import dev.brighten.ac.handler.PotionHandler;
|
||||
import dev.brighten.ac.handler.VelocityHandler;
|
||||
import dev.brighten.ac.handler.block.BlockUpdateHandler;
|
||||
import dev.brighten.ac.handler.keepalive.KeepAlive;
|
||||
import dev.brighten.ac.handler.protocolsupport.ProtocolAPI;
|
||||
@@ -49,6 +50,10 @@ public class APlayer {
|
||||
private MovementHandler movement;
|
||||
@Getter
|
||||
private PotionHandler potionHandler;
|
||||
|
||||
@Getter
|
||||
private VelocityHandler velocityHandler;
|
||||
|
||||
@Getter
|
||||
private EntityLocationHandler entityLocationHandler;
|
||||
|
||||
@@ -119,6 +124,7 @@ public class APlayer {
|
||||
}
|
||||
this.movement = new MovementHandler(this);
|
||||
this.potionHandler = new PotionHandler(this);
|
||||
this.velocityHandler = new VelocityHandler(this);
|
||||
this.entityLocationHandler = new EntityLocationHandler(this);
|
||||
this.blockUpdateHandler = new BlockUpdateHandler(this);
|
||||
this.info = new GeneralInformation();
|
||||
|
||||
@@ -158,6 +158,9 @@ public class PacketHandler {
|
||||
player.getInfo().setDoingVelocity(true);
|
||||
|
||||
player.runInstantAction(ka -> {
|
||||
if(!ka.isEnd()) {
|
||||
player.getVelocityHandler().onPre(packet);
|
||||
} else player.getVelocityHandler().onPost(packet);
|
||||
if(ka.isEnd() && player.getInfo().getVelocityHistory().contains(velocity)) {
|
||||
player.getOnVelocityTasks().forEach(task -> task.accept(velocity));
|
||||
player.getInfo().setDoingVelocity(false);
|
||||
@@ -305,6 +308,7 @@ public class PacketHandler {
|
||||
|
||||
// Post flying settings
|
||||
if(type.equals(PacketType.FLYING)) {
|
||||
player.getVelocityHandler().onFlyingPost((WPacketPlayInFlying)packetObject);
|
||||
player.getInfo().lsneaking = player.getInfo().sneaking;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,65 @@
|
||||
package dev.brighten.ac.handler;
|
||||
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutEntityVelocity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class VelocityHandler {
|
||||
|
||||
private APlayer player;
|
||||
private final APlayer player;
|
||||
|
||||
private Map<Vector, Boolean> velocities = new HashMap<>();
|
||||
private Set<Consumer<Vector>> accurateVelocityTasks = new HashSet<>();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* I want to be able to verify velocity when the pre packet comes back an the post packet comes back
|
||||
* So essentially I want to only take out the velocity from possibilities after the post flying comes back.
|
||||
*/
|
||||
|
||||
public void onPre(WPacketPlayOutEntityVelocity packet) {
|
||||
if(packet.getEntityId() != player.getBukkitPlayer().getEntityId()) return;
|
||||
|
||||
velocities.put(new Vector(packet.getDeltaX(), packet.getDeltaY(), packet.getDeltaZ()), false);
|
||||
}
|
||||
|
||||
public void onPost(WPacketPlayOutEntityVelocity packet) {
|
||||
if(packet.getEntityId() != player.getBukkitPlayer().getEntityId()) return;
|
||||
|
||||
velocities.computeIfPresent(new Vector(packet.getDeltaX(), packet.getDeltaY(), packet.getDeltaZ()),
|
||||
(velocity, queuedToRemove) -> true);
|
||||
}
|
||||
|
||||
public Set<Vector> getPossibleVectors() {
|
||||
return velocities.keySet();
|
||||
}
|
||||
|
||||
public void onAccurateVelocity(Consumer<Vector> task) {
|
||||
accurateVelocityTasks.add(task);
|
||||
}
|
||||
|
||||
public void onFlyingPost(WPacketPlayInFlying packet) {
|
||||
val iterator = velocities.entrySet().iterator();
|
||||
while(iterator.hasNext()) {
|
||||
val value = iterator.next();
|
||||
|
||||
// Velocity definitely occurred, run task.
|
||||
if(Math.abs(value.getKey().getY() - packet.getY()) < 1E-6) {
|
||||
accurateVelocityTasks.forEach(vel -> vel.accept(value.getKey()));
|
||||
}
|
||||
|
||||
if(value.getValue())
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user