Compare commits

...
28 Commits
Author SHA1 Message Date
Cubicake d46d63668b Implement better version checking 2025-10-16 12:08:49 +10:30
Cubicake 83a278b00a Add run-paper plugin, bump version number 2025-10-16 12:08:12 +10:30
Cubicake c1e0db5613 Merge remote-tracking branch 'origin/main' 2025-10-16 11:08:23 +10:30
Cubicake 34db141f08 Re-enable logging, clean up Logger.java 2025-10-16 11:08:07 +10:30
Cubicake a68bcfdbf5 Update README with dependencies and known issues 2025-10-02 21:43:39 -04:00
Cubicake 77825067de Create FUNDING.yml 2025-09-18 21:22:52 +09:30
Cubicake 085fa59e42 Disable logging temp 2025-09-05 10:00:32 +09:30
Cubicake 2db88a4498 lazy load debug particles 2025-09-03 09:00:29 +09:30
Cubicake e9935f0350 Update latest version to v1.6.1 2025-08-26 08:42:50 +09:30
Cubicake 8d39fa5427 Bump version 2025-08-13 10:55:53 +09:30
Cubicake b958d0dc46 Make intellij shut up 2025-08-12 12:05:36 +09:30
Cubicake e9adb65690 Instead of throwing an error, try and fx the situation. 2025-08-12 12:03:16 +09:30
Cubicake 6a289c81a9 Check world so that distance check doesn't error 2025-08-12 10:40:05 +09:30
Cubicake 34b04ff059 Include update link in update checker 2025-08-11 21:17:52 +09:30
Cubicake 1a73c2509a Fix the previous commit 2025-08-11 20:49:45 +09:30
Cubicake e3731f76f0 Debug mode logging 2025-08-11 20:49:14 +09:30
Cubicake bd1f6ad482 Don't spawn a new thread for each tile entity update 2025-08-11 20:36:26 +09:30
Cubicake 951e4f4ad9 Fix change delta being ignored 2025-08-11 20:28:22 +09:30
Cubicake 114746aeaf Resolves #11 2025-08-11 20:08:06 +09:30
Cubicake 9dc9652917 Use snapshotChunk 2025-08-11 18:03:29 +09:30
Cubicake b97f675159 Bump version 2025-08-11 18:03:08 +09:30
Cubicake f5e16fc75d Resolves #10
OMFG I hate myself
2025-08-11 18:02:48 +09:30
Cubicake c228cef24a Merge remote-tracking branch 'origin/main' 2025-08-09 16:19:36 +09:30
Cubicake 098aab5e31 Don't hardcode plugin name 2025-08-09 16:19:20 +09:30
Cubicake 31b500bc7b Fix bug in issue #9 2025-08-04 11:35:13 +09:30
Cubicake d5e3281cf2 new config layout, to replace config.yml at a later date 2025-08-04 11:33:47 +09:30
Cubicake 98dbefd576 For future packet handling 2025-08-04 11:33:17 +09:30
Cubicake 4dce9b3278 WIP improved debugging 2025-08-04 11:32:45 +09:30
10 changed files with 229 additions and 62 deletions

No files matched your search

