Use the lower eye height when gliding with elytra (selected checks).

* Block checks (interact/place/break): reach and direction.
* Random other places, like BlockProperties.getBreakingDuration.
This commit is contained in:
asofold 2017-05-09 22:04:18 +02:00
parent 344b032d49
commit 0c6cb6577d
10 changed files with 54 additions and 31 deletions

View File

@ -160,12 +160,13 @@ public class BlockBreakListener extends CheckListener {
if (cc.reachCheck || cc.directionCheck) {
flyingHandle = new FlyingQueueHandle(player);
final Location loc = player.getLocation(useLoc);
final double eyeHeight = MovingUtil.getEyeHeight(player);
// Is the block really in reach distance?
if (!cancelled) {
if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_REACH)) {
skippedRedundantChecks ++;
}
else if (reach.isEnabled(player) && reach.check(player, block, data)) {
else if (reach.isEnabled(player) && reach.check(player, eyeHeight, block, data)) {
cancelled = true;
}
}
@ -177,8 +178,8 @@ public class BlockBreakListener extends CheckListener {
|| bdata.isPassedCheck(CheckType.BLOCKINTERACT_VISIBLE))) {
skippedRedundantChecks ++;
}
else if (direction.isEnabled(player) && direction.check(player, loc, block, flyingHandle,
data, cc)) {
else if (direction.isEnabled(player) && direction.check(player, loc, eyeHeight, block,
flyingHandle, data, cc)) {
cancelled = true;
}
}

View File

