mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-27 02:48:04 +01:00
Hover check: Check if chunks are loaded before triggering a violation.
This commit is contained in:
parent
fa50f34023
commit
2334bc9f22
@ -1,5 +1,6 @@
|
||||
package fr.neatmonster.nocheatplus.utilities;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
@ -26,6 +27,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);
|
||||
|
||||
|
@ -767,6 +767,23 @@ public class PlayerLocation {
|
||||
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.
|
||||
*/
|
||||
|
@ -1225,6 +1225,15 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user