Skip to content

Commit

Permalink
Hover check: Check if chunks are loaded before triggering a violation.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Apr 21, 2013
1 parent fa50f34 commit 2334bc9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
@@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.utilities;

import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;

Expand All @@ -25,6 +26,32 @@ public static final boolean isFullBounds(final double[] bounds) {
}
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);
Expand Down
Expand Up @@ -766,6 +766,23 @@ public void collectBlockFlags(double maxYonGround){
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.
Expand Down
Expand Up @@ -1224,7 +1224,16 @@ else if (data.hasSetBackWorldChanged(loc)){
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
Expand Down Expand Up @@ -1367,6 +1376,11 @@ private final boolean checkHover(final Player player, final MovingData data, fin
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;
Expand Down

0 comments on commit 2334bc9

Please sign in to comment.