@ -55,7 +55,7 @@ public class Reach extends Check {
* the location
* @return true, if successful
*/
public boolean check(final Player player, final Block block, final BlockBreakData data) {
public boolean check(final Player player, final double eyeHeight, final Block block, final BlockBreakData data) {
boolean cancel = false;
@ -64,7 +64,7 @@ public class Reach extends Check {
// Distance is calculated from eye location to center of targeted block. If the player is further away from their
// target than allowed, the difference will be assigned to "distance".
final Location loc = player.getLocation(useLoc);
loc.setY(loc.getY() + player.getEyeHeight());
loc.setY(loc.getY() + eyeHeight);
final double distance = TrigUtil.distance(loc, block) - distanceLimit;
useLoc.setWorld(null);

View File

@ -201,21 +201,22 @@ public class BlockInteractListener extends CheckListener {
}
if (blockChecks) {
final double eyeHeight = MovingUtil.getEyeHeight(player);
// First the reach check.
if (!cancelled && reach.isEnabled(player)
&& reach.check(player, loc, block, data, cc)) {
&& reach.check(player, loc, eyeHeight, block, data, cc)) {
cancelled = true;
}
// Second the direction check
if (!cancelled && direction.isEnabled(player)
&& direction.check(player, loc, block, flyingHandle, data, cc)) {
&& direction.check(player, loc, eyeHeight, block, flyingHandle, data, cc)) {
cancelled = true;
}
// Ray tracing for freecam use etc.
if (!cancelled && visible.isEnabled(player)
&& visible.check(player, loc, block, face, action, flyingHandle, data, cc)) {
&& visible.check(player, loc, eyeHeight, block, face, action, flyingHandle, data, cc)) {
cancelled = true;
}
}

View File

@ -52,7 +52,7 @@ public class Reach extends Check {
* the location
* @return true, if successful
*/
public boolean check(final Player player, final Location loc, final Block block,
public boolean check(final Player player, final Location loc, final double eyeHeight, final Block block,
final BlockInteractData data, final BlockInteractConfig cc) {
boolean cancel = false;
@ -62,7 +62,7 @@ public class Reach extends Check {
// Distance is calculated from eye location to center of targeted block. If the player is further away from their
// target than allowed, the difference will be assigned to "distance".
// TODO: On failure loop through flying queue, and do set not working entries to null (!).
final double distance = TrigUtil.distance(loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ(), 0.5 + block.getX(), 0.5 + block.getY(), 0.5 + block.getZ()) - distanceLimit;
final double distance = TrigUtil.distance(loc.getX(), loc.getY() + eyeHeight, loc.getZ(), 0.5 + block.getX(), 0.5 + block.getY(), 0.5 + block.getZ()) - distanceLimit;
if (distance > 0) {
// They failed, increment violation level.

View File

@ -111,8 +111,8 @@ public class Visible extends Check {
rayTracing.setMaxSteps(60); // TODO: Configurable ?
}
public boolean check(final Player player, final Location loc, final Block block, final BlockFace face,
final Action action, final FlyingQueueHandle flyingHandle,
public boolean check(final Player player, final Location loc, final double eyeHeight, final Block block,
final BlockFace face, final Action action, final FlyingQueueHandle flyingHandle,
final BlockInteractData data, final BlockInteractConfig cc) {
// TODO: This check might make parts of interact/blockbreak/... + direction (+?) obsolete.
// TODO: Might confine what to check for (left/right-click, target blocks depending on item in hand, container blocks).
@ -121,7 +121,7 @@ public class Visible extends Check {
final int blockY = block.getY();
final int blockZ = block.getZ();
final double eyeX = loc.getX();
final double eyeY = loc.getY() + player.getEyeHeight();
final double eyeY = loc.getY() + eyeHeight;
final double eyeZ = loc.getZ();
tags.clear();

View File

@ -208,12 +208,13 @@ public class BlockPlaceListener extends CheckListener {
if (cc.reachCheck || cc.directionCheck) {
flyingHandle = new FlyingQueueHandle(player);
final Location loc = player.getLocation(useLoc);
final double eyeHeight = MovingUtil.getEyeHeight(player);
// Reach check (distance).
if (!cancelled && !shouldSkipSome) {
if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_REACH)) {
skippedRedundantChecks ++;
}
else if (reach.isEnabled(player) && reach.check(player, block, data, cc)) {
else if (reach.isEnabled(player) && reach.check(player, eyeHeight, block, data, cc)) {
cancelled = true;
}
}
@ -223,8 +224,8 @@ public class BlockPlaceListener extends CheckListener {
if (isInteractBlock && bdata.isPassedCheck(CheckType.BLOCKINTERACT_DIRECTION)) {
skippedRedundantChecks ++;
}
else if (direction.isEnabled(player) && direction.check(player, loc, block, flyingHandle,
data, cc)) {
else if (direction.isEnabled(player) && direction.check(player, loc, eyeHeight, block,
flyingHandle, data, cc)) {
cancelled = true;
}
}

View File

@ -58,7 +58,8 @@ public class Reach extends Check {
* the location
* @return true, if successful
*/
public boolean check(final Player player, final Block block, final BlockPlaceData data, final BlockPlaceConfig cc) {
public boolean check(final Player player, final double eyeHeight, final Block block,
final BlockPlaceData data, final BlockPlaceConfig cc) {
boolean cancel = false;
@ -67,7 +68,7 @@ public class Reach extends Check {
// Distance is calculated from eye location to center of targeted block. If the player is further away from their
// target than allowed, the difference will be assigned to "distance".
final Location eyeLoc = player.getLocation(useLoc);
eyeLoc.setY(eyeLoc.getY() + player.getEyeHeight());
eyeLoc.setY(eyeLoc.getY() + eyeHeight);
final double distance = TrigUtil.distance(eyeLoc, block) - distanceLimit;
if (distance > 0) {

View File

@ -102,7 +102,10 @@ public abstract class AbstractBlockDirectionCheck<D extends ICheckData, C extend
*
* @param player
* @param loc
* Location of the player.
* Foot location to use as base for checking, with looking
* direction set.
* @param eyeHeight
* The eye height above the foot location.
* @param block
* The block the player is supposed to be looking at.
* @param flyingHandle
@ -110,13 +113,13 @@ public abstract class AbstractBlockDirectionCheck<D extends ICheckData, C extend
* @param cc
* @return True, if the check has been failed.
*/
public boolean check(final Player player, final Location loc, final Block block,
final FlyingQueueHandle flyingHandle, final D data, final C cc) {
public boolean check(final Player player, final Location loc, final double eyeHeight,
final Block block, final FlyingQueueHandle flyingHandle, final D data, final C cc) {
boolean cancel = false;
// How far "off" is the player with their aim.
final double x = loc.getX();
final double y = loc.getY() + player.getEyeHeight();
final double y = loc.getY() + eyeHeight;
final double z = loc.getZ();
final int blockX = block.getX();
final int blockY = block.getY();

View File

@ -19,6 +19,7 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
/**
@ -56,7 +57,7 @@ public class CollisionUtil {
{
final Location loc = player.getLocation(useLoc);
final Vector dir = loc.getDirection();
final double res = directionCheck(loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ(), dir.getX(), dir.getY(), dir.getZ(), targetX, targetY, targetZ, targetWidth, targetHeight, precision);
final double res = directionCheck(loc.getX(), loc.getY() + MovingUtil.getEyeHeight(player), loc.getZ(), dir.getX(), dir.getY(), dir.getZ(), targetX, targetY, targetZ, targetWidth, targetHeight, precision);
useLoc.setWorld(null);
return res;
}

View File

@ -39,6 +39,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.Bridge1_9;
import fr.neatmonster.nocheatplus.compat.MCAccess;
@ -1355,21 +1356,35 @@ public class BlockProperties {
}
/**
* TODO: repair signature some day (rid of PlayerLocation).
*
* Convenience method.
*
* @param blockId
* the block id
* @param itemInHand
* May be null.
* @param helmet
* May be null.
* @param player
* the player
* @param location
* The normal location of a player.
* @return the breaking duration
* @return
*/
public static long getBreakingDuration(final int blockId, final ItemStack itemInHand, final ItemStack helmet, final Player player, final Location location) {
public static long getBreakingDuration(final int blockId, final ItemStack itemInHand, final ItemStack helmet,
final Player player, final Location location) {
return getBreakingDuration(blockId, itemInHand, helmet, player, MovingUtil.getEyeHeight(player), location);
}
/**
* Convenience method.
* @param blockId
* @param itemInHand
* @param helmet
* @param player
* @param eyeHEight
* @param location
* @return
*/
public static long getBreakingDuration(final int blockId, final ItemStack itemInHand, final ItemStack helmet,
final Player player, final double eyeHeight, final Location location) {
final BlockCache blockCache = wrapBlockCache.getBlockCache();
blockCache.setAccess(location.getWorld());
pLoc.setBlockCache(blockCache);
@ -1379,7 +1394,7 @@ public class BlockProperties {
// Head in water.
final int bx = pLoc.getBlockX();
final int bz = pLoc.getBlockZ();
final double y = pLoc.getY() + player.getEyeHeight();
final double y = pLoc.getY() + eyeHeight;
final int by = Location.locToBlock(y);
final int headId = blockCache.getTypeId(bx, by, bz);
final long headFlags = blockFlags[headId];