mirror of
https://github.com/Cubicake/RaycastedAntiESP.git
synced 2026-11-17 06:26:04 -05:00
Compare commits
90
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8cb78056ed | ||
|
|
dec5ba5de2 | ||
|
|
30b123ba3c | ||
|
|
87fd94baf4 | ||
|
|
1e5a4eb95b | ||
|
|
981b375d6d | ||
|
|
6de11030b0 | ||
|
|
d445aa58ba | ||
|
|
49311be791 | ||
|
|
0b4df5124b | ||
|
|
4435058373 | ||
|
|
4dfed55d48 | ||
|
|
c2b6941922 | ||
|
|
feb80bf678 | ||
|
|
c4fd919a08 | ||
|
|
40f91482d4 | ||
|
|
3f82330433 | ||
|
|
8cfe2b0a2e | ||
|
|
f2c1d01051 | ||
|
|
e1d0db9d5f | ||
|
|
a86a9bc4c0 | ||
|
|
377c12a00a | ||
|
|
9bc14b2097 | ||
|
|
02f9df6643 | ||
|
|
e2af9f65c1 | ||
|
|
0eb1766a4a | ||
|
|
4a3f25045f | ||
|
|
0c80348416 | ||
|
|
4295d2fe8a | ||
|
|
3f8ccff505 | ||
|
|
bc440490f9 | ||
|
|
5527e38ea4 | ||
|
|
244fde97c0 | ||
|
|
8b3a62f1f5 | ||
|
|
45d0e0581c | ||
|
|
aa7934f258 | ||
|
|
cfdb255b56 | ||
|
|
14e6aaaae6 | ||
|
|
d7cc7abd8c | ||
|
|
73e58e191e | ||
|
|
e5a591af1a | ||
|
|
9951b5d7a1 | ||
|
|
e99c3b9de2 | ||
|
|
0500f4bd5f | ||
|
|
9a841308ff | ||
|
|
c4bf1cbf0b | ||
|
|
db22c675db | ||
|
|
5a42fd74ad | ||
|
|
85b788742c | ||
|
|
20f660b8a3 | ||
|
|
4d17483a5a | ||
|
|
274b081c78 | ||
|
|
45e14637e0 | ||
|
|
b007735636 | ||
|
|
bb7275a618 | ||
|
|
853fa1531a | ||
|
|
396382bcc2 | ||
|
|
aae6bdb53c | ||
|
|
2f8f698069 | ||
|
|
fc3badb90a | ||
|
|
7aab3b60e8 | ||
|
|
2ab157bd4a | ||
|
|
3227c63e2e | ||
|
|
1dc77b3e6f | ||
|
|
cb044f789d | ||
|
|
c110aab634 | ||
|
|
5d407afbdf | ||
|
|
a8f12c9a24 | ||
|
|
0e4c251c6c | ||
|
|
e2b598a361 | ||
|
|
8c140cf8b6 | ||
|
|
4fe9ab02ef | ||
|
|
a21102d04f | ||
|
|
22488e9e71 | ||
|
|
bc40438cb3 | ||
|
|
3f633710e7 | ||
|
|
8de5d53198 | ||
|
|
53650f9b63 | ||
|
|
ba812bce3a | ||
|
|
42932abaa5 | ||
|
|
290749dde8 | ||
|
|
e19808fb4b | ||
|
|
691d429652 | ||
|
|
1575091d12 | ||
|
|
4919383c73 | ||
|
|
5293db6c86 | ||
|
|
c5f17a7b12 | ||
|
|
ddafbd0c25 | ||
|
|
8d9a354154 | ||
|
|
33ab1cd234 |
No files matched your search
+1
-3
@@ -118,9 +118,7 @@ gradle-app.setting
|
||||
**/build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
runs/
|
||||
run-1-21-11/
|
||||
run*/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
## Contributions
|
||||
Contributions via pull requests are welcome. Please join our [discord](https://discord.cubi.games) or make an `issue` to discuss any contributions beforehand to make sure they will not conflict with or hinder existing plans.
|
||||
|
||||
A good place to start with contributions is to look for `issue`s flagged with the label `help wanted`.
|
||||
A good place to start with contributions is to look for `issue`s flagged with the label `Outside Help Welcome`. These have been deemed as uninvasive changes, typically not requiring a complete understanding of the project. You are welcome to send a PR resolving these issues without first discussing changes with a maintainer.
|
||||
|
||||
You must hold the rights to any code you contribute, and must agree to licence it under the same licence as the rest of the project in perpetuity, explicitly including any and all changes to the project's licence by project maintainers in the future. The project's licence can always be found at [LICENSE](LICENSE).
|
||||
|
||||
|
||||
@@ -11,12 +11,20 @@ The supported minecraft versions are 1.21.4+. Only Paper and derivative software
|
||||
## Use cases:
|
||||
|
||||
- Prevent cheating (anti-esp hacks)
|
||||
- Block usage of pie-ray to locate underground bases or farms
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of hidden entities
|
||||
- This is the plugin's primary purpose.
|
||||
- Block usage of pie-ray to locate underground bases or farms.
|
||||
- Prevent mods such as mini-maps or cheat clients from displaying the locations of entities which would not be visible to vanilla players.
|
||||
- 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. Raycasted AntiESP will cull those entities for the client, reducing the number of entities to process.
|
||||
- Reduce network load by limiting packets
|
||||
- With `keep-client-entity-when-hidden` set to true, running RaycastedAntiESP will significantly reduce the number of entity packets sent to the client.
|
||||
- While entity packets are only a small portion of network bandwidth, this will still have a measurable impact and may be useful on extremely bandwidth-limited servers.
|
||||
- Unless you are extremely limited by bandwidth, this will probably be unnoticeable.
|
||||
- Hide nametags behind walls
|
||||
- Yes, this plugin is overkill for doing that, yes you can do it anyways.
|
||||
|
||||
## Configuration
|
||||
RaycastedAntiESP has many configuration options. A full list with explanations can be found at https://raycastedantiesp.cubi.games/config/.
|
||||
|
||||
## Dependencies:
|
||||
- Packetevents
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
plugins {
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" apply false
|
||||
id("xyz.jpenilla.run-paper") version "3.0.2" apply false
|
||||
}
|
||||
@@ -36,9 +36,11 @@ dependencies {
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testImplementation("it.unimi.dsi:fastutil:8.5.18")
|
||||
|
||||
compileOnly("com.google.code.gson:gson:2.11.0")
|
||||
}
|
||||
|
||||
val coreVersion = "0.7.0-SNAPSHOT"
|
||||
val coreVersion = "0.7.2-SNAPSHOT"
|
||||
|
||||
val isRelease = gradle.startParameter.taskNames.any {
|
||||
it.contains("buildRelease")
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
public interface AsyncRunner {
|
||||
void runNow(Runnable task);
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import games.cubi.logs.PlatformLogger;
|
||||
|
||||
+25
-45
@@ -1,42 +1,33 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.paper;
|
||||
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigManager;
|
||||
import games.cubi.raycastedantiesp.core.config.UpdateConfig;
|
||||
import games.cubi.raycastedantiesp.core.utils.BuildProperties;
|
||||
import games.cubi.raycastedantiesp.core.utils.BuildProperties.Version;
|
||||
import games.cubi.raycastedantiesp.paper.utils.PaperScheduler;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URI;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class UpdateChecker {
|
||||
private static final String VERSION_API_ENDPOINT = "https://api.modrinth.com/v2/project/bCjNZu0C/version?include_changelog=false";
|
||||
private static final String PLATFORM_NAME = "Paper";
|
||||
private static final String MODRINTH_PAGE_URL = "https://modrinth.com/project/bCjNZu0C";
|
||||
private static final String MODRINTH_PAGE_URL = "https://modrinth.com/project/bCjNZu0C/";
|
||||
private static final String MODRINTH_MM_LINK = "<hover:show_text:'" + MODRINTH_PAGE_URL + "'><aqua><u><click:open_url:'" + MODRINTH_PAGE_URL + "'>" + MODRINTH_PAGE_URL + "</click></u></aqua></hover>";
|
||||
|
||||
|
||||
enum UpdateChannel {
|
||||
STABLE("release", "release"),
|
||||
@@ -80,8 +71,8 @@ public class UpdateChecker {
|
||||
|
||||
record ApiVersion(String rawVersion, Version coreVersion, Version platformVersion) {}
|
||||
|
||||
record UpdateCheckReport(List<UpdateCheckResult> results) {
|
||||
UpdateCheckReport {
|
||||
public record UpdateCheckReport(List<UpdateCheckResult> results) {
|
||||
public UpdateCheckReport {
|
||||
results = List.copyOf(results);
|
||||
}
|
||||
|
||||
@@ -112,20 +103,25 @@ public class UpdateChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private static CompletableFuture<List<VersionEntry>> fetchVersions(RaycastedAntiESP plugin) {
|
||||
private static CompletableFuture<List<VersionEntry>> fetchVersions(AsyncRunner runner) {
|
||||
CompletableFuture<List<VersionEntry>> future = new CompletableFuture<>();
|
||||
|
||||
Bukkit.getAsyncScheduler().runNow(plugin, ignored -> {
|
||||
try (
|
||||
final InputStreamReader reader = new InputStreamReader(new URI(VERSION_API_ENDPOINT).toURL().openConnection().getInputStream());
|
||||
final BufferedReader bufferedReader = new BufferedReader(reader)
|
||||
) {
|
||||
future.complete(parseVersionEntries(bufferedReader));
|
||||
runner.runNow(() -> {
|
||||
try {
|
||||
URLConnection connection = new URI(VERSION_API_ENDPOINT).toURL().openConnection();
|
||||
connection.setConnectTimeout(5_000); //ms
|
||||
connection.setReadTimeout(5_000); //ms
|
||||
try (
|
||||
final InputStreamReader reader = new InputStreamReader(connection.getInputStream());
|
||||
final BufferedReader bufferedReader = new BufferedReader(reader)
|
||||
) {
|
||||
future.complete(parseVersionEntries(bufferedReader));
|
||||
}
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
future.completeExceptionally(new IllegalStateException("Unable to fetch latest version", e));
|
||||
}
|
||||
});
|
||||
return future;
|
||||
return future.orTimeout(10_000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
private static List<VersionEntry> parseVersionEntries(BufferedReader reader) throws IOException {
|
||||
@@ -151,13 +147,13 @@ public class UpdateChecker {
|
||||
return List.copyOf(versionEntries);
|
||||
}
|
||||
|
||||
private static CompletableFuture<UpdateCheckReport> fetchUpdateCheck(RaycastedAntiESP plugin) {
|
||||
public static CompletableFuture<UpdateCheckReport> fetchUpdateCheck(AsyncRunner runner) {
|
||||
UpdateConfig updateConfig = ConfigManager.get().getUpdateConfig();
|
||||
if (!updateConfig.anyChannelEnabled()) {
|
||||
return CompletableFuture.completedFuture(new UpdateCheckReport(List.of()));
|
||||
}
|
||||
|
||||
return fetchVersions(plugin).thenApply(versionEntries -> checkVersions(
|
||||
return fetchVersions(runner).thenApply(versionEntries -> checkVersions(
|
||||
BuildProperties.CORE.version(),
|
||||
BuildProperties.PLATFORM.version(),
|
||||
versionEntries,
|
||||
@@ -268,14 +264,14 @@ public class UpdateChecker {
|
||||
|
||||
static String formatUpdateMessage(UpdateCheckResult result) {
|
||||
return switch (result.status()) {
|
||||
case BEHIND -> "<red>You are behind the latest " + result.channel().messageName() + " of RaycastedAntiESP. Please upgrade to <green>v" + result.apiVersion().rawVersion() + "<red> at " + modrinthLink() + "<red>.";
|
||||
case BEHIND -> "<red>You are behind the latest " + result.channel().messageName() + " of RaycastedAntiESP. Please upgrade to <green>v" + result.apiVersion().rawVersion() + "<red> at " + MODRINTH_MM_LINK + "<red>.";
|
||||
case UP_TO_DATE -> "<green>You are up to date with the latest " + result.channel().messageName() + " of RaycastedAntiESP.";
|
||||
case AHEAD, NO_COMPARABLE_VERSION -> "<yellow>You are ahead of the latest " + result.channel().messageName() + " of RaycastedAntiESP.";
|
||||
case INVALID_CURRENT_VERSION -> "<red>Unable to check for updates to RaycastedAntiESP, invalid current version format.";
|
||||
};
|
||||
}
|
||||
|
||||
static String formatUpdateMessage(UpdateCheckReport report) {
|
||||
public static String formatUpdateMessage(UpdateCheckReport report) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
for (UpdateCheckResult result : report.results()) {
|
||||
messages.add(formatUpdateMessage(result));
|
||||
@@ -283,20 +279,4 @@ public class UpdateChecker {
|
||||
|
||||
return String.join("\n", messages);
|
||||
}
|
||||
|
||||
private static String modrinthLink() {
|
||||
return "<hover:show_text:'" + MODRINTH_PAGE_URL + "'><aqua><u><click:open_url:'" + MODRINTH_PAGE_URL + "'>" + MODRINTH_PAGE_URL + "</click></u></aqua></hover>";
|
||||
}
|
||||
|
||||
public static void checkForUpdates(RaycastedAntiESP plugin, CommandSender audience) {
|
||||
fetchUpdateCheck(plugin).thenAccept(report -> {
|
||||
if (report.results().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PaperScheduler.runForAudience(plugin, audience, () -> audience.sendRichMessage(formatUpdateMessage(report)));
|
||||
}).exceptionally(ex -> {
|
||||
Logger.error("An error occurred while checking for plugin updates", ex, 4, UpdateChecker.class);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.BlockChunkDataBuilder;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
public final class ChunkData {
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.chunks.ChunkData.LOCAL_MASK;
|
||||
|
||||
public interface ChunkOcclusionView {
|
||||
/**
|
||||
* The parameters here are local coordinates within the chunk section, so they must be in the range [0, 15].
|
||||
@@ -9,4 +19,12 @@ public interface ChunkOcclusionView {
|
||||
* @return true if the block at the given local coordinates is occluding, false otherwise.
|
||||
*/
|
||||
boolean isOccludingLocal(@Range(from = 0, to = 15) int x, @Range(from = 0, to = 15) int y, @Range(from = 0, to = 15) int z);
|
||||
|
||||
default boolean isOccludingGlobal(int x, int y, int z) {
|
||||
return isOccludingLocal(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK);
|
||||
}
|
||||
|
||||
default boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
@@ -45,5 +53,10 @@ public sealed interface OccludingChunkData extends ChunkOcclusionView permits Oc
|
||||
public OccludingChunkData setOccluding(int x, int y, int z, boolean occluding) {
|
||||
return filled().setOccluding(x, y, z, occluding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks.blocks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public interface Config {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
public class ConfigLoadException extends RuntimeException {
|
||||
|
||||
@@ -20,17 +20,21 @@ import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ConfigManager {
|
||||
@@ -306,6 +310,8 @@ public class ConfigManager {
|
||||
Files.createFile(configPath);
|
||||
}
|
||||
}
|
||||
ConfigMigrations.prependConfigDocumentationHeaderIfMissing(configPath);
|
||||
ConfigMigrations.migrateSoundEffectsEnabled(configPath);
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to create config.yml", e);
|
||||
}
|
||||
@@ -357,6 +363,108 @@ public class ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary text-level config mutations. Remove this class when these migrations are no longer needed.
|
||||
*/
|
||||
private static final class ConfigMigrations {
|
||||
private static final Pattern YAML_KEY = Pattern.compile("^([ \\t]*)([^:#\\s][^:]*):.*$");
|
||||
private static final Pattern SOUND_EFFECTS_ENABLED_TRUE = Pattern.compile("^([ \\t]*enabled[ \\t]*:[ \\t]*)true([ \\t]*(?:#.*)?)$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private ConfigMigrations() {
|
||||
}
|
||||
|
||||
private static void prependConfigDocumentationHeaderIfMissing(Path configPath) {
|
||||
try {
|
||||
String content = Files.readString(configPath);
|
||||
|
||||
if (content.startsWith("#")) {
|
||||
Logger.debug("Config starts with comment");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.debug("no starting comment");
|
||||
Files.writeString(configPath, "# An explanation of this configuration file and what all the options do can be found at https://raycastedantiesp.cubi.games/config/" + System.lineSeparator() + content);
|
||||
} catch (Exception e) {
|
||||
Logger.warning(e,3, ConfigManager.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Temporary(forRemovalIn = "0.8.0")
|
||||
private static void migrateSoundEffectsEnabled(Path configPath) {
|
||||
try {
|
||||
String content = Files.readString(configPath, StandardCharsets.UTF_8);
|
||||
String migrated = replaceSoundEffectsEnabled(content);
|
||||
if (!content.equals(migrated)) {
|
||||
Files.writeString(configPath, migrated, StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ConfigLoadException("Failed to migrate sound-effects.enabled in config.yml", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String replaceSoundEffectsEnabled(String content) {
|
||||
StringBuilder migrated = new StringBuilder(content.length());
|
||||
int lineStart = 0;
|
||||
int checksIndent = -1;
|
||||
int soundEffectsIndent = -1;
|
||||
boolean changed = false;
|
||||
|
||||
while (lineStart < content.length()) {
|
||||
int lineEnd = content.indexOf('\n', lineStart);
|
||||
boolean hasLineEnding = lineEnd >= 0;
|
||||
int contentEnd = hasLineEnding ? lineEnd : content.length();
|
||||
int lineContentEnd = contentEnd > lineStart && content.charAt(contentEnd - 1) == '\r'
|
||||
? contentEnd - 1 : contentEnd;
|
||||
String line = content.substring(lineStart, lineContentEnd);
|
||||
String lineEnding = content.substring(lineContentEnd, contentEnd) + (hasLineEnding ? "\n" : "");
|
||||
|
||||
Matcher key = YAML_KEY.matcher(line);
|
||||
if (key.matches()) {
|
||||
int indent = key.group(1).length();
|
||||
String name = key.group(2).trim();
|
||||
|
||||
if (checksIndent < 0) {
|
||||
if (name.equals("checks")) {
|
||||
checksIndent = indent;
|
||||
}
|
||||
} else if (indent <= checksIndent) {
|
||||
checksIndent = name.equals("checks") ? indent : -1;
|
||||
soundEffectsIndent = -1;
|
||||
} else if (soundEffectsIndent < 0) {
|
||||
if (name.equals("sound-effects")) {
|
||||
soundEffectsIndent = indent;
|
||||
}
|
||||
} else if (indent <= soundEffectsIndent) {
|
||||
soundEffectsIndent = name.equals("sound-effects") ? indent : -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (soundEffectsIndent >= 0 && key.matches()
|
||||
&& key.group(2).trim().equals("enabled")
|
||||
&& key.group(1).length() > soundEffectsIndent) {
|
||||
Matcher enabled = SOUND_EFFECTS_ENABLED_TRUE.matcher(line);
|
||||
if (enabled.matches()) {
|
||||
line = enabled.group(1) + "false" + enabled.group(2);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
migrated.append(line).append(lineEnding);
|
||||
if (!hasLineEnding) {
|
||||
break;
|
||||
}
|
||||
lineStart = contentEnd + 1;
|
||||
}
|
||||
|
||||
return changed ? migrated.toString() : content;
|
||||
}
|
||||
|
||||
@Documented
|
||||
private @interface Temporary {
|
||||
String forRemovalIn();
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationNode node(ConfigurationNode root, String path) {
|
||||
String[] parts = path.split("\\.");
|
||||
return ConfigReader.node(root, parts);
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.engine.EngineConfig;
|
||||
|
||||
@@ -18,7 +18,7 @@ public record UpdateConfig(boolean checkRelease, boolean checkBeta, boolean chec
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-release"), "updates.check-release"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-beta"), "updates.check-beta"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "check-alpha"), "updates.check-alpha"),
|
||||
ConfigReader.bool(ConfigReader.node(node, "notify-ingame"), "updates.notify-ingame")
|
||||
ConfigReader.bool(ConfigReader.node(node, "notify-in-game"), "updates.notify-in-game")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.engine;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigEnum;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
+21
-2
@@ -1,15 +1,34 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigReader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
public class PlayerConfig extends RaycastConfig {
|
||||
private PlayerConfig(RaycastConfig config) {
|
||||
private final boolean onlyCheckSneaking;
|
||||
|
||||
private PlayerConfig(RaycastConfig config, boolean onlyCheckSneaking) {
|
||||
super(config.enabled(), config.hideSoundsWhenHidden(), config.getMaxOccludingCount(), config.getAlwaysShowRadius(),
|
||||
config.getRaycastRadius(), config.hideOnSpawnDistance(), config.getVisibleRecheckIntervalTicks(),
|
||||
config.keepClientEntityWhenHidden());
|
||||
this.onlyCheckSneaking = onlyCheckSneaking;
|
||||
}
|
||||
|
||||
public static PlayerConfig load(ConfigurationNode node, String path) {
|
||||
return new PlayerConfig(RaycastConfig.load(node, path, true, true));
|
||||
return new PlayerConfig(
|
||||
RaycastConfig.load(node, path, true, true),
|
||||
ConfigReader.bool(ConfigReader.node(node, "only-check-sneaking"), path + ".only-check-sneaking")
|
||||
);
|
||||
}
|
||||
|
||||
public boolean onlyCheckSneaking() {
|
||||
return onlyCheckSneaking;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
@@ -15,6 +23,10 @@ public class RaycastConfig implements Config {
|
||||
private final short visibleRecheckIntervalTicks;
|
||||
private final boolean keepClientEntityWhenHidden;
|
||||
|
||||
public final int alwaysShowRadiusSquared;
|
||||
public final int raycastRadiusSquared;
|
||||
public final int hideOnSpawnDistanceSquared;
|
||||
|
||||
public RaycastConfig(boolean enabled, boolean hideSoundsWhenHidden, int maxOccludingCount, int alwaysShowRadius,
|
||||
int raycastRadius, int hideOnSpawnDistance, int visibleRecheckIntervalTicks) {
|
||||
this(enabled, hideSoundsWhenHidden, maxOccludingCount, alwaysShowRadius, raycastRadius, hideOnSpawnDistance,
|
||||
@@ -32,6 +44,10 @@ public class RaycastConfig implements Config {
|
||||
this.hideOnSpawnDistance = (short) hideOnSpawnDistance;
|
||||
this.visibleRecheckIntervalTicks = (short) visibleRecheckIntervalTicks;
|
||||
this.keepClientEntityWhenHidden = keepClientEntityWhenHidden;
|
||||
|
||||
alwaysShowRadiusSquared = alwaysShowRadius * alwaysShowRadius;
|
||||
raycastRadiusSquared = raycastRadius * raycastRadius;
|
||||
hideOnSpawnDistanceSquared = hideOnSpawnDistance * hideOnSpawnDistance;
|
||||
}
|
||||
|
||||
protected static RaycastConfig load(ConfigurationNode node, String path, boolean hasHideSoundsWhenHidden) {
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.config.Config;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.AsyncRunner;
|
||||
import games.cubi.raycastedantiesp.core.config.ConfigManager;
|
||||
import games.cubi.raycastedantiesp.core.config.DebugConfig;
|
||||
import games.cubi.raycastedantiesp.core.config.raycast.EntityConfig;
|
||||
@@ -27,7 +27,6 @@ import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
import games.cubi.raycastedantiesp.core.view.EntityView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
@@ -104,7 +103,7 @@ public abstract class AsyncEngine implements Engine {
|
||||
int latestTick = currentTickSupplier.getAsInt();
|
||||
if (latestTick > startTick) {
|
||||
// If running behind, don't yield the thread, just run the next tick immediately
|
||||
Logger.warning("Tick thread completed tick #" + startTick + " after tick #" + latestTick + " had already begun. Starting next tick immediately instead of yielding thread to scheduler. This is probably safe to ignore but may suggest that your server is overloaded.", 5);
|
||||
Logger.warning("Tick thread completed tick #" + startTick + " after tick #" + latestTick + " had already begun. Starting next tick immediately instead of yielding thread to scheduler. This is probably safe to ignore but may suggest that your server is overloaded.", 5, AsyncEngine.class);
|
||||
startTick = latestTick;
|
||||
scheduledNanos = System.nanoTime();
|
||||
scheduledTick = latestTick;
|
||||
@@ -172,13 +171,13 @@ public abstract class AsyncEngine implements Engine {
|
||||
final int currentTick = startTick;
|
||||
runningTick.set(currentTick);
|
||||
claimedRunningTick = true;
|
||||
Collection<PlayerData> allPlayers = PlayerRegistry.getInstance().getAllPlayerData();
|
||||
PlayerData[] allPlayers = PlayerRegistry.get().getPlayerDataArray();
|
||||
|
||||
EntityConfig entityConfig = config.getEntityConfig();
|
||||
PlayerConfig playerConfig = config.getPlayerConfig();
|
||||
TileEntityConfig tileEntityConfig = config.getTileEntityConfig();
|
||||
if (recordTimings) {
|
||||
timings = new TickTimings(scheduledTick, scheduledNanos, currentTick, startNanos, threads, allPlayers.size());
|
||||
timings = new TickTimings(scheduledTick, scheduledNanos, currentTick, startNanos, threads, allPlayers.length);
|
||||
}
|
||||
/*
|
||||
Logger.debug("Tick #" + currentTick);
|
||||
@@ -194,24 +193,30 @@ public abstract class AsyncEngine implements Engine {
|
||||
// If only one thread is configured, just use the current async thread to avoid the overhead of scheduling tasks and context switching.
|
||||
if (threads == 1) {
|
||||
handedOffToSubTick = true;
|
||||
subTick(new ArrayList<>(allPlayers), entityConfig, playerConfig, tileEntityConfig, debugConfig, currentTick, timings, tickTimingStats);
|
||||
subTick(allPlayers, entityConfig, playerConfig, tileEntityConfig, debugConfig, currentTick, timings, tickTimingStats);
|
||||
return true;
|
||||
}
|
||||
|
||||
List<List<PlayerData>> batches = new ArrayList<>(threads);
|
||||
List<PlayerData[]> batches = new ArrayList<>(threads);
|
||||
int playerCount = allPlayers.length;
|
||||
for (int i = 0; i < threads; i++) {
|
||||
batches.add(new ArrayList<>());
|
||||
int batchSize = (playerCount + threads - 1 - i) / threads;
|
||||
batches.add(new PlayerData[batchSize]);
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
for (PlayerData playerData : allPlayers) {
|
||||
batches.get(index++ % threads).add(playerData);
|
||||
int batchIndex = index % threads;
|
||||
int position = index / threads;
|
||||
|
||||
batches.get(batchIndex)[position] = playerData;
|
||||
index++;
|
||||
}
|
||||
|
||||
TickTimings tickTimings = timings; // needs to be effectively-final for lambda
|
||||
int scheduledBatches = 0;
|
||||
try {
|
||||
for (List<PlayerData> batch : batches) {
|
||||
for (PlayerData[] batch : batches) {
|
||||
asyncRunner.runNow(() -> subTick(batch, entityConfig, playerConfig, tileEntityConfig, debugConfig, currentTick, tickTimings, tickTimingStats));
|
||||
scheduledBatches++;
|
||||
}
|
||||
@@ -244,7 +249,7 @@ public abstract class AsyncEngine implements Engine {
|
||||
* @param timingStats the timing sink selected when this tick started, so config changes during
|
||||
* worker execution do not split one tick across sinks.
|
||||
*/
|
||||
private void subTick(List<PlayerData> batch, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig, DebugConfig debugConfig, int currentTick, TickTimings timings, TimingStats timingStats) {
|
||||
private void subTick(PlayerData[] batch, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig, DebugConfig debugConfig, int currentTick, TickTimings timings, TimingStats timingStats) {
|
||||
TickTimingBatch batchTimings = timings == null ? TickTimingBatchNoOp.INSTANCE : new TickTimingBatch();
|
||||
long batchStartNanos = batchTimings.startBatch();
|
||||
try {
|
||||
@@ -329,7 +334,7 @@ public abstract class AsyncEngine implements Engine {
|
||||
}
|
||||
}
|
||||
|
||||
private void processTickForPlayers(List<PlayerData> playerDataList, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig,
|
||||
private void processTickForPlayers(PlayerData[] playerDataList, EntityConfig entityConfig, PlayerConfig playerConfig, TileEntityConfig tileEntityConfig,
|
||||
boolean debugParticles, int currentTick, TickTimingBatch timings) {
|
||||
|
||||
for (PlayerData playerData : playerDataList) {
|
||||
@@ -384,13 +389,16 @@ public abstract class AsyncEngine implements Engine {
|
||||
EntityView<?> entityView = player.entityView();
|
||||
|
||||
int checked = entityView.forEachNeedingRecheckEntity(entityConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, entity -> {
|
||||
boolean wasVisible = entity.visible();
|
||||
if (entity.glowing()) {
|
||||
entityView.setVisibility(entity, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, entityView, entity, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timings.incrementEntityRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, entity, entityConfig.getMaxOccludingCount(), entityConfig.getAlwaysShowRadius(), entityConfig.getRaycastRadius(), debugParticles, blockView, entity.getYOffset(), 1, particleSpawner);
|
||||
boolean canSee = RaycastUtil.raycastUnrolledAccumulated(entityConfig.getMaxOccludingCount(), entityConfig.alwaysShowRadiusSquared, entityConfig.raycastRadiusSquared, debugParticles, entity.getYOffset(), blockView, playerLocation, entity, particleSpawner);
|
||||
entityView.setVisibility(entity, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addEntityChecked(checked);
|
||||
@@ -400,12 +408,15 @@ public abstract class AsyncEngine implements Engine {
|
||||
EntityView<?> playerView = player.playerView();
|
||||
|
||||
int checked = playerView.forEachNeedingRecheckEntity(playerConfig.getVisibleRecheckIntervalTicks(), currentTick, !(timings instanceof TickTimingBatchNoOp), worldEpoch, otherPlayer -> {
|
||||
boolean wasVisible = otherPlayer.visible();
|
||||
if (otherPlayer.glowing() || (playerConfig.onlyCheckSneaking() && !otherPlayer.sneaking())) {
|
||||
playerView.setVisibility(otherPlayer, true, currentTick, worldEpoch);
|
||||
return;
|
||||
}
|
||||
if (attachedToAlwaysVisibleEntityOrSelf(player, playerView, otherPlayer, currentTick, worldEpoch)) {
|
||||
return;
|
||||
}
|
||||
timings.incrementPlayerRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, otherPlayer, playerConfig.getMaxOccludingCount(), playerConfig.getAlwaysShowRadius(), playerConfig.getRaycastRadius(), debugParticles, blockView, 1.5f, 1, particleSpawner);
|
||||
boolean canSee = RaycastUtil.raycastUnrolledAccumulated(playerConfig.getMaxOccludingCount(), playerConfig.alwaysShowRadiusSquared, playerConfig.raycastRadiusSquared, debugParticles, 1.5f, blockView, playerLocation, otherPlayer, particleSpawner);
|
||||
playerView.setVisibility(otherPlayer, canSee, currentTick, worldEpoch);
|
||||
});
|
||||
timings.addPlayerChecked(checked);
|
||||
@@ -432,7 +443,7 @@ public abstract class AsyncEngine implements Engine {
|
||||
return BlockView.VisibilityResolver.HIDE;
|
||||
}
|
||||
timings.incrementTileRaycasts();
|
||||
boolean canSee = RaycastUtil.raycast(playerLocation, tileEntityLocation, tileEntityConfig.getMaxOccludingCount() + 1, tileEntityConfig.getAlwaysShowRadius(), tileEntityConfig.getRaycastRadius(), debugParticles, blockView, 1, particleSpawner);
|
||||
boolean canSee = RaycastUtil.raycastUnrolledAccumulated(tileEntityConfig.getMaxOccludingCount(), tileEntityConfig.alwaysShowRadiusSquared, tileEntityConfig.raycastRadiusSquared, debugParticles, 0, blockView, playerLocation, tileEntityLocation, particleSpawner);
|
||||
return canSee ? BlockView.VisibilityResolver.SHOW : BlockView.VisibilityResolver.HIDE;
|
||||
});
|
||||
timings.addTileChecked(checked);
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface AsyncRunner {
|
||||
void runNow(Runnable task);
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public interface Engine {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatch {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TickTimingBatchNoOp extends TickTimingBatch {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
record TickTimingSnapshot(
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
final class TickTimings {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
public class TimingStatsNoOp extends TimingStats {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
package games.cubi.raycastedantiesp.core.entity;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.CopyOnWriteMTIntSet;
|
||||
import games.cubi.utils.sets.CopyOnWriteMTIntSet;
|
||||
|
||||
/**
|
||||
* Global registry of entity IDs which RaycastedAntiESP must ignore.
|
||||
|
||||
@@ -28,6 +28,9 @@ import static games.cubi.raycastedantiesp.core.tracked.NettyEntity.NO_VEHICLE;
|
||||
* Per-player mutable state intended for Netty-side packet tracking and deferred reconciliation.
|
||||
*/
|
||||
public class NettyData implements Clearable {
|
||||
//
|
||||
public boolean packetsAreWithinBundle = false;
|
||||
//
|
||||
private static final int DEFAULT_MAP_SIZE = 16;
|
||||
//
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.api.FloatingLocatableEquality;
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.MutableFloatingLocatable;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A mutable, thread-safe location and view state for a player.
|
||||
*
|
||||
* <p>Mutations are serialized because platform and packet lifecycle callbacks
|
||||
* may write from different threads. World and scalar reads use relaxed
|
||||
* per-field access: a read may combine values from adjacent updates.</p>
|
||||
* <p></p>
|
||||
* Reads of several fields are not coherently published. This is acceptable
|
||||
* since players typically move in small increments, so an old x and new z
|
||||
* still closely approximate the player's actual position. In less-frequent
|
||||
* cases such as teleports or dimension switches, raycasts may use the incorrect
|
||||
* position briefly. This does not matter, as incorrect state will be fixed by next tick's raycast.
|
||||
*/
|
||||
public final class PlayerLocatable implements MutableFloatingLocatable, FloatingLocatableEquality {
|
||||
private final Object writerMonitor = new Object();
|
||||
|
||||
private volatile UUID world; private static final VarHandle WORLD = VarHandler.get(PlayerLocatable.class, "world", UUID.class);
|
||||
private volatile double x; private static final VarHandle X = VarHandler.get(PlayerLocatable.class, "x", double.class);
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(PlayerLocatable.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(PlayerLocatable.class, "z", double.class);
|
||||
private volatile float yaw; private static final VarHandle YAW = VarHandler.get(PlayerLocatable.class, "yaw", float.class);
|
||||
private volatile float pitch; private static final VarHandle PITCH = VarHandler.get(PlayerLocatable.class, "pitch", float.class);
|
||||
private volatile PlayerPose pose; private static final VarHandle POSE = VarHandler.get(PlayerLocatable.class, "pose", PlayerPose.class);
|
||||
|
||||
public PlayerLocatable() {
|
||||
}
|
||||
|
||||
/** Initialises or replaces the complete valid player state. */
|
||||
public void initialise(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the complete state for a world change. */
|
||||
public void worldChange(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
validateFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
synchronized (writerMonitor) {
|
||||
writeFullState(world, footX, footY, footZ, yaw, pitch, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's foot position while retaining rotation and pose. */
|
||||
public void updateFoot(double footX, double footY, double footZ) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's rotation while retaining position and pose. */
|
||||
public void updateRotation(float yaw, float pitch) {
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates the player's pose while retaining position and rotation. */
|
||||
public void updatePose(PlayerPose pose) {
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
synchronized (writerMonitor) {
|
||||
POSE.setOpaque(this, pose);
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates position and rotation in one logical operation. */
|
||||
public void updateFootAndRotation(double footX, double footY, double footZ, float yaw, float pitch) {
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
/** Invalidates and clears the complete player state. */
|
||||
public void invalidate() {
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, 0.0);
|
||||
Y.setOpaque(this, 0.0);
|
||||
Z.setOpaque(this, 0.0);
|
||||
YAW.setOpaque(this, 0.0f);
|
||||
PITCH.setOpaque(this, 0.0f);
|
||||
POSE.setOpaque(this, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID world() {
|
||||
return (UUID) WORLD.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double x() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double y() {
|
||||
return (double) Y.getOpaque(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double z() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public float yaw() {
|
||||
return (float) YAW.getOpaque(this);
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return (float) PITCH.getOpaque(this);
|
||||
}
|
||||
|
||||
public PlayerPose pose() {
|
||||
return (PlayerPose) POSE.getOpaque(this);
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentPose == null ? 0.0f : currentPose.cameraYOffset();
|
||||
}
|
||||
|
||||
public double cameraX() {
|
||||
return (double) X.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraY() {
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
return currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset());
|
||||
}
|
||||
|
||||
public double cameraZ() {
|
||||
return (double) Z.getOpaque(this);
|
||||
}
|
||||
|
||||
public double cameraDistanceSquared(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
double targetX = spatial.x();
|
||||
double targetY = spatial.y();
|
||||
double targetZ = spatial.z();
|
||||
double currentX = (double) X.getOpaque(this);
|
||||
double currentY = (double) Y.getOpaque(this);
|
||||
double currentZ = (double) Z.getOpaque(this);
|
||||
PlayerPose currentPose = (PlayerPose) POSE.getOpaque(this);
|
||||
double dx = currentX - targetX;
|
||||
double dy = currentY + (currentPose == null ? 0.0 : (double) currentPose.cameraYOffset()) - targetY;
|
||||
double dz = currentZ - targetZ;
|
||||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setX(double x) {
|
||||
validateFinite(x);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setY(double y) {
|
||||
validateFinite(y);
|
||||
synchronized (writerMonitor) {
|
||||
Y.setOpaque(this, y);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setZ(double z) {
|
||||
validateFinite(z);
|
||||
synchronized (writerMonitor) {
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setPosition(Spatial spatial) {
|
||||
Objects.requireNonNull(spatial, "spatial");
|
||||
return setPosition(spatial.x(), spatial.y(), spatial.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setWorld(UUID world) {
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(Locatable locatable) {
|
||||
Objects.requireNonNull(locatable, "locatable");
|
||||
return setLocation(locatable.world(), locatable.x(), locatable.y(), locatable.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable setLocation(UUID world, double x, double y, double z) {
|
||||
validateFinite(x, y, z);
|
||||
if (world == null) {
|
||||
invalidate();
|
||||
return this;
|
||||
}
|
||||
synchronized (writerMonitor) {
|
||||
X.setOpaque(this, x);
|
||||
Y.setOpaque(this, y);
|
||||
Z.setOpaque(this, z);
|
||||
WORLD.setOpaque(this, world);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(Locatable locatable) {
|
||||
return setLocation(locatable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(int x, int y, int z) {
|
||||
return setPosition(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerLocatable set(double x, double y, double z, UUID world) {
|
||||
return setLocation(world, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocatableType getType() {
|
||||
return LocatableType.ThreadSafe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return isEqualTo(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return makeHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean strictlyEquals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof PlayerLocatable that)) {
|
||||
return false;
|
||||
}
|
||||
UUID thisWorld = world();
|
||||
double thisX = x();
|
||||
double thisY = y();
|
||||
double thisZ = z();
|
||||
return Objects.equals(thisWorld, that.world())
|
||||
&& Double.doubleToLongBits(thisX) == Double.doubleToLongBits(that.x())
|
||||
&& Double.doubleToLongBits(thisY) == Double.doubleToLongBits(that.y())
|
||||
&& Double.doubleToLongBits(thisZ) == Double.doubleToLongBits(that.z());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toStringForm();
|
||||
}
|
||||
|
||||
/** This method must only be called while holding {@link #writerMonitor}. */
|
||||
private void writeFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
WORLD.setOpaque(this, null);
|
||||
X.setOpaque(this, footX);
|
||||
Y.setOpaque(this, footY);
|
||||
Z.setOpaque(this, footZ);
|
||||
YAW.setOpaque(this, yaw);
|
||||
PITCH.setOpaque(this, pitch);
|
||||
POSE.setOpaque(this, pose);
|
||||
WORLD.setOpaque(this, world);
|
||||
}
|
||||
|
||||
private static void validateFullState(UUID world, double footX, double footY, double footZ, float yaw, float pitch, PlayerPose pose) {
|
||||
Objects.requireNonNull(world, "world");
|
||||
Objects.requireNonNull(pose, "pose");
|
||||
validateFinite(footX, footY, footZ);
|
||||
validateRotation(yaw, pitch);
|
||||
}
|
||||
|
||||
private static void validateFinite(double x, double y, double z) {
|
||||
if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)) {
|
||||
throw new IllegalArgumentException("Coordinates must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateFinite(double value) {
|
||||
if (!Double.isFinite(value)) {
|
||||
throw new IllegalArgumentException("Coordinate must be finite");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateRotation(float yaw, float pitch) {
|
||||
if (!Float.isFinite(yaw) || !Float.isFinite(pitch) || pitch < -90.0f || pitch > 90.0f) {
|
||||
throw new IllegalArgumentException("Rotation must be finite and pitch must be between -90 and 90 degrees");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
/** Player body poses and the corresponding camera height above the feet. */
|
||||
public enum PlayerPose {
|
||||
UNKNOWN(1.62f),
|
||||
STANDING(1.62f),
|
||||
SNEAKING(1.27f),
|
||||
SWIMMING(0.40f),
|
||||
FALL_FLYING(0.40f),
|
||||
SPIN_ATTACK(0.40f),
|
||||
SLEEPING(0.20f),
|
||||
DYING(0.20f);
|
||||
|
||||
private final float cameraYOffset;
|
||||
|
||||
PlayerPose(float cameraYOffset) {
|
||||
this.cameraYOffset = cameraYOffset;
|
||||
}
|
||||
|
||||
public float cameraYOffset() {
|
||||
return cameraYOffset;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,58 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyEntity;
|
||||
import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerRegistry {
|
||||
public final class PlayerRegistry {
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SelfEntityCreator {
|
||||
NettyEntity<?> createSelfEntity(PlayerData playerData, int selfEntityID, UUID playerUUID);
|
||||
}
|
||||
|
||||
private static PlayerRegistry instance;
|
||||
private static final PlayerRegistry instance = new PlayerRegistry();
|
||||
|
||||
private PlayerRegistry() {}
|
||||
|
||||
public static PlayerRegistry getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new PlayerRegistry();
|
||||
}
|
||||
public static PlayerRegistry get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<UUID, PlayerData> playerDataMap = new ConcurrentHashMap<>();
|
||||
private final Collection<PlayerData> unmodifiablePlayerData = Collections.unmodifiableCollection(playerDataMap.values());
|
||||
private volatile PlayerData[] playerDataArray = new PlayerData[0]; private static final VarHandle PLAYER_DATA_ARRAY = VarHandler.get(PlayerRegistry.class, "playerDataArray", PlayerData[].class);
|
||||
|
||||
/** Forcefully registers a player and returns the new PlayerData, even if they were already registered.**/
|
||||
public PlayerData registerAndGetPlayer(UUID playerUUID, int joinTick, int selfEntityID, SelfEntityCreator selfEntityCreator) {
|
||||
public synchronized PlayerData registerAndGetPlayer(UUID playerUUID, int joinTick, int selfEntityID, SelfEntityCreator selfEntityCreator) {
|
||||
PlayerData newData = new PlayerData(playerUUID, false, joinTick, selfEntityID, selfEntityCreator);
|
||||
PlayerData old = playerDataMap.put(playerUUID, newData);
|
||||
if (old != null) old.markDisconnected();
|
||||
updatePlayerDataArray();
|
||||
return newData;
|
||||
}
|
||||
|
||||
public void unregisterPlayer(UUID playerUUID) {
|
||||
public synchronized void unregisterPlayer(UUID playerUUID) {
|
||||
PlayerData unregisteredPlayer = playerDataMap.remove(playerUUID);
|
||||
if (unregisteredPlayer == null) {
|
||||
return;
|
||||
}
|
||||
unregisteredPlayer.markDisconnected();
|
||||
updatePlayerDataArray();
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData(UUID playerUUID) {
|
||||
@@ -51,9 +64,34 @@ public class PlayerRegistry {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Live, mutable collection of all PlayerData instances.
|
||||
* @return Live, unmodifiable view of all PlayerData instances.
|
||||
* **/
|
||||
public Collection<PlayerData> getAllPlayerData() {
|
||||
return playerDataMap.values();
|
||||
return unmodifiablePlayerData;
|
||||
}
|
||||
|
||||
private void updatePlayerDataArray() {
|
||||
PLAYER_DATA_ARRAY.setRelease(this, playerDataMap.values().toArray(PlayerData[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not mutate this array, all changes must go through {@link #registerAndGetPlayer(UUID, int, int, SelfEntityCreator)} /
|
||||
* {@link #unregisterPlayer(UUID)}.
|
||||
* <p></p>
|
||||
* Changes to this array will be lost on next player join/leave, and will not apply everywhere.
|
||||
*/
|
||||
public PlayerData[] getPlayerDataArray() {
|
||||
return (PlayerData[]) PLAYER_DATA_ARRAY.getAcquire(this);
|
||||
}
|
||||
|
||||
public void forEachPlayer(Consumer<PlayerData> consumer) {
|
||||
PlayerData[] data = getPlayerDataArray();
|
||||
for (PlayerData player : data) {
|
||||
consumer.accept(player);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
return playerDataMap.size();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
@@ -14,4 +22,6 @@ public interface ParticleSpawner {
|
||||
void spawnParticleAt(Locatable locatable, Colour colour);
|
||||
|
||||
void spawnParticleAt(UUID world, Spatial spatial, Colour colour);
|
||||
|
||||
void spawnParticleAt(UUID world, double x, double y, double z, Colour colour);
|
||||
}
|
||||
@@ -1,50 +1,175 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import games.cubi.locatables.api.Spatial;
|
||||
import games.cubi.locatables.implementations.MutableSpatialImpl;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.view.BlockView;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RaycastUtil {
|
||||
|
||||
//True: Has line-of-sight
|
||||
//This is deliberately a ray-stepping algorithm rather than DDA as it is much faster (2x in benchmarking)
|
||||
//Missing blocks is acceptable, as it will be assumed the player can see past those corners.
|
||||
//While this uses objects, JHM and in-game profiling have both shown that all objects used here are consistently scalarised by the JVM.
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, int stepSize, ParticleSpawner particleSpawner) {
|
||||
return raycast(start, end, maxOccluding, alwaysShowRadius, maxRaycastRadius, debug, snap, 0f, stepSize, particleSpawner);
|
||||
/**
|
||||
* Mutable position and chunk-section state is flattened into the advancer so C2 only
|
||||
* needs to scalarise one state holder while retaining a readable ray-stepping method.
|
||||
*/
|
||||
public static boolean raycastUnrolledAccumulated(int maxOccluding, final int alwaysShowRadiusSquared, final int maxRaycastRadiusSquared, boolean debug,
|
||||
float yOffsetEnd, final BlockView snap, final Locatable start, final Spatial end, ParticleSpawner spawner) {
|
||||
double startX = start.x();
|
||||
double startY = start.y();
|
||||
double startZ = start.z();
|
||||
double endOffset = end instanceof BlockSpatial ? 0.5 : 0.0;
|
||||
RayDirection direction = RayDirection.from(end.x() + endOffset, end.y() + endOffset + yOffsetEnd, end.z() + endOffset, startX, startY, startZ);
|
||||
double lengthSquared = direction.getLengthSquared();
|
||||
if (lengthSquared <= alwaysShowRadiusSquared) return true;
|
||||
if (lengthSquared > maxRaycastRadiusSquared) return false;
|
||||
double total = direction.normaliseAndGetLength(lengthSquared);
|
||||
float finalDist = (float) (total - 1);
|
||||
|
||||
final RayAdvancer rayAdvancer = debug ? new DebugRayAdvancer(startX, startY, startZ, direction, snap, start.world(), spawner) : new RayAdvancer(startX, startY, startZ, direction, snap);
|
||||
|
||||
int remainingSteps = (int) Math.floor(finalDist);
|
||||
while (remainingSteps >= 4) {
|
||||
rayAdvancer.advance();
|
||||
rayAdvancer.advance();
|
||||
rayAdvancer.advance();
|
||||
rayAdvancer.advance();
|
||||
if (rayAdvancer.occluded > maxOccluding) return false;
|
||||
remainingSteps -= 4;
|
||||
}
|
||||
while (remainingSteps-- > 0) rayAdvancer.advance();
|
||||
return rayAdvancer.occluded <= maxOccluding;
|
||||
}
|
||||
|
||||
public static boolean raycast(Locatable start, Spatial end, int maxOccluding, int alwaysShowRadius, int maxRaycastRadius, boolean debug, BlockView snap, float yOffsetEnd, int stepSize, ParticleSpawner particleSpawner) {
|
||||
double endOffset = end instanceof BlockSpatial ? 0.5 : 0.0;
|
||||
MutableFloatingSpatial clonedEnd = new MutableSpatialImpl(end.x() + endOffset, end.y() + endOffset + yOffsetEnd, end.z() + endOffset);
|
||||
//Equivalent to end.cloneAndIfBlockThenCentre(); but not used since the JVM was not reliably scalarising that method (probably due to the polymorphic overriding?). This causes 0 object allocations.
|
||||
double total = start.distance(clonedEnd) - stepSize; //benchmarking shows that calling distance() is faster than distanceSquared() then checking distanceSquared < stepSize*stepSize every time despite the latter replacing a square root with multiplication
|
||||
if (total <= alwaysShowRadius) return true;
|
||||
if (total > maxRaycastRadius) return false;
|
||||
if (debug && particleSpawner == null) {
|
||||
Logger.errorAndReturn(new RuntimeException("raycast called with debug enabled but no ParticleSpawner supplied"), 2, RaycastUtil.class);
|
||||
private static sealed class RayAdvancer extends RayPosition permits DebugRayAdvancer {
|
||||
private final RayDirection direction;
|
||||
private final BlockView blockView;
|
||||
|
||||
private int chunkX, chunkY, chunkZ;
|
||||
private ChunkOcclusionView currentOcclusionView;
|
||||
private int occluded = 0;
|
||||
|
||||
private RayAdvancer(double startX, double startY, double startZ, RayDirection direction, BlockView blockView) {
|
||||
super(startX, startY, startZ);
|
||||
this.direction = direction;
|
||||
chunkX = blockX() >> 4;
|
||||
chunkY = blockY() >> 4;
|
||||
chunkZ = blockZ() >> 4;
|
||||
currentOcclusionView = blockView.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
this.blockView = blockView;
|
||||
}
|
||||
|
||||
Spatial dir = clonedEnd.subtract(start).normalise().scalarMultiply(stepSize);
|
||||
|
||||
MutableFloatingSpatial current = new MutableSpatialImpl(start.x(),start.y(),start.z());
|
||||
|
||||
for (double traveled = 0; traveled < total; traveled += stepSize) { //benchmarking shows that for loop is marginally faster than while loop initially (after running for a while they are equal
|
||||
current.add(dir);
|
||||
|
||||
if (snap.isBlockOccluding(current.blockX(), current.blockY(), current.blockZ())) {
|
||||
maxOccluding--;
|
||||
if (debug) particleSpawner.spawnParticleAt(start.world(), current, ParticleSpawner.Colour.RED);
|
||||
if (maxOccluding < 1) return false;
|
||||
continue;
|
||||
private void advance() {
|
||||
add(direction);
|
||||
int blockX = blockX();
|
||||
int blockY = blockY();
|
||||
int blockZ = blockZ();
|
||||
if (!isCurrentChunk(blockX, blockY, blockZ)) {
|
||||
moveToChunk(blockX, blockY, blockZ);
|
||||
currentOcclusionView = blockView.getChunkOcclusionView(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
if (debug) particleSpawner.spawnParticleAt(start.world(), current, ParticleSpawner.Colour.GREEN);
|
||||
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) {
|
||||
occluded++;
|
||||
particleRed();
|
||||
} else particleGreen();
|
||||
}
|
||||
|
||||
private boolean isCurrentChunk(int blockX, int blockY, int blockZ) {
|
||||
return blockX >> 4 == chunkX && blockY >> 4 == chunkY && blockZ >> 4 == chunkZ;
|
||||
// ((nextChunkX ^ chunkX) | (nextChunkY ^ chunkY) | (nextChunkZ ^ chunkZ)) != 0 is slower than this
|
||||
}
|
||||
|
||||
private void moveToChunk(int blockX, int blockY, int blockZ) {
|
||||
chunkX = blockX >> 4;
|
||||
chunkY = blockY >> 4;
|
||||
chunkZ = blockZ >> 4;
|
||||
}
|
||||
|
||||
void particleGreen() {}
|
||||
void particleRed() {}
|
||||
}
|
||||
|
||||
private static final class DebugRayAdvancer extends RayAdvancer {
|
||||
private final UUID world;
|
||||
private final ParticleSpawner particleSpawner;
|
||||
private DebugRayAdvancer(double startX, double startY, double startZ, RayDirection direction, BlockView blockView, UUID world, ParticleSpawner particleSpawner) {
|
||||
super(startX, startY, startZ, direction, blockView);
|
||||
this.world = world;
|
||||
this.particleSpawner = particleSpawner;
|
||||
}
|
||||
void particleGreen() {
|
||||
particleSpawner.spawnParticleAt(world, x, y, z, ParticleSpawner.Colour.GREEN);
|
||||
}
|
||||
void particleRed() {
|
||||
particleSpawner.spawnParticleAt(world, x, y, z, ParticleSpawner.Colour.RED);
|
||||
}
|
||||
}
|
||||
|
||||
private static sealed class RayPosition permits RayAdvancer {
|
||||
double x, y, z;
|
||||
|
||||
private RayPosition(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
final void add(RayDirection direction) {
|
||||
x += direction.x;
|
||||
y += direction.y;
|
||||
z += direction.z;
|
||||
}
|
||||
|
||||
final int blockX() {
|
||||
return (int) Math.floor(x);
|
||||
}
|
||||
|
||||
final int blockY() {
|
||||
return (int) Math.floor(y);
|
||||
}
|
||||
|
||||
final int blockZ() {
|
||||
return (int) Math.floor(z);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RayDirection {
|
||||
private double x, y, z;
|
||||
|
||||
private RayDirection(double x, double y, double z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
private static RayDirection from(double endX, double endY, double endZ, double startX, double startY, double startZ) {
|
||||
return new RayDirection(endX - startX, endY - startY, endZ - startZ);
|
||||
}
|
||||
|
||||
private double getLengthSquared() {
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
private double normaliseAndGetLength(double lengthSquared) {
|
||||
double len = Math.sqrt(lengthSquared);
|
||||
double scale = 1 / len;
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
z *= scale;
|
||||
return len;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,7 @@
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import games.cubi.locatables.implementations.ImmutableSpatialImpl;
|
||||
import games.cubi.raycastedantiesp.core.players.PlayerData;
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
|
||||
@@ -38,6 +36,11 @@ public abstract class NettyEntity<PacketReplayData extends Clearable> implements
|
||||
private volatile double y; private static final VarHandle Y = VarHandler.get(NettyEntity.class, "y", double.class);
|
||||
private volatile double z; private static final VarHandle Z = VarHandler.get(NettyEntity.class, "z", double.class);
|
||||
|
||||
// Packet-derived state shared with the engine.
|
||||
private static final byte FLAG_SNEAKING = 1;
|
||||
private static final byte FLAG_GLOWING = 1 << 1;
|
||||
private volatile byte trackedFlags; private static final VarHandle TRACKED_FLAGS = VarHandler.get(NettyEntity.class, "trackedFlags", byte.class);
|
||||
|
||||
// Packet-thread-only replay and client state.
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
@@ -65,7 +68,7 @@ public abstract class NettyEntity<PacketReplayData extends Clearable> implements
|
||||
private volatile boolean visible;
|
||||
|
||||
// Constants
|
||||
|
||||
public static final int NEVER_CHECKED = Integer.MIN_VALUE;
|
||||
public static final int NO_VEHICLE = -1;
|
||||
public static final int NO_LEASHER = -2;
|
||||
public static final int SELF_ENTITY_TYPE = -29;
|
||||
@@ -117,11 +120,43 @@ public abstract class NettyEntity<PacketReplayData extends Clearable> implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean glowing() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_GLOWING) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sneaking() {
|
||||
return (((byte) TRACKED_FLAGS.getOpaque(this)) & FLAG_SNEAKING) != 0;
|
||||
}
|
||||
|
||||
public boolean setGlowing(boolean glowing) {
|
||||
return setTrackedFlag(FLAG_GLOWING, glowing);
|
||||
}
|
||||
|
||||
public boolean setSneaking(boolean sneaking) {
|
||||
return setTrackedFlag(FLAG_SNEAKING, sneaking);
|
||||
}
|
||||
|
||||
private boolean setTrackedFlag(byte mask, boolean enabled) {
|
||||
byte previous = enabled
|
||||
? (byte) TRACKED_FLAGS.getAndBitwiseOrRelease(this, mask)
|
||||
: (byte) TRACKED_FLAGS.getAndBitwiseAndRelease(this, (byte) ~mask);
|
||||
boolean changed = (previous & mask) != (enabled ? mask : 0);
|
||||
if (changed) {
|
||||
// A concurrent engine check may overwrite this marker. Hidden entities retry next tick; visible entities
|
||||
// may wait for their configured recheck or remain visible if rechecks are disabled.
|
||||
// This is acceptable and not considered an issue.
|
||||
LAST_CHECKED.setOpaque(this, NEVER_CHECKED);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastChecked() {
|
||||
return (int) LAST_CHECKED.getOpaque(this);
|
||||
}
|
||||
// todo it may be that this is only ever set by the engine thread? If so, just volatile annotation may be safe enough, as no two engine threads should update a single player at the same time (add guard lock for this)
|
||||
|
||||
@Override
|
||||
public TrackedEntity<?> setLastChecked(int lastChecked) {
|
||||
LAST_CHECKED.setOpaque(this, lastChecked);
|
||||
@@ -381,6 +416,7 @@ public abstract class NettyEntity<PacketReplayData extends Clearable> implements
|
||||
if (packetReplayData != null) packetReplayData.clear();
|
||||
packetReplayData = null;
|
||||
|
||||
TRACKED_FLAGS.setOpaque(this, (byte) 0);
|
||||
VEHICLE_ID.setOpaque(this, NO_VEHICLE);
|
||||
PASSENGER_IDS.setRelease(this, null);
|
||||
leashedIDs = null;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
@@ -7,9 +15,10 @@ import games.cubi.raycastedantiesp.core.utils.VarHandler;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
/** Tile visibility and lifecycle are shared with the engine; block and replay data are packet-thread-only. */
|
||||
/** Tile desired visibility and lifecycle are shared with the engine; client, block, and replay data are packet-thread-only. */
|
||||
public abstract class NettyTileEntity<PacketReplayData extends Clearable> extends InvasivelyLinkedSWMRList<NettyTileEntity<PacketReplayData>> implements TrackedTileEntity<PacketReplayData> {
|
||||
private volatile boolean visible;
|
||||
private boolean clientVisible;
|
||||
private volatile int lastChecked; private static final VarHandle LAST_CHECKED = VarHandler.get(NettyTileEntity.class, "lastChecked", int.class);
|
||||
private char blockID;
|
||||
private PacketReplayData extraData;
|
||||
@@ -24,6 +33,7 @@ public abstract class NettyTileEntity<PacketReplayData extends Clearable> extend
|
||||
|
||||
this.blockID = blockID;
|
||||
this.visible = visible;
|
||||
this.clientVisible = visible;
|
||||
LAST_CHECKED.set(this, lastChecked);
|
||||
}
|
||||
|
||||
@@ -32,6 +42,7 @@ public abstract class NettyTileEntity<PacketReplayData extends Clearable> extend
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.visible = visible;
|
||||
this.clientVisible = visible;
|
||||
this.blockID = blockID;
|
||||
LAST_CHECKED.set(this, NEVER_CHECKED);
|
||||
}
|
||||
@@ -47,6 +58,17 @@ public abstract class NettyTileEntity<PacketReplayData extends Clearable> extend
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clientVisible() {
|
||||
return clientVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackedTileEntity<PacketReplayData> setClientVisible(boolean clientVisible) {
|
||||
this.clientVisible = clientVisible;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastChecked() {
|
||||
return (int) LAST_CHECKED.getAcquire(this);
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableSpatial;
|
||||
import games.cubi.locatables.api.MutableFloatingSpatial;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -18,6 +25,10 @@ public interface TrackedEntity<PacketReplayData> extends MutableFloatingSpatial
|
||||
boolean visible();
|
||||
TrackedEntity<?> setVisible(boolean visible);
|
||||
|
||||
boolean glowing();
|
||||
|
||||
boolean sneaking();
|
||||
|
||||
int lastChecked();
|
||||
TrackedEntity<?> setLastChecked(int lastChecked);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.locatables.api.ImmutableBlockSpatial;
|
||||
@@ -9,6 +17,10 @@ public interface TrackedTileEntity<T> extends ImmutableBlockSpatial, Clearable {
|
||||
boolean visible();
|
||||
TrackedTileEntity<T> setVisible(boolean visible);
|
||||
|
||||
/** Packet-thread-only client state. */
|
||||
boolean clientVisible();
|
||||
TrackedTileEntity<T> setClientVisible(boolean clientVisible);
|
||||
|
||||
int lastChecked();
|
||||
TrackedTileEntity<T> setLastChecked(int lastChecked);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public interface Clearable {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
/**
|
||||
* Thread-safe int sets. Hashcode and equals are not implemented.
|
||||
*/
|
||||
public interface CopyOnWriteMTIntSet {
|
||||
boolean contains(int value);
|
||||
|
||||
void add(int value);
|
||||
|
||||
/**
|
||||
* @return whether the value was removed
|
||||
*/
|
||||
boolean remove(int value);
|
||||
|
||||
// testing both impls by changing this factory method
|
||||
static CopyOnWriteMTIntSet get() {
|
||||
return new SortedMTIntSet();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.*; /**
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.Hash;
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
|
||||
/**
|
||||
* A thread-safe copy-on-write int set backed by an open-addressing int hash set from fastutil.
|
||||
* Designed for highly concurrent reads and rare writes.
|
||||
*/
|
||||
public class MTWrappedFastIntSet implements CopyOnWriteMTIntSet {
|
||||
private volatile IntOpenHashSet backingSet; private static final VarHandle BACKING_SET = VarHandler.get(MTWrappedFastIntSet.class, "backingSet", IntOpenHashSet.class);
|
||||
|
||||
public MTWrappedFastIntSet() {
|
||||
backingSet = new IntOpenHashSet();
|
||||
}
|
||||
|
||||
public boolean contains(int value) {
|
||||
return ((IntOpenHashSet) BACKING_SET.getAcquire(this)).contains(value);
|
||||
}
|
||||
|
||||
public void add(int value) {
|
||||
while (true) {
|
||||
IntOpenHashSet oldSet = (IntOpenHashSet) BACKING_SET.getAcquire(this);
|
||||
if (oldSet.contains(value)) return;
|
||||
|
||||
IntOpenHashSet newSet = oldSet.clone();
|
||||
newSet.add(value);
|
||||
boolean success = BACKING_SET.weakCompareAndSetRelease(this, oldSet, newSet);
|
||||
if (success) return;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(int value) {
|
||||
while (true) {
|
||||
IntOpenHashSet oldSet = (IntOpenHashSet) BACKING_SET.getAcquire(this);
|
||||
if (!oldSet.contains(value)) return false;
|
||||
|
||||
IntOpenHashSet newSet = oldSet.clone();
|
||||
boolean setSuccess = newSet.remove(value);
|
||||
boolean casSuccess = BACKING_SET.weakCompareAndSetRelease(this, oldSet, newSet);
|
||||
if (!setSuccess) throw new IllegalStateException("Backing set was mutated after publication");
|
||||
if (casSuccess) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A thread-safe copy-on-write int set where values are stored in ascending order.
|
||||
* Designed for highly concurrent reads and rare writes.
|
||||
*/
|
||||
public class SortedMTIntSet implements CopyOnWriteMTIntSet {
|
||||
private volatile int[] values = new int[0]; private static final VarHandle VALUES = VarHandler.get(SortedMTIntSet.class, "values", int[].class);
|
||||
|
||||
public boolean contains(int value) {
|
||||
int[] valueSnapshot = (int[]) VALUES.getAcquire(this);
|
||||
return Arrays.binarySearch(valueSnapshot, value) >= 0;
|
||||
}
|
||||
|
||||
public void add(int value) {
|
||||
while (true) {
|
||||
int[] oldValues = (int[]) VALUES.getAcquire(this);
|
||||
int result = Arrays.binarySearch(oldValues, value);
|
||||
|
||||
if (result >= 0) return; //already in array
|
||||
int[] newValues = new int[oldValues.length + 1];
|
||||
int insertionPoint = -result - 1;
|
||||
|
||||
System.arraycopy(oldValues, 0, newValues, 0, insertionPoint);
|
||||
newValues[insertionPoint] = value;
|
||||
// If the new value is larger than the old values, this will do nothing
|
||||
System.arraycopy(oldValues, insertionPoint, newValues, insertionPoint + 1, oldValues.length - insertionPoint);
|
||||
|
||||
boolean success = VALUES.weakCompareAndSetRelease(this, oldValues, newValues);
|
||||
if (success) return;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(int value) {
|
||||
while (true) {
|
||||
int[] oldValues = (int[]) VALUES.getAcquire(this);
|
||||
int result = Arrays.binarySearch(oldValues, value);
|
||||
|
||||
if (result < 0) return false; //not in array
|
||||
int[] newValues = new int[oldValues.length - 1];
|
||||
|
||||
System.arraycopy(oldValues, 0, newValues, 0, result);
|
||||
System.arraycopy(oldValues, result + 1, newValues, result, oldValues.length - result - 1);
|
||||
|
||||
boolean success = VALUES.weakCompareAndSetRelease(this, oldValues, newValues);
|
||||
if (success) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
public class ThreadGuard {
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRInt2ObjectHashTable;
|
||||
@@ -6,6 +14,7 @@ import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.logs.Logger;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.tracked.NettyTileEntity;
|
||||
@@ -58,6 +67,10 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
|
||||
protected abstract T createTrackedTileEntity(BlockSpatial position, char blockID, boolean visible);
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ) {
|
||||
return chunks.getSection(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockOccluding(int x, int y, int z) {
|
||||
@@ -155,6 +168,7 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
public void recordOutboundTileEntityVisibility(TrackedTileEntity<?> tileEntity, boolean visible) {
|
||||
if (tileEntity != null) {
|
||||
tileEntity.setVisible(visible);
|
||||
tileEntity.setClientVisible(visible);
|
||||
tileEntity.setLastChecked(TrackedTileEntity.NEVER_CHECKED);
|
||||
}
|
||||
}
|
||||
@@ -178,6 +192,8 @@ public abstract class AbstractBlockView<R extends Clearable, T extends NettyTile
|
||||
if (!tileEntity.visible()) {
|
||||
tileEntity.setVisible(true);
|
||||
tileEntity.setLastChecked(currentTick);
|
||||
}
|
||||
if (!tileEntity.clientVisible()) {
|
||||
visibilityRepairConsumer.accept(tileEntity);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.locatables.api.BlockLocatable;
|
||||
import games.cubi.locatables.api.BlockSpatial;
|
||||
import games.cubi.locatables.api.SpatialChunkSection;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
@@ -19,6 +29,15 @@ import java.util.function.IntSupplier;
|
||||
* decisions; visibility fields and the transition queue are safe for that Netty/engine overlap.</p>
|
||||
*/
|
||||
public interface BlockView extends Clearable {
|
||||
/**
|
||||
* Parameters are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getChunkOcclusionView(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
default ChunkOcclusionView getChunkOcclusionView(SpatialChunkSection chunkSection) {
|
||||
return getChunkOcclusionView(chunkSection.chunkX(), chunkSection.chunkY(), chunkSection.chunkZ());
|
||||
}
|
||||
|
||||
boolean isBlockOccluding(BlockLocatable location);
|
||||
|
||||
boolean isBlockOccluding(int x, int y, int z);
|
||||
@@ -36,21 +55,23 @@ public interface BlockView extends Clearable {
|
||||
|
||||
TrackedTileEntity<?> getTrackedTileEntity(UUID world, BlockSpatial position);
|
||||
|
||||
/** Returns the engine's desired visibility, not the state currently applied to the client. */
|
||||
boolean isVisible(UUID world, BlockSpatial position, int currentTick);
|
||||
|
||||
/**
|
||||
* Records visibility established by the current outbound packet without queuing another packet. This also resets
|
||||
* the check timestamp because the transmitted state supersedes the result of any previous visibility check. The
|
||||
* tile entity must be the current state returned by this view's structural-writer operations.
|
||||
* Records visibility established by the current outbound packet without queuing another packet. This synchronizes
|
||||
* both desired and client visibility and resets the check timestamp because the transmitted state supersedes the
|
||||
* result of any previous visibility check. The tile entity must be the current state returned by this view's
|
||||
* structural-writer operations.
|
||||
*/
|
||||
void recordOutboundTileEntityVisibility(TrackedTileEntity<?> tileEntity, boolean visible);
|
||||
|
||||
/**
|
||||
* Applies a mode change from the structural writer.
|
||||
*
|
||||
* Invokes {@code visibilityRepairConsumer} for each tile entity made visible when checks are disabled. The
|
||||
* structural writer must send their current state directly rather than publishing them to the engine transition
|
||||
* queue.
|
||||
* Sets every desired state visible when checks are disabled and invokes {@code visibilityRepairConsumer} for each
|
||||
* tile entity still hidden from the client. The structural writer must send their current state directly rather
|
||||
* than publishing them to the engine transition queue.
|
||||
*/
|
||||
void applyTileEntityCheckMode(boolean enabled, int currentTick, Consumer<TrackedTileEntity<?>> visibilityRepairConsumer);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedTileEntity;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
@@ -62,14 +70,14 @@ public interface EntityView<T extends TrackedEntity<?>> extends Clearable {
|
||||
*
|
||||
* @return number of entities passed to {@code action}.
|
||||
*/
|
||||
int forEachNeedingRecheck(int recheckTicks, int currentTick, Consumer<UUID> action);
|
||||
int forEachNeedingRecheck(int visibleRecheckTicks, int currentTick, Consumer<UUID> action);
|
||||
|
||||
/**
|
||||
* Iterates currently tracked entities that should be visibility-checked.
|
||||
*
|
||||
* @return number of entities passed to {@code action}, or 0 if {@code countingActuallyNeeded} is false.
|
||||
*/
|
||||
int forEachNeedingRecheckEntity(int recheckTicks, int currentTick, boolean countingActuallyNeeded, int expectedWorldEpoch, Consumer<NettyEntity<?>> action);
|
||||
int forEachNeedingRecheckEntity(int visibleRecheckTicks, int currentTick, boolean countingActuallyNeeded, int expectedWorldEpoch, Consumer<NettyEntity<?>> action);
|
||||
|
||||
boolean hasPendingTransitions();
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.tracked.TrackedEntity;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view;
|
||||
|
||||
import games.cubi.logs.Logger;
|
||||
|
||||
+15
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.TwoBlockChunkData;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
@@ -16,6 +25,12 @@ public final class BlockChunkSectionStore extends SWMRLong2ObjectHashTable<Block
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
|
||||
+14
@@ -1,9 +1,23 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkOcclusionView;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
|
||||
public interface ChunkSectionStore {
|
||||
/**
|
||||
* Coordinates are chunk coordinates
|
||||
*/
|
||||
ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ);
|
||||
|
||||
boolean isOccluding(int x, int y, int z);
|
||||
|
||||
void setBlockID(int x, int y, int z, int blockID);
|
||||
|
||||
+15
-4
@@ -1,10 +1,15 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.view.chunks;
|
||||
|
||||
import ca.spottedleaf.concurrentutil.map.SWMRLong2ObjectHashTable;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.BlockInfoResolver;
|
||||
import games.cubi.raycastedantiesp.core.chunks.ChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.OccludingChunkData;
|
||||
import games.cubi.raycastedantiesp.core.chunks.*;
|
||||
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packChunkCoords;
|
||||
import static games.cubi.raycastedantiesp.core.view.chunks.ChunkSectionStore.packGlobalCoords;
|
||||
@@ -16,6 +21,12 @@ public final class OccludingChunkSectionStore extends SWMRLong2ObjectHashTable<O
|
||||
this.blockInfoResolver = blockInfoResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkOcclusionView getSection(int chunkX, int chunkY, int chunkZ) {
|
||||
long key = packChunkCoords(chunkX, chunkY, chunkZ);
|
||||
return get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOccluding(int x, int y, int z) {
|
||||
long key = packGlobalCoords(x, y, z);
|
||||
|
||||
+13
-7
@@ -50,11 +50,9 @@ public abstract class PacketEntityViewController<P> {
|
||||
|
||||
protected EntityConfig entityConfig = null;
|
||||
protected PlayerConfig playerConfig = null;
|
||||
protected double hideOnSpawnEntityDistanceSquared = 0;
|
||||
protected double hideOnSpawnPlayerDistanceSquared = 0;
|
||||
|
||||
protected void handleWorldStatePacket(UUID player, String world, UUID worldUUID, int minWorldHeight, int currentTick) {
|
||||
PlayerData playerData = PlayerRegistry.getInstance().getPlayerData(player);
|
||||
PlayerData playerData = PlayerRegistry.get().getPlayerData(player);
|
||||
if (playerData == null) {
|
||||
Logger.error("Received world state packet for unknown player, uuid=" + player, 2, PacketEntityViewController.class);
|
||||
return;
|
||||
@@ -91,7 +89,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
}
|
||||
|
||||
protected PlayerData handlePlayPhaseLoginPacket(int entityID, UUID playerUUID, int currentTick) {
|
||||
return PlayerRegistry.getInstance().registerAndGetPlayer(playerUUID, currentTick, entityID, this::createSelfEntity);
|
||||
return PlayerRegistry.get().registerAndGetPlayer(playerUUID, currentTick, entityID, this::createSelfEntity);
|
||||
}
|
||||
|
||||
protected abstract NettyEntity<?> createSelfEntity(PlayerData ownData, int entityID, UUID playerUUID);
|
||||
@@ -103,7 +101,7 @@ public abstract class PacketEntityViewController<P> {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
PlayerRegistry.getInstance().unregisterPlayer(player);
|
||||
PlayerRegistry.get().unregisterPlayer(player);
|
||||
}
|
||||
/**
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
@@ -123,11 +121,13 @@ public abstract class PacketEntityViewController<P> {
|
||||
|
||||
NettyEntity<?> entity = Logger.requireNonNull(processEntitySpawn(playerData, packet, world, currentTick), "processEntitySpawn returned null", 3, PacketEntityViewController.class);
|
||||
|
||||
if ((!isPlayer && entityConfig.enabled()) || isPlayer && playerConfig.enabled()) {
|
||||
RaycastConfig config = (isPlayer) ? playerConfig : entityConfig;
|
||||
|
||||
if (config.enabled()) {
|
||||
Locatable ownLocation = playerData.ownLocation();
|
||||
boolean staleOwnLocation = ownLocation == null || ownLocation.world() == null || !ownLocation.world().equals(world);
|
||||
double distanceSquared = staleOwnLocation ? Double.POSITIVE_INFINITY : ownLocation.distanceSquared(entity);
|
||||
if (distanceSquared > (isPlayer ? hideOnSpawnPlayerDistanceSquared : hideOnSpawnEntityDistanceSquared)) {
|
||||
if (distanceSquared > config.hideOnSpawnDistanceSquared) {
|
||||
entity.setVisible(false);
|
||||
entity.setClientVisible(false);
|
||||
if (isPlayer) {
|
||||
@@ -209,6 +209,10 @@ public abstract class PacketEntityViewController<P> {
|
||||
* @return Whether or not to cancel the packet event. <code>true</code> to cancel, <code>false</code> to do nothing.
|
||||
*/
|
||||
protected boolean handleEntityMetadata(P packet, int entityID, PlayerData playerData, int currentTick) {
|
||||
NettyEntity<?> entity = playerData.entityFromID(entityID);
|
||||
if (entity != null) {
|
||||
processTrackedMetadata(packet, entity);
|
||||
}
|
||||
cachePacket(packet, entityID, playerData, currentTick);
|
||||
return cancelIfEnabledAndHidden(entityID, playerData);
|
||||
}
|
||||
@@ -787,6 +791,8 @@ public abstract class PacketEntityViewController<P> {
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processPositionSyncPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
protected abstract void processTrackedMetadata(P packet, NettyEntity<?> entity);
|
||||
|
||||
protected abstract void cachePacket(P packet, int entityID, PlayerData playerData, int currentTick);
|
||||
/** @return The entity ID of the entity */
|
||||
protected abstract int processRotationPacket(P packet, PlayerData playerData, int currentTick);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.paper;
|
||||
package games.cubi.raycastedantiesp.core;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.BuildProperties.Version;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.chunks;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.chunks.blocks.ByteArrayBlockChunkData;
|
||||
|
||||
+20
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.config.raycast;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -15,9 +23,20 @@ class RaycastConfigTest {
|
||||
EntityConfig entityConfig = EntityConfig.load(entityNode(false), "checks.entity");
|
||||
|
||||
assertTrue(playerConfig.keepClientEntityWhenHidden());
|
||||
assertFalse(playerConfig.onlyCheckSneaking());
|
||||
assertFalse(entityConfig.keepClientEntityWhenHidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
void playerSneakingOnlySettingLoadsIndependently() throws SerializationException {
|
||||
ConfigurationNode node = entityNode(true);
|
||||
node.node("only-check-sneaking").set(true);
|
||||
|
||||
PlayerConfig playerConfig = PlayerConfig.load(node, "checks.player");
|
||||
|
||||
assertTrue(playerConfig.onlyCheckSneaking());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tileEntityConfigDoesNotRequireOrEnableClientRetention() throws SerializationException {
|
||||
TileEntityConfig config = TileEntityConfig.load(baseNode(), "checks.tile-entity");
|
||||
@@ -38,6 +57,7 @@ class RaycastConfigTest {
|
||||
ConfigurationNode node = baseNode();
|
||||
node.node("hide-sounds-when-hidden").set(true);
|
||||
node.node("keep-client-entity-when-hidden").set(keepClientEntityWhenHidden);
|
||||
node.node("only-check-sneaking").set(false);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.engine;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.implementations.ImmutableLocatableImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlayerLocatableConcurrencyTest {
|
||||
private static final UUID WORLD = UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
private static final UUID OTHER_WORLD = UUID.fromString("00000000-0000-0000-0000-000000000002");
|
||||
|
||||
@Test
|
||||
void concurrentReadersAndWritersObserveFiniteSamples() throws Exception {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
location.initialise(WORLD, 0.0, 1.0, 2.0, 0.0f, 0.0f, PlayerPose.STANDING);
|
||||
ImmutableLocatableImpl target = new ImmutableLocatableImpl(WORLD, 10.0, 11.0, 12.0);
|
||||
|
||||
AtomicBoolean running = new AtomicBoolean(true);
|
||||
AtomicReference<Throwable> failure = new AtomicReference<>();
|
||||
CountDownLatch readersStarted = new CountDownLatch(4);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
List<Future<?>> readers = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Future<?> lifecycleWriter = executor.submit(() -> runLifecycleWriter(location));
|
||||
Future<?> partialWriter = executor.submit(() -> runPartialWriter(location));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
readers.add(executor.submit(() -> runReader(location, target, running, readersStarted, failure)));
|
||||
}
|
||||
|
||||
assertTrue(readersStarted.await(5, TimeUnit.SECONDS));
|
||||
lifecycleWriter.get(10, TimeUnit.SECONDS);
|
||||
partialWriter.get(10, TimeUnit.SECONDS);
|
||||
running.set(false);
|
||||
for (Future<?> reader : readers) {
|
||||
reader.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
assertNull(failure.get(), () -> "Concurrent reader failed: " + failure.get());
|
||||
} finally {
|
||||
running.set(false);
|
||||
executor.shutdownNow();
|
||||
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
private static void runLifecycleWriter(PlayerLocatable location) {
|
||||
for (int i = 0; i < 20_000; i++) {
|
||||
UUID world = (i & 1) == 0 ? WORLD : OTHER_WORLD;
|
||||
location.worldChange(world, i, i + 1.0, i + 2.0, i % 360.0f, (i % 180.0f) - 90.0f, poseFor(i));
|
||||
if ((i & 255) == 0) {
|
||||
location.invalidate();
|
||||
location.initialise(world, i, i + 1.0, i + 2.0, 0.0f, 0.0f, PlayerPose.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void runPartialWriter(PlayerLocatable location) {
|
||||
for (int i = 0; i < 20_000; i++) {
|
||||
try {
|
||||
location.updateFoot(i + 0.25, i + 1.25, i + 2.25);
|
||||
location.updateRotation(i % 360.0f, (i % 180.0f) - 90.0f);
|
||||
location.updatePose(poseFor(i + 1));
|
||||
} catch (IllegalStateException ignored) {
|
||||
// The lifecycle writer is allowed to invalidate between partial updates.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void runReader(PlayerLocatable location, ImmutableLocatableImpl target, AtomicBoolean running,
|
||||
CountDownLatch readersStarted, AtomicReference<Throwable> failure) {
|
||||
readersStarted.countDown();
|
||||
try {
|
||||
while (running.get()) {
|
||||
location.world();
|
||||
double x = location.x();
|
||||
double y = location.y();
|
||||
double z = location.z();
|
||||
float yaw = location.yaw();
|
||||
float pitch = location.pitch();
|
||||
location.pose();
|
||||
float cameraYOffset = location.cameraYOffset();
|
||||
double cameraX = location.cameraX();
|
||||
double cameraY = location.cameraY();
|
||||
double cameraZ = location.cameraZ();
|
||||
double distanceSquared = location.cameraDistanceSquared(target);
|
||||
|
||||
if (!Double.isFinite(x) || !Double.isFinite(y) || !Double.isFinite(z)
|
||||
|| !Float.isFinite(yaw) || !Float.isFinite(pitch)
|
||||
|| !Float.isFinite(cameraYOffset)
|
||||
|| !Double.isFinite(cameraX) || !Double.isFinite(cameraY) || !Double.isFinite(cameraZ)
|
||||
|| !Double.isFinite(distanceSquared)) {
|
||||
throw new AssertionError("Observed a non-finite player sample");
|
||||
}
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
failure.compareAndSet(null, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
private static PlayerPose poseFor(int value) {
|
||||
return switch (Math.floorMod(value, 4)) {
|
||||
case 0 -> PlayerPose.STANDING;
|
||||
case 1 -> PlayerPose.SNEAKING;
|
||||
case 2 -> PlayerPose.SWIMMING;
|
||||
default -> PlayerPose.SLEEPING;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.players;
|
||||
|
||||
import games.cubi.locatables.implementations.ImmutableLocatableImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class PlayerLocatableTest {
|
||||
private static final UUID WORLD = UUID.fromString("00000000-0000-0000-0000-000000000001");
|
||||
private static final UUID OTHER_WORLD = UUID.fromString("00000000-0000-0000-0000-000000000002");
|
||||
|
||||
@Test
|
||||
void poseCameraOffsetsAreExposed() {
|
||||
assertEquals(1.62f, PlayerPose.UNKNOWN.cameraYOffset());
|
||||
assertEquals(1.62f, PlayerPose.STANDING.cameraYOffset());
|
||||
assertEquals(1.27f, PlayerPose.SNEAKING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.SWIMMING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.FALL_FLYING.cameraYOffset());
|
||||
assertEquals(0.40f, PlayerPose.SPIN_ATTACK.cameraYOffset());
|
||||
assertEquals(0.20f, PlayerPose.SLEEPING.cameraYOffset());
|
||||
assertEquals(0.20f, PlayerPose.DYING.cameraYOffset());
|
||||
}
|
||||
|
||||
@Test
|
||||
void startsInvalidAndInitializesCompleteCameraState() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
|
||||
assertNull(location.world());
|
||||
assertNull(location.pose());
|
||||
assertEquals(0.0f, location.cameraYOffset());
|
||||
|
||||
location.initialise(WORLD, 10.0, 20.0, 30.0, 90.0f, -25.0f, PlayerPose.SNEAKING);
|
||||
|
||||
assertEquals(WORLD, location.world());
|
||||
assertEquals(10.0, location.x());
|
||||
assertEquals(20.0, location.y());
|
||||
assertEquals(30.0, location.z());
|
||||
assertEquals(90.0f, location.yaw());
|
||||
assertEquals(-25.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SNEAKING, location.pose());
|
||||
assertEquals(1.27f, location.cameraYOffset());
|
||||
assertEquals(10.0, location.cameraX());
|
||||
assertEquals(21.27, location.cameraY(), 1.0e-6);
|
||||
assertEquals(30.0, location.cameraZ());
|
||||
assertEquals(1.27 * 1.27, location.cameraDistanceSquared(new ImmutableLocatableImpl(WORLD, 10.0, 20.0, 30.0)), 1.0e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
void partialUpdatesPreserveOmittedStateAndRequireInitialization() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
assertThrows(IllegalStateException.class, () -> location.updateFoot(1.0, 2.0, 3.0));
|
||||
assertThrows(IllegalStateException.class, () -> location.updateRotation(1.0f, 2.0f));
|
||||
assertThrows(IllegalStateException.class, () -> location.updatePose(PlayerPose.STANDING));
|
||||
|
||||
location.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.STANDING);
|
||||
location.updateFoot(6.0, 7.0, 8.0);
|
||||
location.updateRotation(9.0f, 10.0f);
|
||||
location.updatePose(PlayerPose.SNEAKING);
|
||||
|
||||
assertEquals(6.0, location.x());
|
||||
assertEquals(7.0, location.y());
|
||||
assertEquals(8.0, location.z());
|
||||
assertEquals(9.0f, location.yaw());
|
||||
assertEquals(10.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SNEAKING, location.pose());
|
||||
}
|
||||
|
||||
@Test
|
||||
void locatableMutationsPreserveViewStateAndSetWorldNullInvalidates() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
location.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.SLEEPING);
|
||||
|
||||
assertSame(location, location.setPosition(6.0, 7.0, 8.0));
|
||||
assertSame(location, location.setLocation(OTHER_WORLD, 9.0, 10.0, 11.0));
|
||||
assertEquals(4.0f, location.yaw());
|
||||
assertEquals(5.0f, location.pitch());
|
||||
assertEquals(PlayerPose.SLEEPING, location.pose());
|
||||
assertEquals(OTHER_WORLD, location.world());
|
||||
assertEquals(9.0, location.x());
|
||||
assertEquals(10.0, location.y());
|
||||
assertEquals(11.0, location.z());
|
||||
|
||||
location.setWorld(null);
|
||||
|
||||
assertNull(location.world());
|
||||
assertNull(location.pose());
|
||||
assertEquals(0.0, location.x());
|
||||
assertEquals(0.0, location.y());
|
||||
assertEquals(0.0, location.z());
|
||||
assertThrows(IllegalStateException.class, () -> location.setWorld(WORLD));
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalityUsesWorldAndFootCoordinatesOnly() {
|
||||
PlayerLocatable first = new PlayerLocatable();
|
||||
PlayerLocatable second = new PlayerLocatable();
|
||||
first.initialise(WORLD, 1.0, 2.0, 3.0, 4.0f, 5.0f, PlayerPose.STANDING);
|
||||
second.initialise(WORLD, 1.0, 2.0, 3.0, 90.0f, -5.0f, PlayerPose.SLEEPING);
|
||||
|
||||
assertEquals(first, second);
|
||||
assertEquals(first.hashCode(), second.hashCode());
|
||||
assertTrue(first.strictlyEquals(second));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullStateRejectsInvalidValues() {
|
||||
PlayerLocatable location = new PlayerLocatable();
|
||||
|
||||
assertThrows(NullPointerException.class, () -> location.initialise(null, 0.0, 0.0, 0.0, 0.0f, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(NullPointerException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, 0.0f, 0.0f, null));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, Double.NaN, 0.0, 0.0, 0.0f, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, Float.NaN, 0.0f, PlayerPose.STANDING));
|
||||
assertThrows(IllegalArgumentException.class, () -> location.initialise(WORLD, 0.0, 0.0, 0.0, 0.0f, 91.0f, PlayerPose.STANDING));
|
||||
assertNull(location.world());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.raycast;
|
||||
|
||||
import games.cubi.locatables.api.Locatable;
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Copyright © 2026 Cubicake.
|
||||
* This file is part of RaycastedAntiESP.
|
||||
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
|
||||
* See README.md for warranty disclaimer and further information.
|
||||
*/
|
||||
|
||||
package games.cubi.raycastedantiesp.core.tracked;
|
||||
|
||||
import games.cubi.raycastedantiesp.core.utils.Clearable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Phaser;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class NettyEntityTrackedStateTest {
|
||||
@Test
|
||||
void trackedFlagsUpdateIndependentlyAndReportChanges() {
|
||||
TestEntity entity = new TestEntity();
|
||||
|
||||
assertTrue(entity.setSneaking(true));
|
||||
assertTrue(entity.sneaking());
|
||||
assertFalse(entity.glowing());
|
||||
assertEquals(NettyEntity.NEVER_CHECKED, entity.lastChecked());
|
||||
|
||||
entity.setLastChecked(10);
|
||||
assertFalse(entity.setSneaking(true));
|
||||
assertEquals(10, entity.lastChecked());
|
||||
|
||||
assertTrue(entity.setGlowing(true));
|
||||
assertTrue(entity.sneaking());
|
||||
assertTrue(entity.glowing());
|
||||
assertEquals(NettyEntity.NEVER_CHECKED, entity.lastChecked());
|
||||
|
||||
entity.clear();
|
||||
|
||||
assertFalse(entity.sneaking());
|
||||
assertFalse(entity.glowing());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentUpdatesToDifferentFlagsDoNotOverwriteEachOther() {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
|
||||
TestEntity entity = new TestEntity();
|
||||
int iterations = 2_000;
|
||||
Phaser phases = new Phaser(3);
|
||||
AtomicBoolean lostUpdate = new AtomicBoolean();
|
||||
|
||||
try (var executor = Executors.newFixedThreadPool(2)) {
|
||||
var sneakingTask = executor.submit(() -> {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
phases.arriveAndAwaitAdvance();
|
||||
entity.setSneaking(true);
|
||||
phases.arriveAndAwaitAdvance();
|
||||
}
|
||||
});
|
||||
var glowingTask = executor.submit(() -> {
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
phases.arriveAndAwaitAdvance();
|
||||
entity.setGlowing(true);
|
||||
phases.arriveAndAwaitAdvance();
|
||||
}
|
||||
});
|
||||
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
entity.clear();
|
||||
phases.arriveAndAwaitAdvance();
|
||||
phases.arriveAndAwaitAdvance();
|
||||
if (!entity.sneaking() || !entity.glowing()) {
|
||||
lostUpdate.set(true);
|
||||
}
|
||||
}
|
||||
sneakingTask.get();
|
||||
glowingTask.get();
|
||||
}
|
||||
|
||||
assertFalse(lostUpdate.get());
|
||||
});
|
||||
}
|
||||
|
||||
private static final class TestEntity extends NettyEntity<Clearable> {
|
||||
private TestEntity() {
|
||||
super(null, 0, 0, 0, 1, UUID.randomUUID(), false, 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
+87
-22
@@ -8,12 +8,16 @@
|
||||
|
||||
package games.cubi.raycastedantiesp.core.utils;
|
||||
|
||||
import games.cubi.utils.sets.CopyOnWriteMTIntSet;
|
||||
import games.cubi.utils.sets.SortedStripedMTIntSet;
|
||||
import org.junit.jupiter.api.DynamicContainer;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -22,6 +26,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -30,8 +35,7 @@ import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
||||
|
||||
class CopyOnWriteMTIntSetTest {
|
||||
private static final List<Implementation> IMPLEMENTATIONS = List.of(
|
||||
new Implementation("sorted array", SortedMTIntSet::new),
|
||||
new Implementation("fastutil wrapper", MTWrappedFastIntSet::new)
|
||||
new Implementation("sorted stripes", SortedStripedMTIntSet::new)
|
||||
);
|
||||
|
||||
@TestFactory
|
||||
@@ -41,6 +45,7 @@ class CopyOnWriteMTIntSetTest {
|
||||
Stream.of(
|
||||
dynamicTest("adds, finds, and removes all int values", () -> basicOperations(implementation.create())),
|
||||
dynamicTest("removes beginning, middle, and end values", () -> removalPositions(implementation.create())),
|
||||
dynamicTest("traverses one coherent snapshot", () -> snapshotTraversal(implementation.create())),
|
||||
dynamicTest("supports concurrent readers and writers", () -> concurrentReadersAndWriters(implementation.create()))
|
||||
)
|
||||
));
|
||||
@@ -77,41 +82,80 @@ class CopyOnWriteMTIntSetTest {
|
||||
assertFalse(set.contains(5));
|
||||
}
|
||||
|
||||
private static void snapshotTraversal(CopyOnWriteMTIntSet set) {
|
||||
set.add(1);
|
||||
set.add(2);
|
||||
set.add(3);
|
||||
|
||||
Set<Integer> observed = new HashSet<>();
|
||||
set.forEach(value -> {
|
||||
assertTrue(observed.add(value));
|
||||
if (value == 1) {
|
||||
assertTrue(set.remove(2));
|
||||
set.add(4);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(observed.containsAll(Set.of(1, 2, 3)));
|
||||
assertTrue(observed.size() == 3);
|
||||
assertFalse(set.contains(2));
|
||||
assertTrue(set.contains(4));
|
||||
|
||||
set.remove(1);
|
||||
set.remove(3);
|
||||
set.remove(4);
|
||||
set.forEach(value -> assertTrue(false, "An empty set must not be traversed: " + value));
|
||||
}
|
||||
|
||||
private static void concurrentReadersAndWriters(CopyOnWriteMTIntSet set) {
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(10), () -> {
|
||||
int valueCount = 512;
|
||||
int addedBase = 10_000;
|
||||
for (int value = 0; value < valueCount; value++) {
|
||||
set.add(value);
|
||||
assertTimeoutPreemptively(Duration.ofSeconds(20), () -> {
|
||||
int transientCount = 512;
|
||||
int transientBase = 100_000;
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
set.add(transientBase + value);
|
||||
}
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(6);
|
||||
int valueCount = 2_048;
|
||||
ExecutorService executor = Executors.newFixedThreadPool(8);
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
try {
|
||||
for (int worker = 0; worker < 2; worker++) {
|
||||
int from = worker * valueCount / 2;
|
||||
int to = (worker + 1) * valueCount / 2;
|
||||
int workerIndex = worker;
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int value = from; value < to; value++) {
|
||||
assertTrue(set.remove(value));
|
||||
}
|
||||
}));
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int value = from; value < to; value++) {
|
||||
set.add(addedBase + value);
|
||||
if (workerIndex == 0) {
|
||||
for (int value = 0; value < valueCount; value++) {
|
||||
addFinalValues(set, value);
|
||||
}
|
||||
} else {
|
||||
for (int value = valueCount - 1; value >= 0; value--) {
|
||||
addFinalValues(set, value);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (int reader = 0; reader < 2; reader++) {
|
||||
for (int remover = 0; remover < 2; remover++) {
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
set.remove(transientBase + value);
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (int reader = 0; reader < 3; reader++) {
|
||||
futures.add(executor.submit(() -> {
|
||||
await(start);
|
||||
for (int iteration = 0; iteration < 10_000; iteration++) {
|
||||
int value = iteration % valueCount;
|
||||
set.contains(value);
|
||||
set.contains(addedBase + value);
|
||||
set.contains(-value - 1);
|
||||
set.contains(Integer.MIN_VALUE);
|
||||
set.contains(Integer.MAX_VALUE);
|
||||
if (iteration % 100 == 0) {
|
||||
Set<Integer> snapshot = new HashSet<>();
|
||||
set.forEach(snapshotValue -> assertTrue(snapshot.add(snapshotValue), "Duplicate value in traversal snapshot: " + snapshotValue));
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -125,13 +169,34 @@ class CopyOnWriteMTIntSetTest {
|
||||
executor.awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Set<Integer> expected = new HashSet<>();
|
||||
for (int value = 0; value < valueCount; value++) {
|
||||
assertFalse(set.contains(value));
|
||||
assertTrue(set.contains(addedBase + value));
|
||||
expected.add(value);
|
||||
expected.add(-value - 1);
|
||||
}
|
||||
expected.add(Integer.MIN_VALUE);
|
||||
expected.add(Integer.MAX_VALUE);
|
||||
|
||||
Set<Integer> actual = new HashSet<>();
|
||||
set.forEach(value -> assertTrue(actual.add(value), "Duplicate value in final snapshot: " + value));
|
||||
assertEquals(expected, actual);
|
||||
for (int value = 0; value < transientCount; value++) {
|
||||
assertFalse(set.contains(transientBase + value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void addFinalValues(CopyOnWriteMTIntSet set, int value) {
|
||||
set.add(value);
|
||||
set.add(-value - 1);
|
||||
set.add(value);
|
||||
set.add(-value - 1);
|
||||
if (value == 0) {
|
||||
set.add(Integer.MIN_VALUE);
|
||||
set.add(Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void await(CountDownLatch latch) {
|
||||
try {
|
||||
latch.await();
|
||||
|
||||
Loaded 100 of 158 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user