use of fr.neatmonster.nocheatplus.utilities.location.PlayerLocation in project NoCheatPlus by NoCheatPlus.
the class MovingListener method outputMoveDebug.
/**
* Output information specific to player-move events.
* @param player
* @param from
* @param to
* @param mcAccess
*/
private void outputMoveDebug(final Player player, final PlayerLocation from, final PlayerLocation to, final double maxYOnGround, final MCAccess mcAccess) {
final StringBuilder builder = new StringBuilder(250);
final Location loc = player.getLocation();
builder.append(CheckUtils.getLogMessagePrefix(player, checkType));
builder.append("MOVE in world " + from.getWorld().getName() + ":\n");
DebugUtil.addMove(from, to, loc, builder);
final double jump = mcAccess.getJumpAmplifier(player);
final double speed = mcAccess.getFasterMovementAmplifier(player);
final double strider = BridgeEnchant.getDepthStriderLevel(player);
if (BuildParameters.debugLevel > 0) {
try {
// TODO: Check backwards compatibility (1.4.2). Remove try-catch
builder.append("\n(walkspeed=" + player.getWalkSpeed() + " flyspeed=" + player.getFlySpeed() + ")");
} catch (Throwable t) {
}
if (player.isSprinting()) {
builder.append("(sprinting)");
}
if (player.isSneaking()) {
builder.append("(sneaking)");
}
if (player.isBlocking()) {
builder.append("(blocking)");
}
final Vector v = player.getVelocity();
if (v.lengthSquared() > 0.0) {
builder.append("(svel=" + v.getX() + "," + v.getY() + "," + v.getZ() + ")");
}
}
if (!Double.isInfinite(speed)) {
builder.append("(e_speed=" + (speed + 1) + ")");
}
final double slow = PotionUtil.getPotionEffectAmplifier(player, PotionEffectType.SLOW);
if (!Double.isInfinite(slow)) {
builder.append("(e_slow=" + (slow + 1) + ")");
}
if (!Double.isInfinite(jump)) {
builder.append("(e_jump=" + (jump + 1) + ")");
}
if (strider != 0) {
builder.append("(e_depth_strider=" + strider + ")");
}
if (Bridge1_9.isGliding(player)) {
builder.append("(gliding)");
}
if (player.getAllowFlight()) {
builder.append("(allow_flight)");
}
if (player.isFlying()) {
builder.append("(flying)");
}
// Print basic info first in order
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, builder.toString());
// Extended info.
if (BuildParameters.debugLevel > 0) {
builder.setLength(0);
// Note: the block flags are for normal on-ground checking, not with yOnGrond set to 0.5.
from.collectBlockFlags(maxYOnGround);
if (from.getBlockFlags() != 0) {
builder.append("\nfrom flags: " + StringUtil.join(BlockProperties.getFlagNames(from.getBlockFlags()), "+"));
}
if (from.getTypeId() != Material.AIR) {
DebugUtil.addBlockInfo(builder, from, "\nfrom");
}
if (from.getTypeIdBelow() != Material.AIR) {
DebugUtil.addBlockBelowInfo(builder, from, "\nfrom");
}
if (!from.isOnGround() && from.isOnGround(0.5)) {
builder.append(" (ground within 0.5)");
}
to.collectBlockFlags(maxYOnGround);
if (to.getBlockFlags() != 0) {
builder.append("\nto flags: " + StringUtil.join(BlockProperties.getFlagNames(to.getBlockFlags()), "+"));
}
if (to.getTypeId() != Material.AIR) {
DebugUtil.addBlockInfo(builder, to, "\nto");
}
if (to.getTypeIdBelow() != Material.AIR) {
DebugUtil.addBlockBelowInfo(builder, to, "\nto");
}
if (!to.isOnGround() && to.isOnGround(0.5)) {
builder.append(" (ground within 0.5)");
}
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, builder.toString());
}
}
use of fr.neatmonster.nocheatplus.utilities.location.PlayerLocation in project NoCheatPlus by NoCheatPlus.
the class LostGround method lostGroundDescend.
/**
* Check if a ground-touch has been lost due to event-sending-frequency or
* other reasons.<br>
* This is for descending "mildly" only (-0.5 <= yDistance <= 0). Needs last
* move data.
*
* @param player
* @param from
* @param to
* @param hDistance
* @param yDistance
* @param sprinting
* @param data
* @param cc
* @return
*/
private static boolean lostGroundDescend(final Player player, final PlayerLocation from, final PlayerLocation to, final double hDistance, final double yDistance, final boolean sprinting, final PlayerMoveData lastMove, final MovingData data, final MovingConfig cc, final Collection<String> tags) {
// TODO: re-organize for faster exclusions (hDistance, yDistance).
// TODO: more strict conditions
final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
final double setBackYDistance = to.getY() - data.getSetBackY();
// Note: checking loc should make sense, rather if loc is higher than from?
if (yDistance < 0.0 && !to.isOnGround() && from.isOnGround(from.getY() - to.getY() + 0.001)) {
// Test for passability of the entire box, roughly from feet downwards.
// TODO: Efficiency with Location instances.
// TODO: Full bounds check (!).
final Location ref = from.getLocation();
ref.setY(to.getY());
// TODO: passable test is obsolete with PassableAxisTracing.
if (Passable.isPassable(from.getLocation(), ref)) {
// TODO: Needs new model (store detailed on-ground properties).
return applyLostGround(player, from, false, thisMove, data, "vcollide", tags);
}
}
if (!lastMove.toIsValid) {
return false;
}
if (data.sfJumpPhase <= 7) {
// Check for sprinting down blocks etc.
if (lastMove.yDistance <= yDistance && setBackYDistance < 0 && !to.isOnGround()) {
// TODO: account for half steps !?
if (from.isOnGround(0.6, 0.4, 0.0, 0L)) {
// TODO: Seems to virtually always be preceded by a "vcollide" move.
return applyLostGround(player, from, true, thisMove, data, "pyramid", tags);
}
}
// Check for jumping up strange blocks like flower pots on top of other blocks.
if (yDistance == 0.0 && lastMove.yDistance > 0.0 && lastMove.yDistance < 0.25 && data.sfJumpPhase <= Math.max(0, 6 + data.jumpAmplifier * 3.0) && setBackYDistance > 1.0 && setBackYDistance < Math.max(0.0, 1.5 + 0.2 * data.jumpAmplifier) && !to.isOnGround()) {
// TODO: confine by block types ?
if (from.isOnGround(0.25, 0.4, 0, 0L)) {
// data.sfThisAllowBunny = true;
return applyLostGround(player, from, true, thisMove, data, "ministep", tags);
}
}
}
// Lost ground while falling onto/over edges of blocks.
if (yDistance < 0 && hDistance <= 1.5 && lastMove.yDistance < 0.0 && yDistance > lastMove.yDistance && !to.isOnGround()) {
// if (to.isOnGround(0.5) || from.isOnGround(0.5)) {
if (from.isOnGround(0.5, 0.2, 0) || to.isOnGround(0.5, Math.min(0.2, 0.01 + hDistance), Math.min(0.1, 0.01 + -yDistance))) {
return applyLostGround(player, from, true, thisMove, data, "edgedesc", tags);
}
}
// Nothing found.
return false;
}
use of fr.neatmonster.nocheatplus.utilities.location.PlayerLocation 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.utilities.location.PlayerLocation 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.utilities.location.PlayerLocation in project NoCheatPlus by NoCheatPlus.
the class BlockProperties method init.
/**
* Initialize blocks and tools properties. This can be called at any time
* during runtime.
*
* @param mcAccess
* If mcAccess implements BlockPropertiesSetup,
* mcAccess.setupBlockProperties will be called directly after
* basic initialization but before the configuration is applied.
* @param worldConfigProvider
* the world config provider
*/
public static void init(final IHandle<MCAccess> mcAccess, final WorldConfigProvider<?> worldConfigProvider) {
wrapBlockCache = new WrapBlockCache();
rtRay = new PassableRayTracing();
rtAxis = new PassableAxisTracing();
pLoc = new PlayerLocation(mcAccess, null);
// getClass().getName() or some abstract.
final Set<String> blocksFeatures = new LinkedHashSet<String>();
try {
initTools(mcAccess, worldConfigProvider);
initBlocks(mcAccess, worldConfigProvider);
blocksFeatures.add("BlocksMC1_4");
// Extra hand picked setups.
try {
blocksFeatures.addAll(new VanillaBlocksFactory().setupVanillaBlocks(worldConfigProvider));
} catch (Throwable t) {
StaticLog.logSevere("Could not initialize vanilla blocks: " + t.getClass().getSimpleName() + " - " + t.getMessage());
StaticLog.logSevere(t);
}
// Allow mcAccess to setup block properties.
if (mcAccess instanceof BlockPropertiesSetup) {
try {
((BlockPropertiesSetup) mcAccess).setupBlockProperties(worldConfigProvider);
blocksFeatures.add(mcAccess.getClass().getSimpleName());
} catch (Throwable t) {
StaticLog.logSevere("McAccess.setupBlockProperties (" + mcAccess.getClass().getSimpleName() + ") could not execute properly: " + t.getClass().getSimpleName() + " - " + t.getMessage());
StaticLog.logSevere(t);
}
}
// TODO: Add registry for further BlockPropertiesSetup instances.
} catch (Throwable t) {
StaticLog.logSevere(t);
}
// Override feature tags for blocks.
NCPAPIProvider.getNoCheatPlusAPI().setFeatureTags("blocks", blocksFeatures);
}
Aggregations