forked from upstream/RaycastedAntiESP
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fe9434856 | ||
|
|
43dc579078 | ||
|
|
4d290c2803 | ||
|
|
c4766f33ec | ||
|
|
43d96a3018 |
No files matched your search
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 Cubicake
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'games.cubi'
|
||||
version = '1.0-SNAPSHOT'
|
||||
version = '1.1.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
Whitespace-only changes.
@@ -31,7 +31,7 @@ public class Raycast {
|
||||
} else {
|
||||
// A solid block was hit
|
||||
callback.onResult(false);
|
||||
plugin.getLogger().info("Raycast hit a solid block: " + result.getHitBlock().getType() + " at " + result.getHitBlock().getLocation());
|
||||
//plugin.getLogger().info("Raycast hit a solid block: " + result.getHitBlock().getType() + " at " + result.getHitBlock().getLocation());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -15,10 +18,12 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
public int alwaysShowRadius;
|
||||
public int raycastRadius;
|
||||
public int searchRadius;
|
||||
public boolean moreChecks;
|
||||
public boolean occludePlayers;
|
||||
public int tickCounter = 0;
|
||||
public RaycastedEntityOcclusion plugin = this;
|
||||
|
||||
// Use ConcurrentHashMap for thread-safe access
|
||||
//ConcurrentHashMap allows for Thread-safe operations. Don't use regular hashmaps
|
||||
private final Map<Player, Set<Entity>> entitiesToShow = new ConcurrentHashMap<>();
|
||||
private final Map<Player, Set<Entity>> entitiesToHide = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -29,16 +34,13 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Clear the maps at the start of each tick
|
||||
entitiesToShow.clear();
|
||||
entitiesToHide.clear();
|
||||
|
||||
// Check visibility for all players
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
checkEntityVisibility(player);
|
||||
}
|
||||
|
||||
// Apply visibility changes at the end of the tick
|
||||
applyVisibilityChanges();
|
||||
|
||||
tickCounter++;
|
||||
@@ -46,7 +48,7 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
tickCounter = 0;
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(this, 0L, 1L); // Run every tick (20 times per second)
|
||||
}.runTaskTimer(this, 0L, 1L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,10 +56,21 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void entityTargetLivingEntityEvent(EntityTargetLivingEntityEvent event) {
|
||||
if (event.getTarget() instanceof Player) {
|
||||
Player player = (Player) event.getTarget();
|
||||
addEntityToShow(player, event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEntityVisibility(Player player) {
|
||||
List<Entity> nearbyEntities = player.getNearbyEntities(searchRadius, searchRadius, searchRadius);
|
||||
|
||||
for (Entity entity : nearbyEntities) {
|
||||
if (entity instanceof Player && !occludePlayers) {
|
||||
continue;
|
||||
}
|
||||
double distance = player.getLocation().distance(entity.getLocation());
|
||||
if (distance <= alwaysShowRadius) {
|
||||
// Always show entities within this radius
|
||||
@@ -70,19 +83,51 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
continue;
|
||||
}
|
||||
if (!player.canSee(entity) || tickCounter % 10 == 0) {
|
||||
// Perform raycast to check visibility
|
||||
Location entityLocation = entity.getLocation().add(0, entity.getHeight() / 2, 0);
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), entityLocation, plugin, canSeePlayer -> {
|
||||
if (canSeePlayer) {
|
||||
addEntityToShow(player, entity);
|
||||
} else {
|
||||
addEntityToHide(player, entity);
|
||||
}
|
||||
});
|
||||
//check whether to run intensive or light checks
|
||||
Double height = entity.getHeight();
|
||||
if (moreChecks) {
|
||||
Double width = entity.getWidth();
|
||||
Location checkOne = entity.getLocation().add(0, height - 0.01, 0);
|
||||
Location checkTwo = entity.getLocation().add(0, 0.01, 0);
|
||||
Location checkThree = entity.getLocation().add(width / 2, height / 2, 0);
|
||||
Location checkFour = entity.getLocation().add(-width / 2, height / 2, 0);
|
||||
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), checkOne, plugin, canSeePlayer -> {
|
||||
if (canSeePlayer) {
|
||||
addEntityToShow(player, entity);
|
||||
} else {
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), checkTwo, plugin, canSeePlayer2 -> {
|
||||
if (canSeePlayer2) addEntityToShow(player, entity);
|
||||
else {
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), checkThree, plugin, canSeePlayer3 -> {
|
||||
if (canSeePlayer3) addEntityToShow(player, entity);
|
||||
else {
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), checkFour, plugin, canSeePlayer4 -> {
|
||||
if (canSeePlayer4) addEntityToShow(player, entity);
|
||||
else addEntityToHide(player, entity);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Location entityLocation = entity.getLocation().add(0, height / 2, 0);
|
||||
|
||||
Raycast.asyncRaycast(player.getEyeLocation(), entityLocation, plugin, canSeePlayer -> {
|
||||
if (canSeePlayer) {
|
||||
addEntityToShow(player, entity);
|
||||
} else {
|
||||
addEntityToHide(player, entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void addEntityToShow(Player player, Entity entity) {
|
||||
entitiesToShow.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).add(entity);
|
||||
entitiesToHide.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).remove(entity);
|
||||
@@ -93,6 +138,10 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
entitiesToShow.computeIfAbsent(player, k -> ConcurrentHashMap.newKeySet()).remove(entity);
|
||||
}
|
||||
|
||||
private boolean entityPendingVisible(Player player, Entity entity) {
|
||||
return entitiesToShow.get(player) != null && entitiesToShow.get(player).contains(entity);
|
||||
}
|
||||
|
||||
private void applyVisibilityChanges() {
|
||||
for (Map.Entry<Player, Set<Entity>> entry : entitiesToShow.entrySet()) {
|
||||
Player player = entry.getKey();
|
||||
@@ -109,15 +158,15 @@ public final class RaycastedEntityOcclusion extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void loadConfig() {
|
||||
// Ensure the config file exists
|
||||
saveDefaultConfig();
|
||||
|
||||
// Load values from config
|
||||
alwaysShowRadius = getConfig().getInt("AlwaysShowRadius", 4);
|
||||
raycastRadius = getConfig().getInt("RaycastRadius", 64);
|
||||
searchRadius = getConfig().getInt("SearchRadius", 72);
|
||||
moreChecks = getConfig().getBoolean("MoreChecks", false);
|
||||
occludePlayers = getConfig().getBoolean("OccludePlayers", false);
|
||||
|
||||
|
||||
// Log loaded values
|
||||
getLogger().info("AlwaysShowRadius: " + alwaysShowRadius);
|
||||
getLogger().info("RaycastRadius: " + raycastRadius);
|
||||
getLogger().info("SearchRadius: " + searchRadius);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
AlwaysShowRadius: 4
|
||||
RaycastRadius: 64
|
||||
SearchRadius: 72
|
||||
SearchRadius: 72
|
||||
MoreChecks: false #This will enable more raycasts per mob, increasing performance hit but showing partially visible mobs
|
||||
OccludePlayers: false #This will disable occlusion checks for players. Setting this to true is the interim fix for players being removed from tab list
|
||||
@@ -1,5 +1,5 @@
|
||||
name: RaycastedEntityOcclusion
|
||||
version: '1.0-SNAPSHOT'
|
||||
version: ${version}
|
||||
main: games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion
|
||||
api-version: '1.21'
|
||||
prefix: EntityOcclusion
|
||||
|
||||
Reference in new issue
Block a user