Skip to content

Commit

Permalink
[BLEEDING] Common super class for PlayerMoveData and VehicleMoveData.
Browse files Browse the repository at this point in the history
* Now MoveData is the common super class of the above.
* MoveTrace has a generic type parameter for the MoveData sub class.
  • Loading branch information
asofold committed May 11, 2016
1 parent 970915c commit 929578a
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 191 deletions.
Expand Up @@ -31,7 +31,7 @@
import fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace;
import fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.TraceEntry;
import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveInfo;
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
import fr.neatmonster.nocheatplus.compat.BridgeEnchant;
Expand Down Expand Up @@ -321,7 +321,7 @@ else if (normalizedMove > 2.0 && Improbable.check(player, 1f, now, "fight.speed"
if (!cancelled && TrigUtil.distance(loc.getX(), loc.getZ(), damagedLoc.getX(), damagedLoc.getZ()) < 4.5){
final MovingData mData = MovingData.getData(player);
// Check if fly checks is an issue at all, re-check "real sprinting".
final MoveData lastMove = mData.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = mData.playerMoves.getFirstPastMove();
if (lastMove.valid && mData.liftOffEnvelope == LiftOffEnvelope.NORMAL) {
final double hDist = TrigUtil.distance(loc.getX(), loc.getZ(), lastMove.from.x, lastMove.from.z);
if (hDist >= 0.23) {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -18,7 +19,8 @@
import fr.neatmonster.nocheatplus.checks.moving.magic.Magic;
import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveConsistency;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.VehicleMoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveTrace;
import fr.neatmonster.nocheatplus.checks.moving.velocity.AccountEntry;
import fr.neatmonster.nocheatplus.checks.moving.velocity.FrictionAxisVelocity;
Expand Down Expand Up @@ -170,11 +172,21 @@ public static void onReload() {
private int morePacketsSetBackResetTime = 0;

/** Keep track of currently processed (if) and past moves for player moving. */
public final MoveTrace playerMoves = new MoveTrace();
public final MoveTrace <PlayerMoveData> playerMoves = new MoveTrace<PlayerMoveData>(new Callable<PlayerMoveData>() {
@Override
public PlayerMoveData call() throws Exception {
return new PlayerMoveData();
}
}, 2);

/** Keep track of currently processed (if) and past moves for vehicle moving. */
// TODO: There may be need to store such data with vehicles, or detect tandem abuse in a different way.
public final MoveTrace vehicleMoves = new MoveTrace();
public final MoveTrace <VehicleMoveData> vehicleMoves = new MoveTrace<VehicleMoveData>(new Callable<VehicleMoveData>() {
@Override
public VehicleMoveData call() throws Exception {
return new VehicleMoveData();
}
}, 2);

// Velocity handling.
/** Vertical velocity modeled as an axis (positive and negative possible) */
Expand Down Expand Up @@ -477,7 +489,7 @@ public void onWorldUnload(final String worldName) {
public void resetPositions(PlayerLocation loc) {
resetPositions();
if (loc != null) {
final MoveData lastMove = playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = playerMoves.getFirstPastMove();
// Always set with extra properties.
lastMove.setWithExtraProperties(loc);
}
Expand Down
Expand Up @@ -49,7 +49,7 @@
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.checks.moving.location.LocUtil;
import fr.neatmonster.nocheatplus.checks.moving.magic.Magic;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
import fr.neatmonster.nocheatplus.checks.moving.model.MoveInfo;
import fr.neatmonster.nocheatplus.checks.moving.player.CreativeFly;
import fr.neatmonster.nocheatplus.checks.moving.player.MorePackets;
Expand Down Expand Up @@ -405,7 +405,7 @@ else if (!from.getWorld().equals(to.getWorld())) {
final MovingConfig cc = MovingConfig.getConfig(player);
final MoveInfo moveInfo = aux.useMoveInfo();
final Location loc = player.getLocation(moveInfo.useLoc);
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
// TODO: On pistons pulling the player back: -1.15 yDistance for split move 1 (untracked position > 0.5 yDistance!).
if (
// Handling split moves has been disabled.
Expand Down Expand Up @@ -552,12 +552,12 @@ else if (time < data.timeSprinting) {
}

// Set some data for this move.
final MoveData thisMove = data.playerMoves.getCurrentMove();
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
thisMove.set(pFrom, pTo);
if (mightBeMultipleMoves) {
thisMove.mightBeMultipleMoves = true;
}
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();

// Potion effect "Jump".
final double jumpAmplifier = aux.getJumpAmplifier(player);
Expand Down Expand Up @@ -804,7 +804,7 @@ private boolean checkBounceEnvelope(Player player, PlayerLocation from, PlayerLo
* @param data
* @return True, if bounce has been used, i.e. to do without fall damage.
*/
private boolean onPreparedBounceSupport(Player player, Location from, Location to, MoveData lastMove, int tick, MovingData data) {
private boolean onPreparedBounceSupport(Player player, Location from, Location to, PlayerMoveData lastMove, int tick, MovingData data) {
if (to.getY() > from.getY() || to.getY() == from.getY() && data.verticalBounce.value < 0.13) {
// Apply bounce.
if (to.getY() == from.getY()) {
Expand Down Expand Up @@ -841,8 +841,8 @@ private boolean onPreparedBounceSupport(Player player, Location from, Location t
*/
@SuppressWarnings("unused")
private Location checkExtremeMove(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
final MoveData thisMove = data.playerMoves.getCurrentMove();
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
// TODO: Latency effects.
double violation = 0.0; // h + v violation (full move).
// Vertical move.
Expand Down Expand Up @@ -926,7 +926,7 @@ private Location checkExtremeMove(final Player player, final PlayerLocation from
* @param data
*/
private void workaroundFlyNoFlyTransition(final Player player, final int tick, final MovingData data) {
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
final double amount = guessFlyNoFlyVelocity(player, data.playerMoves.getCurrentMove(), lastMove, data);
data.clearActiveHorVel(); // Clear active velocity due to adding actual speed here.
data.addHorizontalVelocity(new AccountEntry(tick, amount, 1, MovingData.getHorVelValCount(amount)));
Expand All @@ -942,14 +942,14 @@ private void workaroundFlyNoFlyTransition(final Player player, final int tick, f
}
}

private static double guessFlyNoFlyVelocity(final Player player, final MoveData thisMove, final MoveData lastMove, final MovingData data) {
private static double guessFlyNoFlyVelocity(final Player player, final PlayerMoveData thisMove, final PlayerMoveData lastMove, final MovingData data) {
// Default margin: Allow slightly less than the previous speed.
final double defaultAmount = lastMove.hDistance * (1.0 + Magic.FRICTION_MEDIUM_AIR) / 2.0;
// Test for exceptions.
if (thisMove.hDistance > defaultAmount && Bridge1_9.isGlidingWithElytra(player)) {
// Allowing the same speed won't always work on elytra (still increasing, differing modeling on client side with motXYZ).
// (Doesn't seem to be overly effective.)
final MoveData secondPastMove = data.playerMoves.getSecondPastMove();
final PlayerMoveData secondPastMove = data.playerMoves.getSecondPastMove();
if (lastMove.modelFlying != null && secondPastMove.modelFlying != null && Magic.glideEnvelopeWithHorizontalGain(thisMove, lastMove, secondPastMove)) {
return thisMove.hDistance + Magic.GLIDE_HORIZONTAL_GAIN_MAX;
}
Expand All @@ -973,7 +973,7 @@ private void processBounce(final Player player,final double fromY, final double
final double fallDistance = MovingUtil.getRealisticFallDistance(player, fromY, toY, data);
final double base = Math.sqrt(fallDistance) / 3.3;
double effect = Math.min(3.5, base + Math.min(base / 10.0, Magic.GRAVITY_MAX)); // Ancient Greek technology with gravity added.
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
if (effect > 0.42 && lastMove.toIsValid) {
// Extra cap by last y distance(s).
final double max_gain = Math.abs(lastMove.yDistance < 0.0 ? Math.min(lastMove.yDistance, toY - fromY) : (toY - fromY)) - Magic.GRAVITY_SPAN;
Expand Down Expand Up @@ -1118,7 +1118,7 @@ else if (!from.getWorld().getName().equals(toWorldName)) {
}
else {
// TODO: Detect differing location (a teleport event would follow).
final MoveData lastMove = mData.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = mData.playerMoves.getFirstPastMove();
if (!lastMove.toIsValid || !TrigUtil.isSamePos(to, lastMove.to.x, lastMove.to.y, lastMove.to.z)) {
// Something odd happened.
aux.resetPositionsAndMediumProperties(player, to, mData, mCc);
Expand Down Expand Up @@ -1609,7 +1609,7 @@ public void playerLeaves(final Player player) {
// TODO: Force-load chunks [log if (!)] ?
// TODO: Consider to catch all, at least (debug-) logging-wise.
if (!BlockProperties.isPassable(loc)) {
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
if (lastMove.toIsValid) {
final Location refLoc = new Location(loc.getWorld(), lastMove.to.x, lastMove.to.y, lastMove.to.z);
final double d = refLoc.distanceSquared(loc);
Expand Down Expand Up @@ -1772,7 +1772,7 @@ else if (data.sfHoverLoginTicks > 0) {
}

private Location enforceLocation(final Player player, final Location loc, final MovingData data) {
final MoveData lastMove = data.playerMoves.getFirstPastMove();
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
if (lastMove.toIsValid && TrigUtil.distanceSquared(lastMove.to.x, lastMove.to.y, lastMove.to.z, loc.getX(), loc.getY(), loc.getZ()) > 1.0 / 256.0) {
// Teleport back.
// TODO: Add history / alert?
Expand Down

0 comments on commit 929578a

Please sign in to comment.