Route set back getting through a utility method (for most).
Preparation for set back policies. Special cases missing: illegal move, passable, more packets.
This commit is contained in:
parent
a3027eb6ce
commit
a641137176
|
@ -657,6 +657,7 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData {
|
|||
|
||||
/**
|
||||
* Convenience method.
|
||||
*
|
||||
* @param loc
|
||||
*/
|
||||
public void setSetBack(final Location loc) {
|
||||
|
@ -671,6 +672,7 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData {
|
|||
|
||||
/**
|
||||
* Get the set back location with yaw and pitch set form ref.
|
||||
*
|
||||
* @param ref
|
||||
* @return
|
||||
*/
|
||||
|
@ -680,6 +682,7 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData {
|
|||
|
||||
/**
|
||||
* Get the set back location with yaw and pitch set from ref.
|
||||
*
|
||||
* @param ref
|
||||
* @return
|
||||
*/
|
||||
|
@ -687,6 +690,18 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData {
|
|||
return LocUtil.clone(setBack, ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set back location with yaw and pitch set from the given
|
||||
* arguments.
|
||||
*
|
||||
* @param refYaw
|
||||
* @param refPitch
|
||||
* @return
|
||||
*/
|
||||
public Location getSetBack(final float yaw, final float pitch) {
|
||||
return LocUtil.clone(setBack, yaw, pitch);
|
||||
}
|
||||
|
||||
public boolean hasSetBack() {
|
||||
return setBack != null;
|
||||
}
|
||||
|
@ -798,6 +813,10 @@ public class MovingData extends ACheckData implements IRemoveSubCheckData {
|
|||
return morePacketsSetBackResetTime < setBackResetTime;
|
||||
}
|
||||
|
||||
public void setMorePacketsSetBackFromSurvivalfly() {
|
||||
setMorePacketsSetBack(setBack);
|
||||
}
|
||||
|
||||
public final void setMorePacketsSetBack(final PlayerLocation loc) {
|
||||
if (morePacketsSetback == null) {
|
||||
morePacketsSetback = loc.getLocation();
|
||||
|
|
|
@ -115,6 +115,7 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
|
|||
import fr.neatmonster.nocheatplus.utilities.location.LocUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.PlayerLocation;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.MapUtil;
|
||||
|
||||
|
@ -284,7 +285,9 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
final boolean sfCheck = MovingUtil.shouldCheckSurvivalFly(player, moveInfo.from, data, cc, pData);
|
||||
aux.returnPlayerMoveInfo(moveInfo);
|
||||
if (sfCheck) {
|
||||
target = data.getSetBack(loc);
|
||||
target = MovingUtil.getApplicableSetBackLocation(player,
|
||||
loc.getYaw(), loc.getPitch(), moveInfo.from.getBlockCache(),
|
||||
data, cc);
|
||||
}
|
||||
if (target == null) {
|
||||
// TODO: Add something to guess the best set back location (possibly data.guessSetBack(Location)).
|
||||
|
@ -707,7 +710,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
if (!TrigUtil.isSamePosAndLook(pFrom, pTo) // Safety check.
|
||||
&& TrigUtil.isSamePosAndLook(pTo, data.crossWorldFrom)) {
|
||||
// Assume to (and possibly the player location) to be set to the location the player teleported from within the other world.
|
||||
newTo = data.getSetBack(from);
|
||||
newTo = data.getSetBack(from); // (OK, cross-world)
|
||||
checkNf = false;
|
||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().warning(Streams.STATUS, CheckUtils.getLogMessagePrefix(player, CheckType.MOVING) + " Player move end point seems to be set wrongly.");
|
||||
}
|
||||
|
@ -1291,7 +1294,9 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
// Some resetting is done in MovingListener.
|
||||
if (check.executeActions(vd).willCancel()) {
|
||||
// Set back + view direction of to (more smooth).
|
||||
return data.getSetBack(to);
|
||||
return MovingUtil.getApplicableSetBackLocation(player,
|
||||
to.getYaw(), to.getPitch(), from.getBlockCache(),
|
||||
data, cc);
|
||||
}
|
||||
}
|
||||
// No cancel intended.
|
||||
|
@ -2613,7 +2618,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
if (data.hasSetBack()) {
|
||||
// Might have to re-check all context with playerJoins and keeping old set backs...
|
||||
// Could use a flexible set back policy (switch to in-air on login).
|
||||
return data.getSetBack(loc);
|
||||
return data.getSetBack(loc); // (OK? ~ legacy)
|
||||
}
|
||||
else {
|
||||
return new Location(player.getWorld(), lastMove.to.getX(), lastMove.to.getY(), lastMove.to.getZ(), loc.getYaw(), loc.getPitch());
|
||||
|
@ -2655,8 +2660,10 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
// Re-Check if survivalfly can apply at all.
|
||||
final PlayerMoveInfo moveInfo = aux.usePlayerMoveInfo();
|
||||
moveInfo.set(player, loc, null, cc.yOnGround);
|
||||
if (MovingUtil.shouldCheckSurvivalFly(player, moveInfo.from, data, cc, pData)) {
|
||||
handleHoverViolation(player, loc, cc, data, pData);
|
||||
if (MovingUtil.shouldCheckSurvivalFly(player, moveInfo.from,
|
||||
data, cc, pData)) {
|
||||
handleHoverViolation(player, loc, moveInfo.from.getBlockCache(),
|
||||
cc, data, pData);
|
||||
// Assume the player might still be hovering.
|
||||
res = false;
|
||||
data.sfHoverTicks = 0;
|
||||
|
@ -2676,7 +2683,8 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
return res;
|
||||
}
|
||||
|
||||
private void handleHoverViolation(final Player player, final Location loc,
|
||||
private void handleHoverViolation(final Player player,
|
||||
final Location loc, final BlockCache blockCache,
|
||||
final MovingConfig cc, final MovingData data, final IPlayerData pData) {
|
||||
// Check nofall damage (!).
|
||||
if (cc.sfHoverFallDamage && noFall.isEnabled(player, pData)) {
|
||||
|
@ -2684,7 +2692,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
|||
noFall.checkDamage(player, loc.getY(), data, pData);
|
||||
}
|
||||
// Delegate violation handling.
|
||||
survivalFly.handleHoverViolation(player, loc, cc, data);
|
||||
survivalFly.handleHoverViolation(player, loc, blockCache, cc, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -225,13 +225,13 @@ public class CreativeFly extends Check {
|
|||
if (executeActions(vd).willCancel()) {
|
||||
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
|
||||
// to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
||||
setBack = data.getSetBack(to);
|
||||
setBack = data.getSetBack(to); // (OK)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Maximum height check (silent set back).
|
||||
if (to.getY() > maximumHeight) {
|
||||
setBack = data.getSetBack(to);
|
||||
setBack = data.getSetBack(to); // (OK)
|
||||
if (debug) {
|
||||
debug(player, "Maximum height exceeded, silent set-back.");
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class MorePackets extends Check {
|
|||
if (allowSetSetBack && !data.hasMorePacketsSetBack()){
|
||||
// TODO: Check if other set back is appropriate or if to set/reset on other events.
|
||||
if (data.hasSetBack()) {
|
||||
data.setMorePacketsSetBack(data.getSetBack(to));
|
||||
data.setMorePacketsSetBackFromSurvivalfly();
|
||||
}
|
||||
else {
|
||||
data.setMorePacketsSetBack(from);
|
||||
|
@ -103,7 +103,11 @@ public class MorePackets extends Check {
|
|||
}
|
||||
if (executeActions(vd).willCancel()) {
|
||||
// Set to cancel the move.
|
||||
return data.hasMorePacketsSetBack() ? data.getMorePacketsSetBack() : data.getSetBack(to);
|
||||
/*
|
||||
* TODO: Harmonize with MovingUtil.getApplicableSetBackLocation
|
||||
* (somehow include the desired set back type / loc / context).
|
||||
*/
|
||||
return data.hasMorePacketsSetBack() ? data.getMorePacketsSetBack() : data.getSetBack(to); // TODO
|
||||
}
|
||||
}
|
||||
else if (allowSetSetBack && data.getMorePacketsSetBackAge() > cc.morePacketsSetBackAge) {
|
||||
|
|
|
@ -216,7 +216,11 @@ public class Passable extends Check {
|
|||
|
||||
// Prefer the set back location from the data.
|
||||
if (data.hasSetBack()) {
|
||||
setBackLoc = data.getSetBack(to);
|
||||
/*
|
||||
* TODO: Harmonize with MovingUtil.getApplicableSetBackLocation
|
||||
* (somehow include the desired set back type / loc / context).
|
||||
*/
|
||||
setBackLoc = data.getSetBack(to); // TODO
|
||||
if (debug) {
|
||||
debug(player, "Using set back location for passable.");
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
|
|||
import fr.neatmonster.nocheatplus.checks.moving.model.LocationData;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.util.AuxMoving;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.velocity.VelocityFlags;
|
||||
import fr.neatmonster.nocheatplus.checks.workaround.WRPT;
|
||||
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
|
||||
|
@ -55,6 +56,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
|||
import fr.neatmonster.nocheatplus.utilities.ds.count.ActionAccumulator;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.PlayerLocation;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
||||
|
||||
/**
|
||||
|
@ -444,7 +446,8 @@ public class SurvivalFly extends Check {
|
|||
yDistance, vAllowedDistance, fromOnGround, resetFrom, toOnGround, resetTo, thisMove);
|
||||
data.ws.setJustUsedIds(null);
|
||||
}
|
||||
return data.getSetBack(to);
|
||||
// (No need for MovingUtil.getApplicableSetBackLocation.)
|
||||
return data.getSetBack(to); // (OK)
|
||||
}
|
||||
}
|
||||
else if (from.isOnClimbable()) {
|
||||
|
@ -2048,7 +2051,9 @@ public class SurvivalFly extends Check {
|
|||
// Some resetting is done in MovingListener.
|
||||
if (executeActions(vd).willCancel()) {
|
||||
// Set back + view direction of to (more smooth).
|
||||
return data.getSetBack(to);
|
||||
return MovingUtil.getApplicableSetBackLocation(player,
|
||||
to.getYaw(), to.getPitch(), to.getBlockCache(),
|
||||
data, cc);
|
||||
}
|
||||
else {
|
||||
// TODO: Evaluate how data resetting can be done minimal (skip certain things flags)?
|
||||
|
@ -2063,10 +2068,12 @@ public class SurvivalFly extends Check {
|
|||
* Hover violations have to be handled in this check, because they are handled as SurvivalFly violations (needs executeActions).
|
||||
* @param player
|
||||
* @param loc
|
||||
* @param blockCache
|
||||
* @param cc
|
||||
* @param data
|
||||
*/
|
||||
public final void handleHoverViolation(final Player player, final Location loc,
|
||||
public final void handleHoverViolation(final Player player,
|
||||
final Location loc, final BlockCache blockCache,
|
||||
final MovingConfig cc, final MovingData data) {
|
||||
data.survivalFlyVL += cc.sfHoverViolation;
|
||||
|
||||
|
@ -2082,8 +2089,9 @@ public class SurvivalFly extends Check {
|
|||
}
|
||||
if (executeActions(vd).willCancel()) {
|
||||
// Set back or kick.
|
||||
if (data.hasSetBack()) {
|
||||
final Location newTo = data.getSetBack(loc);
|
||||
final Location newTo = MovingUtil.getApplicableSetBackLocation(player,
|
||||
loc.getYaw(), loc.getPitch(), blockCache, data, cc);
|
||||
if (newTo != null) {
|
||||
data.prepareSetBack(newTo);
|
||||
player.teleport(newTo, BridgeMisc.TELEPORT_CAUSE_CORRECTION_OF_POSITION);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ import fr.neatmonster.nocheatplus.utilities.location.LocUtil;
|
|||
import fr.neatmonster.nocheatplus.utilities.location.PlayerLocation;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.RichBoundsLocation;
|
||||
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.map.MapUtil;
|
||||
|
||||
|
@ -231,7 +232,11 @@ public class MovingUtil {
|
|||
// (Mind that we don't set the block cache here).
|
||||
final Location loc = player.getLocation();
|
||||
if (!restored && data.hasSetBack()) {
|
||||
final Location setBack = data.getSetBack(loc);
|
||||
/*
|
||||
* TODO: Harmonize with MovingUtil.getApplicableSetBackLocation
|
||||
* (somehow include the desired set back type / loc / context).
|
||||
*/
|
||||
final Location setBack = data.getSetBack(loc); // TODO
|
||||
pLoc.set(setBack, player);
|
||||
if (!pLoc.hasIllegalCoords() && (cc.ignoreStance || !pLoc.hasIllegalStance())) {
|
||||
event.setFrom(setBack);
|
||||
|
@ -639,4 +644,46 @@ public class MovingUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the applicable set-back location at this moment.
|
||||
* <hr>
|
||||
* <ul>
|
||||
* <li>The idea is that this method call remains side effect free.</li>
|
||||
* <li>Because set-back policies may need scanning for ground down to the
|
||||
* void, calling this method can have an impact on performance, if called
|
||||
* excessively.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param player
|
||||
* @param refYaw
|
||||
* @param refPitch
|
||||
* @param blockCache
|
||||
* @param data
|
||||
* @param cc
|
||||
* @return The applicable set back location
|
||||
*/
|
||||
public static Location getApplicableSetBackLocation(final Player player,
|
||||
final float refYaw, final float refPitch, final BlockCache blockCache,
|
||||
final MovingData data, final MovingConfig cc) {
|
||||
/*
|
||||
* TODO: Signature adjust for best reuse with both hover and ordinary sf
|
||||
* violations. Also consider returning more context.
|
||||
*/
|
||||
/*
|
||||
* TODO: Might generalize and move elsewhere (MovingListener, MovingUtil,
|
||||
* generic: ISetBackHelper).
|
||||
*/
|
||||
/*
|
||||
* TODO: May need more context information, e.g. PlayerLocation from+to
|
||||
* - to is null, if not applicable (hover) or illegal (illegal to but
|
||||
* legal from).
|
||||
*/
|
||||
// TODO: Set back policies.
|
||||
if (data.hasSetBack()) {
|
||||
return data.getSetBack(refYaw, refPitch); // (OK)
|
||||
}
|
||||
// Nothing appropriate found.
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue