From 6999695422d265792ec003d1550d6ca9ec9e5550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Eisenbl=C3=A4tter?= Date: Sat, 9 Sep 2023 02:56:39 +0200 Subject: [PATCH] chore: update README --- README.md | 32 +++++++++++-------- ...rappedClientboundLevelChunkPacketData.java | 2 +- .../orebfuscator-nms-v1_20_R1/pom.xml | 4 +-- orebfuscator-plugin/pom.xml | 15 ++++++++- .../net/imprex/orebfuscator/Orebfuscator.java | 1 + .../net/imprex/orebfuscator/UpdateSystem.java | 8 ++--- .../orebfuscator/cache/ObfuscationCache.java | 5 +-- .../obfuscation/ObfuscationListenerAsync.java | 5 ++- .../ObfuscationTaskDispatcher.java | 15 +++++++-- .../proximity/ProximityWorker.java | 5 ++- .../imprex/orebfuscator/util/ConsoleUtil.java | 17 ++++++---- .../src/main/resources/plugin.yml | 1 + 12 files changed, 73 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 95d8be01..9b97addf 100644 --- a/README.md +++ b/README.md @@ -3,37 +3,40 @@ # Orebfuscator - Anti X-Ray [![Release Status](https://github.com/Imprex-Development/Orebfuscator/workflows/Releases/badge.svg)](https://github.com/Imprex-Development/Orebfuscator/releases/latest) [![Build Status](https://github.com/Imprex-Development/Orebfuscator/workflows/Build/badge.svg)](https://github.com/Imprex-Development/Orebfuscator/actions?query=workflow%3ABuild) -Orebfuscator is plugin for Spigot based Minecraft Servers that modifies packets in order to hide blocks of interest from X-Ray Clients and Texture Packs. Thus it doesn't modify your world and is safe to use. +Orebfuscator empowers server owners to protect their server from X-Ray Clients and Texture Packs, all while offering a high degree of configurability. This is achieved through modifying network packets without altering your game world, guaranteeing a secure and reliable experience for users. With Orebfuscator, you can tailor the settings to suit your server's needs, ensuring precise control over the visibility of specific blocks. This means that not only does Orebfuscator safeguard your world's integrity, but it also empowers you to fine-tune your Anti-X-Ray measures for the best gameplay experience. ### Features -* Plug & Play -* Highly configurable config -* Support for Spigot based servers 1.9.4+ (only tested on spigot) -* Obfuscate non-visible blocks -* Hide block entities like Chests and Furnaces -* Make blocks in a players proximity visible based on their distance an +* Seamless Integration: Plug & Play functionality for effortless use. +* Extensive Configuration: Highly customizable settings to tailor the experience to your liking. +* Server Compatibility: Designed for Spigot-based servers 1.9.4 and newer (primarily tested on Spigot). +* Block Obfuscation: Conceal non-visible blocks from players' view. +* Block-Entity Support: Hide block entities such as Chests and Furnaces. +* Dynamic Block Visibility: Adjust block visibility based on player proximity and distance. ### Requirements -- Java 11 or higher -- Spigot and (proably) any other fork of Spigot (1.9.4 or higher) -- [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997) 5.0.0 or higher +* Java 11 or higher +* Spigot or compatible forks (1.9.4 or newer) +* [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997) 5.0.0 or later ### Installation 1. Download [ProtocolLib](https://github.com/dmulloy2/ProtocolLib/releases) 2. Download [Orebfuscator](https://github.com/Imprex-Development/Orebfuscator/releases) -3. Put both in your *plugins* directory -4. Start your server and [configure](https://github.com/Imprex-Development/Orebfuscator/wiki/Config) orebfuscator to your liking +3. Place both plugins in your _plugins_ directory +4. Start your server and [configure Orebfuscator](https://github.com/Imprex-Development/Orebfuscator/wiki/Config) to your liking Still having trouble getting Orebfuscator to run check out our [common issues](https://github.com/Imprex-Development/Orebfuscator/wiki/Common-Issues). ### Maven -```maven + +To include the API in your Maven project, add the following configuration to your `pom.xml`: + +```xml codemc-repo https://repo.codemc.io/repository/maven-public/ - ... + @@ -42,6 +45,7 @@ Still having trouble getting Orebfuscator to run check out our [common issues](h orebfuscator-api 5.2.4 + ``` diff --git a/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/WrappedClientboundLevelChunkPacketData.java b/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/WrappedClientboundLevelChunkPacketData.java index 9072f73f..89717131 100644 --- a/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/WrappedClientboundLevelChunkPacketData.java +++ b/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/WrappedClientboundLevelChunkPacketData.java @@ -17,7 +17,7 @@ public class WrappedClientboundLevelChunkPacketData { private static final FieldAccessor BUFFER = Accessors.getFieldAccessor(CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA, byte[].class, true); private static final FieldAccessor BLOCK_ENTITIES = Accessors.getFieldAccessor(CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA, List.class, true); - private static final Class BLOCK_ENTITY_INFO = MinecraftReflection.getMinecraftClass("network.protocol.game.ClientboundLevelChunkPacketData$a"); + private static final Class BLOCK_ENTITY_INFO = MinecraftReflection.getMinecraftClass("network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); private static final FieldAccessor[] INT_FIELDS = Accessors.getFieldAccessorArray(BLOCK_ENTITY_INFO, int.class, true); private static final FieldAccessor PACKED_XZ = INT_FIELDS[0]; private static final FieldAccessor Y = INT_FIELDS[1]; diff --git a/orebfuscator-nms/orebfuscator-nms-v1_20_R1/pom.xml b/orebfuscator-nms/orebfuscator-nms-v1_20_R1/pom.xml index db6760c7..dd18df95 100644 --- a/orebfuscator-nms/orebfuscator-nms-v1_20_R1/pom.xml +++ b/orebfuscator-nms/orebfuscator-nms-v1_20_R1/pom.xml @@ -28,7 +28,7 @@ - + \ No newline at end of file diff --git a/orebfuscator-plugin/pom.xml b/orebfuscator-plugin/pom.xml index dd0c924a..1167e487 100644 --- a/orebfuscator-plugin/pom.xml +++ b/orebfuscator-plugin/pom.xml @@ -11,7 +11,14 @@ orebfuscator-plugin jar - + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + @@ -69,6 +76,12 @@ org.spigotmc spigot-api ${dependency.bukkit.version} + test + + + dev.folia + folia-api + 1.20.1-R0.1-SNAPSHOT provided diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/Orebfuscator.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/Orebfuscator.java index 030d2eb4..6bcdad0e 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/Orebfuscator.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/Orebfuscator.java @@ -115,6 +115,7 @@ public void onDisable() { this.proximityThread.close(); } + getServer().getAsyncScheduler().cancelTasks(this); this.getServer().getScheduler().cancelTasks(this); NmsInstance.close(); diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/UpdateSystem.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/UpdateSystem.java index e85b0933..c82d1867 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/UpdateSystem.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/UpdateSystem.java @@ -115,7 +115,7 @@ private boolean isUpdateAvailable() { } private void checkForUpdates() { - Bukkit.getScheduler().runTaskAsynchronously(this.orebfuscator, () -> { + Bukkit.getAsyncScheduler().runNow(this.orebfuscator, (task) -> { if (this.isUpdateAvailable()) { ConsoleUtil.printBox(Level.WARNING, "UPDATE AVAILABLE", "", this.getHtmlUrl()); @@ -124,15 +124,15 @@ private void checkForUpdates() { } public void checkForUpdates(Player player) { - Bukkit.getScheduler().runTaskAsynchronously(this.orebfuscator, () -> { + Bukkit.getAsyncScheduler().runNow(this.orebfuscator, (task) -> { if (this.isUpdateAvailable()) { BaseComponent[] components = new ComponentBuilder("[§bOrebfuscator§f]§7 A new release is available ") .append("§f§l[CLICK HERE]") .event(new ClickEvent(ClickEvent.Action.OPEN_URL, this.getHtmlUrl())) .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§7Click here to see the latest release").create())).create(); - Bukkit.getScheduler().runTask(this.orebfuscator, () -> { + player.getScheduler().run(this.orebfuscator, (task2) -> { player.spigot().sendMessage(components); - }); + }, null); } }); } diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/ObfuscationCache.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/ObfuscationCache.java index 9d37e099..26225d42 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/ObfuscationCache.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/ObfuscationCache.java @@ -38,8 +38,9 @@ public ObfuscationCache(Orebfuscator orebfuscator) { } if (this.cacheConfig.enabled() && this.cacheConfig.deleteRegionFilesAfterAccess() > 0) { - Bukkit.getScheduler().runTaskTimerAsynchronously(orebfuscator, new CacheFileCleanupTask(orebfuscator), 0, - 3_600_000L); + var temp = new CacheFileCleanupTask(orebfuscator); + Bukkit.getAsyncScheduler().runAtFixedRate(orebfuscator, task -> temp.run(), 0, + 3_600_000L, TimeUnit.MILLISECONDS); } } diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationListenerAsync.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationListenerAsync.java index 228eae15..cccd8a4f 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationListenerAsync.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationListenerAsync.java @@ -1,5 +1,7 @@ package net.imprex.orebfuscator.obfuscation; +import org.bukkit.Bukkit; + import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.async.AsyncListenerHandler; @@ -17,7 +19,8 @@ public ObfuscationListenerAsync(Orebfuscator orebfuscator) { this.asynchronousManager = ProtocolLibrary.getProtocolManager().getAsynchronousManager(); this.asyncListenerHandler = this.asynchronousManager.registerAsyncHandler(this); - this.asyncListenerHandler.start(); + Bukkit.getAsyncScheduler().runNow(orebfuscator, (task) -> this.asyncListenerHandler.getListenerLoop().run()); +// this.asyncListenerHandler.start(); } @Override diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskDispatcher.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskDispatcher.java index 2871d585..09fac9a3 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskDispatcher.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskDispatcher.java @@ -12,6 +12,7 @@ class ObfuscationTaskDispatcher implements Runnable { + private final Orebfuscator orebfuscator; private final ObfuscationProcessor processor; private final Queue requests = new ConcurrentLinkedQueue<>(); @@ -21,6 +22,7 @@ class ObfuscationTaskDispatcher implements Runnable { private final ObfuscationTaskWorker[] worker; public ObfuscationTaskDispatcher(Orebfuscator orebfuscator, ObfuscationProcessor processor) { + this.orebfuscator = orebfuscator; this.processor = processor; AdvancedConfig config = orebfuscator.getOrebfuscatorConfig().advanced(); @@ -31,18 +33,25 @@ public ObfuscationTaskDispatcher(Orebfuscator orebfuscator, ObfuscationProcessor this.worker[i] = new ObfuscationTaskWorker(this, this.processor); } - Bukkit.getScheduler().runTaskTimer(orebfuscator, this, 0, 1); +// Bukkit.getScheduler().runTaskTimer(orebfuscator, this, 0, 1); } public void submitRequest(ObfuscationRequest request) { - this.requests.offer(request); + Bukkit.getRegionScheduler().run(this.orebfuscator, + request.getChunkStruct().world, + request.getChunkStruct().chunkX, + request.getChunkStruct().chunkZ, + (unused) -> { + this.tasks.offer(ObfuscationTask.fromRequest(request)); + }); +// this.requests.offer(request); } public ObfuscationTask retrieveTask() throws InterruptedException { ObfuscationTask task; while ((task = this.tasks.poll()) == null) { - LockSupport.park(this); + LockSupport.parkNanos(this, 50000000L/*50ms*/); if (Thread.interrupted()) { throw new InterruptedException(); } diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityWorker.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityWorker.java index aea054fc..30e128b3 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityWorker.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityWorker.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; @@ -149,10 +148,10 @@ private void process(Player player) { } } - Bukkit.getScheduler().runTask(this.orebfuscator, () -> { + player.getScheduler().run(this.orebfuscator, (task) -> { if (player.isOnline() && player.getWorld().equals(world)) { NmsInstance.sendBlockUpdates(player, updateBlocks); } - }); + }, null); } } diff --git a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/util/ConsoleUtil.java b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/util/ConsoleUtil.java index 5cc923ac..1b9a4c40 100644 --- a/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/util/ConsoleUtil.java +++ b/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/util/ConsoleUtil.java @@ -1,11 +1,10 @@ package net.imprex.orebfuscator.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; -import org.apache.commons.lang.StringUtils; - public final class ConsoleUtil { private static final int BOX_PADDING = 3; @@ -61,7 +60,7 @@ public static Iterable createBox(String...lines) { int totalWidth = width + BOX_PADDING * 2; // create top/bottom lines - String bottomTopLine = StringUtils.repeat("═", totalWidth); + String bottomTopLine = repeat('═', totalWidth); String topLine = String.format("╔%s╗", bottomTopLine); String bottomLine = String.format("╚%s╝", bottomTopLine); @@ -75,10 +74,10 @@ public static Iterable createBox(String...lines) { // center line String leftPadding, rightPadding; if (space % 2 == 0) { - leftPadding = rightPadding = StringUtils.repeat(" ", space / 2); + leftPadding = rightPadding = repeat(' ', space / 2); } else { - leftPadding = StringUtils.repeat(" ", space / 2 + 1); - rightPadding = StringUtils.repeat(" ", space / 2); + leftPadding = repeat(' ', space / 2 + 1); + rightPadding = repeat(' ', space / 2); } box.add(String.format("║%s%s%s║", leftPadding, line, rightPadding)); @@ -87,4 +86,10 @@ public static Iterable createBox(String...lines) { box.add(bottomLine); return box; } + + private static String repeat(char character, int length) { + char[] string = new char[length]; + Arrays.fill(string, character); + return new String(string); + } } diff --git a/orebfuscator-plugin/src/main/resources/plugin.yml b/orebfuscator-plugin/src/main/resources/plugin.yml index c6946cc6..2143ced4 100644 --- a/orebfuscator-plugin/src/main/resources/plugin.yml +++ b/orebfuscator-plugin/src/main/resources/plugin.yml @@ -10,6 +10,7 @@ author: Ingrim4 authors: [NgLoader, lishid, SydMontague, ProgrammerDan, Aleksey-Terzi] depend: [ProtocolLib] +folia-supported: true commands: orebfuscator: