mirror of
https://github.com/Cubicake/RaycastedAntiESP.git
synced 2026-11-17 06:26:04 -05:00
Compare commits
3
Commits
eventbench
...
v1.7.x
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0823dc9a83 | ||
|
|
36a44c9e0d | ||
|
|
29f7ec211a |
No files matched your search
@@ -5,6 +5,7 @@ import games.cubi.raycastedAntiESP.packets.PacketProcessor;
|
||||
import games.cubi.raycastedAntiESP.snapshot.ChunkSnapshotManager;
|
||||
import games.cubi.raycastedAntiESP.data.DataHolder;
|
||||
import games.cubi.raycastedAntiESP.config.ConfigManager;
|
||||
import games.cubi.raycastedAntiESP.utils.Enums;
|
||||
import io.papermc.paper.event.entity.EntityMoveEvent;
|
||||
import io.papermc.paper.event.player.PlayerTrackEntityEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -15,6 +16,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockExplodeEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@@ -68,17 +70,22 @@ public class EventListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onPlace(BlockPlaceEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), e.getBlock().getType());
|
||||
manager.onBlockChange(e.getBlock().getLocation(), e.getBlock().getType(), Enums.BlockChangeType.BROKEN);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onBreak(BlockBreakEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR, Enums.BlockChangeType.BROKEN);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onBurn(BlockBurnEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR, Enums.BlockChangeType.BROKEN);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onExplode(BlockExplodeEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), e.getBlock().getType(), Enums.BlockChangeType.BROKEN);
|
||||
}
|
||||
// These events do not cover all cases, but I can't be bothered to figure out a better solution rn. Frequent snapshot refreshes is the solution. If anyone has a solution please let me know.
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class UpdateChecker {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
final String url = "https://api.modrinth.com/v2/project/bCjNZu0C/version?featured=true";
|
||||
final String url = "https://api.modrinth.com/v2/project/bCjNZu0C/version?version_type=release";
|
||||
|
||||
try (final InputStreamReader reader = new InputStreamReader(new URI(url).toURL().openConnection().getInputStream())) {
|
||||
final JsonArray array = new JsonArray();
|
||||
|
||||
@@ -5,6 +5,7 @@ import games.cubi.raycastedAntiESP.Logger;
|
||||
import games.cubi.raycastedAntiESP.RaycastedAntiESP;
|
||||
|
||||
import games.cubi.raycastedAntiESP.utils.BlockLocation;
|
||||
import games.cubi.raycastedAntiESP.utils.Enums;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -21,21 +22,21 @@ import java.util.Collections;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ChunkSnapshotManager {
|
||||
public static class Data {
|
||||
private static class ChunkData {
|
||||
public final ChunkSnapshot snapshot;
|
||||
public final ConcurrentHashMap<BlockLocation, Material> delta = new ConcurrentHashMap<>();
|
||||
public final Set<Location> tileEntities = ConcurrentHashMap.newKeySet();
|
||||
public final Set<BlockLocation> tileEntities = ConcurrentHashMap.newKeySet();
|
||||
public long lastRefresh;
|
||||
public int minHeight;
|
||||
public int maxHeight;
|
||||
|
||||
public Data(ChunkSnapshot snapshot, long time) {
|
||||
public ChunkData(ChunkSnapshot snapshot, long time) {
|
||||
this.snapshot = snapshot;
|
||||
this.lastRefresh = time;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<String, Data> dataMap = new ConcurrentHashMap<>();
|
||||
private static final ConcurrentHashMap<String, ChunkData> dataMap = new ConcurrentHashMap<>();
|
||||
private final ConfigManager cfg;
|
||||
private final RaycastedAntiESP plugin;
|
||||
|
||||
@@ -55,7 +56,7 @@ public class ChunkSnapshotManager {
|
||||
long now = System.currentTimeMillis();
|
||||
int chunksRefreshed = 0;
|
||||
int chunksToRefreshMaximum = getNumberOfCachedChunks() / 3;
|
||||
for (Map.Entry<String, Data> e : dataMap.entrySet()) {
|
||||
for (Map.Entry<String, ChunkData> e : dataMap.entrySet()) {
|
||||
if (now - e.getValue().lastRefresh >= cfg.getSnapshotConfig().getWorldSnapshotRefreshInterval() * 1000L && chunksRefreshed < chunksToRefreshMaximum) {
|
||||
chunksRefreshed++;
|
||||
String key = e.getKey();
|
||||
@@ -76,6 +77,7 @@ public class ChunkSnapshotManager {
|
||||
}
|
||||
|
||||
public void snapshotChunk(Chunk c) {
|
||||
Logger.info("ChunkSnapshotManager: Taking snapshot of chunk " + c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ(),10);
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
public void snapshotChunk(String key) {
|
||||
@@ -87,30 +89,34 @@ public class ChunkSnapshotManager {
|
||||
}
|
||||
|
||||
// Used by EventListener to update the delta map when a block is placed or broken
|
||||
public void onBlockChange(Location loc, Material m) {
|
||||
public void onBlockChange(Location loc, Material m, Enums.BlockChangeType type) {
|
||||
Logger.info("ChunkSnapshotManager: Block change at " + loc + " to " + m, 9);
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
ChunkData d = dataMap.get(key(loc.getChunk()));
|
||||
if (d == null) {
|
||||
Logger.error("Data map value empty, ignoring block update!",3);
|
||||
Logger.error("Data map value empty, ignoring block update!",2);
|
||||
return;
|
||||
}
|
||||
d.delta.put(new BlockLocation(loc), m);
|
||||
BlockLocation location = new BlockLocation(loc);
|
||||
d.delta.put(location, m);
|
||||
if (cfg.getTileEntityConfig().isEnabled()) {
|
||||
// Check if the block is a tile entity
|
||||
BlockState data = loc.getBlock().getState();
|
||||
loc = loc.clone().add(0.5, 0.5, 0.5);
|
||||
if (data instanceof TileState) {
|
||||
Logger.info("ChunkSnapshotManager: Tile entity at " + loc, 8);
|
||||
d.tileEntities.add(loc);
|
||||
}
|
||||
else {
|
||||
d.tileEntities.remove(loc);
|
||||
if (type == Enums.BlockChangeType.PLACED) {
|
||||
d.tileEntities.add(location);
|
||||
} else if (type == Enums.BlockChangeType.BROKEN) {
|
||||
d.tileEntities.remove(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {Logger.error("Data map value empty, ignoring block update!", 2);}
|
||||
}
|
||||
|
||||
private Data takeSnapshot(Chunk c, long now) {
|
||||
private ChunkData takeSnapshot(Chunk c, long now) {
|
||||
World w = c.getWorld();
|
||||
Data data = new Data(c.getChunkSnapshot(), now);
|
||||
ChunkData data = new ChunkData(c.getChunkSnapshot(), now);
|
||||
int chunkX = c.getX() * 16;
|
||||
int chunkZ = c.getZ() * 16;
|
||||
int minHeight = w.getMinHeight();
|
||||
@@ -124,7 +130,7 @@ public class ChunkSnapshotManager {
|
||||
BlockState bs = data.snapshot.getBlockData(x, y, z).createBlockState();
|
||||
|
||||
if (bs instanceof TileState) {
|
||||
data.tileEntities.add(new Location(w, x+ chunkX +0.5, y+0.5, z + chunkZ+0.5));
|
||||
data.tileEntities.add(new BlockLocation(w, x+ chunkX, y, z + chunkZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +163,7 @@ public class ChunkSnapshotManager {
|
||||
|
||||
public Material getMaterialAt(Location loc) {
|
||||
Chunk chunk = loc.getChunk();
|
||||
Data d = dataMap.get(key(chunk));
|
||||
ChunkData d = dataMap.get(key(chunk));
|
||||
if (d == null) {
|
||||
Chunk c = loc.getChunk();
|
||||
Logger.error("ChunkSnapshotManager: No snapshot for " + c+ " If this error persists, please report this on our discord (discord.cubi.games)", 3);
|
||||
@@ -182,11 +188,11 @@ public class ChunkSnapshotManager {
|
||||
|
||||
//get TileEntity Locations in chunk
|
||||
public Set<Location> getTileEntitiesInChunk(World world, int x, int z) {
|
||||
Data d = dataMap.get(key(world, x, z));
|
||||
ChunkData d = dataMap.get(key(world, x, z));
|
||||
if (d == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return d.tileEntities;
|
||||
return BlockLocation.toCentredLocations(d.tileEntities);
|
||||
}
|
||||
|
||||
public int getNumberOfCachedChunks() {
|
||||
|
||||
@@ -4,7 +4,9 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockLocation {
|
||||
@@ -43,6 +45,18 @@ public class BlockLocation {
|
||||
return new Location(Bukkit.getWorld(world), x + 0.5, y + 0.5, z + 0.5);
|
||||
}
|
||||
|
||||
public static Location toCentredLocation(BlockLocation blockLocation) {
|
||||
return new Location(Bukkit.getWorld(blockLocation.world), blockLocation.x + 0.5, blockLocation.y + 0.5, blockLocation.z + 0.5);
|
||||
}
|
||||
|
||||
public static Set<Location> toCentredLocations(Set<BlockLocation> blockLocations) {
|
||||
Set<Location> locations = new HashSet<>();
|
||||
for (BlockLocation bl : blockLocations) {
|
||||
locations.add(BlockLocation.toCentredLocation(bl));
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package games.cubi.raycastedAntiESP.utils;
|
||||
|
||||
public class Enums {
|
||||
public enum BlockChangeType {
|
||||
PLACED,
|
||||
BROKEN
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user