use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.
the class SurvivalFly method handleViolation.
/**
* Violation handling put here to have less code for the frequent processing of check.
* @param now
* @param result
* @param player
* @param from
* @param to
* @param data
* @param cc
* @return
*/
private Location handleViolation(final long now, final double result, final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
// Increment violation level.
data.survivalFlyVL += result;
data.sfVLTime = data.getPlayerMoveCount();
final ViolationData vd = new ViolationData(this, player, data.survivalFlyVL, result, cc.survivalFlyActions);
if (vd.needsParameters()) {
vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
}
// Some resetting is done in MovingListener.
if (executeActions(vd).willCancel()) {
// Set back + view direction of to (more smooth).
return MovingUtil.getApplicableSetBackLocation(player, to.getYaw(), to.getPitch(), to, data, cc);
} else {
// TODO: Evaluate how data resetting can be done minimal (skip certain things flags)?
data.clearAccounting();
data.sfJumpPhase = 0;
// Cancelled by other plugin, or no cancel set by configuration.
return null;
}
}
use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.
the class VehicleEnvelope method check.
public SetBackEntry check(final Player player, final Entity vehicle, final VehicleMoveData thisMove, final boolean isFake, final MovingData data, final MovingConfig cc, final IPlayerData pData) {
final boolean debug = pData.isDebugActive(type);
// Delegate to a sub-check.
tags.clear();
tags.add("entity." + vehicle.getType());
if (debug) {
debugDetails.clear();
// Add just used workaround ids to this list directly, for now.
data.ws.setJustUsedIds(debugDetails);
}
final boolean violation = checkEntity(player, vehicle, thisMove, isFake, data, cc, debug);
if (debug && !debugDetails.isEmpty()) {
debugDetails(player);
debugDetails.clear();
}
if (violation) {
// Add up one for now.
data.vehicleEnvelopeVL += 1.0;
final ViolationData vd = new ViolationData(this, player, data.vehicleEnvelopeVL, 1, cc.vehicleEnvelopeActions);
vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
if (executeActions(vd).willCancel()) {
return data.vehicleSetBacks.getValidSafeMediumEntry();
}
} else {
// Random cool down for now.
data.vehicleEnvelopeVL *= 0.99;
// Do not set a set back here.
}
return null;
}
use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.
the class CreativeFly method check.
/**
* @param player
* @param from
* @param to
* @param data
* @param cc
* @param time Milliseconds.
* @return
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc, final IPlayerData pData, final long time, final int tick, final boolean useBlockChangeTracker) {
// Reset tags, just in case.
tags.clear();
final boolean debug = pData.isDebugActive(type);
// Some edge data for this move.
final GameMode gameMode = player.getGameMode();
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
// if (!data.thisMove.from.extraPropertiesValid) {
// // TODO: Confine by model config flag or just always do [if the latter: do it in the listener]?
// data.thisMove.setExtraProperties(from, to);
// }
final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
final ModelFlying model = thisMove.modelFlying;
// Proactive reset of elytraBoost (MC 1.11.2).
if (data.fireworksBoostDuration > 0) {
if (!lastMove.valid || lastMove.flyCheck != CheckType.MOVING_CREATIVEFLY || lastMove.modelFlying != model || data.fireworksBoostTickExpire < tick) {
data.fireworksBoostDuration = 0;
} else {
data.fireworksBoostDuration--;
}
}
// Calculate some distances.
final double yDistance = thisMove.yDistance;
final double hDistance = thisMove.hDistance;
final boolean flying = gameMode == BridgeMisc.GAME_MODE_SPECTATOR || player.isFlying();
final boolean sprinting = time <= data.timeSprinting + cc.sprintingGrace;
// Lost ground, if set so.
if (model.getGround()) {
MovingUtil.prepareFullCheck(from, to, thisMove, Math.max(cc.yOnGround, cc.noFallyOnGround));
if (!thisMove.from.onGroundOrResetCond) {
if (from.isSamePos(to)) {
if (// Copy and paste from sf.
lastMove.toIsValid && lastMove.hDistance > 0.0 && lastMove.yDistance < -0.3 && LostGround.lostGroundStill(player, from, to, hDistance, yDistance, sprinting, lastMove, data, cc, tags)) {
// Nothing to do.
}
} else if (LostGround.lostGround(player, from, to, hDistance, yDistance, sprinting, lastMove, data, cc, useBlockChangeTracker ? blockChangeTracker : null, tags)) {
// Nothing to do.
}
}
}
// Horizontal distance check.
double[] resH = hDist(player, from, to, hDistance, yDistance, sprinting, flying, lastMove, time, model, data, cc);
double limitH = resH[0];
double resultH = resH[1];
// Check velocity.
if (resultH > 0) {
double hFreedom = data.getHorizontalFreedom();
if (hFreedom < resultH) {
// Use queued velocity if possible.
hFreedom += data.useHorizontalVelocity(resultH - hFreedom);
}
if (hFreedom > 0.0) {
resultH = Math.max(0.0, resultH - hFreedom);
if (resultH <= 0.0) {
limitH = hDistance;
}
tags.add("hvel");
}
} else {
// TODO: test/check !
data.clearActiveHorVel();
}
// Normalize to % of a block.
resultH *= 100.0;
if (resultH > 0.0) {
tags.add("hdist");
}
// Vertical move.
// Limit.
double limitV = 0.0;
// Violation (normalized to 100 * 1 block, applies if > 0.0).
double resultV = 0.0;
// Distinguish checking method by y-direction of the move.
if (yDistance > 0.0) {
// Ascend.
double[] res = vDistAscend(from, to, yDistance, flying, thisMove, lastMove, model, data, cc);
resultV = Math.max(resultV, res[1]);
limitV = res[0];
} else if (yDistance < 0.0) {
// Descend.
double[] res = vDistDescend(from, to, yDistance, flying, lastMove, model, data, cc);
resultV = Math.max(resultV, res[1]);
limitV = res[0];
} else {
// Keep altitude.
double[] res = vDistZero(from, to, yDistance, flying, lastMove, model, data, cc);
resultV = Math.max(resultV, res[1]);
limitV = res[0];
}
// Velocity.
if (resultV > 0.0 && data.getOrUseVerticalVelocity(yDistance) != null) {
resultV = 0.0;
tags.add("vvel");
}
// Add tag for maximum height check (silent set back).
final double maximumHeight = model.getMaxHeight() + player.getWorld().getMaxHeight();
if (to.getY() > maximumHeight) {
// TODO: Allow use velocity there (would need a flag to signal the actual check below)?
tags.add("maxheight");
}
// Normalize to % of a block.
resultV *= 100.0;
if (resultV > 0.0) {
tags.add("vdist");
}
final double result = Math.max(0.0, resultH) + Math.max(0.0, resultV);
if (debug) {
outpuDebugMove(player, hDistance, limitH, yDistance, limitV, model, tags, data);
}
// Violation handling.
// Might get altered below.
Location setBack = null;
if (result > 0.0) {
// Increment violation level.
data.creativeFlyVL += result;
// Execute whatever actions are associated with this check and the violation level and find out if we
// should cancel the event.
final ViolationData vd = new ViolationData(this, player, data.creativeFlyVL, result, cc.creativeFlyActions);
if (vd.needsParameters()) {
vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
if (!tags.isEmpty()) {
vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
}
}
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.
// (OK)
setBack = data.getSetBack(to);
}
} else {
// Maximum height check (silent set back).
if (to.getY() > maximumHeight) {
// (OK)
setBack = data.getSetBack(to);
if (debug) {
debug(player, "Maximum height exceeded, silent set-back.");
}
}
if (setBack == null) {
// Slowly reduce the violation level with each event.
data.creativeFlyVL *= 0.97;
}
}
// Return setBack, if set.
if (setBack != null) {
// Check for max height of the set back.
if (setBack.getY() > maximumHeight) {
// Correct the y position.
setBack.setY(getCorrectedHeight(maximumHeight, setBack.getWorld()));
if (debug) {
debug(player, "Maximum height exceeded by set back, correct to: " + setBack.getY());
}
}
data.sfJumpPhase = 0;
return setBack;
} else {
// Adjust the set back and other last distances.
data.setSetBack(to);
// Adjust jump phase.
if (!thisMove.from.onGroundOrResetCond && !thisMove.to.onGroundOrResetCond) {
data.sfJumpPhase++;
} else if (thisMove.touchedGround && !thisMove.to.onGroundOrResetCond) {
data.sfJumpPhase = 1;
} else {
data.sfJumpPhase = 0;
}
return null;
}
}
use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.
the class Passable method actualViolation.
private Location actualViolation(final Player player, final PlayerLocation from, final PlayerLocation to, final String tags, final boolean debug, final MovingData data, final MovingConfig cc) {
// Alternative to from.getLocation().
Location setBackLoc = null;
// Prefer the set back location from the data.
if (data.hasSetBack()) {
/*
* TODO: Harmonize with MovingUtil.getApplicableSetBackLocation
* (somehow include the desired set back type / loc / context).
*/
// TODO
setBackLoc = data.getSetBack(to);
if (debug) {
debug(player, "Using set back location for passable.");
}
}
// Return the reset position.
data.passableVL += 1d;
final ViolationData vd = new ViolationData(this, player, data.passableVL, 1, cc.passableActions);
if (debug || vd.needsParameters()) {
vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
if (!tags.isEmpty()) {
vd.setParameter(ParameterName.TAGS, tags);
}
}
if (executeActions(vd).willCancel()) {
// TODO: Consider another set back position for this, also keeping track of players moving around in blocks.
final Location newTo;
if (setBackLoc != null) {
// Ensure the given location is cloned.
newTo = LocUtil.clone(setBackLoc);
} else {
newTo = from.getLocation();
if (debug) {
debug(player, "Using from location for passable.");
}
}
newTo.setYaw(to.getYaw());
newTo.setPitch(to.getPitch());
return newTo;
} else {
// No cancel action set.
return null;
}
}
use of fr.neatmonster.nocheatplus.checks.ViolationData in project NoCheatPlus by NoCheatPlus.
the class InstantEat method check.
/**
* Checks a player.
*
* @param player
* the player
* @param level
* the level
* @return true, if successful
*/
public boolean check(final Player player, final int level) {
// Take time once.
final long time = System.currentTimeMillis();
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
boolean cancel = false;
// Hunger level change seems to not be the result of eating.
if (data.instantEatFood == null || level <= player.getFoodLevel())
return false;
// Rough estimation about how long it should take to eat
final long expectedTimeWhenEatingFinished = Math.max(data.instantEatInteract, data.lastClickTime) + 700L;
if (data.instantEatInteract > 0 && expectedTimeWhenEatingFinished < time) {
// Acceptable, reduce VL to reward the player.
data.instantEatVL *= 0.6D;
} else if (data.instantEatInteract > time) {
// Security test, if time ran backwards.
} else {
final double difference = (expectedTimeWhenEatingFinished - time) / 100D;
// Player was too fast, increase their violation level.
data.instantEatVL += difference;
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
final ViolationData vd = new ViolationData(this, player, data.instantEatVL, difference, pData.getGenericInstance(InventoryConfig.class).instantEatActions);
if (data.instantEatFood != null) {
vd.setParameter(ParameterName.FOOD, data.instantEatFood.toString());
}
cancel = executeActions(vd).willCancel();
}
data.instantEatInteract = 0;
data.instantEatFood = null;
return cancel;
}
Aggregations