use of com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray in project RayTraceAntiXray by stonar96.
the class WorldListener method onWorldInit.
@SuppressWarnings("deprecation")
@EventHandler
public void onWorldInit(WorldInitEvent event) {
if (plugin.isEnabled(event.getWorld())) {
List<String> toTrace = plugin.getConfig().getList("world-settings." + event.getWorld().getName() + ".anti-xray.ray-trace-blocks", plugin.getConfig().getList("world-settings.default.anti-xray.ray-trace-blocks")).stream().filter(o -> o != null).map(String::valueOf).collect(Collectors.toList());
try {
Field chunkPacketBlockController = Level.class.getDeclaredField("chunkPacketBlockController");
chunkPacketBlockController.setAccessible(true);
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
Unsafe unsafe = (Unsafe) theUnsafe.get(null);
unsafe.putObject(((CraftWorld) event.getWorld()).getHandle(), unsafe.objectFieldOffset(chunkPacketBlockController), new ChunkPacketBlockControllerAntiXray(plugin, plugin.getConfig().getInt("world-settings." + event.getWorld().getName() + ".anti-xray.max-ray-trace-block-count-per-chunk", plugin.getConfig().getInt("world-settings.default.anti-xray.max-ray-trace-block-count-per-chunk")), toTrace.isEmpty() ? null : toTrace, ((CraftWorld) event.getWorld()).getHandle(), MinecraftServer.getServer().executor));
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray in project RayTraceAntiXray by stonar96.
the class RayTraceRunnable method run.
@Override
public void run() {
List<? extends Location> locations = playerData.getLocations();
Location playerLocation = locations.get(0);
ChunkPacketBlockController chunkPacketBlockController = ((CraftWorld) playerLocation.getWorld()).getHandle().chunkPacketBlockController;
if (!(chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray)) {
return;
}
boolean[] solidGlobal = ((ChunkPacketBlockControllerAntiXray) chunkPacketBlockController).solidGlobal;
double rayTraceDistance = Math.max(plugin.getConfig().getDouble("world-settings." + playerLocation.getWorld().getName() + ".anti-xray.ray-trace-distance", plugin.getConfig().getDouble("world-settings.default.anti-xray.ray-trace-distance")), 0.);
Location temp = playerLocation.clone();
temp.setX(playerLocation.getX() - rayTraceDistance);
temp.setZ(playerLocation.getZ() - rayTraceDistance);
int chunkXMin = temp.getBlockX() >> 4;
int chunkZMin = temp.getBlockZ() >> 4;
temp.setX(playerLocation.getX() + rayTraceDistance);
temp.setZ(playerLocation.getZ() + rayTraceDistance);
int chunkXMax = temp.getBlockX() >> 4;
int chunkZMax = temp.getBlockZ() >> 4;
double rayTraceDistanceSquared = rayTraceDistance * rayTraceDistance;
for (Location location : locations) {
Vector vector = location.toVector();
Vector direction = location.getDirection();
for (Entry<ChunkPos, ChunkBlocks> chunkEntry : playerData.getChunks().entrySet()) {
ChunkBlocks chunkBlocks = chunkEntry.getValue();
LevelChunk chunk = chunkBlocks.getChunk();
if (chunk == null) {
playerData.getChunks().remove(chunkEntry.getKey(), chunkBlocks);
continue;
}
if (chunk.locX < chunkXMin || chunk.locX > chunkXMax || chunk.locZ < chunkZMin || chunk.locZ > chunkZMax) {
continue;
}
Iterator<? extends BlockPos> iterator = chunkBlocks.getBlocks().iterator();
while (iterator.hasNext()) {
BlockPos block = iterator.next();
block = new BlockPos((chunk.locX << 4) + block.getX(), block.getY(), (chunk.locZ << 4) + block.getZ());
Vector blockCenter = new Vector(block.getX() + 0.5, block.getY() + 0.5, block.getZ() + 0.5);
Vector difference = vector.clone().subtract(blockCenter);
if (difference.lengthSquared() > rayTraceDistanceSquared || difference.dot(direction) > 0.) {
continue;
}
Iterator<BlockPos> blockIterator = new BlockIterator(blockCenter, vector);
boolean update = true;
while (blockIterator.hasNext()) {
BlockPos rayBlock = blockIterator.next();
ChunkPos chunkPos = new ChunkPos(rayBlock);
ChunkBlocks rayChunkBlocks = playerData.getChunks().get(chunkPos);
if (rayChunkBlocks == null) {
update = false;
break;
}
LevelChunk rayChunk = rayChunkBlocks.getChunk();
if (rayChunk == null) {
playerData.getChunks().remove(chunkPos, rayChunkBlocks);
update = false;
break;
}
int sectionY = rayBlock.getY() >> 4;
if (sectionY < rayChunk.getMinSection() || sectionY > rayChunk.getMaxSection() - 1) {
continue;
}
LevelChunkSection section = rayChunk.getSections()[sectionY - rayChunk.getMinSection()];
if (section == null || section.hasOnlyAir()) {
// Sections aren't null anymore.
continue;
}
BlockState blockState;
// section.getStates().acquire();
try {
blockState = section.getBlockState(rayBlock.getX() & 15, rayBlock.getY() & 15, rayBlock.getZ() & 15);
} catch (MissingPaletteEntryException e) {
blockState = Blocks.AIR.defaultBlockState();
}
if (solidGlobal[ChunkPacketBlockControllerAntiXray.GLOBAL_BLOCKSTATE_PALETTE.idFor(blockState)] && checkSurroundingBlocks(block.getX(), block.getY(), block.getZ(), rayBlock.getX(), rayBlock.getY(), rayBlock.getZ(), difference, section, chunkPos.x, sectionY, chunkPos.z, playerData, solidGlobal)) {
update = false;
break;
}
}
if (update) {
playerData.getResult().add(block);
iterator.remove();
}
}
}
}
}
use of com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray in project RayTraceAntiXray by stonar96.
the class UpdateBukkitRunnable method run.
@Override
public void run() {
for (Entry<UUID, PlayerData> entry : plugin.getPlayerData().entrySet()) {
PlayerData playerData = entry.getValue();
Level level = ((CraftWorld) playerData.getLocations().get(0).getWorld()).getHandle();
ChunkPacketBlockController chunkPacketBlockController = level.chunkPacketBlockController;
if (chunkPacketBlockController instanceof ChunkPacketBlockControllerAntiXray) {
Queue<BlockPos> result = playerData.getResult();
for (BlockPos block = result.poll(); block != null; block = result.poll()) {
((ChunkPacketBlockControllerAntiXray) chunkPacketBlockController).updateBlock(level, block);
}
}
}
}
Aggregations