Search in sources :

Example 1 with PlayerData

use of com.vanillage.raytraceantixray.data.PlayerData in project RayTraceAntiXray by stonar96.

the class PacketListener method onPacketSending.

@Override
public void onPacketSending(PacketEvent event) {
    if (event.getPacketType() == PacketType.Play.Server.MAP_CHUNK) {
        PlayerData playerData = plugin.getPlayerData().get(event.getPlayer().getUniqueId());
        ChunkBlocks chunkBlocks = plugin.getPacketChunkBlocksCache().get(event.getPacket().getHandle());
        if (chunkBlocks == null) {
            Location location = event.getPlayer().getEyeLocation();
            if (!location.getWorld().equals(playerData.getLocations().get(0).getWorld())) {
                playerData = new PlayerData(plugin.getLocations(event.getPlayer(), location));
                plugin.getPlayerData().put(event.getPlayer().getUniqueId(), playerData);
            }
            // Not enabled in this world.
            return;
        }
        LevelChunk chunk = chunkBlocks.getChunk();
        if (chunk == null) {
            return;
        }
        if (!chunk.getLevel().getWorld().equals(playerData.getLocations().get(0).getWorld())) {
            Location location = event.getPlayer().getEyeLocation();
            if (!chunk.getLevel().getWorld().equals(location.getWorld())) {
                // The packet can be ignored.
                return;
            }
            playerData = new PlayerData(plugin.getLocations(event.getPlayer(), location));
            plugin.getPlayerData().put(event.getPlayer().getUniqueId(), playerData);
        }
        playerData.getChunks().put(chunk.getPos(), chunkBlocks);
    } else if (event.getPacketType() == PacketType.Play.Server.UNLOAD_CHUNK) {
        StructureModifier<Integer> integers = event.getPacket().getIntegers();
        plugin.getPlayerData().get(event.getPlayer().getUniqueId()).getChunks().remove(new ChunkPos(integers.read(0), integers.read(1)));
    }
}
Also used : LevelChunk(net.minecraft.world.level.chunk.LevelChunk) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) ChunkBlocks(com.vanillage.raytraceantixray.data.ChunkBlocks) ChunkPos(net.minecraft.world.level.ChunkPos) PlayerData(com.vanillage.raytraceantixray.data.PlayerData) Location(org.bukkit.Location)

Example 2 with PlayerData

use of com.vanillage.raytraceantixray.data.PlayerData 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);
            }
        }
    }
}
Also used : ChunkPacketBlockController(com.destroystokyo.paper.antixray.ChunkPacketBlockController) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) UUID(java.util.UUID) ChunkPacketBlockControllerAntiXray(com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray) PlayerData(com.vanillage.raytraceantixray.data.PlayerData) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 3 with PlayerData

use of com.vanillage.raytraceantixray.data.PlayerData in project RayTraceAntiXray by stonar96.

the class PlayerListener method onPlayerMove.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
    PlayerData playerData = plugin.getPlayerData().get(event.getPlayer().getUniqueId());
    Location location = event.getTo();
    if (location.getWorld().equals(playerData.getLocations().get(0).getWorld())) {
        location = location.clone();
        location.setY(location.getY() + event.getPlayer().getEyeHeight());
        playerData.setLocations(plugin.getLocations(event.getPlayer(), location));
    }
}
Also used : PlayerData(com.vanillage.raytraceantixray.data.PlayerData) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PlayerData (com.vanillage.raytraceantixray.data.PlayerData)3 Location (org.bukkit.Location)2 StructureModifier (com.comphenix.protocol.reflect.StructureModifier)1 ChunkPacketBlockController (com.destroystokyo.paper.antixray.ChunkPacketBlockController)1 ChunkPacketBlockControllerAntiXray (com.vanillage.raytraceantixray.antixray.ChunkPacketBlockControllerAntiXray)1 ChunkBlocks (com.vanillage.raytraceantixray.data.ChunkBlocks)1 UUID (java.util.UUID)1 BlockPos (net.minecraft.core.BlockPos)1 ChunkPos (net.minecraft.world.level.ChunkPos)1 Level (net.minecraft.world.level.Level)1 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)1 EventHandler (org.bukkit.event.EventHandler)1