Hover check: Check if chunks are loaded before triggering a violation.

This commit is contained in:
asofold 2013-04-21 19:48:04 +02:00
parent fa50f34023
commit 2334bc9f22
3 changed files with 59 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.utilities;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
@ -25,6 +26,32 @@ public abstract class BlockCache {
}
return true;
}
/**
* Check if chunks are loaded and load all not yet loaded chunks, using normal world coordinates.<br>
* NOTE: Not sure where to put this. Method does not use any caching.
* @param world
* @param x
* @param z
* @param xzMargin
* @return Number of loaded chunks.
*/
public static int ensureChunksLoaded(final World world, final double x, final double z, final double xzMargin) {
int loaded = 0;
final int minX = Location.locToBlock(x - xzMargin) / 16;
final int maxX = Location.locToBlock(x + xzMargin) / 16;
final int minZ = Location.locToBlock(z - xzMargin) / 16;
final int maxZ = Location.locToBlock(z + xzMargin) / 16;
for (int cx = minX; cx <= maxX; cx ++){
for (int cz = minZ; cz <= maxZ; cz ++){
if (!world.isChunkLoaded(cx * 16, cz * 16)){
world.loadChunk(cx * 16, cz * 16);
loaded ++;
}
}
}
return loaded;
}
/** Cached type-ids. */
private final CoordMap<Integer> idMap = new CoordMap<Integer>(23);

View File

@ -766,6 +766,23 @@ public class PlayerLocation {
final double xzM = 0; //0.001;
blockFlags = BlockProperties.collectFlagsSimple(blockCache, minX - xzM, minY - yExtra - maxYonGround, minZ - xzM, maxX + xzM, Math.max(maxY, minY + 1.5), maxZ + xzM);
}
/**
* Check chunks within 1 block distance for if they are loaded and load unloaded chunks.
* @return Number of chunks loaded.
*/
public int ensureChunksLoaded() {
return ensureChunksLoaded(1.0);
}
/**
* Check chunks within xzMargin radius for if they are loaded and load unloaded chunks.
* @param xzMargin
* @return Number of chunks loaded.
*/
public int ensureChunksLoaded(final double xzMargin) {
return BlockCache.ensureChunksLoaded(world, x, z, xzMargin);
}
/**
* Set some references to null.

View File

@ -1224,7 +1224,16 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
data.sfHoverLoginTicks = 0;
data.sfHoverTicks = -1;
}
// // Check loaded chunks.
// if (cc.loadChunksOnJoin){
// final int loaded = BlockCache.ensureChunksLoaded(loc.getWorld(), loc.getX(), loc.getZ(), 3.0);
// if (loaded > 0 && BuildParameters.debugLevel > 0){
// // DEBUG
// LogUtil.logInfo("[NoCheatPlus] Player join: Loaded " + loaded + " chunk" + (loaded == 1 ? "" : "s") + " for the world " + loc.getWorld().getName() + " for player: " + player.getName());
// }
// }
}
@Override
@ -1367,6 +1376,11 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
info.set(player, loc, null, cc.yOnGround);
final boolean res;
// TODO: Collect flags, more margin ?
final int loaded = info.from.ensureChunksLoaded();
if (loaded > 0 && BuildParameters.debugLevel > 0){
// DEBUG
LogUtil.logInfo("[NoCheatPlus] Hover check: Needed to load " + loaded + " chunk" + (loaded == 1 ? "" : "s") + " for the world " + loc.getWorld().getName() + " around " + loc.getBlockX() + "," + loc.getBlockZ() + " in order to check player: " + player.getName());
}
if (info.from.isOnGround() || info.from.isResetCond() || info.from.isAboveLadder() || info.from.isAboveStairs()){
res = true;
data.sfHoverTicks = 0;