mirror of
https://github.com/Cubicake/RaycastedAntiESP.git
synced 2026-11-17 14:29:40 -05:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1f70a296c | ||
|
|
3eccd69669 | ||
|
|
9f27f1c58f |
No files matched your search
@@ -1,15 +0,0 @@
|
||||
# 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']
|
||||
+1
-3
@@ -1,13 +1,11 @@
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
|
||||
README.md
|
||||
*.md
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
README.md
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Latest version: v1.6.1
|
||||
Latest version: v1.5.1
|
||||
|
||||
The latest version can currently only be found on Modrinth https://modrinth.com/plugin/raycasted-entity-occlusions/
|
||||
|
||||
@@ -15,10 +15,7 @@ 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, and is worse for players with higher ping.
|
||||
- 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.
|
||||
+2
-18
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
}
|
||||
|
||||
group = 'games.cubi'
|
||||
version = '1.6.2'
|
||||
version = '1.6.0-dev-1'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -22,19 +21,10 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-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
|
||||
java {
|
||||
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
|
||||
@@ -60,10 +50,4 @@ processResources {
|
||||
filesMatching('plugin.yml') {
|
||||
expand props
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes "paperweight-mappings-namespace": "mojang"
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,13 @@ public class PacketsListener implements PacketListener {
|
||||
@Override
|
||||
public void onPacketSend(PacketSendEvent event) {
|
||||
if (event.getPacketType() == PacketType.Play.Server.PLAYER_INFO_REMOVE) {
|
||||
initializePacketProcessor();
|
||||
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();
|
||||
}
|
||||
packetProcessor.processPlayerInfoRemovePacket(event);
|
||||
}
|
||||
}
|
||||
|
||||
private void initializePacketProcessor() {
|
||||
if (packetProcessor == null) {
|
||||
packetProcessor = plugin.getPacketProcessor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +1,28 @@
|
||||
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 games.cubi.raycastedEntityOcclusion.Snapshot.EntitySnapshotManager;
|
||||
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler;
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import org.bukkit.*;
|
||||
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 org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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;
|
||||
@@ -60,33 +49,30 @@ public class Engine {
|
||||
visible = v;
|
||||
}
|
||||
}
|
||||
private static class TileResult {
|
||||
private static class PlayerInfo {
|
||||
final Player player;
|
||||
final Location loc;
|
||||
final boolean visible;
|
||||
final Location location;
|
||||
final Location predLoc;
|
||||
|
||||
TileResult(Player p, Location location, boolean v) {
|
||||
PlayerInfo(Player p, Location loc, Location pred) {
|
||||
player = p;
|
||||
loc = location;
|
||||
visible = v;
|
||||
location = loc;
|
||||
predLoc = pred;
|
||||
}
|
||||
}
|
||||
|
||||
public static void runEngine(ConfigManager cfg, ChunkSnapshotManager snapMgr, MovementTracker tracker, RaycastedEntityOcclusion plugin) {
|
||||
private static Consumer<ScheduledTask> raycastEntitiesAroundPlayer(Player player, Location eye, Location predEye){
|
||||
|
||||
return task -> { /* This is needed for it to return, idk why*/ };
|
||||
}
|
||||
|
||||
Map<UUID, RayResult> results = new ConcurrentHashMap<>();
|
||||
|
||||
public static void runEngine(ConfigManager cfg, ChunkSnapshotManager snapMgr, MovementTracker tracker, EntitySnapshotManager entitySnapshotManager, 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<>();
|
||||
List<PlayerInfo> info = new ArrayList<>();
|
||||
// TODO: Store players in EntitySnapshotManager and use that to avoid iterating through all players every tick
|
||||
AsyncScheduler asyncScheduler = plugin.getServer().getAsyncScheduler();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
|
||||
Location eye = p.getEyeLocation().clone();
|
||||
@@ -95,12 +81,20 @@ public class Engine {
|
||||
// getPredictedLocation returns null if insufficient data or too slow
|
||||
predEye = tracker.getPredictedLocation(p);
|
||||
}
|
||||
asyncScheduler.runNow(plugin, raycastEntitiesAroundPlayer(p, eye, predEye));
|
||||
}
|
||||
|
||||
for (Entity e : p.getNearbyEntities(cfg.searchRadius, cfg.searchRadius, cfg.searchRadius)) {
|
||||
// ----- PHASE 2: ASYNC RAYCASTS -----
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
List<RayResult> results = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
for (Entity e : entitySnapshotManager.getBukkitEntitiesNear(eye, 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);
|
||||
//TODO: Add to result that player should be shown
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -110,16 +104,22 @@ 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) {
|
||||
} 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, 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())) {
|
||||
@@ -158,18 +158,14 @@ 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()) {
|
||||
if (p.hasPermission("raycastedentityocclusions.bypass")) continue;
|
||||
World world = p.getWorld();
|
||||
String world = p.getWorld().getName();
|
||||
//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;
|
||||
@@ -188,28 +184,28 @@ public class Engine {
|
||||
|
||||
if (snapMgr.getMaterialAt(loc).equals(Material.BEACON)) continue;
|
||||
|
||||
if (!loc.getWorld().equals(playerLoc.getWorld())) continue;
|
||||
double distSquared = loc.distanceSquared(playerLoc);
|
||||
double distSquared = loc.distanceSquared(p.getLocation());
|
||||
if (distSquared > cfg.searchRadius * cfg.searchRadius) {
|
||||
results.add(new TileResult(p, loc,false));
|
||||
hideTileEntity(p, loc);
|
||||
continue;
|
||||
}
|
||||
if (distSquared < cfg.alwaysShowRadius * cfg.alwaysShowRadius) {
|
||||
results.add(new TileResult(p, loc,true));
|
||||
showTileEntity(p, loc);
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean visible = RaycastUtil.raycast(p.getEyeLocation(), loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
if (cfg.engineMode == 2 && !visible) {
|
||||
boolean result = RaycastUtil.raycast(p.getEyeLocation(), loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
if (cfg.engineMode == 2) {
|
||||
Location predEye = tracker.getPredictedLocation(p);
|
||||
if (predEye != null) {
|
||||
boolean result2 = RaycastUtil.raycast(predEye, loc, cfg.maxOccludingCount, cfg.debugMode, snapMgr);
|
||||
if (result2) {
|
||||
visible = true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible) {
|
||||
syncToggleTileEntity(p, loc, result, plugin);
|
||||
if (result) {
|
||||
canSeeTileEntity.computeIfAbsent(loc, k -> ConcurrentHashMap.newKeySet()).add(p);
|
||||
} else {
|
||||
Set<Player> seenPlayers = canSeeTileEntity.get(loc);
|
||||
@@ -220,50 +216,36 @@ 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;
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class MovementTracker {
|
||||
* Predicts location 5 ticks ahead based on last 5 ticks. Returns null if insufficient or too slow.
|
||||
*/
|
||||
public Location getPredictedLocation(Player p) {
|
||||
//TODO: Make the predicted location incorporate ping
|
||||
Deque<Location> dq = history.get(p);
|
||||
if (dq == null || dq.size() < 5) return null;
|
||||
Location old = dq.peekFirst();
|
||||
|
||||
@@ -7,21 +7,10 @@ import org.bukkit.Particle;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class RaycastUtil {
|
||||
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);
|
||||
}
|
||||
}
|
||||
private static final Particle.DustOptions DUST_RED = new Particle.DustOptions(org.bukkit.Color.RED, 1f);
|
||||
private static final Particle.DustOptions DUST_GREEN = 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();
|
||||
@@ -36,12 +25,12 @@ public class RaycastUtil {
|
||||
if (mat.isOccluding()) {
|
||||
maxOccluding--;
|
||||
if (debug) {
|
||||
start.getWorld().spawnParticle(Particle.DUST, curr, 1, dustRed);
|
||||
start.getWorld().spawnParticle(Particle.DUST, curr, 1, DUST_RED);
|
||||
}
|
||||
if (maxOccluding < 1) return false;
|
||||
}
|
||||
else if (debug) {
|
||||
start.getWorld().spawnParticle(Particle.DUST, curr, 1, dustGreen);
|
||||
start.getWorld().spawnParticle(Particle.DUST, curr, 1, DUST_GREEN);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -7,6 +7,7 @@ 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 games.cubi.raycastedEntityOcclusion.Snapshot.EntitySnapshotManager;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
@@ -20,10 +21,12 @@ import games.cubi.raycastedEntityOcclusion.bStats.MetricsCollector;
|
||||
public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecutor {
|
||||
private ConfigManager cfg;
|
||||
private ChunkSnapshotManager snapMgr;
|
||||
private EntitySnapshotManager entitySnapshotManager;
|
||||
private MovementTracker tracker;
|
||||
private CommandsManager commands;
|
||||
private boolean packetEventsPresent = false;
|
||||
private PacketProcessor packetProcessor = null;
|
||||
private UpdateChecker updateChecker;
|
||||
|
||||
public int tick = 0;
|
||||
|
||||
@@ -46,7 +49,8 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
|
||||
snapMgr = new ChunkSnapshotManager(this);
|
||||
tracker = new MovementTracker(this, cfg);
|
||||
commands = new CommandsManager(this, cfg);
|
||||
new UpdateChecker(this);
|
||||
updateChecker = new UpdateChecker(this);
|
||||
entitySnapshotManager = new EntitySnapshotManager();
|
||||
getServer().getPluginManager().registerEvents(new EventListener(this, snapMgr, cfg), this);
|
||||
//Brigadier API
|
||||
LiteralCommandNode<CommandSourceStack> buildCommand = commands.registerCommand();
|
||||
@@ -72,7 +76,7 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
|
||||
@Override
|
||||
public void run() {
|
||||
tick++;
|
||||
Engine.runEngine(cfg, snapMgr, tracker, RaycastedEntityOcclusion.this);
|
||||
Engine.runEngine(cfg, snapMgr, tracker, entitySnapshotManager, RaycastedEntityOcclusion.this);
|
||||
Engine.runTileEngine(cfg, snapMgr, tracker, RaycastedEntityOcclusion.this);
|
||||
}
|
||||
}.runTaskTimer(this, 0L, 1L);
|
||||
@@ -83,7 +87,7 @@ public class RaycastedEntityOcclusion extends JavaPlugin implements CommandExecu
|
||||
if (packetEventsPresent && Bukkit.getPluginManager().isPluginEnabled("packetevents")) {
|
||||
cfg.setPacketEventsPresent(true);
|
||||
packetProcessor = new PacketProcessor(RaycastedEntityOcclusion.this);
|
||||
Logger.info("PacketEvents is enabled, enabling packet-based tablist modification.");
|
||||
getLogger().info("PacketEvents is enabled, enabling packet-based tablist modification.");
|
||||
}
|
||||
}
|
||||
}.runTaskLater(this, 1L);
|
||||
|
||||
+28
-83
@@ -1,29 +1,19 @@
|
||||
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.*;
|
||||
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.*;
|
||||
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 Map<Location, Material> delta = new ConcurrentHashMap<>();
|
||||
public final Set<Location> tileEntities = ConcurrentHashMap.newKeySet();
|
||||
public long lastRefresh;
|
||||
public int minHeight;
|
||||
@@ -35,7 +25,7 @@ public class ChunkSnapshotManager {
|
||||
}
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<String, Data> dataMap = new ConcurrentHashMap<>();
|
||||
private final Map<String, Data> dataMap = new ConcurrentHashMap<>();
|
||||
private final ConfigManager cfg;
|
||||
|
||||
public ChunkSnapshotManager(RaycastedEntityOcclusion plugin) {
|
||||
@@ -43,7 +33,7 @@ public class ChunkSnapshotManager {
|
||||
//get loaded chunks and add them to dataMap
|
||||
for (World w : plugin.getServer().getWorlds()) {
|
||||
for (Chunk c : w.getLoadedChunks()) {
|
||||
snapshotChunk(c);
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,55 +47,49 @@ public class ChunkSnapshotManager {
|
||||
if (now - e.getValue().lastRefresh >= cfg.snapshotRefreshInterval * 1000L && chunksRefreshed < chunksToRefreshMaximum) {
|
||||
chunksRefreshed++;
|
||||
String key = e.getKey();
|
||||
snapshotChunk(key);
|
||||
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) {
|
||||
Logger.info("ChunkSnapshotManager: Refreshed " + chunksRefreshed + " chunks out of " + chunksToRefreshMaximum + " maximum.");
|
||||
plugin.getLogger().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);
|
||||
dataMap.put(key(c), takeSnapshot(c, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
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);
|
||||
Bukkit.getLogger().info("ChunkSnapshotManager: Block change at " + loc + " to " + m);
|
||||
}
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
if (d != null) {
|
||||
d.delta.put(blockLoc(loc), m);
|
||||
d.delta.put(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);
|
||||
Bukkit.getLogger().info("ChunkSnapshotManager: Tile entity at " + loc);
|
||||
}
|
||||
d.tileEntities.add(loc);
|
||||
} else {
|
||||
@@ -113,7 +97,6 @@ public class ChunkSnapshotManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {Logger.error("Data map value empty, ignoring block update!");}
|
||||
}
|
||||
|
||||
private Data takeSnapshot(Chunk c, long now) {
|
||||
@@ -141,44 +124,24 @@ public class ChunkSnapshotManager {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String key(Chunk c) {
|
||||
private 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));
|
||||
Data d = dataMap.get(key(loc.getChunk()));
|
||||
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);
|
||||
//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)'");
|
||||
return loc.getBlock().getType();
|
||||
}
|
||||
double yLevel = loc.getY();
|
||||
if (yLevel < d.minHeight || yLevel > d.maxHeight) {
|
||||
return null;
|
||||
}
|
||||
Material dm = d.delta.get(blockLoc(loc));
|
||||
Material dm = d.delta.get(loc);
|
||||
if (dm != null) {
|
||||
if (cfg.debugMode) Logger.info("Using delta");
|
||||
return dm;
|
||||
}
|
||||
int x = loc.getBlockX() & 0xF;
|
||||
@@ -189,35 +152,17 @@ public class ChunkSnapshotManager {
|
||||
}
|
||||
|
||||
//get TileEntity Locations in chunk
|
||||
public Set<Location> getTileEntitiesInChunk(World world, int x, int z) {
|
||||
Data d = dataMap.get(key(world, x, z));
|
||||
public Set<Location> getTileEntitiesInChunk(String worldName, int x, int z) {
|
||||
Data d = dataMap.get(worldName + ":" + 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;
|
||||
}
|
||||
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package games.cubi.raycastedEntityOcclusion.Snapshot;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class EntitySnapshotManager {
|
||||
|
||||
public static class EntityData {
|
||||
|
||||
//Entity data for a single entity in a world.
|
||||
|
||||
private volatile Location location;
|
||||
/** Player UUID → can-see flag (true/false). Absence = NOT_SET. */
|
||||
private final Map<UUID, Boolean> visibility = new ConcurrentHashMap<>();
|
||||
|
||||
public EntityData(Location initial) {
|
||||
this.location = initial.clone();
|
||||
}
|
||||
|
||||
/* ---- location ---- */
|
||||
public Location getLocation() { return location.clone(); }
|
||||
public void setLocation(Location loc) { this.location = loc.clone(); }
|
||||
|
||||
/* ---- visibility ---- */
|
||||
public void setVisibleFor(UUID playerId, boolean canSee) {
|
||||
visibility.put(playerId, canSee);
|
||||
}
|
||||
public void clearVisibility(UUID playerId) { visibility.remove(playerId); }
|
||||
|
||||
public Boolean getVisibility(UUID playerId) {
|
||||
return visibility.get(playerId); // may be null
|
||||
}
|
||||
}
|
||||
|
||||
// Cache: world-name → (entity-UUID → data)
|
||||
private final Map<String, Map<UUID, EntityData>> cache = new ConcurrentHashMap<>();
|
||||
|
||||
public void addEntity(Entity entity) {
|
||||
Objects.requireNonNull(entity, "EntitySnapshotManager: Cannot add null entity");
|
||||
cache.computeIfAbsent(entity.getWorld().getName(),
|
||||
w -> new ConcurrentHashMap<>())
|
||||
.putIfAbsent(entity.getUniqueId(),
|
||||
new EntityData(entity.getLocation()));
|
||||
}
|
||||
|
||||
public void removeEntity(Entity entity) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(entity.getWorld().getName());
|
||||
if (entitiesInWorld != null) {
|
||||
entitiesInWorld.remove(entity.getUniqueId());
|
||||
if (entitiesInWorld.isEmpty()) cache.remove(entity.getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates (or inserts) the latest location for the entity. */
|
||||
public void updateLocation(Entity entity) {
|
||||
cache.computeIfAbsent(entity.getWorld().getName(),
|
||||
w -> new ConcurrentHashMap<>())
|
||||
.compute(entity.getUniqueId(), (id, data) -> {
|
||||
if (data == null) return new EntityData(entity.getLocation());
|
||||
data.setLocation(entity.getLocation());
|
||||
return data;
|
||||
});
|
||||
}
|
||||
|
||||
// put anywhere inside EntitySnapshotManager
|
||||
public @Nullable Location getLocation(Entity entity) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(entity.getWorld().getName());
|
||||
if (entitiesInWorld == null) return null;
|
||||
EntityData data = entitiesInWorld.get(entity.getUniqueId());
|
||||
return (data == null) ? null : data.getLocation();
|
||||
}
|
||||
|
||||
|
||||
/* ---- visibility helpers ---- */
|
||||
public void setVisibility(Entity entity, Player player, boolean canSee) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(entity.getWorld().getName());
|
||||
if (entitiesInWorld != null) {
|
||||
EntityData d = entitiesInWorld.get(entity.getUniqueId());
|
||||
if (d != null) d.setVisibleFor(player.getUniqueId(), canSee);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearVisibility(Entity entity, Player player) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(entity.getWorld().getName());
|
||||
if (entitiesInWorld != null) {
|
||||
EntityData d = entitiesInWorld.get(entity.getUniqueId());
|
||||
if (d != null) d.clearVisibility(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Boolean getVisibility(Entity entity, Player player) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(entity.getWorld().getName());
|
||||
if (entitiesInWorld == null) return null;
|
||||
EntityData d = entitiesInWorld.get(entity.getUniqueId());
|
||||
return (d == null) ? null : d.getVisibility(player.getUniqueId());
|
||||
}
|
||||
|
||||
/* ---- miscellaneous ---- */
|
||||
public Collection<EntityData> getEntitiesInWorld(World world) {
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(world.getName());
|
||||
return (entitiesInWorld == null) ? Collections.emptyList() : entitiesInWorld.values();
|
||||
}
|
||||
|
||||
public List<Entity> getBukkitEntitiesNear(Location origin, int radiusX, int radiusY, int radiusZ) {
|
||||
|
||||
World world = origin.getWorld();
|
||||
Map<UUID, EntityData> entitiesInWorld = cache.get(world.getName());
|
||||
if (entitiesInWorld == null || entitiesInWorld.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
double ox = origin.getX(), oy = origin.getY(), oz = origin.getZ();
|
||||
double minX = ox - radiusX, maxX = ox + radiusX;
|
||||
double minY = oy - radiusY, maxY = oy + radiusY;
|
||||
double minZ = oz - radiusZ, maxZ = oz + radiusZ;
|
||||
|
||||
List<Entity> result = new ArrayList<>();
|
||||
for (Map.Entry<UUID, EntityData> entry : entitiesInWorld.entrySet()) {
|
||||
EntityData data = entry.getValue();
|
||||
Location loc = data.getLocation();
|
||||
double x = loc.getX(), y = loc.getY(), z = loc.getZ();
|
||||
|
||||
if (x < minX || x > maxX || y < minY || y > maxY || z < minZ || z > maxZ) {
|
||||
|
||||
Entity live = world.getEntity(entry.getKey());
|
||||
if (live != null) {
|
||||
if (!live.isDead()) {
|
||||
result.add(live);
|
||||
}
|
||||
else removeEntity(live);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return cache.values().stream().mapToInt(Map::size).sum();
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ package games.cubi.raycastedEntityOcclusion;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class UpdateChecker {
|
||||
@@ -22,6 +23,7 @@ public class UpdateChecker {
|
||||
|
||||
public UpdateChecker(RaycastedEntityOcclusion plugin) {
|
||||
this.plugin = plugin;
|
||||
plugin.getLogger().info("Checking for updates...");
|
||||
checkForUpdates(plugin, Bukkit.getConsoleSender());
|
||||
}
|
||||
|
||||
@@ -31,7 +33,7 @@ public class UpdateChecker {
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
final String url = "https://api.modrinth.com/v2/project/bCjNZu0C/version?featured=true";
|
||||
final String url = "https://api.modrinth.com/v2/project/raycasted-entity-occlusions/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,57 +56,23 @@ 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) {
|
||||
//plugin.getLogger().info("Fetching latest version from Modrinth...");
|
||||
fetchFeaturedVersion(plugin).thenAccept(version -> {
|
||||
//plugin.getLogger().info("Latest version fetched: " + 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) {
|
||||
//plugin.getLogger().info("Checking if current version matches the latest version...");
|
||||
if (plugin.getDescription().getVersion().equals(version)) {
|
||||
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.");
|
||||
} else {
|
||||
audience.sendRichMessage("<red>You are not using the latest version of Raycasted Entity Occlusions. Please update to <green>v" + version);
|
||||
}
|
||||
});
|
||||
}).exceptionally(ex -> {
|
||||
// Handle error (e.g., log the exception)
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Logger.warning("Failed to fetch version: " + ex.getMessage());
|
||||
plugin.getLogger().warning("Failed to fetch version: " + ex.getMessage());
|
||||
});
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
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
|
||||
@@ -16,8 +16,5 @@ 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
|
||||
Reference in new issue
Block a user