Compare commits

...
21 Commits
Author SHA1 Message Date
Cubicake d5bf02b4ea Merge remote-tracking branch 'origin/main' 2025-07-27 18:52:36 +09:30
Cubicake ed98e2abeb Update README.md 2025-07-27 17:39:13 +09:30
Cubicake 9a07bd0119 v1.6.0 release 2025-07-27 17:21:42 +09:30
Cubicake 74aca26910 Update .gitignore 2025-07-27 16:32:49 +09:30
Cubicake 25f5652a12 Kinda crappy way to hopefully fix the missing snapshots while I work on a more permanant fix 2025-07-27 16:08:40 +09:30
Cubicake 7679f08d06 Use the new logger to format messages 2025-07-27 16:07:26 +09:30
Cubicake 7ad99917d1 Might use this later? 2025-07-27 16:06:44 +09:30
Cubicake ce56eb316e Might use this later? 2025-07-27 16:06:39 +09:30
Cubicake 74426d80af Mark as mojmapped 2025-07-27 16:06:13 +09:30
Cubicake fdb1f567ac Snapshot changes 2025-07-26 16:26:14 +09:30
Cubicake e823f7a2f7 Move string operations to their own methods 2025-07-26 16:25:15 +09:30
Cubicake 7c1f7fd2a6 Version bump 2025-07-25 20:35:25 +09:30
Cubicake c26e6a1623 Oops forgot to pass config to movement tracker 2025-07-25 20:35:16 +09:30
Cubicake 8155903342 More readable imports 2025-07-25 20:32:53 +09:30
Cubicake f2ade6b0b8 Merge remote-tracking branch 'origin/main' 2025-07-25 20:31:26 +09:30
Cubicake f486d1fc2e Stop intellij from complaining 2025-07-25 20:30:09 +09:30
Cubicake 50eeab8cfe Bump api version 2025-07-25 20:26:37 +09:30
Cubicake 4009fe6d02 Use built in bukkit chunk keys instead of making custom ones 2025-07-25 20:26:25 +09:30
Cubicake b7e6fa9c5f Stop using * imports, use plugin logger, use built in bukkit chunk keys instead of making custom ones, hopefully fix chunks not being snapshotted. 2025-07-25 20:25:44 +09:30
Cubicake dcc986c232 Stop using * imports 2025-07-23 13:47:52 +09:30
Cubicake 95cea9f875 Stop using * imports 2025-07-23 13:47:20 +09:30
9 changed files with 159 additions and 43 deletions

No files matched your search

