Skip to content

Commit 125a239

Browse files
committed
Update some comments and Javadocs
Remove references to ViaVersion's input emulation. It just tries to guess which input the player is moving with; totally unreliable.
1 parent eff2d83 commit 125a239

File tree

6 files changed

+30
-41
lines changed

6 files changed

+30
-41
lines changed

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import fr.neatmonster.nocheatplus.checks.CheckType;
2020
import fr.neatmonster.nocheatplus.checks.access.ACheckData;
21-
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
2221
import fr.neatmonster.nocheatplus.components.data.IDataOnRemoveSubCheckData;
2322
import fr.neatmonster.nocheatplus.players.PlayerData;
2423
import fr.neatmonster.nocheatplus.utilities.PenaltyTime;
@@ -35,12 +34,10 @@ public class CombinedData extends ACheckData implements IDataOnRemoveSubCheckDat
3534

3635
/**
3736
* Last sprinting state of the player as set by {@link PlayerData#isSprinting()}. Set in SurvivalFly.
38-
* If the server and client are capable of reading and sending inputs respectively, {@link MovingData#input}should be used instead.
3937
*/
4038
public boolean wasSprinting;
4139
/**
4240
* Last shift state of the player as set by {@link PlayerData#isShiftKeyPressed()}. Set in SurvivalFly.
43-
* If the server and client are capable of reading and sending inputs respectively, {@link MovingData#input}should be used instead.
4441
*/
4542
public boolean wasPressingShift;
4643

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/model/MoveData.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,34 @@ public class MoveData {
4545

4646
/**
4747
* Start point of a move, or a static location (join/teleport).
48+
*
49+
* <p>Quick note on semantics: these fields (from/to) follow Bukkit's PlayerMoveEvent semantics.<br>
50+
* {@code from} is the server's last known position for the entity. <br>
51+
* For example, if the player was at (1,1,1) and the client sends an update to (2,1,1),
52+
* Bukkit will fire a move event with {@code from}=(1,1,1) and {@code to}=(2,1,1).<br>
53+
* From the server's perspective, the {@code from} location is the current/last-known position
54+
* and {@code to} one is the destination <i>about</i> to be applied that's been reported by the client; however, from the client's perspective they
55+
* already are at the {@code to} position when the packet is sent.
4856
*/
4957
public final LocationData from = new LocationData();
5058

5159
/**
5260
* Indicate if coordinates for a move end-point and distances are present.
5361
* Always set on setPositions call.
5462
*/
55-
public boolean toIsValid = false; // Must initialize.
63+
public boolean toIsValid = false; // Must initialize here as false.
5664

5765

5866
/////////////////////////////////////////////////////////////////////
5967
// Only set if a move end-point is set, i.e. toIsValid set to true.
6068
/////////////////////////////////////////////////////////////////////
6169
// Coordinates and distances.
6270
/**
63-
* End point of a move.
71+
* End point (destination) of a move.
72+
*
73+
* Essentially represents the destination reported by the client and about to be applied by the server. Example: client updates to
74+
* (2,1,1) => {@code to}=(2,1,1) (the client may already be at that position).
75+
* See {@link #from} for more details on semantics.
6476
*/
6577
public final LocationData to = new LocationData();
6678

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/model/PlayerKeyboardInput.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/**
2323
* Carry information regarding the player's key presses (WASD, space bar, shift, sprint).
24+
* To not be conflated with the status of the player (isSprinting, isSneaking, etc).<br>
2425
*/
2526
public class PlayerKeyboardInput implements Cloneable {
2627

NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/moving/player/SurvivalFly.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ else if (lastMove.from.inLava) {
11251125
// NOTE: this is after the riptiding propelling force.
11261126
// NOTE: here the game uses isShiftKeyDown (so this is shifting not sneaking, using Bukkit's isShift is correct)
11271127
if (!player.isFlying() && pData.isShiftKeyPressed() && from.isAboveGround() && thisMove.yDistance <= 0.0) {
1128-
Vector backOff = from.maybeBackOffFromEdge(new Vector(thisMove.xAllowedDistance, thisMove.yDistance, thisMove.zAllowedDistance));
1128+
Vector backOff = from.maybeBackOffFromEdge(new Vector(thisMove.xAllowedDistance, yDistanceBeforeCollide, thisMove.zAllowedDistance));
11291129
thisMove.xAllowedDistance = backOff.getX();
11301130
thisMove.zAllowedDistance = backOff.getZ();
11311131
}
@@ -1234,7 +1234,7 @@ else if (lastMove.from.inLava) {
12341234
if (!player.isFlying() && pData.isShiftKeyPressed() && from.isAboveGround() && thisMove.yDistance <= 0.0) {
12351235
for (i = 0; i < 9; i++) {
12361236
// TODO: Optimize. Brute forcing collisions with all 9 speed combinations will tank performance.
1237-
Vector backOff = from.maybeBackOffFromEdge(new Vector(xTheoreticalDistance[i], thisMove.yDistance, zTheoreticalDistance[i]));
1237+
Vector backOff = from.maybeBackOffFromEdge(new Vector(xTheoreticalDistance[i], yDistanceBeforeCollide, zTheoreticalDistance[i]));
12381238
xTheoreticalDistance[i] = backOff.getX();
12391239
zTheoreticalDistance[i] = backOff.getZ();
12401240
}
@@ -1508,7 +1508,7 @@ private double[] vDistRel(final Player player, final PlayerLocation from,
15081508
// NOTE: pressing space bar on a bouncy block will override the bounce (in that case, vdistrel will fall back to the jump check above).
15091509
// updateEntityAfterFallOn(), this function is called on the next move
15101510
if (pData.isShiftKeyPressed() && lastMove.collideY) {
1511-
if (lastMove.yAllowedDistance < 0.0) { // NOTE: Must be the allowed distance, not the actual one (exploit)
1511+
if (thisMove.yAllowedDistance < 0.0) { // NOTE: Must be the allowed distance, not the actual one (exploit)
15121512
if (lastMove.to.onBouncyBlock) {
15131513
// The effect works by inverting the distance.
15141514
// Beds have a weaker bounce effect (BedBlock.java).
@@ -1532,13 +1532,13 @@ private double[] vDistRel(final Player player, final PlayerLocation from,
15321532
thisMove.yAllowedDistance = 0.0;
15331533
}
15341534
}
1535-
// *----------Finalization of handleRelativeFrictionAndCalculateMovement; this check/condition is called after having called the move(). The former method is called only when the player is traveling in air, thus the liquid and gliding checks ----------*
1535+
// *----------Finalization of handleRelativeFrictionAndCalculateMovement; this check/condition is called after having called the move() function. The former method is called only when the player is traveling in air, thus the liquid and gliding checks ----------*
15361536
if (!lastMove.from.inLiquid && !lastMove.isGliding) {
15371537
// TODO: Which condition is correct ??? Check for past versions to see when this check changed... Fun.
15381538
// if ((this.horizontalCollision || this.jumping) && (this.onClimbable() || this.getInBlockState().is(Blocks.POWDER_SNOW) && PowderSnowBlock.canEntityWalkOnPowderSnow(this))) {
15391539
// if ((this.horizontalCollision || this.jumping) && (this.onClimbable() || this.wasInPowderSnow && PowderSnowBlock.canEntityWalkOnPowderSnow(this))) {
15401540
// TODO: We have to loop the jumping state for 1.21.1 and below... No other way to put it unfortunately. This will make the code an ugly mess than it already is.
1541-
final boolean jumpedOrCollided = lastMove.collidesHorizontally || data.input.isSpaceBarPressed() && BridgeMisc.isSpaceBarImpulseKnown(player);
1541+
final boolean jumpedOrCollided = lastMove.collidesHorizontally || data.input.wasSpaceBarPressed() && BridgeMisc.isSpaceBarImpulseKnown(player);
15421542
if (jumpedOrCollided && (lastMove.from.onClimbable || lastMove.from.inPowderSnow && BridgeMisc.canStandOnPowderSnow(player))) { // this.wasInPowderSnow. The living entity field already checks for the past state, does that mean we need to check for the second last move?
15431543
thisMove.yAllowedDistance = 0.2;
15441544
}
@@ -1838,6 +1838,7 @@ private double[] hDistAfterFailure(final Player player,
18381838
* Because this move is not sent by the client and cannot be predicted through normal means, we have to brute force it.
18391839
*/
18401840
if (hDistanceAboveLimit > 0.0 && lastMove.isPossibleStoppingMotion(pData.getClientVersion())) {
1841+
tags.add("stop_motion");
18411842
double[] res = prepareSpeedEstimation(from, to, pData, player, data, thisMove, lastMove, fromOnGround, toOnGround, debug, isNormalOrPacketSplitMove, false, false);
18421843
hAllowedDistance = res[0];
18431844
hDistanceAboveLimit = res[1];
@@ -1846,6 +1847,7 @@ private double[] hDistAfterFailure(final Player player,
18461847
* 2: Undetectable jump (must brute force here): player failed with the onGround flag, lets try with off-ground then.
18471848
*/
18481849
if (PhysicsEnvelope.isVerticallyConstricted(from, to, pData) && hDistanceAboveLimit > 0.0) {
1850+
tags.add("vert_constricted");
18491851
double[] res = prepareSpeedEstimation(from, to, pData, player, data, thisMove, lastMove, fromOnGround, toOnGround, debug, isNormalOrPacketSplitMove, false, true);
18501852
hAllowedDistance = res[0];
18511853
hDistanceAboveLimit = res[1];

NCPCore/src/main/java/fr/neatmonster/nocheatplus/compat/BridgeMisc.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.bukkit.inventory.meta.ItemMeta;
3636

3737
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
38-
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
3938
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeMaterial;
4039
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
4140
import fr.neatmonster.nocheatplus.players.DataManager;
@@ -104,9 +103,8 @@ public static boolean hasAnyUsingItemMethod() {
104103
* Test if the player's horizontal impulse (WASD presses) is either known or emulated by ViaVersion.
105104
*
106105
* @param player The player whose input is being checked.
107-
* @return <b>Always</b><code>true</code>, if both client and server are on a version that supports impulse sending and reading respectively (1.21.2 and above).<br>
108-
* <b>Always</b><code>false</code>, if the server is unable to read inputs at all (legacy, pre 1.21.2). <br>
109-
* <b>Note</b>: currently, we cannot rely on ViaVersion's input emulation for older clients on newer servers (1.21.2+); it seems to be way off from the actual input.
106+
* @return True if both client and server are on a version that supports impulse reading and sending respectively (1.21.2 and above).<br>
107+
* Always false, if the server or the client is unable to read inputs at all (legacy, pre 1.21.2). <br>
110108
* <hr>
111109
* Check {@link BridgeMisc#isSpaceBarImpulseKnown(Player)} for the vertical impulse.
112110
*
@@ -117,43 +115,24 @@ public static boolean isWASDImpulseKnown(final Player player) {
117115
// TODO: What about modern clients (1.21.2+) on legacy servers (1.21.2-)? Is there a way to intercept and translate the sent input by ourselves?
118116
return false;
119117
}
120-
if (DataManager.getPlayerData(player).getClientVersion().isAtLeast(ClientVersion.V_1_21_2)) {
121-
// Client sends impulses and server can read them. Inputs are always known, regardless of any other condition.
122-
return true;
123-
}
124-
//final IPlayerData pData = DataManager.getPlayerData(player);
125-
//final MovingData data = pData.getGenericInstance(MovingData.class);
126-
// A legacy client (which doesn't natively send inputs) is connected to a server that supports impulse-reading.
127-
// Connection is enabled by ViaVersion, which emulates the PLAYER_INPUT packet.
128-
// TODO: Check how exactly ViaVersion is emulating the packet. It would be useful to have the logic within NCP.
129-
//return !data.hasActiveHorVel();
130-
return false;
118+
// Client sends impulses and server can read them. Inputs are always known, regardless of any other condition.
119+
return DataManager.getPlayerData(player).getClientVersion().isAtLeast(ClientVersion.V_1_21_2);
131120
}
132121

133122
/**
134123
* Test if the player's vertical impulse (space bar presses) is either known or emulated by ViaVersion.
135124
*
136125
* @param player The player whose input is being checked.
137-
* @return <b>Always</b> <code>true</code> if both client and server are on a version that supports impulse reading and sending respectively (1.21.2 and above).<br>
138-
* <b>Always</b> <code>false</code>, if the server is unable to read inputs at all (legacy, pre 1.21.2). <br>
139-
* <code>true</code>, if the server supports impulse reading, but the client does not natively support impulse-sending, which is instead enabled by ViaVersion
140-
* through emulation of the PLAYER_INPUT packet. Because the packet is emulated, the actual impulse may not always reflect what the player actually pressed; particularly if the
141-
* player's speed was affected by external velocity sources. In which case, this will return <code>false</code>.
126+
* @return True if both client and server are on a version that supports impulse reading and sending respectively (1.21.2 and above).<br>
127+
* Always false, if the server or the client is unable to read inputs at all (legacy, pre 1.21.2). <br>
142128
* <hr>
143129
* Check {@link BridgeMisc#isWASDImpulseKnown(Player)} for the horizontal impulse.
144130
*/
145131
public static boolean isSpaceBarImpulseKnown(final Player player) {
146132
if (!hasInputGetterMethod) {
147133
return false;
148134
}
149-
if (DataManager.getPlayerData(player).getClientVersion().isAtLeast(ClientVersion.V_1_21_2)) {
150-
return true;
151-
}
152-
//final IPlayerData pData = DataManager.getPlayerData(player);
153-
//final MovingData data = pData.getGenericInstance(MovingData.class);
154-
// TODO: getOrUseVerticalVelocity or peekVerticalVelocity?
155-
// TODO: How exactly does ViaVersion provide?
156-
return false;
135+
return DataManager.getPlayerData(player).getClientVersion().isAtLeast(ClientVersion.V_1_21_2);
157136
}
158137

159138
/**

NCPCore/src/main/java/fr/neatmonster/nocheatplus/utilities/location/RichBoundsLocation.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,7 @@ public boolean isInPowderSnow() {
785785
if (blockFlags != null && (blockFlags & BlockFlags.F_POWDER_SNOW) == 0) {
786786
inPowderSnow = false;
787787
}
788-
else {
789-
inPowderSnow = isInside(BlockFlags.F_POWDER_SNOW);
790-
}
788+
else inPowderSnow = isInside(BlockFlags.F_POWDER_SNOW);
791789
}
792790
return inPowderSnow;
793791
}

0 commit comments

Comments
 (0)