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)));
}
}
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);
}
}
}
}
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));
}
}
Aggregations