mirror of
https://github.com/Cubicake/RaycastedAntiESP.git
synced 2026-11-17 06:26:04 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d46d63668b | ||
|
|
83a278b00a | ||
|
|
c1e0db5613 | ||
|
|
34db141f08 | ||
|
|
a68bcfdbf5 | ||
|
|
77825067de | ||
|
|
085fa59e42 | ||
|
|
2db88a4498 | ||
|
|
e9935f0350 | ||
|
|
8d39fa5427 | ||
|
|
b958d0dc46 | ||
|
|
e9adb65690 | ||
|
|
6a289c81a9 | ||
|
|
34b04ff059 | ||
|
|
1a73c2509a | ||
|
|
e3731f76f0 | ||
|
|
bd1f6ad482 | ||
|
|
951e4f4ad9 | ||
|
|
114746aeaf | ||
|
|
9dc9652917 | ||
|
|
b97f675159 | ||
|
|
f5e16fc75d | ||
|
|
c228cef24a | ||
|
|
098aab5e31 | ||
|
|
31b500bc7b | ||
|
|
d5e3281cf2 | ||
|
|
98dbefd576 | ||
|
|
4dce9b3278 | ||
|
|
d5bf02b4ea | ||
|
|
ed98e2abeb | ||
|
|
9a07bd0119 | ||
|
|
74aca26910 | ||
|
|
25f5652a12 | ||
|
|
7679f08d06 | ||
|
|
7ad99917d1 | ||
|
|
ce56eb316e | ||
|
|
74426d80af | ||
|
|
fdb1f567ac | ||
|
|
e823f7a2f7 | ||
|
|
7c1f7fd2a6 | ||
|
|
c26e6a1623 | ||
|
|
8155903342 | ||
|
|
f2ade6b0b8 | ||
|
|
f486d1fc2e | ||
|
|
50eeab8cfe | ||
|
|
4009fe6d02 | ||
|
|
b7e6fa9c5f | ||
|
|
dcc986c232 | ||
|
|
95cea9f875 | ||
|
|
6e8d47b96e | ||
|
|
f04b79bb4a | ||
|
|
bf17a65246 | ||
|
|
3d4702e520 | ||
|
|
266302f09c | ||
|
|
ac130a739e | ||
|
|
dcc316e7e7 | ||
|
|
754214fa8d | ||
|
|
a6f47f137c | ||
|
|
97e43e65f8 | ||
|
|
ef81d97eef | ||
|
|
36d75c8933 | ||
|
|
b37f8465aa | ||
|
|
3d34992fcc | ||
|
|
4602dde7df | ||
|
|
a81d5caa45 | ||
|
|
7ef25e5dc3 | ||
|
|
529ab3f583 | ||
|
|
951883cb1b | ||
|
|
08113b57ba | ||
|
|
63e9c8bea1 | ||
|
|
1d14468924 | ||
|
|
5378fd5907 | ||
|
|
5e8d8bb43e | ||
|
|
da5c68b07c | ||
|
|
0f9af7c217 | ||
|
|
1fd227e8ba | ||
|
|
e4c653fe6a | ||
|
|
f2dc9f7d18 | ||
|
|
8998338563 | ||
|
|
361bbf84bc | ||
|
|
384393358c | ||
|
|
9c2d542f3c | ||
|
|
ab930c4c30 | ||
|
|
1f64514366 | ||
|
|
398592225e | ||
|
|
a95b79d428 | ||
|
|
67c9758a96 | ||
|
|
f555249cc9 | ||
|
|
5e4bc1f0fb | ||
|
|
53d49cf542 | ||
|
|
9b34fa51a0 | ||
|
|
573d8331dc | ||
|
|
333b211b00 | ||
|
|
81718b8848 | ||
|
|
6084a373c8 | ||
|
|
f22f6db331 | ||
|
|
4c7733420f |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: cubicake
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
+3
-1
@@ -1,11 +1,13 @@
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
README.md
|
||||
*.md
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
README.md
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
@@ -1,41 +1,24 @@
|
||||
Latest version: v1.4.1
|
||||
Latest version: v1.6.1
|
||||
|
||||
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusion/
|
||||
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusions/
|
||||
|
||||
This is an async plugin for PaperMC and its forks that hides/culls entities (and tile entities) from players if they do not have line-of-sight.
|
||||
|
||||
The supported versions are 1.21.x PaperMC and Pufferfish. Other server versions and software may work too.
|
||||
|
||||
This is a simple server-side plugin for PaperMC (May also work with Spigot, this is untested) that hides/culls entities from players if they do not have line-of-sight. All raycasts are run async to reduce performance impact.
|
||||
Use cases:
|
||||
|
||||
- To prevent mob nametags from being visible through walls
|
||||
- If the mobs don't exist, you can't see them
|
||||
- Act as an "anticheat" to block players from using mods such as freecam to find entities through walls
|
||||
- This is not an actual anticheat and will not detect freecam, instead just making freecam less useful
|
||||
- Freecam will still be useful for locating structures and features such as caves
|
||||
- Reduce client lag
|
||||
- In servers with large megabases full of item frames, armour stands and other entities, RaycastedEntityOcclusion will prevent these entities from lagging the client unless they are within line-of-sight
|
||||
|
||||
EVERYTHING BELOW IS OUT OF DATE, READ THE CHANGELOG FOR v1.4.1 https://modrinth.com/plugin/raycasted-entity-occlusions/version/1.4.1
|
||||
|
||||
Default Config:
|
||||
|
||||
- AlwaysShowRadius: 8
|
||||
- RaycastRadius: 48
|
||||
- SearchRadius: 52
|
||||
- MoreChecks: false
|
||||
- OccludePlayers: false
|
||||
- RecheckInterval: 20
|
||||
|
||||
Entities inside the AlwaysShowRadius are always shown, even if occluded. This is to prevent nasty surprises when turning a corner quickly.
|
||||
|
||||
The SearchRadius is a cubic bounding box around the player within which entities will be checked. If an entity is within the SearchRadius but not the RaycastRadius, it will be automatically hidden.
|
||||
|
||||
The RaycastRadius is the radius where entities will be checked. If an entity is currently hidden it will run a raycast every tick. This is to quickly detect when the entity becomes visible. If the entity is currently visible, it will only run the raycast every {RecheckInterval} ticks to reduce performance impact.
|
||||
|
||||
MoreChecks toggles between two raycasting modes. By default (MoreChecks = false) the plugin runs one raycast from the center of each mob to the player. This means that if the center of the mob is hidden but some parts should be visible, the player won't be able to see the mob at all. Enabling MoreChecks runs a raycast from the top, bottom, left and right of the entity to the player.
|
||||
|
||||
OccludePlayers toggles whether players will be checked. Enabling this prevents ESP mods from revealing players.
|
||||
|
||||
- Prevent cheating (anti-esp hacks)
|
||||
- Block usage of pie-ray to locate underground bases
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of hidden entities
|
||||
- Increase client-side performance for low-end devices
|
||||
- Massive megabases containing hundreds of armour stands, item frames, banners etc can cause performance issues on low-end devices unable to process so many entities. REO will cull those entities for the client, reducing the number of entities to process.
|
||||
- Hide nametags behind walls
|
||||
- Yes, this plugin is a bit overkill for doing that, yes you can do it anyways.
|
||||
|
||||
Dependencies:
|
||||
- Packetevents (soft depend)
|
||||
- Only needed if you are using the cull-players option and wish for the players to remain in the tablist
|
||||
|
||||
Known issues:
|
||||
- Due to the nature of the plugin, there will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. This issue is partially resolved by turning MoreChecks on
|
||||
- If OccludePlayers is set to true any occluded players will be removed from tablist
|
||||
- When updating the plugin to a version with more config versions, no checks are performed to detect this and add the new configs to config.yml. This means that the config file will be missing several options. (This is an issue when updating to v1.1.0 or v1.2.0). To fix, just copy the new config options from the Default Config section above.
|
||||
- Due to the nature of the plugin, there will be a short delay once an entity should be visible before it appears, causing it to appear like it "popped" into view. This issue is partially resolved by turning engine-mode to 2, and is worse for players with higher ping.
|
||||
+22
-2
@@ -1,9 +1,10 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
}
|
||||
|
||||
group = 'games.cubi'
|
||||
version = '1.4.2'
|
||||
version = '1.6.2'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -15,10 +16,23 @@ repositories {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/groups/public/"
|
||||
}
|
||||
maven { url = uri("https://repo.codemc.io/repository/maven-releases/") }
|
||||
|
||||
maven { url = uri("https://repo.codemc.io/repository/maven-snapshots/") }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
compileOnly("com.github.retrooper:packetevents-spigot:2.8.0")
|
||||
}
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
// Configure the Minecraft version for our task.
|
||||
// This is the only required configuration besides applying the plugin.
|
||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||
minecraftVersion("1.21.10")
|
||||
}
|
||||
}
|
||||
|
||||
def targetJavaVersion = 21
|
||||
@@ -46,4 +60,10 @@ processResources {
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes "paperweight-mappings-namespace": "mojang"
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ChunkSnapshotManager {
|
||||
public static class Data {
|
||||
public final ChunkSnapshot snapshot;
|
||||
public final Map<Location, Material> delta = new ConcurrentHashMap<>();
|
||||
public long lastRefresh;
|
||||
|
||||
public Data(ChunkSnapshot snapshot, long time) {
|
||||
this.snapshot = snapshot;
|
||||
this.lastRefresh = time;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, Data> dataMap = new ConcurrentHashMap<>();
|
||||
|
||||
public ChunkSnapshotManager(RaycastedEntityOcclusion plugin, int refreshIntervalSecs) {
|
||||
ConfigManager cfg = plugin.getConfigManager();
|
||||
//get loaded chunks and add them to dataMap
|
||||
for (World w : plugin.getServer().getWorlds()) {
|
||||
for (Chunk c : w.getLoadedChunks()) {
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long now = System.currentTimeMillis();
|
||||
int chunksRefreshed = 0;
|
||||
for (Map.Entry<String, Data> e : dataMap.entrySet()) {
|
||||
if (now - e.getValue().lastRefresh >= refreshIntervalSecs * 1000L) {
|
||||
if (cfg.debugMode) {
|
||||
chunksRefreshed++;
|
||||
}
|
||||
String key = e.getKey();
|
||||
String[] parts = key.split(":");
|
||||
World w = plugin.getServer().getWorld(parts[0]);
|
||||
if (w == null) {
|
||||
plugin.getLogger().warning("ChunkSnapshotManager: World " + parts[0] + " not found. Please report this on our discord (discord.cubi.games)'");
|
||||
continue;
|
||||
}
|
||||
Chunk c = w.getChunkAt(
|
||||
Integer.parseInt(parts[1]),
|
||||
Integer.parseInt(parts[2])
|
||||
);
|
||||
e.setValue(takeSnapshot(c, now));
|
||||
}
|
||||
}
|
||||
if (cfg.debugMode) {
|
||||
plugin.getLogger().info("ChunkSnapshotManager: Refreshed " + chunksRefreshed + " chunks.");
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, refreshIntervalSecs * 5L, refreshIntervalSecs * 5L /* This runs 4 times per refreshInterval, spreading out the refreshes */);
|
||||
}
|
||||
|
||||
public void onChunkLoad(Chunk c) {
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void onChunkUnload(Chunk c) {
|
||||
dataMap.remove(key(c));
|
||||
}
|
||||
|
||||
// Used by SnapshotListener to update the delta map when a block is placed or broken
|
||||
public void onBlockChange(Location loc, Material m) {
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
if (d != null) {
|
||||
d.delta.put(loc, m);
|
||||
}
|
||||
}
|
||||
|
||||
private Data takeSnapshot(Chunk c, long now) {
|
||||
return new Data(c.getChunkSnapshot(), now);
|
||||
}
|
||||
|
||||
private String key(Chunk c) {
|
||||
return c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ();
|
||||
}
|
||||
|
||||
public Material getMaterialAt(Location loc) {
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
if (d == null) {
|
||||
Chunk c = loc.getChunk();
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
System.err.println("ChunkSnapshotManager: No snapshot for " + loc.getChunk()+ " Please report this on our discord (discord.cubi.games)'");
|
||||
return loc.getBlock().getType();
|
||||
}
|
||||
Material dm = d.delta.get(loc);
|
||||
if (dm != null) {
|
||||
return dm;
|
||||
}
|
||||
int x = loc.getBlockX() & 0xF;
|
||||
int y = loc.getBlockY();
|
||||
int z = loc.getBlockZ() & 0xF;
|
||||
return d.snapshot.getBlockType(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package games.cubi.raycastedEntityOcclusion;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
@@ -10,6 +11,8 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
|
||||
|
||||
public class CommandsManager {
|
||||
private final RaycastedEntityOcclusion plugin;
|
||||
private final ConfigManager cfg;
|
||||
@@ -78,12 +81,19 @@ public class CommandsManager {
|
||||
)
|
||||
)
|
||||
)
|
||||
/*.then(Commands.literal("test")
|
||||
.then(Commands.literal("test")
|
||||
.executes(context -> {
|
||||
testCommand(context);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)*/
|
||||
)
|
||||
.then(Commands.literal("check-for-updates")
|
||||
.executes(context -> {
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
UpdateChecker.checkForUpdates(plugin, sender);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
.build();
|
||||
return buildCommand;
|
||||
}
|
||||
@@ -98,10 +108,6 @@ public class CommandsManager {
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
private void testCommand(CommandContext<CommandSourceStack> context) {
|
||||
CommandSender sender = context.getSource().getSender();
|
||||
sender.sendRichMessage("This is a test command for use in development. It does nothing on publicly released versions (unless I have forgotten to remove the tests).");
|
||||
|
||||
//sender.sendMessage(new UpdateChecker(plugin).hasNewUpdate());
|
||||
private void testCommand(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,23 @@ public class ConfigManager {
|
||||
public boolean cullPlayers;
|
||||
public boolean onlyCullSneakingPlayers;
|
||||
public int recheckInterval;
|
||||
public boolean checkTileEntities;
|
||||
public int tileEntityRecheckInterval;
|
||||
public FileConfiguration cfg;
|
||||
public boolean packetEventsPresent = false;
|
||||
|
||||
public static final int SNAPSHOT_REFRESH_INTERVAL_DEFAULT = 60;
|
||||
public static final int ENGINE_MODE_DEFAULT = 1;
|
||||
public static final int MAX_OCCLUDING_COUNT_DEFAULT = 3;
|
||||
public static final boolean DEBUG_MODE_DEFAULT = false;
|
||||
public static final int ALWAYS_SHOW_RADIUS_DEFAULT = 16;
|
||||
public static final int RAYCAST_RADIUS_DEFAULT = 48;
|
||||
public static final int SEARCH_RADIUS_DEFAULT = 48;
|
||||
public static final boolean CULL_PLAYERS_DEFAULT = false;
|
||||
public static final boolean ONLY_CULL_SNEAKING_PLAYERS_DEFAULT = false;
|
||||
public static final int RECHECK_INTERVAL_DEFAULT = 50;
|
||||
public static final boolean CHECK_TILE_ENTITIES_DEFAULT = true;
|
||||
public static final int TILE_ENTITY_RECHECK_INTERVAL_DEFAULT = 0;
|
||||
|
||||
public ConfigManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -27,29 +43,34 @@ public class ConfigManager {
|
||||
plugin.reloadConfig();
|
||||
cfg = plugin.getConfig();
|
||||
|
||||
snapshotRefreshInterval = cfg.getInt("snapshot-refresh-interval", 60);
|
||||
engineMode = cfg.getInt("engine-mode", 1);
|
||||
maxOccludingCount = cfg.getInt("max-occluding-count", 3);
|
||||
debugMode = cfg.getBoolean("debug-mode", false);
|
||||
snapshotRefreshInterval = cfg.getInt("snapshot-refresh-interval", SNAPSHOT_REFRESH_INTERVAL_DEFAULT);
|
||||
engineMode = cfg.getInt("engine-mode", ENGINE_MODE_DEFAULT);
|
||||
maxOccludingCount = cfg.getInt("max-occluding-count", MAX_OCCLUDING_COUNT_DEFAULT);
|
||||
debugMode = cfg.getBoolean("debug-mode", DEBUG_MODE_DEFAULT);
|
||||
|
||||
alwaysShowRadius = cfg.getInt("always-show-radius", 8);
|
||||
raycastRadius = cfg.getInt("raycast-radius", 48);
|
||||
searchRadius = cfg.getInt("search-radius", 48);
|
||||
cullPlayers = cfg.getBoolean("cull-players", false);
|
||||
onlyCullSneakingPlayers = cfg.getBoolean("only-cull-sneaking-players", false);
|
||||
recheckInterval = cfg.getInt("recheck-interval", 20);
|
||||
alwaysShowRadius = cfg.getInt("always-show-radius", ALWAYS_SHOW_RADIUS_DEFAULT);
|
||||
raycastRadius = cfg.getInt("raycast-radius", RAYCAST_RADIUS_DEFAULT);
|
||||
searchRadius = cfg.getInt("search-radius", SEARCH_RADIUS_DEFAULT);
|
||||
cullPlayers = cfg.getBoolean("cull-players", CULL_PLAYERS_DEFAULT);
|
||||
onlyCullSneakingPlayers = cfg.getBoolean("only-cull-sneaking-players", ONLY_CULL_SNEAKING_PLAYERS_DEFAULT);
|
||||
recheckInterval = cfg.getInt("recheck-interval", RECHECK_INTERVAL_DEFAULT);
|
||||
|
||||
checkTileEntities = cfg.getBoolean("check-tile-entities", CHECK_TILE_ENTITIES_DEFAULT);
|
||||
tileEntityRecheckInterval = cfg.getInt("tile-entity-recheck-interval", TILE_ENTITY_RECHECK_INTERVAL_DEFAULT);
|
||||
|
||||
// Write defaults if missing
|
||||
cfg.addDefault("snapshot-refresh-interval", 60);
|
||||
cfg.addDefault("engine-mode", 1);
|
||||
cfg.addDefault("max-occluding-count", 3);
|
||||
cfg.addDefault("debug-mode", false);
|
||||
cfg.addDefault("always-show-radius", 8);
|
||||
cfg.addDefault("raycast-radius", 48);
|
||||
cfg.addDefault("search-radius", 48);
|
||||
cfg.addDefault("cull-players", false);
|
||||
cfg.addDefault("only-cull-sneaking-players", false);
|
||||
cfg.addDefault("recheck-interval", 20);
|
||||
cfg.addDefault("snapshot-refresh-interval", SNAPSHOT_REFRESH_INTERVAL_DEFAULT);
|
||||
cfg.addDefault("engine-mode", ENGINE_MODE_DEFAULT);
|
||||
cfg.addDefault("max-occluding-count", MAX_OCCLUDING_COUNT_DEFAULT);
|
||||
cfg.addDefault("debug-mode", DEBUG_MODE_DEFAULT);
|
||||
cfg.addDefault("always-show-radius", ALWAYS_SHOW_RADIUS_DEFAULT);
|
||||
cfg.addDefault("raycast-radius", RAYCAST_RADIUS_DEFAULT);
|
||||
cfg.addDefault("search-radius", SEARCH_RADIUS_DEFAULT);
|
||||
cfg.addDefault("cull-players", CULL_PLAYERS_DEFAULT);
|
||||
cfg.addDefault("only-cull-sneaking-players", ONLY_CULL_SNEAKING_PLAYERS_DEFAULT);
|
||||
cfg.addDefault("recheck-interval", RECHECK_INTERVAL_DEFAULT);
|
||||
cfg.addDefault("check-tile-entities", CHECK_TILE_ENTITIES_DEFAULT);
|
||||
cfg.addDefault("tile-entity-recheck-interval", TILE_ENTITY_RECHECK_INTERVAL_DEFAULT);
|
||||
cfg.options().copyDefaults(true);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
@@ -84,4 +105,7 @@ public class ConfigManager {
|
||||
1 = success
|
||||
*/
|
||||
}
|
||||
public void setPacketEventsPresent(boolean present) {
|
||||
this.packetEventsPresent = present;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Engine {
|
||||
|
||||
private static class RayJob {
|
||||
final UUID playerId, entityId;
|
||||
final Location start, predictedStart, end;
|
||||
|
||||
RayJob(UUID p, UUID e, Location s, Location pred, Location t) {
|
||||
playerId = p;
|
||||
entityId = e;
|
||||
start = s;
|
||||
predictedStart = pred;
|
||||
end = t;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RayResult {
|
||||
final UUID playerId, entityId;
|
||||
final boolean visible;
|
||||
|
||||
RayResult(UUID p, UUID e, boolean v) {
|
||||
playerId = p;
|
||||
entityId = e;
|
||||
visible = v;
|
||||
}
|
||||
}
|
||||
|
||||
public static void runEngine(ConfigManager cfg, ChunkSnapshotManager snapMgr, MovementTracker tracker, RaycastedEntityOcclusion plugin) {
|
||||
// ----- PHASE 1: SYNC GATHER -----
|
||||
List<RayJob> jobs = new ArrayList<>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
Location eye = p.getEyeLocation().clone();
|
||||
Location predEye = null;
|
||||
if (cfg.engineMode == 2) {
|
||||
// getPredictedLocation returns null if insufficient data or too slow
|
||||
predEye = tracker.getPredictedLocation(p);
|
||||
}
|
||||
|
||||
for (Entity e : p.getNearbyEntities(cfg.searchRadius, cfg.searchRadius, cfg.searchRadius)) {
|
||||
if (e == p) continue;
|
||||
// Cull-players logic
|
||||
if (e instanceof Player pl && (!cfg.cullPlayers || (cfg.onlyCullSneakingPlayers && !pl.isSneaking()))) {
|
||||
p.showEntity(plugin, e);
|
||||
continue;
|
||||
}
|
||||
|
||||
Location target = e.getLocation().add(0, e.getHeight() / 2, 0).clone();
|
||||
double dist = eye.distance(target);
|
||||
if (dist <= cfg.alwaysShowRadius) {
|
||||
p.showEntity(plugin, e);
|
||||
} else if (dist > cfg.raycastRadius) {
|
||||
p.hideEntity(plugin, e);
|
||||
} else if (p.canSee(e) && plugin.tick % cfg.recheckInterval != 0) {
|
||||
// player can see entity, no need to raycast
|
||||
}
|
||||
else {
|
||||
// schedule for async raycast (with or without predEye)
|
||||
jobs.add(new RayJob(p.getUniqueId(), e.getUniqueId(), eye, predEye, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----- PHASE 2: ASYNC RAYCASTS -----
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
List<RayResult> results = new ArrayList<>(jobs.size());
|
||||
for (RayJob job : jobs) {
|
||||
// first cast from real eye
|
||||
boolean vis = RaycastUtil.raycast(job.start, job.end, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
|
||||
// if that fails and we have a predEye, cast again from predicted
|
||||
if (!vis && job.predictedStart != null) {
|
||||
if (cfg.debugMode) {
|
||||
job.predictedStart.getWorld().spawnParticle(Particle.DUST, job.predictedStart, 1, new Particle.DustOptions(org.bukkit.Color.BLUE,1f));
|
||||
}
|
||||
vis = RaycastUtil.raycast(job.predictedStart, job.end, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
}
|
||||
|
||||
results.add(new RayResult(job.playerId, job.entityId, vis));
|
||||
}
|
||||
|
||||
// ----- PHASE 3: SYNC APPLY -----
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
for (RayResult r : results) {
|
||||
Player p = Bukkit.getPlayer(r.playerId);
|
||||
Entity ent = Bukkit.getEntity(r.entityId);
|
||||
if (p != null && ent != null) {
|
||||
if (r.visible) p.showEntity(plugin, ent);
|
||||
else p.hideEntity(plugin, ent);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.Packets.PacketProcessor;
|
||||
import games.cubi.raycastedEntityOcclusion.Snapshot.ChunkSnapshotManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static games.cubi.raycastedEntityOcclusion.UpdateChecker.checkForUpdates;
|
||||
|
||||
public class EventListener implements Listener {
|
||||
private final ChunkSnapshotManager manager;
|
||||
private final ConfigManager config;
|
||||
private PacketProcessor packetProcessor;
|
||||
private final RaycastedEntityOcclusion plugin;
|
||||
|
||||
public EventListener(RaycastedEntityOcclusion plugin, ChunkSnapshotManager mgr, ConfigManager cfg) {
|
||||
this.manager = mgr;
|
||||
this.config = cfg;
|
||||
this.plugin = plugin;
|
||||
//load packet processor after 2 ticks in a bukkit runnable to ensure the plugin is fully loaded
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
if (config.packetEventsPresent) {
|
||||
packetProcessor = plugin.getPacketProcessor();
|
||||
} else {
|
||||
packetProcessor = null;
|
||||
}
|
||||
}, 2L);
|
||||
}
|
||||
|
||||
// Snapshot events
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent e) {
|
||||
manager.onChunkLoad(e.getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||
manager.onChunkUnload(e.getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlace(BlockPlaceEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), e.getBlock().getType());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBurn(BlockBurnEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
}
|
||||
// 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.
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDisconnect(PlayerQuitEvent e) {
|
||||
if (config.packetEventsPresent && packetProcessor != null) {
|
||||
UUID player = e.getPlayer().getUniqueId();
|
||||
packetProcessor.sendPlayerInfoRemovePacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
|
||||
if (event.getPlayer().hasPermission("raycastedentityocclusions.updatecheck")) {
|
||||
Player sender = event.getPlayer();
|
||||
checkForUpdates(plugin, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
public class Logger {
|
||||
private final static String PREFIX = "<hover:show_text:'Raycasted Entity Occlusions'><click:suggest_command:'/reo'><grey>[<gold>REO<grey>]</click></hover><reset> ";
|
||||
private final static String PREFIX_WARNING = "<hover:show_text:'Raycasted Entity Occlusions'><click:suggest_command:'/reo'><grey>[<gold>REO<grey>]</click></hover> <yellow><hover:show_text:'<yellow>Something went wrong'>[Warning]</hover> ";
|
||||
private final static String PREFIX_ERROR = "<hover:show_text:'Raycasted Entity Occlusions'><click:suggest_command:'/reo'><grey>[<gold>REO<grey>]</click></hover> <red><hover:show_text:'<red>Something went wrong'>[Error]</hover> ";
|
||||
private static JavaPlugin plugin = null;
|
||||
|
||||
private enum Level {
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR
|
||||
}
|
||||
|
||||
public static void info(String message) {
|
||||
forwardLog(/*PREFIX+*/message, Level.INFO);
|
||||
}
|
||||
|
||||
public static void warning(String message) {
|
||||
forwardLog(/* PREFIX_WARNING + */ message, Level.WARN);
|
||||
}
|
||||
|
||||
public static void error(String message) {
|
||||
forwardLog(/* PREFIX_ERROR+ */ message, Level.ERROR);
|
||||
}
|
||||
|
||||
public static void debug(String message, @Range(from = 1, to = 10) int level) {
|
||||
int debugLevel = 2; // TODO: grab real debug level from config
|
||||
if (debugLevel <= level) {
|
||||
forwardLog(message, Level.INFO);
|
||||
}
|
||||
}
|
||||
|
||||
private static void forwardLog(String message, Level severity) {
|
||||
if (plugin == null) {
|
||||
plugin = JavaPlugin.getProvidingPlugin(Logger.class);
|
||||
}
|
||||
Component messageComponent = MiniMessage.miniMessage().deserialize(message);
|
||||
switch (severity) {
|
||||
case INFO:
|
||||
plugin.getComponentLogger().info(messageComponent);
|
||||
break;
|
||||
case WARN:
|
||||
plugin.getComponentLogger().warn(messageComponent);
|
||||
break;
|
||||
case ERROR:
|
||||
plugin.getComponentLogger().error(messageComponent);
|
||||
break;
|
||||
default:
|
||||
plugin.getComponentLogger().error("{} | Additionally, severity {} is not supported by the logger.", messageComponent, severity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Packets;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.manager.player.PlayerManager;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPlayerInfoRemove;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketProcessor {
|
||||
private final RaycastedEntityOcclusion plugin;
|
||||
private final UUID key;
|
||||
|
||||
public PacketProcessor(RaycastedEntityOcclusion plugin) {
|
||||
this.plugin = plugin;
|
||||
key = UUID.randomUUID();
|
||||
}
|
||||
|
||||
public void processPlayerInfoRemovePacket(PacketSendEvent event) {
|
||||
WrapperPlayServerPlayerInfoRemove removePacket = new WrapperPlayServerPlayerInfoRemove(event);
|
||||
List<UUID> playersBeingRemoved = removePacket.getProfileIds();
|
||||
if (playersBeingRemoved.size() != 2) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (!playersBeingRemoved.contains(key)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
public void sendPlayerInfoRemovePacket(UUID uuid) {
|
||||
WrapperPlayServerPlayerInfoRemove removePacket = new WrapperPlayServerPlayerInfoRemove(uuid, key);
|
||||
PlayerManager playerManager = PacketEvents.getAPI().getPlayerManager();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
playerManager.sendPacket(player, removePacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Packets;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketListener;
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
|
||||
public class PacketsListener implements PacketListener {
|
||||
private RaycastedEntityOcclusion plugin;
|
||||
private PacketProcessor packetProcessor;
|
||||
public PacketsListener(RaycastedEntityOcclusion plugin) {
|
||||
// This is run on load, not on enable.
|
||||
this.plugin = plugin;
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onPacketSend(PacketSendEvent event) {
|
||||
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_REMOVE) {
|
||||
initializePacketProcessor();
|
||||
packetProcessor.processPlayerInfoRemovePacket(event);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePacketProcessor() {
|
||||
if (packetProcessor == null) {
|
||||
packetProcessor = plugin.getPacketProcessor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Packets;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.event.PacketListenerPriority;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
|
||||
public class Registrar {
|
||||
|
||||
public Registrar(RaycastedEntityOcclusion plugin) {
|
||||
// Register the packet listener
|
||||
PacketEvents.getAPI().getEventManager().registerListener(new PacketsListener(plugin), PacketListenerPriority.NORMAL);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Raycast;
|
||||
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.Logger;
|
||||
import games.cubi.raycastedEntityOcclusion.Snapshot.ChunkSnapshotManager;
|
||||
import games.cubi.raycastedEntityOcclusion.ConfigManager;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class Engine {
|
||||
|
||||
public static ConcurrentHashMap<Location, Set<Player>> canSeeTileEntity = new ConcurrentHashMap<>();
|
||||
public static Set<Chunk> syncRecheck = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private final static BlockData STONE = Material.STONE.createBlockData();
|
||||
private final static BlockData DEEPSLATE = Material.DEEPSLATE.createBlockData();
|
||||
|
||||
private static class RayJob {
|
||||
final Player player;
|
||||
final Entity target;
|
||||
final Location start, predictedStart, end;
|
||||
|
||||
RayJob(Player p, Entity e, Location s, Location pred, Location t) {
|
||||
player = p;
|
||||
target = e;
|
||||
start = s;
|
||||
predictedStart = pred;
|
||||
end = t;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RayResult {
|
||||
final Player player;
|
||||
final Entity target;
|
||||
final boolean visible;
|
||||
|
||||
RayResult(Player p, Entity e, boolean v) {
|
||||
player = p;
|
||||
target = e;
|
||||
visible = v;
|
||||
}
|
||||
}
|
||||
private static class TileResult {
|
||||
final Player player;
|
||||
final Location loc;
|
||||
final boolean visible;
|
||||
|
||||
TileResult(Player p, Location location, boolean v) {
|
||||
player = p;
|
||||
loc = location;
|
||||
visible = v;
|
||||
}
|
||||
}
|
||||
|
||||
public static void runEngine(ConfigManager cfg, ChunkSnapshotManager snapMgr, MovementTracker tracker, RaycastedEntityOcclusion plugin) {
|
||||
// ----- PHASE 1: SYNC GATHER -----
|
||||
|
||||
if (!syncRecheck.isEmpty()) {
|
||||
Logger.warning(syncRecheck.size() + " chunks failed to snapshot asynchronously, rechecking them now.");
|
||||
for (Chunk c : syncRecheck) {
|
||||
if (c.isLoaded()) {
|
||||
plugin.getChunkSnapshotManager().snapshotChunk(c);
|
||||
syncRecheck.remove(c);
|
||||
Logger.info("Successfully rechecked chunk " + c.getX() + ", " + c.getZ() + " in world " + c.getWorld().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<RayJob> jobs = new ArrayList<>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
|
||||
Location eye = p.getEyeLocation().clone();
|
||||
Location predEye = null;
|
||||
if (cfg.engineMode == 2) {
|
||||
// getPredictedLocation returns null if insufficient data or too slow
|
||||
predEye = tracker.getPredictedLocation(p);
|
||||
}
|
||||
|
||||
for (Entity e : p.getNearbyEntities(cfg.searchRadius, cfg.searchRadius, cfg.searchRadius)) {
|
||||
if (e == p) continue;
|
||||
// Cull-players logic
|
||||
if (e instanceof Player pl && (!cfg.cullPlayers || (cfg.onlyCullSneakingPlayers && !pl.isSneaking()))) {
|
||||
p.showEntity(plugin, e);
|
||||
continue;
|
||||
}
|
||||
|
||||
Location target = e.getLocation().add(0, e.getHeight() / 2, 0).clone();
|
||||
double dist = eye.distance(target);
|
||||
if (dist <= cfg.alwaysShowRadius) {
|
||||
p.showEntity(plugin, e);
|
||||
} else if (dist > cfg.raycastRadius) {
|
||||
p.hideEntity(plugin, e);
|
||||
} else if (!p.canSee(e) || plugin.tick % cfg.recheckInterval == 0) {
|
||||
// schedule for async raycast (with or without predEye)
|
||||
jobs.add(new RayJob(p, e, eye, predEye, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----- PHASE 2: ASYNC RAYCASTS -----
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
List<RayResult> results = new ArrayList<>(jobs.size());
|
||||
for (RayJob job : jobs) {
|
||||
// if the player is not in the same world as the target, skip
|
||||
if (!job.player.getWorld().equals(job.target.getWorld())) {
|
||||
continue;
|
||||
}
|
||||
// first cast from real eye
|
||||
boolean vis = RaycastUtil.raycast(job.start, job.end, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
|
||||
// if that fails and we have a predEye, cast again from predicted
|
||||
if (!vis && job.predictedStart != null) {
|
||||
if (cfg.debugMode) {
|
||||
job.predictedStart.getWorld().spawnParticle(Particle.DUST, job.predictedStart, 1, new Particle.DustOptions(Color.BLUE, 1f));
|
||||
}
|
||||
vis = RaycastUtil.raycast(job.predictedStart, job.end, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
}
|
||||
|
||||
results.add(new RayResult(job.player, job.target, vis));
|
||||
}
|
||||
|
||||
// ----- PHASE 3: SYNC APPLY -----
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
for (RayResult r : results) {
|
||||
Player p = r.player;
|
||||
Entity ent = r.target;
|
||||
if (p != null && ent != null) {
|
||||
boolean currentState = p.canSee(ent);
|
||||
if (currentState == r.visible) continue;
|
||||
if (r.visible) p.showEntity(plugin, ent);
|
||||
else {
|
||||
p.hideEntity(plugin, ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private final static ConcurrentLinkedQueue<TileResult> results = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public static void runTileEngine(ConfigManager cfg, ChunkSnapshotManager snapMgr, MovementTracker tracker, RaycastedEntityOcclusion plugin) {
|
||||
if (cfg.checkTileEntities) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
|
||||
World world = p.getWorld();
|
||||
//get player's chunk location
|
||||
int chunkX = p.getLocation().getBlockX() >> 4;
|
||||
int chunkZ = p.getLocation().getBlockZ() >> 4;
|
||||
Location playerLoc = p.getLocation();
|
||||
|
||||
//async run with vars passed in
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
int chunksRadius = (cfg.searchRadius + 15) / 16;
|
||||
HashSet<Location> tileEntities = new HashSet<>();
|
||||
for (int x = (-chunksRadius/2)+chunkX; x <= chunksRadius+chunkX; x++) {
|
||||
for (int z = (-chunksRadius/2)+chunkZ; z <= chunksRadius+chunkZ; z++) {
|
||||
tileEntities.addAll(snapMgr.getTileEntitiesInChunk(world, x, z));
|
||||
}
|
||||
}
|
||||
for (Location loc : tileEntities) {
|
||||
Set<Player> seen = canSeeTileEntity.get(loc);
|
||||
if (seen != null && seen.contains(p)) {
|
||||
if (cfg.tileEntityRecheckInterval == 0) continue;
|
||||
if (plugin.tick % (cfg.tileEntityRecheckInterval*20) != 0) continue;
|
||||
}
|
||||
|
||||
if (snapMgr.getMaterialAt(loc).equals(Material.BEACON)) continue;
|
||||
|
||||
if (!loc.getWorld().equals(playerLoc.getWorld())) continue;
|
||||
double distSquared = loc.distanceSquared(playerLoc);
|
||||
if (distSquared > cfg.searchRadius * cfg.searchRadius) {
|
||||
results.add(new TileResult(p, loc,false));
|
||||
continue;
|
||||
}
|
||||
if (distSquared < cfg.alwaysShowRadius * cfg.alwaysShowRadius) {
|
||||
results.add(new TileResult(p, loc,true));
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean visible = RaycastUtil.raycast(p.getEyeLocation(), loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
if (cfg.engineMode == 2 && !visible) {
|
||||
Location predEye = tracker.getPredictedLocation(p);
|
||||
if (predEye != null) {
|
||||
boolean result2 = RaycastUtil.raycast(predEye, loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
if (result2) {
|
||||
visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible) {
|
||||
canSeeTileEntity.computeIfAbsent(loc, k -> ConcurrentHashMap.newKeySet()).add(p);
|
||||
} else {
|
||||
Set<Player> seenPlayers = canSeeTileEntity.get(loc);
|
||||
if (seenPlayers != null) {
|
||||
seenPlayers.remove(p);
|
||||
if (seenPlayers.isEmpty()) {
|
||||
canSeeTileEntity.remove(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
results.add(new TileResult(p, loc, visible));
|
||||
}
|
||||
});
|
||||
}
|
||||
for (TileResult r : results) {
|
||||
Player p = r.player;
|
||||
Location loc = r.loc;
|
||||
boolean visible = r.visible;
|
||||
|
||||
syncToggleTileEntity(p, loc, visible, plugin);
|
||||
results.remove(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void hideTileEntity(Player p, Location location, RaycastedEntityOcclusion plugin) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (p.hasPermission("raycastedentityocclusions.bypass")) return;
|
||||
if (location.getBlockY() < 0) p.sendBlockChange(location, DEEPSLATE);
|
||||
else p.sendBlockChange(location, STONE);
|
||||
});
|
||||
}
|
||||
public static void showTileEntity(Player p, Location location, RaycastedEntityOcclusion plugin) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Block block = location.getBlock();
|
||||
BlockState data = block.getState();
|
||||
if (data instanceof TileState tileData) {
|
||||
p.sendBlockChange(location, block.getBlockData());
|
||||
p.sendBlockUpdate(location, tileData);
|
||||
}
|
||||
else {
|
||||
Logger.warning("Tried to show tile entity at " + location + " to "+p.getName()+" but it was not a TileState! Block type: " + block.getType()+". Removing from the list of tile entities.");
|
||||
canSeeTileEntity.remove(location);
|
||||
plugin.getChunkSnapshotManager().removeTileEntity(location);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
public static void syncToggleTileEntity(Player p, Location loc, boolean show, RaycastedEntityOcclusion plugin) {
|
||||
if (show) {
|
||||
showTileEntity(p, loc, plugin);
|
||||
} else {
|
||||
hideTileEntity(p, loc, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-8
@@ -1,9 +1,10 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
package games.cubi.raycastedEntityOcclusion.Raycast;
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.ConfigManager;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
@@ -14,16 +15,18 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class MovementTracker {
|
||||
private final Map<Player, Deque<Location>> history = new ConcurrentHashMap<>();
|
||||
|
||||
public MovementTracker(Plugin plugin) {
|
||||
public MovementTracker(RaycastedEntityOcclusion plugin, ConfigManager config) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
history.computeIfAbsent(p, k -> new ArrayDeque<>(5));
|
||||
Deque<Location> dq = history.get(p);
|
||||
if (dq.size() >= 5) dq.removeFirst();
|
||||
if (config.engineMode == 2) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
history.computeIfAbsent(p, k -> new ArrayDeque<>(5));
|
||||
Deque<Location> dq = history.get(p);
|
||||
if (dq.size() >= 5) dq.removeFirst();
|
||||
|
||||
dq.addLast(p.getEyeLocation().clone());
|
||||
dq.addLast(p.getEyeLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(plugin, 1L, 1L);
|
||||
@@ -37,6 +40,7 @@ public class MovementTracker {
|
||||
if (dq == null || dq.size() < 5) return null;
|
||||
Location old = dq.peekFirst();
|
||||
Location now = dq.peekLast();
|
||||
if (old == null || now == null) return null;
|
||||
double dx = now.getX() - old.getX();
|
||||
double dy = now.getY() - old.getY();
|
||||
double dz = now.getZ() - old.getZ();
|
||||
+17
-9
@@ -1,21 +1,27 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
package games.cubi.raycastedEntityOcclusion.Raycast;
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.Snapshot.ChunkSnapshotManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
||||
|
||||
|
||||
public class RaycastUtil {
|
||||
public static boolean raycast(Location start, Location end, int maxOccluding, boolean debug, ChunkSnapshotManager snap) {
|
||||
Particle.DustOptions dustRed = null;
|
||||
Particle.DustOptions dustGreen = null;
|
||||
if (debug) {
|
||||
static Particle.DustOptions dustRed = null;
|
||||
static Particle.DustOptions dustGreen = null;
|
||||
|
||||
private static void initDebugParticles() {
|
||||
if (dustRed == null) {
|
||||
dustRed = new Particle.DustOptions(org.bukkit.Color.RED, 1f);
|
||||
}
|
||||
if (dustGreen == null) {
|
||||
dustGreen = new Particle.DustOptions(org.bukkit.Color.GREEN, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean raycast(Location start, Location end, int maxOccluding, boolean debug, ChunkSnapshotManager snap) {
|
||||
initDebugParticles();
|
||||
if (!start.getWorld().equals(end.getWorld())) return false;
|
||||
double total = start.distance(end);
|
||||
double traveled = 0;
|
||||
Location curr = start.clone();
|
||||
@@ -24,7 +30,9 @@ public class RaycastUtil {
|
||||
curr.add(dir);
|
||||
traveled += 1;
|
||||
Material mat = snap.getMaterialAt(curr);
|
||||
//System.out.println(curr + " " + mat);
|
||||
if (mat == null) {
|
||||
continue;
|
||||
}
|
||||
if (mat.isOccluding()) {
|
||||
maxOccluding--;
|
||||
if (debug) {
|
||||
@@ -2,38 +2,52 @@ package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import games.cubi.raycastedEntityOcclusion.Packets.PacketProcessor;
|
||||
import games.cubi.raycastedEntityOcclusion.Packets.Registrar;
|
||||
import games.cubi.raycastedEntityOcclusion.Raycast.Engine;
|
||||
import games.cubi.raycastedEntityOcclusion.Raycast.MovementTracker;
|
||||
import games.cubi.raycastedEntityOcclusion.Snapshot.ChunkSnapshotManager;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import games.cubi.raycastedEntityOcclusion.bStats.MetricsCollector;
|
||||
|
||||
public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecutor {
|
||||
private ConfigManager cfg;
|
||||
private ChunkSnapshotManager snapMgr;
|
||||
private MovementTracker tracker;
|
||||
private CommandsManager commands;
|
||||
private boolean packetEventsPresent = false;
|
||||
private PacketProcessor packetProcessor = null;
|
||||
|
||||
public int tick = 0;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
Plugin packetEvents = Bukkit.getPluginManager().getPlugin("packetevents");
|
||||
if (packetEvents != null) {
|
||||
packetEventsPresent = true;
|
||||
getLogger().info("PacketEvents detected.");
|
||||
new Registrar(this);
|
||||
|
||||
} else {
|
||||
getLogger().info("PacketEvents not detected, disabling packet-based tablist modification. Don't worry, the plugin will still work without it.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
cfg = new ConfigManager(this);
|
||||
snapMgr = new ChunkSnapshotManager(this, cfg.snapshotRefreshInterval);
|
||||
tracker = new MovementTracker(this);
|
||||
snapMgr = new ChunkSnapshotManager(this);
|
||||
tracker = new MovementTracker(this, cfg);
|
||||
commands = new CommandsManager(this, cfg);
|
||||
getServer().getPluginManager().registerEvents(new SnapshotListener(snapMgr), this);
|
||||
|
||||
new UpdateChecker(this);
|
||||
getServer().getPluginManager().registerEvents(new EventListener(this, snapMgr, cfg), this);
|
||||
//Brigadier API
|
||||
LiteralCommandNode<CommandSourceStack> buildCommand = commands.registerCommand();
|
||||
|
||||
@@ -50,19 +64,45 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
|
||||
});
|
||||
|
||||
//bStats
|
||||
int pluginId = 24553;
|
||||
new Metrics(this, pluginId);
|
||||
new MetricsCollector(this, cfg);
|
||||
|
||||
|
||||
// TODO: Move this somewhere else, the main class should be cleaner
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
tick++;
|
||||
Engine.runEngine(cfg, snapMgr, tracker, RaycastedEntityOcclusion.this);
|
||||
Engine.runTileEngine(cfg, snapMgr, tracker, RaycastedEntityOcclusion.this);
|
||||
}
|
||||
}.runTaskTimer(this, 0L, 1L);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (packetEventsPresent && Bukkit.getPluginManager().isPluginEnabled("packetevents")) {
|
||||
cfg.setPacketEventsPresent(true);
|
||||
packetProcessor = new PacketProcessor(RaycastedEntityOcclusion.this);
|
||||
Logger.info("PacketEvents is enabled, enabling packet-based tablist modification.");
|
||||
}
|
||||
}
|
||||
}.runTaskLater(this, 1L);
|
||||
}
|
||||
|
||||
|
||||
public ConfigManager getConfigManager() {
|
||||
return cfg;
|
||||
}
|
||||
public ChunkSnapshotManager getChunkSnapshotManager() {
|
||||
return snapMgr;
|
||||
}
|
||||
public MovementTracker getMovementTracker() {
|
||||
return tracker;
|
||||
}
|
||||
public CommandsManager getCommandsManager() {
|
||||
return commands;
|
||||
}
|
||||
public PacketProcessor getPacketProcessor() {
|
||||
return packetProcessor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Snapshot;
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.ConfigManager;
|
||||
import games.cubi.raycastedEntityOcclusion.Logger;
|
||||
import games.cubi.raycastedEntityOcclusion.Raycast.Engine;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ChunkSnapshotManager {
|
||||
public static class Data {
|
||||
public final ChunkSnapshot snapshot;
|
||||
public final ConcurrentHashMap<Location, Material> delta = new ConcurrentHashMap<>();
|
||||
public final Set<Location> tileEntities = ConcurrentHashMap.newKeySet();
|
||||
public long lastRefresh;
|
||||
public int minHeight;
|
||||
public int maxHeight;
|
||||
|
||||
public Data(ChunkSnapshot snapshot, long time) {
|
||||
this.snapshot = snapshot;
|
||||
this.lastRefresh = time;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<String, Data> dataMap = new ConcurrentHashMap<>();
|
||||
private final ConfigManager cfg;
|
||||
|
||||
public ChunkSnapshotManager(RaycastedEntityOcclusion plugin) {
|
||||
cfg = plugin.getConfigManager();
|
||||
//get loaded chunks and add them to dataMap
|
||||
for (World w : plugin.getServer().getWorlds()) {
|
||||
for (Chunk c : w.getLoadedChunks()) {
|
||||
snapshotChunk(c);
|
||||
}
|
||||
}
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long now = System.currentTimeMillis();
|
||||
int chunksRefreshed = 0;
|
||||
int chunksToRefreshMaximum = getNumberOfCachedChunks() / 3;
|
||||
for (Map.Entry<String, Data> e : dataMap.entrySet()) {
|
||||
if (now - e.getValue().lastRefresh >= cfg.snapshotRefreshInterval * 1000L && chunksRefreshed < chunksToRefreshMaximum) {
|
||||
chunksRefreshed++;
|
||||
String key = e.getKey();
|
||||
snapshotChunk(key);
|
||||
}
|
||||
}
|
||||
if (cfg.debugMode) {
|
||||
Logger.info("ChunkSnapshotManager: Refreshed " + chunksRefreshed + " chunks out of " + chunksToRefreshMaximum + " maximum.");
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, cfg.snapshotRefreshInterval * 2L, cfg.snapshotRefreshInterval * 2L /* This runs 10 times per refreshInterval, spreading out the refreshes */);
|
||||
}
|
||||
|
||||
public void onChunkLoad(Chunk c) {
|
||||
snapshotChunk(c);
|
||||
}
|
||||
|
||||
public void onChunkUnload(Chunk c) {
|
||||
removeChunkSnapshot(c);
|
||||
}
|
||||
|
||||
public void snapshotChunk(Chunk c) {
|
||||
//if (cfg.debugMode) {
|
||||
//Logger.info("ChunkSnapshotManager: Taking snapshot of chunk " + c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ());
|
||||
//}
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
public void snapshotChunk(String key) {
|
||||
snapshotChunk(getKeyChunk(key));
|
||||
}
|
||||
public void removeChunkSnapshot(Chunk c) {
|
||||
if (cfg.debugMode) {
|
||||
Logger.info("ChunkSnapshotManager: Removing snapshot of chunk " + c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ());
|
||||
}
|
||||
dataMap.remove(key(c));
|
||||
}
|
||||
|
||||
// Used by EventListener to update the delta map when a block is placed or broken
|
||||
public void onBlockChange(Location loc, Material m) {
|
||||
if (cfg.debugMode) {
|
||||
Logger.info("ChunkSnapshotManager: Block change at " + loc + " to " + m);
|
||||
}
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
if (d != null) {
|
||||
d.delta.put(blockLoc(loc), m);
|
||||
if (cfg.checkTileEntities) {
|
||||
// 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) {
|
||||
if (cfg.debugMode){
|
||||
Logger.info("ChunkSnapshotManager: Tile entity at " + loc);
|
||||
}
|
||||
d.tileEntities.add(loc);
|
||||
} else {
|
||||
d.tileEntities.remove(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {Logger.error("Data map value empty, ignoring block update!");}
|
||||
}
|
||||
|
||||
private Data takeSnapshot(Chunk c, long now) {
|
||||
World w = c.getWorld();
|
||||
Data data = new Data(c.getChunkSnapshot(), now);
|
||||
int chunkX = c.getX() * 16;
|
||||
int chunkZ = c.getZ() * 16;
|
||||
int minHeight = w.getMinHeight();
|
||||
int maxHeight = w.getMaxHeight();
|
||||
data.maxHeight = maxHeight;
|
||||
data.minHeight = minHeight;
|
||||
if (cfg.checkTileEntities) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = minHeight; y < maxHeight; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public String key(Chunk c) {
|
||||
return c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ();
|
||||
}
|
||||
public String key(World world, int x, int z) {
|
||||
return world.getName() + ":" + x + ":" + z;
|
||||
}
|
||||
public int getKeyX(String key) {
|
||||
String[] parts = key.split(":");
|
||||
return Integer.parseInt(parts[1]);
|
||||
}
|
||||
public int getKeyZ(String key) {
|
||||
String[] parts = key.split(":");
|
||||
return Integer.parseInt(parts[2]);
|
||||
}
|
||||
public World getKeyWorld(String key) {
|
||||
String[] parts = key.split(":");
|
||||
return Bukkit.getWorld(parts[0]);
|
||||
}
|
||||
public Chunk getKeyChunk(String key) {
|
||||
return getKeyWorld(key).getChunkAt(getKeyX(key), getKeyZ(key));
|
||||
}
|
||||
|
||||
public Material getMaterialAt(Location loc) {
|
||||
Chunk chunk = loc.getChunk();
|
||||
Data 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)");
|
||||
Engine.syncRecheck.add(chunk);
|
||||
return loc.getBlock().getType();
|
||||
}
|
||||
double yLevel = loc.getY();
|
||||
if (yLevel < d.minHeight || yLevel > d.maxHeight) {
|
||||
return null;
|
||||
}
|
||||
Material dm = d.delta.get(blockLoc(loc));
|
||||
if (dm != null) {
|
||||
if (cfg.debugMode) Logger.info("Using delta");
|
||||
return dm;
|
||||
}
|
||||
int x = loc.getBlockX() & 0xF;
|
||||
int y = loc.getBlockY();
|
||||
int z = loc.getBlockZ() & 0xF;
|
||||
|
||||
return d.snapshot.getBlockType(x, y, z);
|
||||
}
|
||||
|
||||
//get TileEntity Locations in chunk
|
||||
public Set<Location> getTileEntitiesInChunk(World world, int x, int z) {
|
||||
Data d = dataMap.get(key(world, x, z));
|
||||
if (d == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return d.tileEntities;
|
||||
}
|
||||
|
||||
public void removeTileEntity(Location loc) {
|
||||
Chunk c = loc.getChunk();
|
||||
Data d = dataMap.get(key(c));
|
||||
if (d != null) {
|
||||
d.tileEntities.remove(blockLoc(loc));
|
||||
Logger.info("ChunkSnapshotManager: Removed tile entity at " + loc);
|
||||
} else {
|
||||
Logger.error("ChunkSnapshotManager: No snapshot for " + c + " when removing tile entity at " + loc);
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumberOfCachedChunks() {
|
||||
return dataMap.size();
|
||||
//created to use in a debug command maybe
|
||||
}
|
||||
|
||||
public static Location blockLoc(Location fullLoc) {
|
||||
Location blockLoc = fullLoc.toBlockLocation();
|
||||
blockLoc.setYaw(0);
|
||||
blockLoc.setPitch(0);
|
||||
return blockLoc;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockBurnEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
public class SnapshotListener implements Listener {
|
||||
private final ChunkSnapshotManager manager;
|
||||
|
||||
public SnapshotListener(ChunkSnapshotManager mgr) {
|
||||
this.manager = mgr;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent e) {
|
||||
manager.onChunkLoad(e.getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||
manager.onChunkUnload(e.getChunk());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlace(BlockPlaceEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), e.getBlock().getType());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBreak(BlockBreakEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBurn(BlockBurnEvent e) {
|
||||
manager.onBlockChange(e.getBlock().getLocation(), Material.AIR);
|
||||
}
|
||||
// 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 solutioon please let me know.
|
||||
}
|
||||
@@ -1,88 +1,112 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
public class UpdateChecker {
|
||||
/*private final RaycastedEntityOcclusion plugin;
|
||||
private final RaycastedEntityOcclusion plugin;
|
||||
|
||||
public UpdateChecker(RaycastedEntityOcclusion plugin) {
|
||||
this.plugin = plugin;
|
||||
checkForUpdates();
|
||||
checkForUpdates(plugin, Bukkit.getConsoleSender());
|
||||
}
|
||||
|
||||
public void checkForUpdates() {
|
||||
|
||||
public static CompletableFuture<String> fetchFeaturedVersion(RaycastedEntityOcclusion plugin) {
|
||||
CompletableFuture<String> future = new CompletableFuture<>();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if (hasNewUpdate() != null) {
|
||||
plugin.getLogger().info("A new version of RaycastedEntityOcclusions is available! ");
|
||||
plugin.getLogger().info("Please update to the latest version for the best experience.");
|
||||
} else {
|
||||
plugin.getLogger().info("You are using the latest version of RaycastedEntityOcclusions.");
|
||||
|
||||
final String url = "https://api.modrinth.com/v2/project/bCjNZu0C/version?featured=true";
|
||||
try (final InputStreamReader reader = new InputStreamReader(new URL(url).openConnection().getInputStream())) {
|
||||
final JsonArray array = new JsonArray();
|
||||
array.add(new BufferedReader(reader).readLine());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
|
||||
sb.append(array.get(i).getAsString());
|
||||
}
|
||||
String apiData = sb.toString();
|
||||
JsonArray jsonArray = JsonParser.parseString(apiData).getAsJsonArray();
|
||||
JsonObject firstObject = jsonArray.get(0).getAsJsonObject();
|
||||
String versionNumber = firstObject.get("version_number").getAsString();
|
||||
|
||||
future.complete(versionNumber);
|
||||
|
||||
} catch (IOException e) {
|
||||
future.completeExceptionally(new IllegalStateException("Unable to fetch latest version", e));
|
||||
}
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public String hasNewUpdate() {
|
||||
try {
|
||||
String versionUrl = "https://example.com/version.txt";
|
||||
URL url = new URI(versionUrl).toURL();
|
||||
URLConnection conn = url.openConnection();
|
||||
conn.setConnectTimeout(500); // 5s connect timeout
|
||||
conn.setReadTimeout(500); // 5s read timeout
|
||||
private static final int INVALID_VERSION_FORMAT = -2; private static final int CURRENT_IS_OLDER = -1; private static final int VERSIONS_ARE_EQUAL = 0; private static final int CURRENT_IS_NEWER = 1;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(conn.getInputStream()))) {
|
||||
String version = reader.readLine();
|
||||
if (version == null) {
|
||||
plugin.getLogger().warning("Could not check for updates: version is null");
|
||||
return null;
|
||||
}
|
||||
String currentVersion = plugin.getDescription().getVersion();
|
||||
if (!currentVersion.equals(version)) {
|
||||
return version;
|
||||
}
|
||||
return null;
|
||||
private static int checkIfLaterThan(String currentVersion, String fetchedVersion) {
|
||||
String[] currentParts = currentVersion.replace("v", "").split("\\.");
|
||||
String[] fetchedParts = fetchedVersion.replace("v", "").split("\\.");
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
plugin.getLogger().warning("Could not check for updates: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().warning("Could not check for updates: " + e.getMessage());
|
||||
return null;
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (currentParts.length != 3 || fetchedParts.length != 3) {
|
||||
return INVALID_VERSION_FORMAT;
|
||||
}
|
||||
|
||||
int majorVersionDifference = Integer.parseInt(currentParts[0]) - Integer.parseInt(fetchedParts[0]);
|
||||
|
||||
if (majorVersionDifference == VERSIONS_ARE_EQUAL) {
|
||||
int minorVersionDifference = Integer.parseInt(currentParts[1]) - Integer.parseInt(fetchedParts[1]);
|
||||
|
||||
if (minorVersionDifference == VERSIONS_ARE_EQUAL) {
|
||||
int patchVersionDifference = Integer.parseInt(currentParts[2]) - Integer.parseInt(fetchedParts[2]);
|
||||
return patchVersionDifference;
|
||||
}
|
||||
return minorVersionDifference;
|
||||
}
|
||||
return majorVersionDifference;
|
||||
}
|
||||
|
||||
//on join
|
||||
@EventHandler
|
||||
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) {
|
||||
if (event.getPlayer().hasPermission("raycastedentityocclusions.updatecheck")) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
String newVersion = hasNewUpdate();
|
||||
if (newVersion != null) {
|
||||
event.getPlayer().sendRichMessage("<#FF00FF>A new version of <green>RaycastedEntityOcclusions<#FF00FF> is available! \n" +
|
||||
"\n" +
|
||||
"<white>Please update to the latest version for the best experience.\n" +
|
||||
"\n" +
|
||||
"<blue><aqua><u><click:open_url:'https://modrinth.com/plugin/raycasted-entity-occlusions/versions'>Click here to download</click></u></aqua></blue>");
|
||||
} else {
|
||||
event.getPlayer().sendMessage("<green>You are using the latest version of RaycastedEntityOcclusions.");
|
||||
public static void checkForUpdates(RaycastedEntityOcclusion plugin, CommandSender audience) {
|
||||
fetchFeaturedVersion(plugin).thenAccept(version -> {
|
||||
// This runs synchronously when the version is fetched
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
int versionCheck = checkIfLaterThan(plugin.getDescription().getVersion(), version);
|
||||
|
||||
if (versionCheck == VERSIONS_ARE_EQUAL) {
|
||||
audience.sendRichMessage("<green>You are using the latest version of Raycasted Entity Occlusions.");
|
||||
}
|
||||
|
||||
if (versionCheck == CURRENT_IS_OLDER) {
|
||||
audience.sendRichMessage("<red>You are not using the latest version of Raycasted Entity Occlusions. Please update to <green>v" + version+".");
|
||||
if (audience instanceof Player) audience.sendRichMessage("\n" + "<hover:show_text:'https://modrinth.com/project/bCjNZu0C/versions'><aqua><u><click:open_url:'https://modrinth.com/project/bCjNZu0C/versions'>Click here to download it.</click></u></aqua></hover>");
|
||||
}
|
||||
|
||||
if (versionCheck == CURRENT_IS_NEWER) {
|
||||
audience.sendRichMessage("<yellow>You are using a development build of Raycasted Entity Occlusions. The latest stable version is <green>v" + version + "<yellow>.");
|
||||
}
|
||||
|
||||
if (versionCheck == INVALID_VERSION_FORMAT) {
|
||||
audience.sendRichMessage("<red>Unable to check for updates, invalid version format.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}).exceptionally(ex -> {
|
||||
// Handle error (e.g., log the exception)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Logger.warning("Failed to fetch version: " + ex.getMessage());
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
*/
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package games.cubi.raycastedEntityOcclusion;
|
||||
package games.cubi.raycastedEntityOcclusion.bStats;
|
||||
/*
|
||||
* This Metrics class was auto-generated and can be copied into your project if you are
|
||||
* not using a build tool like Gradle or Maven for dependency management.
|
||||
@@ -0,0 +1,157 @@
|
||||
package games.cubi.raycastedEntityOcclusion.bStats;
|
||||
|
||||
import games.cubi.raycastedEntityOcclusion.ConfigManager;
|
||||
import games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MetricsCollector {
|
||||
private final RaycastedEntityOcclusion plugin;
|
||||
private final Metrics metrics;
|
||||
private final ConfigManager config;
|
||||
|
||||
private List<Integer> playersOnline = new ArrayList<>();
|
||||
private List<Integer> entities = new ArrayList<>();
|
||||
|
||||
public MetricsCollector(RaycastedEntityOcclusion plugin, ConfigManager config) {
|
||||
this.plugin = plugin;
|
||||
int pluginId = 24553;
|
||||
metrics = new Metrics(plugin, pluginId);
|
||||
this.config = config;
|
||||
registerCustomMetrics();
|
||||
|
||||
plugin.getServer().getScheduler().runTaskTimer(plugin, this::collectMetrics, 0L, 6000L); // 6000 ticks = 5 minutes
|
||||
}
|
||||
|
||||
public void registerCustomMetrics() {
|
||||
metrics.addCustomChart(new Metrics.SimplePie("max_occluding_count", () -> String.valueOf(config.maxOccludingCount)));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("cull_players", this::getCullPlayersStatus));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("raycast_radius", () -> getRoundedValue(config.raycastRadius, ConfigManager.RAYCAST_RADIUS_DEFAULT)));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("search_radius", () -> getRoundedValue(config.searchRadius, ConfigManager.SEARCH_RADIUS_DEFAULT)));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("always_show_radius", () -> getRoundedValue(config.alwaysShowRadius, ConfigManager.ALWAYS_SHOW_RADIUS_DEFAULT)));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("engine_mode", () -> String.valueOf(config.engineMode)));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("snapshot_refresh_interval", () -> getRoundedValue(config.snapshotRefreshInterval, ConfigManager.SNAPSHOT_REFRESH_INTERVAL_DEFAULT)));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("entity_recheck_interval", () -> getRoundedValue(config.recheckInterval, ConfigManager.RECHECK_INTERVAL_DEFAULT)));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("tile_entity_recheck_interval", this::tileEntityCheckStatus));
|
||||
|
||||
metrics.addCustomChart(new Metrics.SimplePie("server_size", this::getPlayersOnline));
|
||||
metrics.addCustomChart(new Metrics.SimplePie("entities", this::getEntities));
|
||||
}
|
||||
|
||||
public String getCullPlayersStatus() {
|
||||
if (config.cullPlayers) {
|
||||
if (config.onlyCullSneakingPlayers) {
|
||||
return "Sneaking";
|
||||
} else {
|
||||
return "Always";
|
||||
}
|
||||
} else {
|
||||
return "Never";
|
||||
}
|
||||
}
|
||||
|
||||
public String tileEntityCheckStatus() {
|
||||
if (config.checkTileEntities) {
|
||||
return getRoundedValue(config.tileEntityRecheckInterval, ConfigManager.TILE_ENTITY_RECHECK_INTERVAL_DEFAULT);
|
||||
} else {
|
||||
return "Disabled";
|
||||
}
|
||||
}
|
||||
|
||||
public String getRoundedValue(int value, int defaultValue) {
|
||||
if (value == defaultValue) {
|
||||
return defaultValue + ".0";
|
||||
} else {
|
||||
int roundedValue = Math.round(value / 5.0f) * 5;
|
||||
return String.valueOf(roundedValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void collectMetrics() {
|
||||
playersOnline.add(Bukkit.getServer().getOnlinePlayers().size());
|
||||
// TODO: Cache all entities in Engine, and also use that here
|
||||
int totalEntities = 0;
|
||||
for (World world : Bukkit.getWorlds()) {
|
||||
totalEntities += world.getEntities().size();
|
||||
}
|
||||
entities.add(totalEntities);
|
||||
}
|
||||
public String getPlayersOnline() {
|
||||
if (playersOnline == null) {
|
||||
return "Null";
|
||||
}
|
||||
int averaged = (int) playersOnline.stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.average()
|
||||
.orElse(-1);
|
||||
playersOnline.clear();
|
||||
|
||||
if (averaged < 0) {
|
||||
return "Null";
|
||||
} else if (averaged < 4) {
|
||||
return String.valueOf(averaged);
|
||||
} else if (averaged < 7) {
|
||||
return "4-6";
|
||||
} else if (averaged < 11) {
|
||||
return "7-10";
|
||||
} else if (averaged < 16) {
|
||||
return "11-15";
|
||||
} else if (averaged < 26) {
|
||||
return "15-25";
|
||||
} else if (averaged < 40) {
|
||||
return "26-40";
|
||||
} else if (averaged < 71) {
|
||||
return "41-70";
|
||||
} else if (averaged < 101) {
|
||||
return "71-100";
|
||||
} else if (averaged < 201) {
|
||||
return "101-200";
|
||||
} else if (averaged < 301) {
|
||||
return "201-300";
|
||||
} else if (averaged < 501) {
|
||||
return "301-500";
|
||||
} else {
|
||||
return "500+";
|
||||
}
|
||||
|
||||
}
|
||||
public String getEntities() {
|
||||
if (entities == null) {
|
||||
return "Null";
|
||||
}
|
||||
int averaged = (int) entities.stream()
|
||||
.mapToInt(Integer::intValue)
|
||||
.average()
|
||||
.orElse(-1);
|
||||
entities.clear();
|
||||
|
||||
if (averaged < 0) {
|
||||
return "Null";
|
||||
} else if (averaged < 21) {
|
||||
return "0-20";
|
||||
} else if (averaged < 51) {
|
||||
return "21-50";
|
||||
} else if (averaged < 101) {
|
||||
return "51-100";
|
||||
} else if (averaged < 301) {
|
||||
return "101-300";
|
||||
} else if (averaged < 501) {
|
||||
return "301-500";
|
||||
} else if (averaged < 1001) {
|
||||
return "501-1000";
|
||||
} else if (averaged < 2001) {
|
||||
return "1001-2000";
|
||||
} else if (averaged < 5000) {
|
||||
return "2001-5000";
|
||||
} else {
|
||||
return "5000+";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
config-version: 1.0 # Do not change this value, it is used internally by the plugin to determine if the config is up to date.
|
||||
|
||||
checks:
|
||||
entities:
|
||||
enabled: true
|
||||
max-occluding-count: 3
|
||||
raycast-radius: 48
|
||||
always-show-radius: 16 # radius to always show entities
|
||||
recheck-interval: 50 # ticks between forced rechecks for visible entities
|
||||
engine-mode: 1 # 1 = straight-line; 2 = predictive and straight-line
|
||||
tile-entities:
|
||||
enabled: true
|
||||
max-occluding-count: 3
|
||||
raycast-radius: 48
|
||||
always-show-radius: 16
|
||||
recheck-interval: 0 # seconds between forced rechecks for visible tile entities. If set to 0, they will never be rechecked.
|
||||
engine-mode: 1 # 1 = straight-line; 2 = predictive and straight-line
|
||||
players:
|
||||
enabled: false
|
||||
only-cull-sneaking: false
|
||||
max-occluding-count: 3
|
||||
raycast-radius: 48
|
||||
always-show-radius: 16
|
||||
recheck-interval: 50 # ticks between forced rechecks for visible players
|
||||
engine-mode: 1 # 1 = straight-line; 2 = predictive and straight-line
|
||||
snapshots:
|
||||
chunk-refresh-interval: 60 # seconds between chunk snapshot refresh, won't change without restart
|
||||
debug:
|
||||
log-level: 1 # Scale from 0-10, where larger numbers mean more verbose logging and 0 disables logging
|
||||
particles: false # enable debug particles
|
||||
@@ -1,10 +1,18 @@
|
||||
snapshot-refresh-interval: 60 # seconds between chunk snapshot refresh, won't change without restart
|
||||
engine-mode: 1 # 1 = straight-line; 2 = predictive and straight-line
|
||||
max-occluding-count: 3 # blocks before blocking
|
||||
debug-mode: false # enable debug particles
|
||||
always-show-radius: 8 # radius to always show entities
|
||||
raycast-radius: 82 # beyond this, entities auto-hide
|
||||
search-radius: 82 # search radius for entities
|
||||
snapshot-refresh-interval: 60 # seconds between chunk snapshot refresh, won't change without restart
|
||||
|
||||
engine-mode: 1 # 1 = straight-line; 2 = predictive and straight-line
|
||||
max-occluding-count: 3 # blocks before blocking
|
||||
|
||||
debug-mode: false # enable debug particles and more verbose logging
|
||||
|
||||
always-show-radius: 16 # radius to always show entities
|
||||
raycast-radius: 48 # beyond this, entities auto-hide
|
||||
search-radius: 48 # search radius for entities
|
||||
|
||||
cull-players: false # cull hidden players as well as other entities
|
||||
only-cull-sneaking-players: false # only cull sneaking players (requires cull-players)
|
||||
recheck-interval: 20 # ticks between forced rechecks for visible entities
|
||||
|
||||
recheck-interval: 50 # ticks between forced rechecks for visible entities
|
||||
|
||||
check-tile-entities: true # check tile entities for occlusion
|
||||
tile-entity-recheck-interval: 0 # seconds between forced rechecks for visible tile entities. If set to 0, they will never be rechecked.
|
||||
@@ -2,10 +2,22 @@ name: RaycastedEntityOcclusions
|
||||
version: ${version}
|
||||
main: games.cubi.raycastedEntityOcclusion.RaycastedEntityOcclusion
|
||||
api-version: '1.21'
|
||||
prefix: EntityOcclusions
|
||||
prefix: REO
|
||||
authors: [ _Cubicake ]
|
||||
load: STARTUP
|
||||
website: https://cubi.games
|
||||
permissions:
|
||||
raycastedentityocclusions.command:
|
||||
description: Permission to use the RaycastedEntityOcclusions command
|
||||
default: op
|
||||
default: op
|
||||
raycastedentityocclusions.bypass:
|
||||
description: Permission to bypass all checks
|
||||
default: false
|
||||
raycastedentityocclusions.updatecheck:
|
||||
description: Permission to check for plugin updates
|
||||
default: op
|
||||
raycastedentityocclusions.receivelogmessages:
|
||||
description: Permission to receive log messages which are sent to the console
|
||||
default: false
|
||||
softdepend:
|
||||
- packetevents
|
||||
Reference in new issue
Block a user