/** * Test the move split into y-move and horizontal move, provided some pre-conditions are met. * * @param from * @param to * @param manhattan * @return */ private boolean allowsSplitMove( final PlayerLocation from, final PlayerLocation to, int manhattan) { final double yDiff = to.getY() - from.getY(); if (manhattan <= 3 && yDiff > 0.0 && Math.abs(yDiff) < 1.0) { // Workaround for client-side calculations not being possible (y vs. horizontal move). // TODO: Alternative: Test if "real" ray-tracing would fix it (might not!). if (yDiff > 0.0) { // y first. rayTracing.set(from.getX(), from.getY(), from.getZ(), from.getX(), to.getY(), from.getZ()); rayTracing.loop(); if (!rayTracing.collides()) { // horizontal second. rayTracing.set(from.getX(), to.getY(), from.getZ(), to.getX(), to.getY(), to.getZ()); rayTracing.loop(); if (!rayTracing.collides()) { return true; } } } else { // horizontal first. rayTracing.set(from.getX(), from.getY(), from.getZ(), to.getX(), from.getY(), to.getZ()); rayTracing.loop(); if (!rayTracing.collides()) { // y second. rayTracing.set(to.getX(), from.getY(), to.getZ(), to.getX(), to.getY(), to.getZ()); rayTracing.loop(); if (!rayTracing.collides()) { return true; } } } } return false; }
/** * Add exact coordinates, multiple lines. No leading new line. * * @param from * @param to * @param loc Reference location for from, usually Player.getLocation(). * @param builder */ public static void addMove( final PlayerLocation from, final PlayerLocation to, final Location loc, final StringBuilder builder) { if (loc != null && !from.isSamePos(loc)) { builder.append("Location: "); addLocation(loc, builder); builder.append("\n"); } addMove(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), builder); }
private Location potentialViolation( final Player player, final Location loc, final PlayerLocation from, final PlayerLocation to, final int manhattan, String tags, final MovingData data, final MovingConfig cc) { // Moving into a block, possibly a violation. // Check the players location if different from others. // (It provides a better set-back for some exploits.) final int lbX = loc.getBlockX(); final int lbY = loc.getBlockY(); final int lbZ = loc.getBlockZ(); Location setBackLoc = null; // Alternative to from.getLocation(). // First check if the player is moving from a passable location. // If not, the move might still be allowed, if moving inside of the same block, or from and to // have head position passable. if (from.isPassable()) { // Put one workaround for 1.5 high blocks here: if (from.isBlockAbove(to) && (BlockProperties.getBlockFlags(to.getTypeId()) & BlockProperties.F_HEIGHT150) != 0) { // Check if the move went from inside of the block. if (BlockProperties.collidesBlock( to.getBlockCache(), from.getX(), from.getY(), from.getZ(), from.getX(), from.getY(), from.getZ(), to.getBlockX(), to.getBlockY(), to.getBlockZ(), to.getTypeId())) { // Allow moving inside of 1.5 high blocks. return null; } } // From should be the set-back. tags += "into"; } else if (BlockProperties.isPassable( from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { // Keep loc, because it it is passable. tags += "into_shift"; setBackLoc = loc; } // } else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(), // loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { // (Mind that this can be the case on the same block theoretically.) // Keep loc as set-back. // } else if (!from.isSameBlock(lbX, lbY, lbZ)) { // Both loc and from are not passable. Use from as set.back (earliest). tags += "cross_shift"; } else if (manhattan == 1 && to.isBlockAbove(from) && BlockProperties.isPassable( from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId( from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))) { // else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(), // from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), // from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), // from.getBlockZ()))) { // Allow the move up if the head is free. // TODO: Better distinguish ray-tracing (through something thin) or check to-head-passable // too? return null; } else if (manhattan > 0) { // Otherwise keep from as set-back. tags += "cross"; } else { // All blocks are the same, allow the move. return null; } // Discard inconsistent locations. // TODO: Might get rid of using the in-between loc - needs use-case checking. if (setBackLoc != null && (TrigUtil.distance(from, to) > 0.75 || TrigUtil.distance(from, setBackLoc) > 0.125)) { setBackLoc = null; } // Prefer the set-back location from the data. if (data.hasSetBack()) { // TODO: Review or make configurable. final Location ref = data.getSetBack(to); if (BlockProperties.isPassable(from.getBlockCache(), ref) || setBackLoc == null || TrigUtil.distance(from, setBackLoc) > 0.13) { // if (BlockProperties.isPassableExact(from.getBlockCache(), ref)) { setBackLoc = ref; if (data.debug) { NCPAPIProvider.getNoCheatPlusAPI() .getLogManager() .debug( Streams.TRACE_FILE, player.getName() + " Using set-back location for passable."); } } else if (data.debug) { NCPAPIProvider.getNoCheatPlusAPI() .getLogManager() .debug(Streams.TRACE_FILE, player.getName() + " Ignoring set-back for passable."); } } // TODO: set data.set-back ? or something: still some aji here. // Return the reset position. data.passableVL += 1d; final ViolationData vd = new ViolationData(this, player, data.passableVL, 1, cc.passableActions); if (data.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))); // TODO: Consider adding from.getTypeId() too, if blocks differ and non-air. vd.setParameter(ParameterName.BLOCK_ID, "" + to.getTypeId()); if (!tags.isEmpty()) { vd.setParameter(ParameterName.TAGS, tags); } } if (executeActions(vd)) { // 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 (data.debug) { NCPAPIProvider.getNoCheatPlusAPI() .getLogManager() .debug(Streams.TRACE_FILE, player.getName() + " Using from location for passable."); } } newTo.setYaw(to.getYaw()); newTo.setPitch(to.getPitch()); return newTo; } else { // No cancel action set. return null; } }
/** * Compares exact coordinates (not the world). * * @param loc * @return */ public boolean isSamePos(final PlayerLocation loc) { return x == loc.getX() && z == loc.getZ() && y == loc.getY(); }
public static void addFormattedLocation(final PlayerLocation loc, final StringBuilder builder) { addFormattedLocation(loc.getX(), loc.getY(), loc.getZ(), builder); }
private Location potentialViolation( final Player player, Location loc, final PlayerLocation from, final PlayerLocation to, final int manhattan, String tags, final MovingData data, final MovingConfig cc) { // Moving into a block, possibly a violation. // Check the players location if different from others. // (It provides a better set-back for some exploits.) final int lbX = loc.getBlockX(); final int lbY = loc.getBlockY(); final int lbZ = loc.getBlockZ(); // First check if the player is moving from a passable location. // If not, the move might still be allowed, if moving inside of the same block, or from and to // have head position passable. if (from.isPassable()) { // Put one workaround for 1.5 high blocks here: if (from.isBlockAbove(to) && (BlockProperties.getBlockFlags(to.getTypeId()) & BlockProperties.F_HEIGHT150) != 0) { // Check if the move went from inside of the block. if (BlockProperties.collidesBlock( to.getBlockCache(), from.getX(), from.getY(), from.getZ(), from.getX(), from.getY(), from.getZ(), to.getBlockX(), to.getBlockY(), to.getBlockZ(), to.getTypeId())) { // Allow moving inside of 1.5 high blocks. return null; } } // From should be the set-back. loc = null; tags += "into"; } else if (BlockProperties.isPassable( from.getBlockCache(), loc.getX(), loc.getY(), loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { tags += "into_shift"; } // } else if (BlockProperties.isPassableExact(from.getBlockCache(), loc.getX(), loc.getY(), // loc.getZ(), from.getTypeId(lbX, lbY, lbZ))) { // (Mind that this can be the case on the same block theoretically.) // Keep loc as set-back. // } else if (!from.isSameBlock(lbX, lbY, lbZ)) { // Otherwise keep loc as set-back. tags += "cross_shift"; } else if (manhattan == 1 && to.isBlockAbove(from) && BlockProperties.isPassable( from.getBlockCache(), from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), from.getTypeId( from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), from.getBlockZ()))) { // else if (to.isBlockAbove(from) && BlockProperties.isPassableExact(from.getBlockCache(), // from.getX(), from.getY() + player.getEyeHeight(), from.getZ(), // from.getTypeId(from.getBlockX(), Location.locToBlock(from.getY() + player.getEyeHeight()), // from.getBlockZ()))) { // Allow the move up if the head is free. return null; } else if (manhattan > 0) { // Otherwise keep from as set-back. loc = null; tags += "cross"; } else { // All blocks are the same, allow the move. return null; } // Discard inconsistent locations. // TODO: Might get rid of using the in-between loc - needs use-case checking. if (loc != null && (TrigUtil.distance(from, to) > 0.75 || TrigUtil.distance(from, loc) > 0.125)) { loc = null; } // Prefer the set-back location from the data. if (data.hasSetBack()) { final Location ref = data.getSetBack(to); if (BlockProperties.isPassable(from.getBlockCache(), ref) || loc == null || TrigUtil.distance(from, loc) > 0.13) { // if (BlockProperties.isPassableExact(from.getBlockCache(), ref)) { loc = ref; if (cc.debug) { System.out.println(player.getName() + " Using set-back location for passable."); } } else if (cc.debug) { System.out.println(player.getName() + " Ignoring set-back for passable."); } } // TODO: set data.set-back ? or something: still some aji here. // Return the reset position. data.passableVL += 1d; final ViolationData vd = new ViolationData(this, player, data.passableVL, 1, cc.passableActions); if (cc.debug || vd.needsParameters()) { vd.setParameter(ParameterName.BLOCK_ID, "" + to.getTypeId()); if (!tags.isEmpty()) { vd.setParameter(ParameterName.TAGS, tags); } } if (executeActions(vd)) { // TODO: Consider another set back position for this, also keeping track of players moving // around in blocks. final Location newTo; if (loc != null) { // Ensure the given location is cloned. newTo = LocUtil.clone(loc); } else { newTo = from.getLocation(); if (cc.debug) { System.out.println(player.getName() + " Using from location for passable."); } } newTo.setYaw(to.getYaw()); newTo.setPitch(to.getPitch()); return newTo; } else { // No cancel action set. return null; } }