+3 -1
View File
@@ -1,11 +1,13 @@
# User-specific stuff
.idea/
README.md
*.md
*.iml
*.ipr
*.iws
README.md
# IntelliJ
out/
+1 -1
View File
@@ -1,4 +1,4 @@
Latest version: v1.5.1
Latest version: v1.6.0
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusions/
+9 -3
View File
@@ -3,7 +3,7 @@ plugins {
}
group = 'games.cubi'
version = '1.6.0-dev-1'
version = '1.6.0'
repositories {
mavenCentral()
@@ -21,8 +21,8 @@ repositories {
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("com.github.retrooper:packetevents-spigot:2.8.0")
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
}
def targetJavaVersion = 21
@@ -50,4 +50,10 @@ processResources {
filesMatching('plugin.yml') {
expand props
}
}
jar {
manifest {
attributes "paperweight-mappings-namespace": "mojang"
}
}
@@ -0,0 +1,52 @@
package games.cubi.raycastedEntityOcclusion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.plugin.java.JavaPlugin;
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);
}
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);
}
//Bukkit.getConsoleSender().sendRichMessage(message);
//Bukkit.broadcast(MiniMessage.miniMessage().deserialize(message), "raycastedentityocclusions.receivelogmessages");
}
}
@@ -1,22 +1,33 @@
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.*;
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.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Set;
import java.util.List;
public class Engine {
public static ConcurrentHashMap<Location, Set<Player>> canSeeTileEntity = new ConcurrentHashMap<>();
public static Set<Chunk> syncRecheck = ConcurrentHashMap.newKeySet();
private static class RayJob {
final Player player;
@@ -46,6 +57,16 @@ public class Engine {
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);
}
}
}
List<RayJob> jobs = new ArrayList<>();
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
@@ -70,9 +91,7 @@ public class Engine {
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 {
} 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));
}
@@ -124,7 +143,7 @@ public class Engine {
if (cfg.checkTileEntities) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
String world = p.getWorld().getName();
World world = p.getWorld();
//get player's chunk location
int chunkX = p.getLocation().getBlockX() >> 4;
int chunkZ = p.getLocation().getBlockZ() >> 4;
@@ -210,7 +229,4 @@ public class Engine {
}
});
}
}
/*
*/
}
@@ -44,8 +44,9 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
public void onEnable() {
cfg = new ConfigManager(this);
snapMgr = new ChunkSnapshotManager(this);
tracker = new MovementTracker(this);
tracker = new MovementTracker(this, cfg);
commands = new CommandsManager(this, cfg);
new UpdateChecker(this);
getServer().getPluginManager().registerEvents(new EventListener(this, snapMgr, cfg), this);
//Brigadier API
LiteralCommandNode<CommandSourceStack> buildCommand = commands.registerCommand();
@@ -82,7 +83,7 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
if (packetEventsPresent && Bukkit.getPluginManager().isPluginEnabled("packetevents")) {
cfg.setPacketEventsPresent(true);
packetProcessor = new PacketProcessor(RaycastedEntityOcclusion.this);
getLogger().info("PacketEvents is enabled, enabling packet-based tablist modification.");
Logger.info("PacketEvents is enabled, enabling packet-based tablist modification.");
}
}
}.runTaskLater(this, 1L);
@@ -1,19 +1,29 @@
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.*;
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.*;
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 Map<Location, Material> delta = new ConcurrentHashMap<>();
public final ConcurrentHashMap<Location, Material> delta = new ConcurrentHashMap<>();
public final Set<Location> tileEntities = ConcurrentHashMap.newKeySet();
public long lastRefresh;
public int minHeight;
@@ -25,15 +35,17 @@ public class ChunkSnapshotManager {
}
}
private final Map<String, Data> dataMap = new ConcurrentHashMap<>();
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()) {
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
snapshotChunk(c);
}
}
@@ -47,38 +59,43 @@ public class ChunkSnapshotManager {
if (now - e.getValue().lastRefresh >= cfg.snapshotRefreshInterval * 1000L && chunksRefreshed < chunksToRefreshMaximum) {
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])
);
//String[] parts = key.split(":");
Chunk c = getKeyChunk(key);
e.setValue(takeSnapshot(c, now));
}
}
if (cfg.debugMode) {
plugin.getLogger().info("ChunkSnapshotManager: Refreshed " + chunksRefreshed + " chunks out of " + chunksToRefreshMaximum + " maximum.");
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) {
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
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 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) {
Bukkit.getLogger().info("ChunkSnapshotManager: Block change at " + loc + " to " + m);
Logger.info("ChunkSnapshotManager: Block change at " + loc + " to " + m);
}
Data d = dataMap.get(key(loc.getChunk()));
if (d != null) {
@@ -89,7 +106,7 @@ public class ChunkSnapshotManager {
loc = loc.clone().add(0.5, 0.5, 0.5);
if (data instanceof TileState) {
if (cfg.debugMode){
Bukkit.getLogger().info("ChunkSnapshotManager: Tile entity at " + loc);
Logger.info("ChunkSnapshotManager: Tile entity at " + loc);
}
d.tileEntities.add(loc);
} else {
@@ -124,16 +141,35 @@ public class ChunkSnapshotManager {
return data;
}
private String key(Chunk c) {
public String key(Chunk c) {
return c.getWorld().getName() + ":" + c.getX() + ":" + c.getZ();
}
public String key(World world, int x, int z) {
return world + ":" + 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) {
Data d = dataMap.get(key(loc.getChunk()));
Chunk chunk = loc.getChunk();
Data d = dataMap.get(key(chunk));
if (d == null) {
Chunk c = loc.getChunk();
//dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis())); infinite loop
System.err.println("ChunkSnapshotManager: No snapshot for " + c+ " Please report this on our discord (discord.cubi.games)'");
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();
@@ -152,8 +188,8 @@ public class ChunkSnapshotManager {
}
//get TileEntity Locations in chunk
public Set<Location> getTileEntitiesInChunk(String worldName, int x, int z) {
Data d = dataMap.get(worldName + ":" + x + ":" + z);
public Set<Location> getTileEntitiesInChunk(World world, int x, int z) {
Data d = dataMap.get(key(world, x, z));
if (d == null) {
return Collections.emptySet();
}
@@ -67,7 +67,7 @@ public class UpdateChecker {
}).exceptionally(ex -> {
// Handle error (e.g., log the exception)
Bukkit.getScheduler().runTask(plugin, () -> {
plugin.getLogger().warning("Failed to fetch version: " + ex.getMessage());
Logger.warning("Failed to fetch version: " + ex.getMessage());
});
return null;
});
+3
View File
@@ -16,5 +16,8 @@ permissions:
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