Hot fix for bounding box problems.

This commit is contained in:
asofold 2012-11-08 06:02:22 +01:00
parent 22f2a5c248
commit 462aeed412
5 changed files with 447 additions and 383 deletions

View File

@ -5,6 +5,7 @@ import org.bukkit.potion.PotionEffectType;
import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask; import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation; import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
@ -45,6 +46,11 @@ public class Critical extends Check {
// We'll need the PlayerLocation to know some important stuff. // We'll need the PlayerLocation to know some important stuff.
final PlayerLocation location = new PlayerLocation(); final PlayerLocation location = new PlayerLocation();
location.set(player.getLocation(), player); location.set(player.getLocation(), player);
if (location.isIllegal()) {
location.cleanup();
CheckUtils.onIllegalMove(player);
return true;
}
// Check if the hit was a critical hit (positive fall distance, entity in the air, not on ladder, not in liquid // Check if the hit was a critical hit (positive fall distance, entity in the air, not on ladder, not in liquid
// and without blindness effect). // and without blindness effect).

View File

@ -45,6 +45,7 @@ import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.permissions.Permissions; import fr.neatmonster.nocheatplus.permissions.Permissions;
import fr.neatmonster.nocheatplus.utilities.BlockCache; import fr.neatmonster.nocheatplus.utilities.BlockCache;
import fr.neatmonster.nocheatplus.utilities.BlockProperties; import fr.neatmonster.nocheatplus.utilities.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation; import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/* /*
@ -355,8 +356,30 @@ public class MovingListener implements Listener {
final MovingConfig cc = MovingConfig.getConfig(player); final MovingConfig cc = MovingConfig.getConfig(player);
moveInfo.set(player, from, to, cc.yOnGround); moveInfo.set(player, from, to, cc.yOnGround);
final MovingData data = MovingData.getData(player); final MovingData data = MovingData.getData(player);
if (pFrom.isIllegal() || pTo.isIllegal()) {
moveInfo.cleanup();
parkedInfo.add(moveInfo);
CheckUtils.onIllegalMove(player);
if (data.setBack != null){
event.setFrom(data.setBack);
event.setTo(data.setBack);
}
else{
pFrom.set(player.getLocation(), player);
if (!pFrom.isIllegal()){
event.setFrom(pFrom.getLocation());
event.setTo(pFrom.getLocation());
}
else{
NoCheatPlus.denyLogin(player.getName(), 24L*60L*60L*1000L);
CheckUtils.logSevere("[NCP] could not restore location for " + player.getName() + " deny login for 24 hours");
}
pFrom.cleanup();
}
return;
}
data.noFallAssumeGround = false; data.noFallAssumeGround = false;
data.teleported = null; data.teleported = null;

View File

@ -863,6 +863,11 @@ public class BlockProperties {
// return blockId != 0 && net.minecraft.server.Block.byId[blockId].//.c();// d(); // return blockId != 0 && net.minecraft.server.Block.byId[blockId].//.c();// d();
// Bit fat workaround, maybe put the object through from check listener ? // Bit fat workaround, maybe put the object through from check listener ?
pLoc.set(location, player, 0.3); pLoc.set(location, player, 0.3);
if (pLoc.isIllegal()) {
pLoc.cleanup();
CheckUtils.onIllegalMove(player);
return false;
}
final boolean onGround = pLoc.isOnGround(); final boolean onGround = pLoc.isOnGround();
pLoc.cleanup(); pLoc.cleanup();
return onGround; return onGround;

View File

@ -328,4 +328,9 @@ public class CheckUtils {
return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight); return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
} else return mcEntity.height; } else return mcEntity.height;
} }
public static void onIllegalMove(final Player player){
player.kickPlayer("Illegal move.");
logWarning("[NCP] Disconnect " + player.getName() + " due to illegal move!");
}
} }

View File

@ -37,7 +37,8 @@ import org.bukkit.util.Vector;
* MMMMMMMMMMM * MMMMMMMMMMM
*/ */
/** /**
* An utility class used to know a lot of things for a player and a location given. * An utility class used to know a lot of things for a player and a location
* given.
*/ */
public class PlayerLocation { public class PlayerLocation {
@ -180,6 +181,7 @@ public class PlayerLocation {
/** /**
* Compares block coordinates (not the world). * Compares block coordinates (not the world).
*
* @param other * @param other
* @return * @return
*/ */
@ -189,6 +191,7 @@ public class PlayerLocation {
/** /**
* Compares exact coordinates (not the world). * Compares exact coordinates (not the world).
*
* @param loc * @param loc
* @return * @return
*/ */
@ -198,6 +201,7 @@ public class PlayerLocation {
/** /**
* Compares exact coordinates (not the world). * Compares exact coordinates (not the world).
*
* @param loc * @param loc
* @return * @return
*/ */
@ -212,7 +216,8 @@ public class PlayerLocation {
*/ */
public boolean isAboveStairs() { public boolean isAboveStairs() {
if (aboveStairs == null) { if (aboveStairs == null) {
// aboveStairs = BlockProperties.isStairs(getTypeIdBelow().intValue()); // aboveStairs =
// BlockProperties.isStairs(getTypeIdBelow().intValue());
// TODO: maybe distinguish upside down stairs and normal stairs ! // TODO: maybe distinguish upside down stairs and normal stairs !
final double diff = getWidth() + 0.001; final double diff = getWidth() + 0.001;
aboveStairs = BlockProperties.collides(getBlockAccess(), x - diff, y + 0.25, z - diff, x + diff, y - 1.0, z + diff, BlockProperties.F_STAIRS); aboveStairs = BlockProperties.collides(getBlockAccess(), x - diff, y + 0.25, z - diff, x + diff, y - 1.0, z + diff, BlockProperties.F_STAIRS);
@ -260,7 +265,6 @@ public class PlayerLocation {
return isInLava() || isInWater(); return isInLava() || isInWater();
} }
/** /**
* Checks if the player is on ice. * Checks if the player is on ice.
* *
@ -269,10 +273,8 @@ public class PlayerLocation {
public boolean isOnIce() { public boolean isOnIce() {
if (onIce == null) { if (onIce == null) {
final org.bukkit.entity.Player entity = this.entityPlayer.getBukkitEntity(); final org.bukkit.entity.Player entity = this.entityPlayer.getBukkitEntity();
if (entity.isSneaking() || entity.isBlocking()) if (entity.isSneaking() || entity.isBlocking()) onIce = getTypeId(blockX, Location.locToBlock(minY - 0.1D), blockZ) == Material.ICE.getId();
onIce = getTypeId(blockX, Location.locToBlock(minY - 0.1D), blockZ) == Material.ICE.getId(); else onIce = getTypeIdBelow().intValue() == Material.ICE.getId();
else
onIce = getTypeIdBelow().intValue() == Material.ICE.getId();
} }
return onIce; return onIce;
} }
@ -368,6 +370,7 @@ public class PlayerLocation {
/** /**
* Simple at the spot passability test, no bounding boxes. * Simple at the spot passability test, no bounding boxes.
*
* @return * @return
*/ */
public boolean isPassable() { public boolean isPassable() {
@ -377,11 +380,13 @@ public class PlayerLocation {
/** /**
* Convenience method: delegate to BlockProperties.isDoppwnStream . * Convenience method: delegate to BlockProperties.isDoppwnStream .
*
* @param xDistance * @param xDistance
* @param zDistance * @param zDistance
* @return * @return
*/ */
public boolean isDownStream(final double xDistance, final double zDistance){ public boolean isDownStream(final double xDistance, final double zDistance)
{
return BlockProperties.isDownStream(getBlockAccess(), blockX, blockY, blockZ, getData(), xDistance, zDistance); return BlockProperties.isDownStream(getBlockAccess(), blockX, blockY, blockZ, getData(), xDistance, zDistance);
} }
@ -390,7 +395,6 @@ public class PlayerLocation {
return typeId; return typeId;
} }
public Integer getTypeIdBelow() { public Integer getTypeIdBelow() {
if (typeIdBelow == null) typeIdBelow = getTypeId(blockX, blockY - 1, blockZ); if (typeIdBelow == null) typeIdBelow = getTypeId(blockX, blockY - 1, blockZ);
return typeIdBelow; return typeIdBelow;
@ -403,6 +407,7 @@ public class PlayerLocation {
/** /**
* Uses id cache if present. * Uses id cache if present.
*
* @param x * @param x
* @param y * @param y
* @param z * @param z
@ -414,6 +419,7 @@ public class PlayerLocation {
/** /**
* Uses id cache if present. * Uses id cache if present.
*
* @param x * @param x
* @param y * @param y
* @param z * @param z
@ -429,6 +435,7 @@ public class PlayerLocation {
/** /**
* Set the id cache for faster id getting. * Set the id cache for faster id getting.
*
* @param cache * @param cache
*/ */
public void setBlockCache(final BlockCache cache) { public void setBlockCache(final BlockCache cache) {
@ -498,7 +505,8 @@ public class PlayerLocation {
typeId = typeIdBelow = data = null; typeId = typeIdBelow = data = null;
aboveStairs = inLava = inWater = inWeb = onGround = onIce = onLadder = passable = null; aboveStairs = inLava = inWater = inWeb = onGround = onIce = onLadder = passable = null;
// TODO: Consider blockCache.setAccess? <- currently rather not, because it might be anything. // TODO: Consider blockCache.setAccess? <- currently rather not, because
// it might be anything.
this.setyOnGround(yFreedom); this.setyOnGround(yFreedom);
} }
@ -513,4 +521,21 @@ public class PlayerLocation {
blockCache = null; // No reset here. blockCache = null; // No reset here.
} }
/**
* Attempt to check for some exploits (!).
*
* @return
*/
public boolean isIllegal() {
if (entityPlayer.dead) return false;
if (!entityPlayer.isSleeping()){
// This can not really test stance but height of bounding box.
final double dY = Math.abs(maxY - minY);
if (dY > 1.8) return true; // dY > 1.65D ||
if (dY < 0.1D) return true;
}
if (Math.abs(minX) > 3.2E7D || Math.abs(maxX) > 3.2E7D || Math.abs(minZ) > 3.2E7D || Math.abs(maxZ) > 3.2E7D) return true;
return false;
}
} }