+15
View File
@@ -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']
+6 -3
View File
@@ -1,4 +1,4 @@
Latest version: v1.6.0
Latest version: v1.6.1
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusions/
@@ -15,7 +15,10 @@ Use cases:
- 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 engine-mode to 2
- If cull-player is set to true any culled players will be removed from tablist. Potential solutions are being investigated, suggestions are welcome.
- 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.
+12 -2
View File
@@ -1,9 +1,10 @@
plugins {
id 'java'
id("xyz.jpenilla.run-paper") version "2.3.1"
}
group = 'games.cubi'
version = '1.6.0'
version = '1.6.2'
repositories {
mavenCentral()
@@ -22,7 +23,16 @@ repositories {
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
compileOnly("com.github.retrooper:packetevents-spigot:2.8.0") //Latest is 2.9.4, but using 2.8.0 api still works and allows for compatibility with older versions
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
@@ -3,6 +3,7 @@ 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> ";
@@ -28,6 +29,13 @@ public class Logger {
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);
@@ -46,7 +54,5 @@ public class Logger {
default:
plugin.getComponentLogger().error("{} | Additionally, severity {} is not supported by the logger.", messageComponent, severity);
}
//Bukkit.getConsoleSender().sendRichMessage(message);
//Bukkit.broadcast(MiniMessage.miniMessage().deserialize(message), "raycastedentityocclusions.receivelogmessages");
}
}
@@ -16,13 +16,15 @@ public class PacketsListener implements PacketListener {
@Override
public void onPacketSend(PacketSendEvent event) {
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_REMOVE) {
if (packetProcessor == null) {
// Initialize the PacketProcessor if it hasn't been initialized yet since the initialization of the PacketsListener is on load, not on enable.
packetProcessor = plugin.getPacketProcessor();
}
initializePacketProcessor();
packetProcessor.processPlayerInfoRemovePacket(event);
}
}
private void initializePacketProcessor() {
if (packetProcessor == null) {
packetProcessor = plugin.getPacketProcessor();
}
}
@@ -14,6 +14,8 @@ 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;
@@ -23,12 +25,16 @@ 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;
@@ -54,6 +60,17 @@ public class Engine {
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 -----
@@ -63,6 +80,8 @@ public class Engine {
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());
}
}
}
@@ -139,6 +158,8 @@ public class Engine {
}
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()) {
@@ -147,6 +168,8 @@ public class Engine {
//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;
@@ -165,28 +188,28 @@ public class Engine {
if (snapMgr.getMaterialAt(loc).equals(Material.BEACON)) continue;
double distSquared = loc.distanceSquared(p.getLocation());
if (!loc.getWorld().equals(playerLoc.getWorld())) continue;
double distSquared = loc.distanceSquared(playerLoc);
if (distSquared > cfg.searchRadius * cfg.searchRadius) {
hideTileEntity(p, loc);
results.add(new TileResult(p, loc,false));
continue;
}
if (distSquared < cfg.alwaysShowRadius * cfg.alwaysShowRadius) {
showTileEntity(p, loc);
results.add(new TileResult(p, loc,true));
continue;
}
boolean result = RaycastUtil.raycast(p.getEyeLocation(), loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
if (cfg.engineMode == 2) {
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) {
result = true;
visible = true;
}
}
}
syncToggleTileEntity(p, loc, result, plugin);
if (result) {
if (visible) {
canSeeTileEntity.computeIfAbsent(loc, k -> ConcurrentHashMap.newKeySet()).add(p);
} else {
Set<Player> seenPlayers = canSeeTileEntity.get(loc);
@@ -197,36 +220,50 @@ public class Engine {
}
}
}
results.add(new TileResult(p, loc, visible));
}
});
}
}
}
for (TileResult r : results) {
Player p = r.player;
Location loc = r.loc;
boolean visible = r.visible;
public static void hideTileEntity(Player p, Location location) {
if (p.hasPermission("raycastedentityocclusions.bypass")) return;
BlockData fake;
if (location.getBlockY() < 0) {
fake = Material.DEEPSLATE.createBlockData();
}
else {
fake = Material.STONE.createBlockData();
}
p.sendBlockChange(location, fake);
}
public static void showTileEntity(Player p, Location location) {
Block block = location.getBlock();
BlockData data = block.getBlockData();
p.sendBlockChange(location, data);
}
public static void syncToggleTileEntity(Player p, Location loc, boolean bool, RaycastedEntityOcclusion plugin) {
Bukkit.getScheduler().runTask(plugin, () -> {
if (bool) {
showTileEntity(p, loc);
} else {
hideTileEntity(p, loc);
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);
}
}
}
@@ -7,13 +7,21 @@ 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();
@@ -37,11 +37,9 @@ public class ChunkSnapshotManager {
private static final ConcurrentHashMap<String, Data> dataMap = new ConcurrentHashMap<>();
private final ConfigManager cfg;
private final RaycastedEntityOcclusion plugin;
public ChunkSnapshotManager(RaycastedEntityOcclusion plugin) {
cfg = plugin.getConfigManager();
this.plugin = plugin;
//get loaded chunks and add them to dataMap
for (World w : plugin.getServer().getWorlds()) {
for (Chunk c : w.getLoadedChunks()) {
@@ -59,9 +57,7 @@ public class ChunkSnapshotManager {
if (now - e.getValue().lastRefresh >= cfg.snapshotRefreshInterval * 1000L && chunksRefreshed < chunksToRefreshMaximum) {
chunksRefreshed++;
String key = e.getKey();
//String[] parts = key.split(":");
Chunk c = getKeyChunk(key);
e.setValue(takeSnapshot(c, now));
snapshotChunk(key);
}
}
if (cfg.debugMode) {
@@ -80,11 +76,14 @@ public class ChunkSnapshotManager {
}
public void snapshotChunk(Chunk c) {
if (cfg.debugMode) {
//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());
@@ -99,7 +98,7 @@ public class ChunkSnapshotManager {
}
Data d = dataMap.get(key(loc.getChunk()));
if (d != null) {
d.delta.put(loc, m);
d.delta.put(blockLoc(loc), m);
if (cfg.checkTileEntities) {
// Check if the block is a tile entity
BlockState data = loc.getBlock().getState();
@@ -114,6 +113,7 @@ public class ChunkSnapshotManager {
}
}
}
else {Logger.error("Data map value empty, ignoring block update!");}
}
private Data takeSnapshot(Chunk c, long now) {
@@ -145,7 +145,7 @@ public class ChunkSnapshotManager {
return c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ();
}
public String key(World world, int x, int z) {
return world + ":" + x + ":" + z;
return world.getName() + ":" + x + ":" + z;
}
public int getKeyX(String key) {
String[] parts = key.split(":");
@@ -176,8 +176,9 @@ public class ChunkSnapshotManager {
if (yLevel < d.minHeight || yLevel > d.maxHeight) {
return null;
}
Material dm = d.delta.get(loc);
Material dm = d.delta.get(blockLoc(loc));
if (dm != null) {
if (cfg.debugMode) Logger.info("Using delta");
return dm;
}
int x = loc.getBlockX() & 0xF;
@@ -196,9 +197,27 @@ public class ChunkSnapshotManager {
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;
}
}
@@ -31,7 +31,7 @@ public class UpdateChecker {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
final String url = "https://api.modrinth.com/v2/project/raycasted-entity-occlusions/version?featured=true";
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());
@@ -54,14 +54,51 @@ public class UpdateChecker {
return future;
}
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;
private static int checkIfLaterThan(String currentVersion, String fetchedVersion) {
String[] currentParts = currentVersion.replace("v", "").split("\\.");
String[] fetchedParts = fetchedVersion.replace("v", "").split("\\.");
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;
}
public static void checkForUpdates(RaycastedEntityOcclusion plugin, CommandSender audience) {
fetchFeaturedVersion(plugin).thenAccept(version -> {
// This runs synchronously when the version is fetched
Bukkit.getScheduler().runTask(plugin, () -> {
if (plugin.getDescription().getVersion().equals(version)) {
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.");
} else {
audience.sendRichMessage("<red>You are not using the latest version of Raycasted Entity Occlusions. Please update to <green>v" + version);
}
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 -> {
+30
View File
@@ -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