();
61 |
62 | blocks.add(origin);
63 |
64 | for (int x = -size; x <= size; x++) {
65 | for (int y = -size; y <= size; y++) {
66 | for (int z = -size; z <= size; z++) {
67 | Block relative = origin.getRelative(x, y, z);
68 | if (!relative.getType().isAir()) {
69 | blocks.add(relative);
70 | }
71 | }
72 | }
73 | }
74 |
75 | return blocks;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/orebfuscator-api-example/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | api-version: 1.21
2 | folia-supported: true
3 |
4 | name: ${project.name}
5 | version: ${project.version}
6 |
7 | main: net.imprex.api.example.Example
8 |
9 | author: Ingrim4
10 |
11 | depend: [Orebfuscator]
12 |
13 | description: 'Orebfuscator api example project'
14 |
--------------------------------------------------------------------------------
/orebfuscator-api/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator
9 | ${revision}
10 |
11 |
12 | orebfuscator-api
13 | jar
14 |
15 |
16 |
17 | org.spigotmc
18 | spigot-api
19 | ${dependency.bukkit.version}
20 | provided
21 |
22 |
23 |
--------------------------------------------------------------------------------
/orebfuscator-api/src/main/java/net/imprex/orebfuscator/api/OrebfuscatorService.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.api;
2 |
3 | import java.util.Collection;
4 |
5 | import org.bukkit.block.Block;
6 |
7 | /**
8 | *
9 | * Service that gives access to some of Orebfuscators internal methods. Use with
10 | * caution.
11 | *
12 | *
13 | *
14 | * All calls to this service are expected to originate from the servers
15 | * main-thread or in case of folia from a region thread (never the global region thread).
16 | *
17 | *
18 | * @since 5.2.0
19 | */
20 | public interface OrebfuscatorService {
21 |
22 | /**
23 | * Deobfuscates a list of blocks. All blocks are expected to be located in the
24 | * same world. It is recommended to call this method after the block update.
25 | *
26 | * @param blocks list of blocks to deobfuscate
27 | */
28 | void deobfuscate(Collection extends Block> blocks);
29 | }
30 |
--------------------------------------------------------------------------------
/orebfuscator-common/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator
9 | ${revision}
10 |
11 |
12 | orebfuscator-common
13 | jar
14 |
15 |
16 |
17 | org.spigotmc
18 | spigot-api
19 | ${dependency.bukkit.version}
20 | provided
21 |
22 |
23 | org.joml
24 | joml
25 | ${dependency.joml.version}
26 | compile
27 |
28 |
29 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/AdvancedConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | public interface AdvancedConfig {
4 |
5 | int obfuscationThreads();
6 |
7 | boolean hasObfuscationTimeout();
8 |
9 | long obfuscationTimeout();
10 |
11 | int maxMillisecondsPerTick();
12 |
13 | int proximityThreads();
14 |
15 | int proximityDefaultBucketSize();
16 |
17 | int proximityThreadCheckInterval();
18 |
19 | boolean hasProximityPlayerCheckInterval();
20 |
21 | int proximityPlayerCheckInterval();
22 | }
23 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/BlockFlags.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | public interface BlockFlags {
4 |
5 | public static final int FLAG_OBFUSCATE = 1;
6 | public static final int FLAG_BLOCK_ENTITY = 2;
7 | public static final int FLAG_PROXIMITY = 4;
8 | public static final int FLAG_USE_BLOCK_BELOW = 8;
9 | public static final int FLAG_ALLOW_FOR_USE_BLOCK_BELOW = 16;
10 |
11 | public static boolean isEmpty(int mask) {
12 | return (mask & 0xFF) == 0;
13 | }
14 |
15 | public static boolean isBitSet(int mask, int flag) {
16 | return (mask & flag) != 0;
17 | }
18 |
19 | public static boolean isObfuscateBitSet(int mask) {
20 | return isBitSet(mask, FLAG_OBFUSCATE);
21 | }
22 |
23 | public static boolean isBlockEntityBitSet(int mask) {
24 | return isBitSet(mask, FLAG_BLOCK_ENTITY);
25 | }
26 |
27 | public static boolean isProximityBitSet(int mask) {
28 | return isBitSet(mask, FLAG_PROXIMITY);
29 | }
30 |
31 | public static boolean isUseBlockBelowBitSet(int mask) {
32 | return isBitSet(mask, FLAG_USE_BLOCK_BELOW);
33 | }
34 |
35 | public static boolean isAllowForUseBlockBelowBitSet(int mask) {
36 | return isBitSet(mask, FLAG_ALLOW_FOR_USE_BLOCK_BELOW);
37 | }
38 |
39 | int flags(int blockState);
40 |
41 | int flags(int blockState, int y);
42 | }
43 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/CacheConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import java.nio.file.Path;
4 |
5 | import net.imprex.orebfuscator.util.ChunkPosition;
6 |
7 | public interface CacheConfig {
8 |
9 | boolean enabled();
10 |
11 | int maximumSize();
12 |
13 | long expireAfterAccess();
14 |
15 | boolean enableDiskCache();
16 |
17 | Path baseDirectory();
18 |
19 | Path regionFile(ChunkPosition chunkPosition);
20 |
21 | int maximumOpenRegionFiles();
22 |
23 | long deleteRegionFilesAfterAccess();
24 |
25 | int maximumTaskQueueSize();
26 | }
27 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/Config.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import org.bukkit.World;
4 |
5 | public interface Config {
6 |
7 | byte[] systemHash();
8 |
9 | String report();
10 |
11 | GeneralConfig general();
12 |
13 | AdvancedConfig advanced();
14 |
15 | CacheConfig cache();
16 |
17 | WorldConfigBundle world(World world);
18 |
19 | boolean proximityEnabled();
20 | }
21 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/GeneralConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | public interface GeneralConfig {
4 |
5 | boolean checkForUpdates();
6 |
7 | boolean updateOnBlockDamage();
8 |
9 | boolean bypassNotification();
10 |
11 | boolean ignoreSpectator();
12 |
13 | int updateRadius();
14 | }
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/ObfuscationConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import net.imprex.orebfuscator.util.BlockProperties;
4 |
5 | public interface ObfuscationConfig extends WorldConfig {
6 |
7 | boolean layerObfuscation();
8 |
9 | Iterable hiddenBlocks();
10 | }
11 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/ProximityConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import java.util.Map;
4 |
5 | import org.joml.Matrix4f;
6 |
7 | import net.imprex.orebfuscator.util.BlockProperties;
8 |
9 | public interface ProximityConfig extends WorldConfig {
10 |
11 | int distance();
12 |
13 | boolean frustumCullingEnabled();
14 |
15 | float frustumCullingMinDistanceSquared();
16 |
17 | Matrix4f frustumCullingProjectionMatrix();
18 |
19 | boolean rayCastCheckEnabled();
20 |
21 | boolean rayCastCheckOnlyCheckCenter();
22 |
23 | Iterable> hiddenBlocks();
24 | }
25 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/WorldConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | public interface WorldConfig {
4 |
5 | boolean isEnabled();
6 |
7 | int getMinY();
8 |
9 | int getMaxY();
10 |
11 | boolean matchesWorldName(String worldName);
12 |
13 | boolean shouldObfuscate(int y);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/config/WorldConfigBundle.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | public interface WorldConfigBundle {
4 |
5 | BlockFlags blockFlags();
6 |
7 | ObfuscationConfig obfuscation();
8 |
9 | ProximityConfig proximity();
10 |
11 | boolean needsObfuscation();
12 |
13 | boolean skipReadSectionIndex(int index);
14 |
15 | boolean skipProcessingSectionIndex(int index);
16 |
17 | int minSectionIndex();
18 |
19 | int maxSectionIndex();
20 |
21 | boolean shouldObfuscate(int y);
22 |
23 | int nextRandomObfuscationBlock(int y);
24 |
25 | int nextRandomProximityBlock(int y);
26 | }
27 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/BlockProperties.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import java.util.HashSet;
4 | import java.util.Objects;
5 | import java.util.Set;
6 |
7 | import com.google.common.collect.ImmutableList;
8 |
9 | public class BlockProperties {
10 |
11 | public static Builder builder(NamespacedKey key) {
12 | return new Builder(key);
13 | }
14 |
15 | private final NamespacedKey key;
16 | private final BlockStateProperties defaultBlockState;
17 | private final ImmutableList blockStates;
18 |
19 | private BlockProperties(Builder builder) {
20 | this.key = builder.key;
21 | this.defaultBlockState = builder.defaultBlockState;
22 | this.blockStates = ImmutableList.copyOf(builder.blockStates);
23 | }
24 |
25 | public NamespacedKey getKey() {
26 | return key;
27 | }
28 |
29 | public BlockStateProperties getDefaultBlockState() {
30 | return defaultBlockState;
31 | }
32 |
33 | public ImmutableList getBlockStates() {
34 | return blockStates;
35 | }
36 |
37 | @Override
38 | public int hashCode() {
39 | return this.key.hashCode();
40 | }
41 |
42 | @Override
43 | public boolean equals(Object obj) {
44 | if (this == obj) {
45 | return true;
46 | }
47 | if (!(obj instanceof BlockProperties)) {
48 | return false;
49 | }
50 | BlockProperties other = (BlockProperties) obj;
51 | return Objects.equals(key, other.key);
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "BlockProperties [key=" + key + ", defaultBlockState=" + defaultBlockState + ", blockStates="
57 | + blockStates + "]";
58 | }
59 |
60 | public static class Builder {
61 |
62 | private final NamespacedKey key;
63 |
64 | private BlockStateProperties defaultBlockState;
65 | private final Set blockStates = new HashSet<>();
66 |
67 | private Builder(NamespacedKey key) {
68 | this.key = key;
69 | }
70 |
71 | public Builder withBlockState(BlockStateProperties blockState) {
72 | if (!blockStates.add(blockState)) {
73 | throw new IllegalStateException(String.format("duplicate block state id (%s) for block: %s", blockState.getId(), key));
74 | }
75 |
76 | if (blockState.isDefaultState()) {
77 | // check for multiple default blocks
78 | if (this.defaultBlockState != null) {
79 | throw new IllegalStateException(String.format("multiple default block states for block: %s", blockState.getId(), key));
80 | }
81 |
82 | this.defaultBlockState = blockState;
83 | }
84 |
85 | return this;
86 | }
87 |
88 | public BlockProperties build() {
89 | Objects.requireNonNull(this.defaultBlockState, "missing default block state for block: " + this.key);
90 |
91 | if (this.blockStates.size() == 0) {
92 | throw new IllegalStateException("missing block states for block: " + this.key);
93 | }
94 |
95 | return new BlockProperties(this);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/BlockStateProperties.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | public class BlockStateProperties {
4 |
5 | public static Builder builder(int id) {
6 | return new Builder(id);
7 | }
8 |
9 | private final int id;
10 |
11 | private final boolean isAir;
12 | private final boolean isOccluding;
13 | private final boolean isBlockEntity;
14 | private final boolean isDefaultState;
15 |
16 | private BlockStateProperties(Builder builder) {
17 | this.id = builder.id;
18 | this.isAir = builder.isAir;
19 | this.isOccluding = builder.isOccluding;
20 | this.isBlockEntity = builder.isBlockEntity;
21 | this.isDefaultState = builder.isDefaultState;
22 | }
23 |
24 | public int getId() {
25 | return id;
26 | }
27 |
28 | public boolean isAir() {
29 | return isAir;
30 | }
31 |
32 | public boolean isOccluding() {
33 | return isOccluding;
34 | }
35 |
36 | public boolean isBlockEntity() {
37 | return isBlockEntity;
38 | }
39 |
40 | public boolean isDefaultState() {
41 | return isDefaultState;
42 | }
43 |
44 | @Override
45 | public int hashCode() {
46 | return id;
47 | }
48 |
49 | @Override
50 | public boolean equals(Object obj) {
51 | if (this == obj) {
52 | return true;
53 | }
54 | if (!(obj instanceof BlockStateProperties)) {
55 | return false;
56 | }
57 | BlockStateProperties other = (BlockStateProperties) obj;
58 | return id == other.id;
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return "BlockStateProperties [id=" + id + ", isDefaultState=" + isDefaultState + ", isAir=" + isAir
64 | + ", isOccluding=" + isOccluding + ", isBlockEntity=" + isBlockEntity + "]";
65 | }
66 |
67 | public static class Builder {
68 |
69 | private final int id;
70 |
71 | private boolean isAir;
72 | private boolean isOccluding;
73 | private boolean isBlockEntity;
74 | private boolean isDefaultState;
75 |
76 | private Builder(int id) {
77 | this.id = id;
78 | }
79 |
80 | public Builder withIsAir(boolean isAir) {
81 | this.isAir = isAir;
82 | return this;
83 | }
84 |
85 | public Builder withIsOccluding(boolean isOccluding) {
86 | this.isOccluding = isOccluding;
87 | return this;
88 | }
89 |
90 | public Builder withIsBlockEntity(boolean isBlockEntity) {
91 | this.isBlockEntity = isBlockEntity;
92 | return this;
93 | }
94 |
95 | public Builder withIsDefaultState(boolean isDefaultState) {
96 | this.isDefaultState = isDefaultState;
97 | return this;
98 | }
99 |
100 | public BlockStateProperties build() {
101 | return new BlockStateProperties(this);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/ChunkDirection.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | public enum ChunkDirection {
4 |
5 | NORTH(1, 0), EAST(0, 1), SOUTH(-1, 0), WEST(0, -1);
6 |
7 | private int offsetX;
8 | private int offsetZ;
9 |
10 | private ChunkDirection(int offsetX, int offsetZ) {
11 | this.offsetX = offsetX;
12 | this.offsetZ = offsetZ;
13 | }
14 |
15 | public int getOffsetX() {
16 | return offsetX;
17 | }
18 |
19 | public int getOffsetZ() {
20 | return offsetZ;
21 | }
22 |
23 | public static ChunkDirection fromPosition(ChunkPosition position, int targetX, int targetZ) {
24 | int offsetX = (targetX >> 4) - position.x;
25 | int offsetZ = (targetZ >> 4) - position.z;
26 |
27 | if (offsetX == 1 && offsetZ == 0) {
28 | return NORTH;
29 | } else if (offsetX == 0 && offsetZ == 1) {
30 | return EAST;
31 | } else if (offsetX == -1 && offsetZ == 0) {
32 | return SOUTH;
33 | } else if (offsetX == 0 && offsetZ == -1) {
34 | return WEST;
35 | }
36 |
37 | throw new IllegalArgumentException(String.format("invalid offset (origin: %s, x: %d, z: %d)", position, targetX, targetZ));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/ChunkPosition.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import java.util.Objects;
4 |
5 | import org.bukkit.World;
6 |
7 | public class ChunkPosition {
8 |
9 | public static long toLong(int chunkX, int chunkZ) {
10 | return (chunkZ & 0xffffffffL) << 32 | chunkX & 0xffffffffL;
11 | }
12 |
13 | public final String world;
14 | public final int x;
15 | public final int z;
16 |
17 | public ChunkPosition(World world, int x, int z) {
18 | this.world = Objects.requireNonNull(world).getName();
19 | this.x = x;
20 | this.z = z;
21 | }
22 |
23 | @Override
24 | public int hashCode() {
25 | int result = 1;
26 | result = 31 * result + world.hashCode();
27 | result = 31 * result + x;
28 | result = 31 * result + z;
29 | return result;
30 | }
31 |
32 | @Override
33 | public boolean equals(Object obj) {
34 | if (this == obj) {
35 | return true;
36 | }
37 | if (!(obj instanceof ChunkPosition)) {
38 | return false;
39 | }
40 | ChunkPosition other = (ChunkPosition) obj;
41 | return x == other.x && z == other.z && Objects.equals(world, other.world);
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return "ChunkPosition [world=" + world + ", x=" + x + ", z=" + z + "]";
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/JavaVersion.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | public final class JavaVersion {
4 |
5 | private static final int JAVA_VERSION = javaMajorVersion();
6 |
7 | public static int get() {
8 | return JAVA_VERSION;
9 | }
10 |
11 | private static int javaMajorVersion() {
12 | return majorVersion(System.getProperty("java.specification.version", "1.6"));
13 | }
14 |
15 | /**
16 | * taken from:
17 | * https://github.com/netty/netty/blob/7ad2b91515b3affaeadb4b2975cd6d2a8342c403/common/src/main/java/io/netty/util/internal/PlatformDependent0.java#L1037
18 | */
19 | private static int majorVersion(final String javaSpecVersion) {
20 | final String[] components = javaSpecVersion.split("\\.");
21 | final int[] version = new int[components.length];
22 | for (int i = 0; i < components.length; i++) {
23 | version[i] = Integer.parseInt(components[i]);
24 | }
25 |
26 | if (version[0] == 1) {
27 | assert version[1] >= 6;
28 | return version[1];
29 | } else {
30 | return version[0];
31 | }
32 | }
33 |
34 | private JavaVersion() {
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/MathUtil.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | public class MathUtil {
4 |
5 | public static int ceilToPowerOfTwo(int value) {
6 | value--;
7 | value |= value >> 1;
8 | value |= value >> 2;
9 | value |= value >> 4;
10 | value |= value >> 8;
11 | value |= value >> 16;
12 | value++;
13 | return value;
14 | }
15 |
16 | public static int clamp(int value, int min, int max) {
17 | return Math.max(min, Math.min(max, value));
18 | }
19 |
20 | public static int ceilLog2(int value) {
21 | int result = 31 - Integer.numberOfLeadingZeros(value);
22 | // add 1 if value is NOT a power of 2 (to do the ceil)
23 | return result + (value != 0 && (value & value - 1) == 0 ? 0 : 1);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/OFCLogger.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import java.util.LinkedList;
4 | import java.util.Queue;
5 | import java.util.logging.Level;
6 | import java.util.logging.Logger;
7 |
8 | public final class OFCLogger {
9 |
10 | public static Logger LOGGER = Logger.getLogger("Orebfuscator");
11 |
12 | private static final Queue VERBOSE_LOG = new LinkedList();
13 | private static boolean verbose = false;
14 |
15 | public static void setVerboseLogging(boolean verbose) {
16 | OFCLogger.verbose = verbose;
17 | if (OFCLogger.verbose) {
18 | debug("Verbose logging has been enabled");
19 | }
20 | }
21 |
22 | public static void debug(String message) {
23 | if (OFCLogger.verbose) {
24 | OFCLogger.LOGGER.log(Level.INFO, "[Debug] " + message);
25 | }
26 |
27 | synchronized (VERBOSE_LOG) {
28 | while (VERBOSE_LOG.size() >= 1000) {
29 | VERBOSE_LOG.poll();
30 | }
31 | VERBOSE_LOG.offer(message);
32 | }
33 | }
34 |
35 | public static String getLatestVerboseLog() {
36 | synchronized (VERBOSE_LOG) {
37 | int length = 0;
38 | for (String message : VERBOSE_LOG) {
39 | length += message.length() + 1;
40 | }
41 |
42 | StringBuilder builder = new StringBuilder(length);
43 | for (String message : VERBOSE_LOG) {
44 | builder.append(message).append("\n");
45 | }
46 | builder.deleteCharAt(builder.length() - 1);
47 | return builder.toString();
48 | }
49 | }
50 |
51 | public static void warn(String message) {
52 | log(Level.WARNING, message);
53 | }
54 |
55 | /**
56 | * Log an information
57 | */
58 | public static void info(String message) {
59 | log(Level.INFO, message);
60 | }
61 |
62 | /**
63 | * Log with a specified level
64 | */
65 | public static void log(Level level, String message) {
66 | OFCLogger.LOGGER.log(level, message);
67 | }
68 |
69 | /**
70 | * Log an error
71 | */
72 | public static void error(Throwable e) {
73 | log(Level.SEVERE, e.getMessage(), e);
74 | }
75 |
76 | /**
77 | * Log an error
78 | */
79 | public static void error(String message, Throwable e) {
80 | log(Level.SEVERE, message, e);
81 | }
82 |
83 | /**
84 | * Log with a specified level and throwable
85 | */
86 | public static void log(Level level, String message, Throwable throwable) {
87 | OFCLogger.LOGGER.log(level, message, throwable);
88 | }
89 | }
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/ServerVersion.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | public class ServerVersion {
4 |
5 | private static final boolean IS_MOJANG_MAPPED = classExists("net.minecraft.core.BlockPos")
6 | && fieldExists("net.minecraft.world.level.block.Blocks", "AIR");
7 | private static final boolean IS_FOLIA = classExists("io.papermc.paper.threadedregions.RegionizedServer");
8 | private static final boolean IS_PAPER = !IS_FOLIA && classExists("com.destroystokyo.paper.PaperConfig");
9 | private static final boolean IS_BUKKIT = !IS_FOLIA && !IS_PAPER;
10 |
11 | private static boolean classExists(String className) {
12 | try {
13 | Class.forName(className);
14 | return true;
15 | } catch (ClassNotFoundException e) {
16 | return false;
17 | }
18 | }
19 |
20 | private static boolean fieldExists(String className, String fieldName) {
21 | try {
22 | Class> target = Class.forName(className);
23 | return target.getDeclaredField(fieldName) != null;
24 | } catch (Exception e) {
25 | return false;
26 | }
27 | }
28 |
29 | public static boolean isMojangMapped() {
30 | return IS_MOJANG_MAPPED;
31 | }
32 |
33 | public static boolean isFolia() {
34 | return IS_FOLIA;
35 | }
36 |
37 | public static boolean isPaper() {
38 | return IS_PAPER;
39 | }
40 |
41 | public static boolean isBukkit() {
42 | return IS_BUKKIT;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/SimpleCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 | import java.util.function.Consumer;
6 |
7 | /**
8 | * Simple cache implementation that removes the oldest element once a certain size is reached
9 | */
10 | public class SimpleCache extends LinkedHashMap {
11 |
12 | private static final long serialVersionUID = -2732738355560313649L;
13 |
14 | private final int maximumSize;
15 | private final Consumer> remove;
16 |
17 | public SimpleCache(int maximumSize, Consumer> remove) {
18 | super(16, 0.75f, true);
19 |
20 | this.maximumSize = maximumSize;
21 | this.remove = remove;
22 | }
23 |
24 | @Override
25 | protected boolean removeEldestEntry(Map.Entry entry) {
26 | if (this.size() > this.maximumSize) {
27 | this.remove.accept(entry);
28 | return true;
29 | }
30 | return false;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/main/java/net/imprex/orebfuscator/util/WeightedIntRandom.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.concurrent.ThreadLocalRandom;
6 |
7 | public class WeightedIntRandom {
8 |
9 | public static Builder builder() {
10 | return new Builder();
11 | }
12 |
13 | /**
14 | * Sum of all weights
15 | */
16 | private final int weight;
17 |
18 | /**
19 | * Flat int array where each entry has a probability of one
20 | *
21 | * @implNote use flat int array instead of treemap cause O(N*log(N)) is too
22 | * slow since this is the second hottest code path
23 | */
24 | private final int[] entries;
25 |
26 | private WeightedIntRandom(Builder builder) {
27 | this.weight = builder.weight;
28 | this.entries = new int[builder.weight];
29 |
30 | int index = 0;
31 | for (Map.Entry entry : builder.entries.entrySet()) {
32 | for (int weight = 0; weight < entry.getValue(); weight++) {
33 | this.entries[index++] = entry.getKey();
34 | }
35 | }
36 | }
37 |
38 | public int next() {
39 | int index = ThreadLocalRandom.current().nextInt(this.weight);
40 | return this.entries[index];
41 | }
42 |
43 | public static class Builder {
44 |
45 | private int weight = 0;
46 |
47 | private final Map entries = new HashMap<>();
48 |
49 | private Builder() {
50 | }
51 |
52 | /**
53 | * Returns true if this random did not already contain the specified value
54 | */
55 | public boolean add(int value, int weight) {
56 | if (entries.putIfAbsent(value, weight) == null) {
57 | this.weight += weight;
58 | return true;
59 | }
60 | return false;
61 | }
62 |
63 | public WeightedIntRandom build() {
64 | return new WeightedIntRandom(this);
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/orebfuscator-common/src/test/java/net/imprex/orebfuscator/util/BlockPosTest.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 |
5 | import org.junit.jupiter.api.Test;
6 |
7 | public class BlockPosTest {
8 |
9 | @Test
10 | public void testLongFormat() {
11 | BlockPos positionA = new BlockPos(-52134, BlockPos.MAX_Y, 6243234);
12 | BlockPos positionB = new BlockPos(0, BlockPos.MIN_Y, -4);
13 | BlockPos positionC = new BlockPos(15, 0, -5663423);
14 | BlockPos positionD = new BlockPos(21523, 16, -5663423);
15 |
16 | long valueA = positionA.toLong();
17 | long valueB = positionB.toLong();
18 | long valueC = positionC.toLong();
19 | long valueD = positionD.toLong();
20 |
21 | assertEquals(positionA, BlockPos.fromLong(valueA));
22 | assertEquals(positionB, BlockPos.fromLong(valueB));
23 | assertEquals(positionC, BlockPos.fromLong(valueC));
24 | assertEquals(positionD, BlockPos.fromLong(valueD));
25 | }
26 |
27 | @Test
28 | public void testSectionPos() {
29 | final int chunkX = -42 << 4;
30 | final int chunkZ = 6521 << 4;
31 |
32 | BlockPos positionA = new BlockPos(chunkX + 8, BlockPos.MAX_Y, chunkZ);
33 | BlockPos positionB = new BlockPos(chunkX, BlockPos.MIN_Y, chunkZ + 15);
34 | BlockPos positionC = new BlockPos(chunkX + 15, 0, chunkZ + 4);
35 |
36 | int sectionPosA = positionA.toSectionPos();
37 | int sectionPosB = positionB.toSectionPos();
38 | int sectionPosC = positionC.toSectionPos();
39 |
40 | assertEquals(positionA, BlockPos.fromSectionPos(chunkX, chunkZ, sectionPosA));
41 | assertEquals(positionB, BlockPos.fromSectionPos(chunkX, chunkZ, sectionPosB));
42 | assertEquals(positionC, BlockPos.fromSectionPos(chunkX, chunkZ, sectionPosC));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-api/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-compatibility
9 | ${revision}
10 |
11 |
12 | orebfuscator-compatibility-api
13 | jar
14 |
15 |
16 |
17 | org.spigotmc
18 | spigot-api
19 | ${dependency.bukkit.version}
20 | provided
21 |
22 |
23 | net.imprex
24 | orebfuscator-common
25 | ${revision}
26 | compile
27 |
28 |
29 | net.imprex
30 | orebfuscator-nms-api
31 | ${revision}
32 | compile
33 |
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-api/src/main/java/net/imprex/orebfuscator/OrebfuscatorCompatibility.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator;
2 |
3 | import java.lang.reflect.Constructor;
4 | import java.util.concurrent.CompletableFuture;
5 |
6 | import org.bukkit.World;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.plugin.Plugin;
9 |
10 | import net.imprex.orebfuscator.compatibility.CompatibilityLayer;
11 | import net.imprex.orebfuscator.config.Config;
12 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.imprex.orebfuscator.util.MinecraftVersion;
15 | import net.imprex.orebfuscator.util.OFCLogger;
16 | import net.imprex.orebfuscator.util.ServerVersion;
17 |
18 | public class OrebfuscatorCompatibility {
19 |
20 | private static CompatibilityLayer instance;
21 |
22 | public static void initialize(Plugin plugin, Config config) {
23 | if (OrebfuscatorCompatibility.instance != null) {
24 | throw new IllegalStateException("Compatibility layer is already initialized!");
25 | }
26 |
27 | String className = "net.imprex.orebfuscator.compatibility.bukkit.BukkitCompatibilityLayer";
28 | if (ServerVersion.isFolia()) {
29 | className = "net.imprex.orebfuscator.compatibility.folia.FoliaCompatibilityLayer";
30 | } else if (ServerVersion.isPaper() && MinecraftVersion.minorVersion() >= 13) {
31 | className = "net.imprex.orebfuscator.compatibility.paper.PaperCompatibilityLayer";
32 | }
33 |
34 | try {
35 | OFCLogger.debug("Loading compatibility layer for: " + className);
36 | Class extends CompatibilityLayer> nmsManager = Class.forName(className).asSubclass(CompatibilityLayer.class);
37 | Constructor extends CompatibilityLayer> constructor = nmsManager.getConstructor(Plugin.class, Config.class);
38 | OrebfuscatorCompatibility.instance = constructor.newInstance(plugin, config);
39 | } catch (ClassNotFoundException e) {
40 | throw new RuntimeException("Compatibility layer is missing", e);
41 | } catch (Exception e) {
42 | throw new RuntimeException("Couldn't initialize compatibility layer", e);
43 | }
44 |
45 | OFCLogger.debug("Compatibility layer successfully loaded");
46 | }
47 |
48 | public static boolean isGameThread() {
49 | return instance.isGameThread();
50 | }
51 |
52 | public static void runForPlayer(Player player, Runnable runnable) {
53 | instance.getScheduler().runForPlayer(player, runnable);
54 | }
55 |
56 | public static void runAsyncNow(Runnable runnable) {
57 | instance.getScheduler().runAsyncNow(runnable);
58 | }
59 |
60 | public static void runAsyncAtFixedRate(Runnable runnable, long delay, long period) {
61 | instance.getScheduler().runAsyncAtFixedRate(runnable, delay, period);
62 | }
63 |
64 | public static void cancelTasks() {
65 | instance.getScheduler().cancelTasks();
66 | }
67 |
68 | public static CompletableFuture getNeighboringChunks(World world, ChunkPosition position) {
69 | return instance.getNeighboringChunks(world, position);
70 | }
71 |
72 | public static void close() {
73 | if (instance != null) {
74 | instance.getScheduler().cancelTasks();
75 | instance = null;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-api/src/main/java/net/imprex/orebfuscator/compatibility/CompatibilityLayer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility;
2 |
3 | import java.util.concurrent.CompletableFuture;
4 |
5 | import org.bukkit.World;
6 |
7 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
8 | import net.imprex.orebfuscator.util.ChunkPosition;
9 |
10 | public interface CompatibilityLayer {
11 |
12 | boolean isGameThread();
13 |
14 | CompatibilityScheduler getScheduler();
15 |
16 | CompletableFuture getNeighboringChunks(World world, ChunkPosition position);
17 | }
18 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-api/src/main/java/net/imprex/orebfuscator/compatibility/CompatibilityScheduler.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | public interface CompatibilityScheduler {
6 |
7 | void runForPlayer(Player player, Runnable runnable);
8 |
9 | void runAsyncNow(Runnable runnable);
10 |
11 | void runAsyncAtFixedRate(Runnable runnable, long delay, long period);
12 |
13 | void cancelTasks();
14 | }
15 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-bukkit/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-compatibility
9 | ${revision}
10 |
11 |
12 | orebfuscator-compatibility-bukkit
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-compatibility-api
19 | ${revision}
20 | provided
21 |
22 |
23 | org.spigotmc
24 | spigot-api
25 | ${dependency.bukkit.version}
26 | provided
27 |
28 |
29 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-bukkit/src/main/java/net/imprex/orebfuscator/compatibility/bukkit/BukkitChunkLoader.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.bukkit;
2 |
3 | import java.util.Queue;
4 | import java.util.concurrent.CompletableFuture;
5 | import java.util.concurrent.ConcurrentLinkedQueue;
6 | import java.util.concurrent.TimeUnit;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.World;
10 | import org.bukkit.plugin.Plugin;
11 |
12 | import net.imprex.orebfuscator.OrebfuscatorNms;
13 | import net.imprex.orebfuscator.config.Config;
14 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
15 | import net.imprex.orebfuscator.util.ChunkDirection;
16 | import net.imprex.orebfuscator.util.ChunkPosition;
17 |
18 | public class BukkitChunkLoader implements Runnable {
19 |
20 | private final Queue requests = new ConcurrentLinkedQueue<>();
21 |
22 | private final long availableNanosPerTick;
23 |
24 | public BukkitChunkLoader(Plugin plugin, Config config) {
25 | this.availableNanosPerTick = TimeUnit.MILLISECONDS.toNanos(config.advanced().maxMillisecondsPerTick());
26 |
27 | Bukkit.getScheduler().runTaskTimer(plugin, this, 0, 1);
28 | }
29 |
30 | public CompletableFuture submitRequest(World world, ChunkPosition chunkPosition) {
31 | Request request = new Request(world, chunkPosition);
32 | this.requests.offer(request);
33 | return request.future;
34 | }
35 |
36 | @Override
37 | public void run() {
38 | final long time = System.nanoTime();
39 |
40 | Request request = null;
41 | while (System.nanoTime() - time < this.availableNanosPerTick && (request = this.requests.poll()) != null) {
42 | request.run();
43 | }
44 | }
45 |
46 | private class Request implements Runnable {
47 |
48 | private final World world;
49 | private final ChunkPosition position;
50 |
51 | private final CompletableFuture future = new CompletableFuture<>();
52 |
53 | public Request(World world, ChunkPosition position) {
54 | this.world = world;
55 | this.position = position;
56 | }
57 |
58 | @Override
59 | public void run() {
60 | final ReadOnlyChunk[] neighboringChunks = new ReadOnlyChunk[4];
61 |
62 | for (ChunkDirection direction : ChunkDirection.values()) {
63 | int chunkX = position.x + direction.getOffsetX();
64 | int chunkZ = position.z + direction.getOffsetZ();
65 |
66 | neighboringChunks[direction.ordinal()] = OrebfuscatorNms.getReadOnlyChunk(world, chunkX, chunkZ);
67 | }
68 |
69 | future.complete(neighboringChunks);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-bukkit/src/main/java/net/imprex/orebfuscator/compatibility/bukkit/BukkitCompatibilityLayer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.bukkit;
2 |
3 | import java.util.concurrent.CompletableFuture;
4 |
5 | import org.bukkit.World;
6 | import org.bukkit.plugin.Plugin;
7 |
8 | import net.imprex.orebfuscator.compatibility.CompatibilityLayer;
9 | import net.imprex.orebfuscator.compatibility.CompatibilityScheduler;
10 | import net.imprex.orebfuscator.config.Config;
11 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
12 | import net.imprex.orebfuscator.util.ChunkPosition;
13 |
14 | public class BukkitCompatibilityLayer implements CompatibilityLayer {
15 |
16 | private final Thread mainThread = Thread.currentThread();
17 |
18 | private final BukkitScheduler scheduler;
19 | private final BukkitChunkLoader chunkLoader;
20 |
21 | public BukkitCompatibilityLayer(Plugin plugin, Config config) {
22 | this.scheduler = new BukkitScheduler(plugin);
23 | this.chunkLoader = new BukkitChunkLoader(plugin, config);
24 | }
25 |
26 | @Override
27 | public boolean isGameThread() {
28 | return Thread.currentThread() == this.mainThread;
29 | }
30 |
31 | @Override
32 | public CompatibilityScheduler getScheduler() {
33 | return this.scheduler;
34 | }
35 |
36 | @Override
37 | public CompletableFuture getNeighboringChunks(World world, ChunkPosition position) {
38 | return this.chunkLoader.submitRequest(world, position);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-bukkit/src/main/java/net/imprex/orebfuscator/compatibility/bukkit/BukkitScheduler.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.bukkit;
2 |
3 | import org.bukkit.Bukkit;
4 | import org.bukkit.entity.Player;
5 | import org.bukkit.plugin.Plugin;
6 |
7 | import net.imprex.orebfuscator.compatibility.CompatibilityScheduler;
8 |
9 | public class BukkitScheduler implements CompatibilityScheduler {
10 |
11 | private final Plugin plugin;
12 |
13 | public BukkitScheduler(Plugin plugin) {
14 | this.plugin = plugin;
15 | }
16 |
17 | @Override
18 | public void runForPlayer(Player player, Runnable runnable) {
19 | if (this.plugin.isEnabled()) {
20 | Bukkit.getScheduler().runTask(this.plugin, runnable);
21 | }
22 | }
23 |
24 | @Override
25 | public void runAsyncNow(Runnable runnable) {
26 | if (this.plugin.isEnabled()) {
27 | Bukkit.getScheduler().runTaskAsynchronously(this.plugin, runnable);
28 | }
29 | }
30 |
31 | @Override
32 | public void runAsyncAtFixedRate(Runnable runnable, long delay, long period) {
33 | if (this.plugin.isEnabled()) {
34 | Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, delay, period);
35 | }
36 | }
37 |
38 | @Override
39 | public void cancelTasks() {
40 | Bukkit.getScheduler().cancelTasks(this.plugin);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-folia/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-compatibility
9 | ${revision}
10 |
11 |
12 | orebfuscator-compatibility-folia
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-compatibility-api
19 | ${revision}
20 | provided
21 |
22 |
23 | net.imprex
24 | orebfuscator-compatibility-paper
25 | ${revision}
26 | provided
27 |
28 |
29 | dev.folia
30 | folia-api
31 | ${dependency.folia.version}
32 | provided
33 |
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-folia/src/main/java/net/imprex/orebfuscator/compatibility/folia/FoliaCompatibilityLayer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.folia;
2 |
3 | import org.bukkit.plugin.Plugin;
4 |
5 | import net.imprex.orebfuscator.compatibility.CompatibilityScheduler;
6 | import net.imprex.orebfuscator.compatibility.paper.AbstractPaperCompatibilityLayer;
7 | import net.imprex.orebfuscator.config.Config;
8 |
9 | public class FoliaCompatibilityLayer extends AbstractPaperCompatibilityLayer {
10 |
11 | private static final Class> TICK_THREAD_CLASS = getTickThreadClass();
12 |
13 | private static Class> getTickThreadClass() {
14 | try {
15 | return Class.forName("io.papermc.paper.threadedregions.TickRegionScheduler$TickThreadRunner");
16 | } catch (ClassNotFoundException e) {
17 | throw new RuntimeException("Can't find tick thread class for folia", e);
18 | }
19 | }
20 |
21 | private final FoliaScheduler scheduler;
22 |
23 | public FoliaCompatibilityLayer(Plugin plugin, Config config) {
24 | this.scheduler = new FoliaScheduler(plugin);
25 | }
26 |
27 | @Override
28 | public boolean isGameThread() {
29 | return TICK_THREAD_CLASS.isInstance(Thread.currentThread());
30 | }
31 |
32 | @Override
33 | public CompatibilityScheduler getScheduler() {
34 | return this.scheduler;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-folia/src/main/java/net/imprex/orebfuscator/compatibility/folia/FoliaScheduler.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.folia;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | import org.bukkit.Bukkit;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.plugin.Plugin;
8 |
9 | import net.imprex.orebfuscator.compatibility.CompatibilityScheduler;
10 |
11 | public class FoliaScheduler implements CompatibilityScheduler {
12 |
13 | private final Plugin plugin;
14 |
15 | public FoliaScheduler(Plugin plugin) {
16 | this.plugin = plugin;
17 | }
18 |
19 | @Override
20 | public void runForPlayer(Player player, Runnable runnable) {
21 | if (this.plugin.isEnabled()) {
22 | player.getScheduler().run(this.plugin, task -> runnable.run(), null);
23 | }
24 | }
25 |
26 | @Override
27 | public void runAsyncNow(Runnable runnable) {
28 | if (this.plugin.isEnabled()) {
29 | Bukkit.getAsyncScheduler().runNow(this.plugin, task -> runnable.run());
30 | }
31 | }
32 |
33 | @Override
34 | public void runAsyncAtFixedRate(Runnable runnable, long delay, long period) {
35 | if (this.plugin.isEnabled()) {
36 | Bukkit.getAsyncScheduler().runAtFixedRate(this.plugin, task -> runnable.run(),
37 | delay * 50, period * 50, TimeUnit.MILLISECONDS);
38 | }
39 | }
40 |
41 | @Override
42 | public void cancelTasks() {
43 | Bukkit.getAsyncScheduler().cancelTasks(this.plugin);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-paper/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-compatibility
9 | ${revision}
10 |
11 |
12 | orebfuscator-compatibility-paper
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-compatibility-api
19 | ${revision}
20 | provided
21 |
22 |
23 | net.imprex
24 | orebfuscator-compatibility-bukkit
25 | ${revision}
26 | provided
27 |
28 |
29 | io.papermc.paper
30 | paper-api
31 | ${dependency.paper.version}
32 | provided
33 |
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-paper/src/main/java/net/imprex/orebfuscator/compatibility/paper/AbstractPaperCompatibilityLayer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.paper;
2 |
3 | import java.util.concurrent.CompletableFuture;
4 |
5 | import org.bukkit.World;
6 |
7 | import net.imprex.orebfuscator.OrebfuscatorNms;
8 | import net.imprex.orebfuscator.compatibility.CompatibilityLayer;
9 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
10 | import net.imprex.orebfuscator.util.ChunkDirection;
11 | import net.imprex.orebfuscator.util.ChunkPosition;
12 |
13 | public abstract class AbstractPaperCompatibilityLayer implements CompatibilityLayer {
14 |
15 | @Override
16 | public CompletableFuture getNeighboringChunks(World world, ChunkPosition position) {
17 | CompletableFuture>[] futures = new CompletableFuture>[4];
18 | ReadOnlyChunk[] neighboringChunks = new ReadOnlyChunk[4];
19 |
20 | for (ChunkDirection direction : ChunkDirection.values()) {
21 | int chunkX = position.x + direction.getOffsetX();
22 | int chunkZ = position.z + direction.getOffsetZ();
23 | int index = direction.ordinal();
24 |
25 | futures[index] = world.getChunkAtAsync(chunkX, chunkZ).thenAccept(chunk -> {
26 | neighboringChunks[index] = OrebfuscatorNms.getReadOnlyChunk(world, chunkX, chunkZ);
27 | });
28 | }
29 |
30 | return CompletableFuture.allOf(futures).thenApply(v -> neighboringChunks);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/orebfuscator-compatibility-paper/src/main/java/net/imprex/orebfuscator/compatibility/paper/PaperCompatibilityLayer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.compatibility.paper;
2 |
3 | import org.bukkit.plugin.Plugin;
4 |
5 | import net.imprex.orebfuscator.compatibility.CompatibilityScheduler;
6 | import net.imprex.orebfuscator.compatibility.bukkit.BukkitScheduler;
7 | import net.imprex.orebfuscator.config.Config;
8 |
9 | public class PaperCompatibilityLayer extends AbstractPaperCompatibilityLayer {
10 |
11 | private final Thread mainThread = Thread.currentThread();
12 |
13 | private final BukkitScheduler scheduler;
14 |
15 | public PaperCompatibilityLayer(Plugin plugin, Config config) {
16 | this.scheduler = new BukkitScheduler(plugin);
17 | }
18 |
19 | @Override
20 | public boolean isGameThread() {
21 | return Thread.currentThread() == this.mainThread;
22 | }
23 |
24 | @Override
25 | public CompatibilityScheduler getScheduler() {
26 | return this.scheduler;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/orebfuscator-compatibility/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator
9 | ${revision}
10 |
11 |
12 | orebfuscator-compatibility
13 | pom
14 |
15 |
16 | orebfuscator-compatibility-api
17 | orebfuscator-compatibility-bukkit
18 | orebfuscator-compatibility-folia
19 | orebfuscator-compatibility-paper
20 |
21 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-api/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-api
11 | jar
12 |
13 |
14 |
15 | org.spigotmc
16 | spigot-api
17 | ${dependency.bukkit.version}
18 | provided
19 |
20 |
21 | net.imprex
22 | orebfuscator-common
23 | ${revision}
24 | compile
25 |
26 |
27 |
28 |
29 |
30 |
31 | org.apache.maven.plugins
32 | maven-shade-plugin
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-api/src/main/java/net/imprex/orebfuscator/nms/AbstractNmsManager.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import net.imprex.orebfuscator.util.BlockProperties;
7 | import net.imprex.orebfuscator.util.BlockStateProperties;
8 | import net.imprex.orebfuscator.util.MathUtil;
9 | import net.imprex.orebfuscator.util.NamespacedKey;
10 |
11 | public abstract class AbstractNmsManager implements NmsManager {
12 |
13 | private final AbstractRegionFileCache> regionFileCache;
14 |
15 | private final int uniqueBlockStateCount;
16 | private final int maxBitsPerBlockState;
17 |
18 | private final BlockStateProperties[] blockStates;
19 | private final Map blocks = new HashMap<>();
20 |
21 | public AbstractNmsManager(int uniqueBlockStateCount, AbstractRegionFileCache> regionFileCache) {
22 | this.regionFileCache = regionFileCache;
23 |
24 | this.uniqueBlockStateCount = uniqueBlockStateCount;
25 | this.maxBitsPerBlockState = MathUtil.ceilLog2(uniqueBlockStateCount);
26 |
27 | this.blockStates = new BlockStateProperties[uniqueBlockStateCount];
28 | }
29 |
30 | protected final void registerBlockProperties(BlockProperties block) {
31 | this.blocks.put(block.getKey(), block);
32 |
33 | for (BlockStateProperties blockState : block.getBlockStates()) {
34 | this.blockStates[blockState.getId()] = blockState;
35 | }
36 | }
37 |
38 | @Override
39 | public final AbstractRegionFileCache> getRegionFileCache() {
40 | return this.regionFileCache;
41 | }
42 |
43 | @Override
44 | public final int getUniqueBlockStateCount() {
45 | return this.uniqueBlockStateCount;
46 | }
47 |
48 | @Override
49 | public final int getMaxBitsPerBlockState() {
50 | return this.maxBitsPerBlockState;
51 | }
52 |
53 | @Override
54 | public final BlockProperties getBlockByName(NamespacedKey key) {
55 | return this.blocks.get(key);
56 | }
57 |
58 | @Override
59 | public final boolean isAir(int id) {
60 | return this.blockStates[id].isAir();
61 | }
62 |
63 | @Override
64 | public final boolean isOccluding(int id) {
65 | return this.blockStates[id].isOccluding();
66 | }
67 |
68 | @Override
69 | public final boolean isBlockEntity(int id) {
70 | return this.blockStates[id].isBlockEntity();
71 | }
72 |
73 | @Override
74 | public final void close() {
75 | this.regionFileCache.clear();
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-api/src/main/java/net/imprex/orebfuscator/nms/NmsManager.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms;
2 |
3 | import org.bukkit.World;
4 | import org.bukkit.entity.Player;
5 |
6 | import net.imprex.orebfuscator.util.BlockPos;
7 | import net.imprex.orebfuscator.util.BlockProperties;
8 | import net.imprex.orebfuscator.util.NamespacedKey;
9 |
10 | public interface NmsManager {
11 |
12 | AbstractRegionFileCache> getRegionFileCache();
13 |
14 | int getUniqueBlockStateCount();
15 |
16 | int getMaxBitsPerBlockState();
17 |
18 | BlockProperties getBlockByName(NamespacedKey key);
19 |
20 | boolean isAir(int blockId);
21 |
22 | boolean isOccluding(int blockId);
23 |
24 | boolean isBlockEntity(int blockId);
25 |
26 | ReadOnlyChunk getReadOnlyChunk(World world, int chunkX, int chunkZ);
27 |
28 | int getBlockState(World world, int x, int y, int z);
29 |
30 | void sendBlockUpdates(World world, Iterable iterable);
31 |
32 | void sendBlockUpdates(Player player, Iterable iterable);
33 |
34 | void close();
35 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-api/src/main/java/net/imprex/orebfuscator/nms/ReadOnlyChunk.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms;
2 |
3 | public interface ReadOnlyChunk {
4 |
5 | int getBlockState(int x, int y, int z);
6 | }
7 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_16_R1
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-nms-api
19 | ${revision}
20 | provided
21 |
22 |
23 | com.comphenix.protocol
24 | ProtocolLib
25 | ${dependency.protocollib.version}
26 | provided
27 |
28 |
29 | org.spigotmc
30 | spigot
31 | 1.16.1-R0.1-SNAPSHOT
32 | provided
33 |
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R1/src/main/java/net/imprex/orebfuscator/nms/v1_16_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.server.v1_16_R1.Chunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final Chunk chunk;
9 |
10 | ReadOnlyChunkWrapper(Chunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R1/src/main/java/net/imprex/orebfuscator/nms/v1_16_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.server.v1_16_R1.ChunkCoordIntPair;
15 | import net.minecraft.server.v1_16_R1.RegionFile;
16 | import net.minecraft.server.v1_16_R1.RegionFileCompression;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().isSyncChunkWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileCompression.c, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.a(new ChunkCoordIntPair(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.c(new ChunkCoordIntPair(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R2/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_16_R2
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-nms-api
19 | ${revision}
20 | provided
21 |
22 |
23 | com.comphenix.protocol
24 | ProtocolLib
25 | ${dependency.protocollib.version}
26 | provided
27 |
28 |
29 | org.spigotmc
30 | spigot
31 | 1.16.3-R0.1-SNAPSHOT
32 | provided
33 |
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R2/src/main/java/net/imprex/orebfuscator/nms/v1_16_R2/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R2;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.server.v1_16_R2.Chunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final Chunk chunk;
9 |
10 | ReadOnlyChunkWrapper(Chunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R2/src/main/java/net/imprex/orebfuscator/nms/v1_16_R2/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R2;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.server.v1_16_R2.ChunkCoordIntPair;
15 | import net.minecraft.server.v1_16_R2.RegionFile;
16 | import net.minecraft.server.v1_16_R2.RegionFileCompression;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().isSyncChunkWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileCompression.c, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.a(new ChunkCoordIntPair(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.c(new ChunkCoordIntPair(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R3/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_16_R3
13 | jar
14 |
15 |
16 |
17 |
18 | net.imprex
19 | orebfuscator-nms-api
20 | ${revision}
21 | provided
22 |
23 |
24 | com.comphenix.protocol
25 | ProtocolLib
26 | ${dependency.protocollib.version}
27 | provided
28 |
29 |
30 | org.spigotmc
31 | spigot
32 | 1.16.5-R0.1-SNAPSHOT
33 | provided
34 |
35 |
36 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R3/src/main/java/net/imprex/orebfuscator/nms/v1_16_R3/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R3;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.server.v1_16_R3.Chunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final Chunk chunk;
9 |
10 | ReadOnlyChunkWrapper(Chunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_16_R3/src/main/java/net/imprex/orebfuscator/nms/v1_16_R3/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_16_R3;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.server.v1_16_R3.ChunkCoordIntPair;
15 | import net.minecraft.server.v1_16_R3.RegionFile;
16 | import net.minecraft.server.v1_16_R3.RegionFileCompression;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().isSyncChunkWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileCompression.c, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.a(new ChunkCoordIntPair(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.c(new ChunkCoordIntPair(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_17_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_17_R1
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-nms-api
19 | ${revision}
20 | provided
21 |
22 |
23 | com.comphenix.protocol
24 | ProtocolLib
25 | ${dependency.protocollib.version}
26 | provided
27 |
28 |
29 | org.spigotmc
30 | spigot
31 | 1.17.1-R0.1-SNAPSHOT
32 | remapped-mojang
33 | provided
34 |
35 |
36 |
37 |
38 |
39 |
40 | net.md-5
41 | specialsource-maven-plugin
42 | ${plugin.specialsource.version}
43 |
44 |
45 | package
46 |
47 | remap
48 |
49 | remap-obf
50 |
51 | org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:txt:maps-mojang
52 | true
53 | org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-mojang
54 | true
55 | remapped-obf
56 |
57 |
58 |
59 | package
60 |
61 | remap
62 |
63 | remap-spigot
64 |
65 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
66 | org.spigotmc:minecraft-server:1.17.1-R0.1-SNAPSHOT:csrg:maps-spigot
67 | org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT:jar:remapped-obf
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_17_R1/src/main/java/net/imprex/orebfuscator/nms/v1_17_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_17_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_17_R1/src/main/java/net/imprex/orebfuscator/nms/v1_17_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_17_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_18_R1
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-nms-api
19 | ${revision}
20 | provided
21 |
22 |
23 | com.comphenix.protocol
24 | ProtocolLib
25 | ${dependency.protocollib.version}
26 | provided
27 |
28 |
29 | org.spigotmc
30 | spigot
31 | 1.18.1-R0.1-SNAPSHOT
32 | remapped-mojang
33 | provided
34 |
35 |
36 |
37 |
38 |
39 |
40 | net.md-5
41 | specialsource-maven-plugin
42 | ${plugin.specialsource.version}
43 |
44 |
45 | package
46 |
47 | remap
48 |
49 | remap-obf
50 |
51 | org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang
52 | true
53 | org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang
54 | true
55 | remapped-obf
56 |
57 |
58 |
59 | package
60 |
61 | remap
62 |
63 | remap-spigot
64 |
65 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
66 | org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot
67 | org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_18_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R1/src/main/java/net/imprex/orebfuscator/nms/v1_18_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_18_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R2/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator-nms
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms-v1_18_R2
13 | jar
14 |
15 |
16 |
17 | net.imprex
18 | orebfuscator-nms-api
19 | ${revision}
20 | provided
21 |
22 |
23 | com.comphenix.protocol
24 | ProtocolLib
25 | ${dependency.protocollib.version}
26 | provided
27 |
28 |
29 | org.spigotmc
30 | spigot
31 | 1.18.2-R0.1-SNAPSHOT
32 | remapped-mojang
33 | provided
34 |
35 |
36 |
37 |
38 |
39 |
40 | net.md-5
41 | specialsource-maven-plugin
42 | ${plugin.specialsource.version}
43 |
44 |
45 | package
46 |
47 | remap
48 |
49 | remap-obf
50 |
51 | org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:txt:maps-mojang
52 | true
53 | org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-mojang
54 | true
55 | remapped-obf
56 |
57 |
58 |
59 | package
60 |
61 | remap
62 |
63 | remap-spigot
64 |
65 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
66 | org.spigotmc:minecraft-server:1.18.2-R0.1-SNAPSHOT:csrg:maps-spigot
67 | org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT:jar:remapped-obf
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R2/src/main/java/net/imprex/orebfuscator/nms/v1_18_R2/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_18_R2;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_18_R2/src/main/java/net/imprex/orebfuscator/nms/v1_18_R2/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_18_R2;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_19_R1
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.19.2-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_19_R1
40 | net.imprex.orebfuscator.nms.v1_19_R1_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R1/src/main/java/net/imprex/orebfuscator/nms/v1_19_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R1/src/main/java/net/imprex/orebfuscator/nms/v1_19_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_19_R2
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.19.3-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_19_R2
40 | net.imprex.orebfuscator.nms.v1_19_R2_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.19.3-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R2/src/main/java/net/imprex/orebfuscator/nms/v1_19_R2/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R2;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R2/src/main/java/net/imprex/orebfuscator/nms/v1_19_R2/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R2;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R3/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_19_R3
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.19.4-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_19_R3
40 | net.imprex.orebfuscator.nms.v1_19_R3_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R3/src/main/java/net/imprex/orebfuscator/nms/v1_19_R3/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R3;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_19_R3/src/main/java/net/imprex/orebfuscator/nms/v1_19_R3/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_19_R3;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_20_R1
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.20.1-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_20_R1
40 | net.imprex.orebfuscator.nms.v1_20_R1_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R1/src/main/java/net/imprex/orebfuscator/nms/v1_20_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R1/src/main/java/net/imprex/orebfuscator/nms/v1_20_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_20_R2
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.20.2-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_20_R2
40 | net.imprex.orebfuscator.nms.v1_20_R2_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R2/src/main/java/net/imprex/orebfuscator/nms/v1_20_R2/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R2;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R2/src/main/java/net/imprex/orebfuscator/nms/v1_20_R2/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R2;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R3/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_20_R3
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.20.4-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_20_R3
40 | net.imprex.orebfuscator.nms.v1_20_R3_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.20.4-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R3/src/main/java/net/imprex/orebfuscator/nms/v1_20_R3/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R3;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R3/src/main/java/net/imprex/orebfuscator/nms/v1_20_R3/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R3;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R4/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_20_R4
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.20.6-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_20_R4
40 | net.imprex.orebfuscator.nms.v1_20_R4_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.20.6-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.20.6-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R4/src/main/java/net/imprex/orebfuscator/nms/v1_20_R4/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R4;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_20_R4/src/main/java/net/imprex/orebfuscator/nms/v1_20_R4/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_20_R4;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_20_R4.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(null, path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_21_R1
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.21.1-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_21_R1
40 | net.imprex.orebfuscator.nms.v1_21_R1_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.21.1-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.21.1-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R1/src/main/java/net/imprex/orebfuscator/nms/v1_21_R1/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R1;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R1/src/main/java/net/imprex/orebfuscator/nms/v1_21_R1/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R1;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_21_R1.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(null, path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_21_R2
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.21.3-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_21_R2
40 | net.imprex.orebfuscator.nms.v1_21_R2_mojang
41 |
42 |
43 |
44 |
45 |
46 | net.md-5
47 | specialsource-maven-plugin
48 | ${plugin.specialsource.version}
49 |
50 |
51 | package
52 |
53 | remap
54 |
55 | remap-obf
56 |
57 | org.spigotmc:minecraft-server:1.21.3-R0.1-SNAPSHOT:txt:maps-mojang
58 | true
59 | org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT:jar:remapped-mojang
60 | true
61 | remapped-obf
62 |
63 |
64 |
65 | package
66 |
67 | remap
68 |
69 | remap-spigot
70 |
71 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
72 | org.spigotmc:minecraft-server:1.21.3-R0.1-SNAPSHOT:csrg:maps-spigot
73 | org.spigotmc:spigot:1.21.3-R0.1-SNAPSHOT:jar:remapped-obf
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R2/src/main/java/net/imprex/orebfuscator/nms/v1_21_R2/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R2;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R2/src/main/java/net/imprex/orebfuscator/nms/v1_21_R2/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R2;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_21_R2.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(null, path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R3/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_21_R3
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.21.4-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-shade-plugin
34 |
35 | true
36 | mojang-mapped
37 |
38 |
39 | net.imprex.orebfuscator.nms.v1_21_R3
40 |
41 | net.imprex.orebfuscator.nms.v1_21_R3_mojang
42 |
43 |
44 |
45 |
46 |
47 | net.md-5
48 | specialsource-maven-plugin
49 | ${plugin.specialsource.version}
50 |
51 |
52 | package
53 |
54 | remap
55 |
56 | remap-obf
57 |
58 |
59 | org.spigotmc:minecraft-server:1.21.4-R0.1-SNAPSHOT:txt:maps-mojang
60 | true
61 |
62 | org.spigotmc:spigot:1.21.4-R0.1-SNAPSHOT:jar:remapped-mojang
63 | true
64 | remapped-obf
65 |
66 |
67 |
68 | package
69 |
70 | remap
71 |
72 | remap-spigot
73 |
74 |
75 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
76 |
77 | org.spigotmc:minecraft-server:1.21.4-R0.1-SNAPSHOT:csrg:maps-spigot
78 |
79 | org.spigotmc:spigot:1.21.4-R0.1-SNAPSHOT:jar:remapped-obf
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R3/src/main/java/net/imprex/orebfuscator/nms/v1_21_R3/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R3;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R3/src/main/java/net/imprex/orebfuscator/nms/v1_21_R3/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R3;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_21_R3.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(null, path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R4/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | net.imprex
6 | orebfuscator-nms
7 | ${revision}
8 |
9 |
10 | orebfuscator-nms-v1_21_R4
11 | jar
12 |
13 |
14 |
15 | net.imprex
16 | orebfuscator-nms-api
17 | ${revision}
18 | provided
19 |
20 |
21 | org.spigotmc
22 | spigot
23 | 1.21.5-R0.1-SNAPSHOT
24 | remapped-mojang
25 | provided
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | org.apache.maven.plugins
34 | maven-shade-plugin
35 |
36 | true
37 | mojang-mapped
38 |
39 |
40 | net.imprex.orebfuscator.nms.v1_21_R4
41 | net.imprex.orebfuscator.nms.v1_21_R4_mojang
42 |
43 |
44 |
45 |
46 |
47 | net.md-5
48 | specialsource-maven-plugin
49 | ${plugin.specialsource.version}
50 |
51 |
52 | package
53 |
54 | remap
55 |
56 | remap-obf
57 |
58 | org.spigotmc:minecraft-server:1.21.5-R0.1-SNAPSHOT:txt:maps-mojang
59 | true
60 | org.spigotmc:spigot:1.21.5-R0.1-SNAPSHOT:jar:remapped-mojang
61 | true
62 | remapped-obf
63 |
64 |
65 |
66 | package
67 |
68 | remap
69 |
70 | remap-spigot
71 |
72 | ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
73 | org.spigotmc:minecraft-server:1.21.5-R0.1-SNAPSHOT:csrg:maps-spigot
74 | org.spigotmc:spigot:1.21.5-R0.1-SNAPSHOT:jar:remapped-obf
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R4/src/main/java/net/imprex/orebfuscator/nms/v1_21_R4/ReadOnlyChunkWrapper.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R4;
2 |
3 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
4 | import net.minecraft.world.level.chunk.LevelChunk;
5 |
6 | public class ReadOnlyChunkWrapper implements ReadOnlyChunk {
7 |
8 | private final LevelChunk chunk;
9 |
10 | ReadOnlyChunkWrapper(LevelChunk chunk) {
11 | this.chunk = chunk;
12 | }
13 |
14 | @Override
15 | public int getBlockState(int x, int y, int z) {
16 | return NmsManager.getBlockState(chunk, x, y, z);//ClientboundSetPlayerTeamPacket
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/orebfuscator-nms/orebfuscator-nms-v1_21_R4/src/main/java/net/imprex/orebfuscator/nms/v1_21_R4/RegionFileCache.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.nms.v1_21_R4;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 | import java.nio.file.Path;
7 |
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.craftbukkit.v1_21_R4.CraftServer;
10 |
11 | import net.imprex.orebfuscator.config.CacheConfig;
12 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 | import net.minecraft.world.level.ChunkPos;
15 | import net.minecraft.world.level.chunk.storage.RegionFile;
16 | import net.minecraft.world.level.chunk.storage.RegionFileVersion;
17 |
18 | public class RegionFileCache extends AbstractRegionFileCache {
19 |
20 | RegionFileCache(CacheConfig cacheConfig) {
21 | super(cacheConfig);
22 | }
23 |
24 | @Override
25 | protected RegionFile createRegionFile(Path path) throws IOException {
26 | boolean isSyncChunkWrites = ((CraftServer) Bukkit.getServer()).getServer().forceSynchronousWrites();
27 | return new RegionFile(null, path, path.getParent(), RegionFileVersion.VERSION_NONE, isSyncChunkWrites);
28 | }
29 |
30 | @Override
31 | protected void closeRegionFile(RegionFile t) throws IOException {
32 | t.close();
33 | }
34 |
35 | @Override
36 | protected DataInputStream createInputStream(RegionFile t, ChunkPosition key) throws IOException {
37 | return t.getChunkDataInputStream(new ChunkPos(key.x, key.z));
38 | }
39 |
40 | @Override
41 | protected DataOutputStream createOutputStream(RegionFile t, ChunkPosition key) throws IOException {
42 | return t.getChunkDataOutputStream(new ChunkPos(key.x, key.z));
43 | }
44 | }
--------------------------------------------------------------------------------
/orebfuscator-nms/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 |
7 | net.imprex
8 | orebfuscator
9 | ${revision}
10 |
11 |
12 | orebfuscator-nms
13 | pom
14 |
15 |
16 | orebfuscator-nms-api
17 | orebfuscator-nms-v1_16_R1
18 | orebfuscator-nms-v1_16_R2
19 | orebfuscator-nms-v1_16_R3
20 | orebfuscator-nms-v1_17_R1
21 | orebfuscator-nms-v1_18_R1
22 | orebfuscator-nms-v1_18_R2
23 | orebfuscator-nms-v1_19_R1
24 | orebfuscator-nms-v1_19_R2
25 | orebfuscator-nms-v1_19_R3
26 | orebfuscator-nms-v1_20_R1
27 | orebfuscator-nms-v1_20_R2
28 | orebfuscator-nms-v1_20_R3
29 | orebfuscator-nms-v1_20_R4
30 | orebfuscator-nms-v1_21_R1
31 | orebfuscator-nms-v1_21_R2
32 | orebfuscator-nms-v1_21_R3
33 | orebfuscator-nms-v1_21_R4
34 |
35 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/DefaultOrebfuscatorService.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator;
2 |
3 | import java.util.Collection;
4 | import java.util.Iterator;
5 |
6 | import org.bukkit.World;
7 | import org.bukkit.block.Block;
8 |
9 | import net.imprex.orebfuscator.api.OrebfuscatorService;
10 | import net.imprex.orebfuscator.obfuscation.ObfuscationSystem;
11 |
12 | public final class DefaultOrebfuscatorService implements OrebfuscatorService {
13 |
14 | private final ObfuscationSystem obfuscationSystem;
15 |
16 | public DefaultOrebfuscatorService(Orebfuscator orebfuscator) {
17 | this.obfuscationSystem = orebfuscator.getObfuscationSystem();
18 | }
19 |
20 | @Override
21 | public final void deobfuscate(Collection extends Block> blocks) {
22 | if (!OrebfuscatorCompatibility.isGameThread()) {
23 | throw new IllegalStateException("Asynchronous deobfuscation! " + Thread.currentThread());
24 | } else if (blocks == null || blocks.isEmpty()) {
25 | throw new IllegalArgumentException("block list is null or empty");
26 | }
27 |
28 | Iterator extends Block> blockIterator = blocks.iterator();
29 | World world = blockIterator.next().getWorld();
30 | while (blockIterator.hasNext()) {
31 | if (blockIterator.next().getWorld() != world) {
32 | throw new IllegalArgumentException("block list is located in more than one world");
33 | }
34 | }
35 |
36 | this.obfuscationSystem.deobfuscate(blocks);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/CacheFileCleanupTask.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.cache;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.FileVisitResult;
5 | import java.nio.file.Files;
6 | import java.nio.file.Path;
7 | import java.nio.file.SimpleFileVisitor;
8 | import java.nio.file.attribute.BasicFileAttributes;
9 |
10 | import net.imprex.orebfuscator.Orebfuscator;
11 | import net.imprex.orebfuscator.OrebfuscatorNms;
12 | import net.imprex.orebfuscator.config.CacheConfig;
13 | import net.imprex.orebfuscator.nms.AbstractRegionFileCache;
14 | import net.imprex.orebfuscator.util.OFCLogger;
15 |
16 | public class CacheFileCleanupTask implements Runnable {
17 |
18 | private final CacheConfig cacheConfig;
19 |
20 | private int deleteCount = 0;
21 |
22 | public CacheFileCleanupTask(Orebfuscator orebfuscator) {
23 | this.cacheConfig = orebfuscator.getOrebfuscatorConfig().cache();
24 | }
25 |
26 | @Override
27 | public void run() {
28 | long deleteAfterMillis = this.cacheConfig.deleteRegionFilesAfterAccess();
29 | AbstractRegionFileCache> regionFileCache = OrebfuscatorNms.getRegionFileCache();
30 |
31 | this.deleteCount = 0;
32 |
33 | try {
34 | Files.walkFileTree(this.cacheConfig.baseDirectory(), new SimpleFileVisitor() {
35 |
36 | @Override
37 | public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException {
38 | if (System.currentTimeMillis() - attributes.lastAccessTime().toMillis() > deleteAfterMillis) {
39 | regionFileCache.close(path);
40 | Files.delete(path);
41 |
42 | CacheFileCleanupTask.this.deleteCount++;
43 | OFCLogger.debug("deleted cache file: " + path);
44 | }
45 | return FileVisitResult.CONTINUE;
46 | }
47 | });
48 | } catch (IOException e) {
49 | e.printStackTrace();
50 | }
51 |
52 | if (this.deleteCount > 0) {
53 | OFCLogger.info(String.format("CacheFileCleanupTask successfully deleted %d cache file(s)", this.deleteCount));
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/cache/ChunkSerializer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.cache;
2 |
3 | import java.io.DataInputStream;
4 | import java.io.DataOutputStream;
5 | import java.io.IOException;
6 |
7 | import net.imprex.orebfuscator.OrebfuscatorNms;
8 | import net.imprex.orebfuscator.util.ChunkPosition;
9 |
10 | public class ChunkSerializer {
11 |
12 | private static final int CACHE_VERSION = 2;
13 |
14 | private static DataInputStream createInputStream(ChunkPosition key) throws IOException {
15 | return OrebfuscatorNms.getRegionFileCache().createInputStream(key);
16 | }
17 |
18 | private static DataOutputStream createOutputStream(ChunkPosition key) throws IOException {
19 | return OrebfuscatorNms.getRegionFileCache().createOutputStream(key);
20 | }
21 |
22 | public static CompressedObfuscationResult read(ChunkPosition key) throws IOException {
23 | try (DataInputStream dataInputStream = createInputStream(key)) {
24 | if (dataInputStream != null) {
25 | // check if cache entry has right version and if chunk is present
26 | if (dataInputStream.readInt() != CACHE_VERSION || !dataInputStream.readBoolean()) {
27 | return null;
28 | }
29 |
30 | byte[] compressedData = new byte[dataInputStream.readInt()];
31 | dataInputStream.readFully(compressedData);
32 |
33 | return new CompressedObfuscationResult(key, compressedData);
34 | }
35 | } catch (IOException e) {
36 | throw new IOException("Unable to read chunk: " + key, e);
37 | }
38 |
39 | return null;
40 | }
41 |
42 | public static void write(ChunkPosition key, CompressedObfuscationResult value) throws IOException {
43 | try (DataOutputStream dataOutputStream = createOutputStream(key)) {
44 | dataOutputStream.writeInt(CACHE_VERSION);
45 |
46 | if (value != null) {
47 | dataOutputStream.writeBoolean(true);
48 |
49 | byte[] compressedData = value.compressedData();
50 | dataOutputStream.writeInt(compressedData.length);
51 | dataOutputStream.write(compressedData);
52 | } else {
53 | dataOutputStream.writeBoolean(false);
54 | }
55 | } catch (IOException e) {
56 | throw new IOException("Unable to write chunk: " + key, e);
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/ByteBufUtil.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | public class ByteBufUtil {
6 |
7 | public static int getVarIntSize(int value) {
8 | for (int bytes = 1; bytes < 5; bytes++) {
9 | if ((value & -1 << bytes * 7) == 0) {
10 | return bytes;
11 | }
12 | }
13 | return 5;
14 | }
15 |
16 | public static void skipVarInt(ByteBuf buffer) {
17 | int bytes = 0;
18 | byte in;
19 | do {
20 | in = buffer.readByte();
21 | if (++bytes > 5) {
22 | throw new IndexOutOfBoundsException("varint32 too long");
23 | }
24 | } while ((in & 0x80) != 0);
25 | }
26 |
27 | public static int readVarInt(ByteBuf buffer) {
28 | int out = 0;
29 | int bytes = 0;
30 | byte in;
31 | do {
32 | in = buffer.readByte();
33 | out |= (in & 0x7F) << bytes++ * 7;
34 | if (bytes > 5) {
35 | throw new IndexOutOfBoundsException("varint32 too long");
36 | }
37 | } while ((in & 0x80) != 0);
38 | return out;
39 | }
40 |
41 | public static void writeVarInt(ByteBuf buffer, int value) {
42 | while ((value & -0x80) != 0) {
43 | buffer.writeByte(value & 0x7F | 0x80);
44 | value >>>= 7;
45 | }
46 | buffer.writeByte(value);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/ChunkCapabilities.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import net.imprex.orebfuscator.util.MinecraftVersion;
4 |
5 | public final class ChunkCapabilities {
6 |
7 | // hasLongArrayLengthField < 1.21.5
8 | // hasChunkPosFieldUnloadPacket >= 1.20.2
9 | // hasClientboundLevelChunkPacketData >= 1.18;
10 | // hasBiomePalettedContainer >= 1.18
11 | // hasSingleValuePalette >= 1.18
12 | // hasHeightBitMask < 1.18
13 | // hasDynamicHeight >= 1.17
14 |
15 | private static final boolean hasLongArrayLengthField = MinecraftVersion.isBelow("1.21.5");
16 | private static final boolean hasChunkPosFieldUnloadPacket = MinecraftVersion.isAtOrAbove("1.20.2");
17 | private static final boolean hasClientboundLevelChunkPacketData = MinecraftVersion.isAtOrAbove("1.18");
18 | private static final boolean hasBiomePalettedContainer = MinecraftVersion.isAtOrAbove("1.18");
19 | private static final boolean hasSingleValuePalette = MinecraftVersion.isAtOrAbove("1.18");
20 | private static final boolean hasHeightBitMask = MinecraftVersion.isBelow("1.18");
21 | private static final boolean hasDynamicHeight = MinecraftVersion.isAtOrAbove("1.17");
22 |
23 | private ChunkCapabilities() {
24 | }
25 |
26 | public static boolean hasLongArrayLengthField() {
27 | return hasLongArrayLengthField;
28 | }
29 |
30 | public static boolean hasChunkPosFieldUnloadPacket() {
31 | return hasChunkPosFieldUnloadPacket;
32 | }
33 |
34 | public static boolean hasClientboundLevelChunkPacketData() {
35 | return hasClientboundLevelChunkPacketData;
36 | }
37 |
38 | public static boolean hasBiomePalettedContainer() {
39 | return hasBiomePalettedContainer;
40 | }
41 |
42 | public static boolean hasSingleValuePalette() {
43 | return hasSingleValuePalette;
44 | }
45 |
46 | public static boolean hasHeightBitMask() {
47 | return hasHeightBitMask;
48 | }
49 |
50 | public static boolean hasDynamicHeight() {
51 | return hasDynamicHeight;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/DirectPalette.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | public class DirectPalette implements Palette {
6 |
7 | @Override
8 | public int idFor(int value) {
9 | return value;
10 | }
11 |
12 | @Override
13 | public int valueFor(int id) {
14 | return id;
15 | }
16 |
17 | @Override
18 | public void read(ByteBuf buffer) {
19 | }
20 |
21 | @Override
22 | public void write(ByteBuf buffer) {
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/IndirectPalette.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import java.util.Arrays;
4 |
5 | import io.netty.buffer.ByteBuf;
6 | import net.imprex.orebfuscator.OrebfuscatorNms;
7 |
8 | public class IndirectPalette implements Palette {
9 |
10 | private final int bitsPerValue;
11 | private final ChunkSection chunkSection;
12 |
13 | private final byte[] byValue;
14 | private final int[] byId;
15 |
16 | private int size = 0;
17 |
18 | public IndirectPalette(int bitsPerValue, ChunkSection chunkSection) {
19 | this.bitsPerValue = bitsPerValue;
20 | this.chunkSection = chunkSection;
21 |
22 | // TODO improve block to index
23 | this.byValue = new byte[OrebfuscatorNms.getUniqueBlockStateCount()];
24 | Arrays.fill(this.byValue, (byte) 0xFF);
25 | this.byId = new int[1 << bitsPerValue];
26 | }
27 |
28 | @Override
29 | public int idFor(int value) {
30 | int id = this.byValue[value] & 0xFF;
31 | if (id == 0xFF) {
32 | id = this.size++;
33 |
34 | if (id != 0xFF && id < this.byId.length) {
35 | this.byValue[value] = (byte) id;
36 | this.byId[id] = value;
37 | } else {
38 | id = this.chunkSection.grow(this.bitsPerValue + 1, value);
39 | }
40 | }
41 | return id;
42 | }
43 |
44 | @Override
45 | public int valueFor(int id) {
46 | if (id < 0 || id >= this.size) {
47 | throw new IndexOutOfBoundsException();
48 | } else {
49 | return this.byId[id];
50 | }
51 | }
52 |
53 | @Override
54 | public void read(ByteBuf buffer) {
55 | this.size = ByteBufUtil.readVarInt(buffer);
56 | for (int id = 0; id < size; id++) {
57 | int value = ByteBufUtil.readVarInt(buffer);
58 | this.byId[id] = value;
59 | this.byValue[value] = (byte) id;
60 | }
61 | }
62 |
63 | @Override
64 | public void write(ByteBuf buffer) {
65 | ByteBufUtil.writeVarInt(buffer, this.size);
66 |
67 | for (int id = 0; id < this.size; id++) {
68 | ByteBufUtil.writeVarInt(buffer, this.valueFor(id));
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/Palette.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | public interface Palette {
6 |
7 | int idFor(int value);
8 |
9 | int valueFor(int id);
10 |
11 | void read(ByteBuf buffer);
12 |
13 | void write(ByteBuf buffer);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/SimpleVarBitBuffer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | public class SimpleVarBitBuffer implements VarBitBuffer {
4 |
5 | public static int calculateArraySize(int bitsPerEntry, int size) {
6 | return bitsPerEntry == 0 ? 0 : (int) Math.ceil((float) size / (64 / bitsPerEntry));
7 | }
8 |
9 | private final int bitsPerEntry;
10 | private final int entriesPerLong;
11 | private final long adjustmentMask;
12 |
13 | private final int size;
14 | private final long[] buffer;
15 |
16 | public SimpleVarBitBuffer(int bitsPerEntry, int size) {
17 | this.bitsPerEntry = bitsPerEntry;
18 | this.entriesPerLong = 64 / bitsPerEntry;
19 | this.adjustmentMask = (1L << bitsPerEntry) - 1L;
20 |
21 | this.size = size;
22 | this.buffer = new long[(int) Math.ceil((float) size / this.entriesPerLong)];
23 | }
24 |
25 | public int get(int index) {
26 | int position = index / this.entriesPerLong;
27 | int offset = (index - position * this.entriesPerLong) * this.bitsPerEntry;
28 | return (int) (this.buffer[position] >> offset & this.adjustmentMask);
29 | }
30 |
31 | public void set(int index, int value) {
32 | int position = index / this.entriesPerLong;
33 | int offset = (index - position * this.entriesPerLong) * this.bitsPerEntry;
34 | this.buffer[position] = this.buffer[position] & ~(this.adjustmentMask << offset)
35 | | (value & this.adjustmentMask) << offset;
36 | }
37 |
38 | public long[] toArray() {
39 | return this.buffer;
40 | }
41 |
42 | public int size() {
43 | return this.size;
44 | }
45 |
46 | @Override
47 | public String toString() {
48 | return String.format("[size=%d, length=%d, bitsPerEntry=%d, entriesPerLong=%d]", size, buffer.length, bitsPerEntry, entriesPerLong);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/SingleValuePalette.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import io.netty.buffer.ByteBuf;
4 |
5 | public class SingleValuePalette implements Palette {
6 |
7 | private final ChunkSection chunkSection;
8 |
9 | private int value = -1;
10 |
11 | public SingleValuePalette(ChunkSection chunkSection, int value) {
12 | this.chunkSection = chunkSection;
13 | this.value = value;
14 | }
15 |
16 | @Override
17 | public int idFor(int value) {
18 | if (this.value != -1 && value != this.value) {
19 | return this.chunkSection.grow(1, value);
20 | } else {
21 | this.value = value;
22 | return 0;
23 | }
24 | }
25 |
26 | @Override
27 | public int valueFor(int id) {
28 | if (this.value != -1 && id == 0) {
29 | return this.value;
30 | } else {
31 | throw new IllegalStateException("value isn't initialized");
32 | }
33 | }
34 |
35 | @Override
36 | public void read(ByteBuf buffer) {
37 | this.value = ByteBufUtil.readVarInt(buffer);
38 | }
39 |
40 | @Override
41 | public void write(ByteBuf buffer) {
42 | if (this.value == -1) {
43 | throw new IllegalStateException("value isn't initialized");
44 | } else {
45 | ByteBufUtil.writeVarInt(buffer, this.value);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/VarBitBuffer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | public interface VarBitBuffer {
4 |
5 | int get(int index);
6 |
7 | void set(int index, int value);
8 |
9 | long[] toArray();
10 |
11 | int size();
12 | }
13 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/WrappedClientboundLevelChunkPacketData.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | import java.util.Iterator;
4 | import java.util.List;
5 | import java.util.function.Predicate;
6 |
7 | import com.comphenix.protocol.events.PacketContainer;
8 | import com.comphenix.protocol.reflect.accessors.Accessors;
9 | import com.comphenix.protocol.reflect.accessors.FieldAccessor;
10 | import com.comphenix.protocol.utility.MinecraftReflection;
11 |
12 | import net.imprex.orebfuscator.util.BlockPos;
13 |
14 | public class WrappedClientboundLevelChunkPacketData {
15 |
16 | private static final Class> CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA = MinecraftReflection.getMinecraftClass("network.protocol.game.ClientboundLevelChunkPacketData");
17 | private static final FieldAccessor BUFFER = Accessors.getFieldAccessor(CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA, byte[].class, true);
18 | private static final FieldAccessor BLOCK_ENTITIES = Accessors.getFieldAccessor(CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA, List.class, true);
19 |
20 | private static final Class> BLOCK_ENTITY_INFO = MinecraftReflection.getMinecraftClass(
21 | "network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo",
22 | "network.protocol.game.ClientboundLevelChunkPacketData$a");
23 | private static final FieldAccessor[] INT_FIELDS = Accessors.getFieldAccessorArray(BLOCK_ENTITY_INFO, int.class, true);
24 | private static final FieldAccessor PACKED_XZ = INT_FIELDS[0];
25 | private static final FieldAccessor Y = INT_FIELDS[1];
26 |
27 | private final Object handle;
28 |
29 | public WrappedClientboundLevelChunkPacketData(PacketContainer packet) {
30 | this.handle = packet.getSpecificModifier(CLIENTBOUND_LEVEL_CHUNK_PACKET_DATA).read(0);
31 | }
32 |
33 | public byte[] getBuffer() {
34 | return (byte[]) BUFFER.get(this.handle);
35 | }
36 |
37 | public void setBuffer(byte[] buffer) {
38 | BUFFER.set(this.handle, buffer);
39 | }
40 |
41 | public void removeBlockEntityIf(Predicate predicate) {
42 | List> blockEntities = (List>) BLOCK_ENTITIES.get(this.handle);
43 | for (Iterator> iterator = blockEntities.iterator(); iterator.hasNext();) {
44 | Object blockEntityInfo = iterator.next();
45 | int packedXZ = (int) PACKED_XZ.get(blockEntityInfo);
46 |
47 | int x = (packedXZ >> 4) & 15;
48 | int y = (int) Y.get(blockEntityInfo);
49 | int z = packedXZ & 15;
50 |
51 | if (predicate.test(new BlockPos(x, y, z))) {
52 | iterator.remove();
53 | }
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/chunk/ZeroVarBitBuffer.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.chunk;
2 |
3 | public class ZeroVarBitBuffer implements VarBitBuffer {
4 |
5 | public static final long[] EMPTY = new long[0];
6 |
7 | private final int size;
8 |
9 | public ZeroVarBitBuffer(int size) {
10 | this.size = size;
11 | }
12 |
13 | @Override
14 | public int get(int index) {
15 | return 0;
16 | }
17 |
18 | @Override
19 | public void set(int index, int value) {
20 | if (value != 0) {
21 | throw new IllegalArgumentException("ZeroVarBitBuffer can't hold any value");
22 | }
23 | }
24 |
25 | @Override
26 | public long[] toArray() {
27 | return EMPTY;
28 | }
29 |
30 | @Override
31 | public int size() {
32 | return this.size;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/OrebfuscatorBlockFlags.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import java.util.Map.Entry;
4 |
5 | import net.imprex.orebfuscator.OrebfuscatorNms;
6 | import net.imprex.orebfuscator.util.BlockProperties;
7 | import net.imprex.orebfuscator.util.BlockStateProperties;
8 |
9 | public class OrebfuscatorBlockFlags implements BlockFlags {
10 |
11 | private static final OrebfuscatorBlockFlags EMPTY_FLAGS = new OrebfuscatorBlockFlags(null, null);
12 |
13 | static OrebfuscatorBlockFlags create(OrebfuscatorObfuscationConfig worldConfig, OrebfuscatorProximityConfig proximityConfig) {
14 | if ((worldConfig != null && worldConfig.isEnabled()) || (proximityConfig != null && proximityConfig.isEnabled())) {
15 | return new OrebfuscatorBlockFlags(worldConfig, proximityConfig);
16 | }
17 | return EMPTY_FLAGS;
18 | }
19 |
20 | private final int[] blockFlags = new int[OrebfuscatorNms.getUniqueBlockStateCount()];
21 |
22 | private OrebfuscatorBlockFlags(OrebfuscatorObfuscationConfig worldConfig, OrebfuscatorProximityConfig proximityConfig) {
23 | if (worldConfig != null && worldConfig.isEnabled()) {
24 | for (BlockProperties block : worldConfig.hiddenBlocks()) {
25 | this.setBlockBits(block, FLAG_OBFUSCATE);
26 | }
27 | }
28 |
29 | if (proximityConfig != null && proximityConfig.isEnabled()) {
30 | for (Entry entry : proximityConfig.hiddenBlocks()) {
31 | this.setBlockBits(entry.getKey(), entry.getValue());
32 | }
33 | for (BlockProperties block : proximityConfig.allowForUseBlockBelow()) {
34 | this.setBlockBits(block, FLAG_ALLOW_FOR_USE_BLOCK_BELOW);
35 | }
36 | }
37 | }
38 |
39 | private void setBlockBits(BlockProperties block, int bits) {
40 | for (BlockStateProperties blockState : block.getBlockStates()) {
41 | int blockMask = this.blockFlags[blockState.getId()] | bits;
42 |
43 | if (blockState.isBlockEntity()) {
44 | blockMask |= FLAG_BLOCK_ENTITY;
45 | }
46 |
47 | this.blockFlags[blockState.getId()] = blockMask;
48 | }
49 | }
50 |
51 | @Override
52 | public int flags(int blockState) {
53 | return this.blockFlags[blockState];
54 | }
55 |
56 | @Override
57 | public int flags(int blockState, int y) {
58 | int flags = this.blockFlags[blockState];
59 | if (ProximityHeightCondition.match(flags, y)) {
60 | flags |= FLAG_PROXIMITY;
61 | }
62 | return flags;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/OrebfuscatorGeneralConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import org.bukkit.configuration.ConfigurationSection;
4 |
5 | import net.imprex.orebfuscator.config.context.ConfigParsingContext;
6 |
7 | public class OrebfuscatorGeneralConfig implements GeneralConfig {
8 |
9 | private boolean checkForUpdates = true;
10 | private boolean updateOnBlockDamage = true;
11 | private boolean bypassNotification = true;
12 | private boolean ignoreSpectator = false;
13 | private int updateRadius = 2;
14 |
15 | public void deserialize(ConfigurationSection section, ConfigParsingContext context) {
16 | this.checkForUpdates = section.getBoolean("checkForUpdates", true);
17 | this.updateOnBlockDamage = section.getBoolean("updateOnBlockDamage", true);
18 | this.bypassNotification = section.getBoolean("bypassNotification", true);
19 | this.ignoreSpectator = section.getBoolean("ignoreSpectator", false);
20 |
21 | this.updateRadius = section.getInt("updateRadius", 2);
22 | context.errorMinValue("updateRadius", 1, this.updateRadius);
23 | }
24 |
25 | public void serialize(ConfigurationSection section) {
26 | section.set("checkForUpdates", this.checkForUpdates);
27 | section.set("updateOnBlockDamage", this.updateOnBlockDamage);
28 | section.set("bypassNotification", this.bypassNotification);
29 | section.set("ignoreSpectator", this.ignoreSpectator);
30 | section.set("updateRadius", this.updateRadius);
31 | }
32 |
33 | @Override
34 | public boolean checkForUpdates() {
35 | return this.checkForUpdates;
36 | }
37 |
38 | @Override
39 | public boolean updateOnBlockDamage() {
40 | return this.updateOnBlockDamage;
41 | }
42 |
43 | @Override
44 | public boolean bypassNotification() {
45 | return this.bypassNotification;
46 | }
47 |
48 | @Override
49 | public boolean ignoreSpectator() {
50 | return this.ignoreSpectator;
51 | }
52 |
53 | @Override
54 | public int updateRadius() {
55 | return this.updateRadius;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/OrebfuscatorObfuscationConfig.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import java.util.ArrayList;
4 | import java.util.LinkedHashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import org.bukkit.configuration.ConfigurationSection;
9 |
10 | import net.imprex.orebfuscator.OrebfuscatorNms;
11 | import net.imprex.orebfuscator.config.context.ConfigParsingContext;
12 | import net.imprex.orebfuscator.util.BlockProperties;
13 |
14 | public class OrebfuscatorObfuscationConfig extends AbstractWorldConfig implements ObfuscationConfig {
15 |
16 | private boolean layerObfuscation = false;
17 |
18 | private final Set hiddenBlocks = new LinkedHashSet<>();
19 |
20 | OrebfuscatorObfuscationConfig(ConfigurationSection section, ConfigParsingContext context) {
21 | super(section.getName());
22 | this.deserializeBase(section);
23 | this.deserializeWorlds(section, context, "worlds");
24 | this.layerObfuscation = section.getBoolean("layerObfuscation", false);
25 | this.deserializeHiddenBlocks(section, context, "hiddenBlocks");
26 | this.deserializeRandomBlocks(section, context, "randomBlocks");
27 | this.disableOnError(context);
28 | }
29 |
30 | void serialize(ConfigurationSection section) {
31 | this.serializeBase(section);
32 | this.serializeWorlds(section, "worlds");
33 | section.set("layerObfuscation", this.layerObfuscation);
34 | this.serializeHiddenBlocks(section, "hiddenBlocks");
35 | this.serializeRandomBlocks(section, "randomBlocks");
36 | }
37 |
38 | private void deserializeHiddenBlocks(ConfigurationSection section, ConfigParsingContext context, String path) {
39 | context = context.section(path);
40 |
41 | for (String blockName : section.getStringList(path)) {
42 | BlockProperties blockProperties = OrebfuscatorNms.getBlockByName(blockName);
43 | if (blockProperties == null) {
44 | context.warnUnknownBlock(blockName);
45 | } else if (blockProperties.getDefaultBlockState().isAir()) {
46 | context.warnAirBlock(blockName);
47 | } else {
48 | this.hiddenBlocks.add(blockProperties);
49 | }
50 | }
51 |
52 | if (this.hiddenBlocks.isEmpty()) {
53 | context.errorMissingOrEmpty();
54 | }
55 | }
56 |
57 | private void serializeHiddenBlocks(ConfigurationSection section, String path) {
58 | List blockNames = new ArrayList<>();
59 |
60 | for (BlockProperties block : this.hiddenBlocks) {
61 | blockNames.add(block.getKey().toString());
62 | }
63 |
64 | section.set(path, blockNames);
65 | }
66 |
67 | @Override
68 | public boolean layerObfuscation() {
69 | return this.layerObfuscation;
70 | }
71 |
72 | @Override
73 | public Iterable hiddenBlocks() {
74 | return this.hiddenBlocks;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/ProximityHeightCondition.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import net.imprex.orebfuscator.util.BlockPos;
4 |
5 | /**
6 | * Only use 25 MSBs of blockFlags for ProximityHeightCondition
7 | * 12 bit min y | 12 bit max y | 1 bit present
8 | */
9 | public class ProximityHeightCondition {
10 |
11 | public static final int MATCH_ALL = ProximityHeightCondition.create(BlockPos.MIN_Y, BlockPos.MAX_Y);
12 |
13 | public static int clampY(int y) {
14 | return Math.min(BlockPos.MAX_Y, Math.max(BlockPos.MIN_Y, y));
15 | }
16 |
17 | private static int unsigned(int y) {
18 | return (clampY(y) - BlockPos.MIN_Y) & 0xFFF;
19 | }
20 |
21 | private static int signed(int y) {
22 | return y + BlockPos.MIN_Y;
23 | }
24 |
25 | public static int create(int minY, int maxY) {
26 | return unsigned(minY) << 20 | unsigned(maxY) << 8 | 0x80;
27 | }
28 |
29 | public static int remove(int hideCondition) {
30 | return hideCondition & 0x7F;
31 | }
32 |
33 | private static int extractHideCondition(int hideCondition) {
34 | return hideCondition & 0xFFFFFF80;
35 | }
36 |
37 | public static boolean equals(int a, int b) {
38 | return extractHideCondition(a) == extractHideCondition(b);
39 | }
40 |
41 | public static boolean match(int hideCondition, int y) {
42 | return isPresent(hideCondition) && getMinY(hideCondition) <= y && getMaxY(hideCondition) >= y;
43 | }
44 |
45 | public static boolean isPresent(int hideCondition) {
46 | return (hideCondition & 0x80) != 0;
47 | }
48 |
49 | public static int getMinY(int hideCondition) {
50 | return signed(hideCondition >>> 20);
51 | }
52 |
53 | public static int getMaxY(int hideCondition) {
54 | return signed(hideCondition << 12 >>> 20);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/components/WorldMatcher.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.components;
2 |
3 | import java.util.function.Predicate;
4 | import java.util.regex.Pattern;
5 |
6 | public class WorldMatcher implements Predicate {
7 |
8 | public static WorldMatcher parseMatcher(String value) {
9 | if (value.startsWith("regex:")) {
10 | return new WorldMatcher(parseRegexMatcher(value.substring(6)), Type.REGEX);
11 | } else {
12 | return new WorldMatcher(parseWildcardMatcher(value), Type.WILDCARD);
13 | }
14 | }
15 |
16 | private static Pattern parseRegexMatcher(String pattern) {
17 | return Pattern.compile(pattern);
18 | }
19 |
20 | private static Pattern parseWildcardMatcher(String value) {
21 | String pattern = ("\\Q" + value + "\\E").replace("*", "\\E.*\\Q");
22 | return Pattern.compile(pattern);
23 | }
24 |
25 | private final Pattern pattern;
26 | private final Type type;
27 |
28 | private WorldMatcher(Pattern pattern, Type type) {
29 | this.pattern = pattern;
30 | this.type = type;
31 | }
32 |
33 | @Override
34 | public boolean test(String value) {
35 | return this.pattern.matcher(value).matches();
36 | }
37 |
38 | public String serialize() {
39 | if (this.type == Type.REGEX) {
40 | return "regex:" + this.pattern.pattern();
41 | } else {
42 | return this.pattern.pattern()
43 | .replace("\\E.*\\Q", "*")
44 | .replaceAll("\\\\Q|\\\\E", "");
45 | }
46 | }
47 |
48 | private enum Type {
49 | REGEX, WILDCARD;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/context/ConfigParsingContext.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.context;
2 |
3 | public interface ConfigParsingContext {
4 |
5 | ConfigParsingContext section(String path, boolean isolateErrors);
6 |
7 | default ConfigParsingContext section(String path) {
8 | return section(path, false);
9 | }
10 |
11 | ConfigParsingContext warn(String message);
12 |
13 | ConfigParsingContext warn(String path, String message);
14 |
15 | default ConfigParsingContext warnMissingSection() {
16 | warn("section is missing, adding default one");
17 | return this;
18 | }
19 |
20 | default ConfigParsingContext warnMissingOrEmpty() {
21 | warn("is missing or empty");
22 | return this;
23 | }
24 |
25 | default ConfigParsingContext warnUnknownBlock(String name) {
26 | warn(String.format("contains unknown block '%s', skipping", name));
27 | return this;
28 | }
29 |
30 | default ConfigParsingContext warnAirBlock(String name) {
31 | warn(String.format("contains air block '%s', skipping", name));
32 | return this;
33 | }
34 |
35 | default boolean disableIfError(boolean enabled) {
36 | if (enabled && hasErrors()) {
37 | warn("section got disabled due to errors");
38 | return false;
39 | }
40 | return enabled;
41 | }
42 |
43 | ConfigParsingContext error(String message);
44 |
45 | ConfigParsingContext error(String path, String message);
46 |
47 | default ConfigParsingContext errorMinValue(String path, long min, long value) {
48 | if (value < min) {
49 | error(path, String.format("value too low {value(%d) < min(%d)}", value, min));
50 | }
51 | return this;
52 | }
53 |
54 | default ConfigParsingContext errorMinMaxValue(String path, long min, long max, long value) {
55 | if (value < min || value > max) {
56 | error(path, String.format("value out of range {value(%d) not in range[%d, %d]}", value, min, max));
57 | }
58 | return this;
59 | }
60 |
61 | default ConfigParsingContext errorMissingOrEmpty() {
62 | error("is missing or empty");
63 | return this;
64 | }
65 |
66 | boolean hasErrors();
67 | }
68 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/migrations/ConfigMigration.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.migrations;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | import org.bukkit.configuration.ConfigurationSection;
7 |
8 | interface ConfigMigration {
9 |
10 | int sourceVersion();
11 |
12 | ConfigurationSection migrate(ConfigurationSection section);
13 |
14 | static void migrateNames(ConfigurationSection section, List> mapping) {
15 | if (section == null) {
16 | return;
17 | }
18 |
19 | for (Map.Entry entry : mapping) {
20 | Object value = section.get(entry.getKey());
21 | if (value != null) {
22 | section.set(entry.getValue(), value);
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/migrations/ConfigMigrationV1.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.migrations;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.bukkit.configuration.ConfigurationSection;
8 |
9 | class ConfigMigrationV1 implements ConfigMigration {
10 |
11 | @Override
12 | public int sourceVersion() {
13 | return 1;
14 | }
15 |
16 | @Override
17 | public ConfigurationSection migrate(ConfigurationSection section) {
18 | // check if config is still using old path
19 | String obfuscationConfigPath = section.contains("world") ? "world" : "obfuscation";
20 | this.convertSectionListToSection(section, obfuscationConfigPath);
21 | this.convertSectionListToSection(section, "proximity");
22 |
23 | return section;
24 | }
25 |
26 | private void convertSectionListToSection(ConfigurationSection parentSection, String path) {
27 | List sections = this.deserializeSectionList(parentSection, path);
28 | ConfigurationSection section = parentSection.createSection(path);
29 | for (ConfigurationSection childSection : sections) {
30 | section.set(childSection.getName(), childSection);
31 | }
32 | }
33 |
34 | private List deserializeSectionList(ConfigurationSection parentSection, String path) {
35 | List sections = new ArrayList<>();
36 |
37 | List> sectionList = parentSection.getList(path);
38 | if (sectionList != null) {
39 | for (int i = 0; i < sectionList.size(); i++) {
40 | Object section = sectionList.get(i);
41 | if (section instanceof Map) {
42 | sections.add(this.convertMapsToSections((Map, ?>) section,
43 | parentSection.createSection(path + "-" + i)));
44 | }
45 | }
46 | }
47 |
48 | return sections;
49 | }
50 |
51 | private ConfigurationSection convertMapsToSections(Map, ?> input, ConfigurationSection section) {
52 | for (Map.Entry, ?> entry : input.entrySet()) {
53 | String key = entry.getKey().toString();
54 | Object value = entry.getValue();
55 |
56 | if (value instanceof Map) {
57 | this.convertMapsToSections((Map, ?>) value, section.createSection(key));
58 | } else {
59 | section.set(key, value);
60 | }
61 | }
62 | return section;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/migrations/ConfigMigrationV2.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.migrations;
2 |
3 | import org.bukkit.configuration.ConfigurationSection;
4 |
5 | import net.imprex.orebfuscator.util.BlockPos;
6 |
7 | class ConfigMigrationV2 implements ConfigMigration {
8 |
9 | @Override
10 | public int sourceVersion() {
11 | return 2;
12 | }
13 |
14 | @Override
15 | public ConfigurationSection migrate(ConfigurationSection section) {
16 | this.convertRandomBlocksToSections(section.getConfigurationSection("obfuscation"));
17 | this.convertRandomBlocksToSections(section.getConfigurationSection("proximity"));
18 | return section;
19 | }
20 |
21 |
22 | private void convertRandomBlocksToSections(ConfigurationSection parentSection) {
23 | for (String key : parentSection.getKeys(false)) {
24 | ConfigurationSection config = parentSection.getConfigurationSection(key);
25 | ConfigurationSection blockSection = config.getConfigurationSection("randomBlocks");
26 | if (blockSection == null) {
27 | continue;
28 | }
29 |
30 | ConfigurationSection newBlockSection = config.createSection("randomBlocks");
31 | newBlockSection = newBlockSection.createSection("section-global");
32 | newBlockSection.set("minY", BlockPos.MIN_Y);
33 | newBlockSection.set("maxY", BlockPos.MAX_Y);
34 | newBlockSection = newBlockSection.createSection("blocks");
35 |
36 | for (String blockName : blockSection.getKeys(false)) {
37 | newBlockSection.set(blockName, blockSection.getInt(blockName, 1));
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/config/migrations/ConfigMigrator.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config.migrations;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import org.bukkit.configuration.ConfigurationSection;
7 |
8 | import net.imprex.orebfuscator.util.OFCLogger;
9 |
10 | public class ConfigMigrator {
11 |
12 | private static final Map MIGRATIONS = new HashMap<>();
13 |
14 | static {
15 | register(new ConfigMigrationV1());
16 | register(new ConfigMigrationV2());
17 | register(new ConfigMigrationV3());
18 | }
19 |
20 | private static void register(ConfigMigration migration) {
21 | MIGRATIONS.put(migration.sourceVersion(), migration);
22 | }
23 |
24 | public static void migrateToLatestVersion(ConfigurationSection section) {
25 | while (true) {
26 | int sourceVersion = section.getInt("version", -1);
27 | int targetVersion = sourceVersion + 1;
28 |
29 | ConfigMigration migration = MIGRATIONS.get(sourceVersion);
30 | if (migration == null) {
31 | break;
32 | }
33 |
34 | OFCLogger.info("Starting to migrate config to version " + targetVersion);
35 |
36 | section = migration.migrate(section);
37 | section.set("version", targetVersion);
38 |
39 | OFCLogger.info("Successfully migrated config to version " + targetVersion);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationRequest.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.List;
4 | import java.util.Set;
5 | import java.util.concurrent.CompletableFuture;
6 |
7 | import com.google.common.hash.HashFunction;
8 | import com.google.common.hash.Hashing;
9 |
10 | import net.imprex.orebfuscator.chunk.ChunkStruct;
11 | import net.imprex.orebfuscator.config.OrebfuscatorConfig;
12 | import net.imprex.orebfuscator.util.BlockPos;
13 | import net.imprex.orebfuscator.util.ChunkPosition;
14 |
15 | public class ObfuscationRequest {
16 |
17 | private static final HashFunction HASH_FUNCTION = Hashing.murmur3_128();
18 | private static final byte[] EMPTY_HASH = new byte[0];
19 |
20 | public static final int HASH_LENGTH = HASH_FUNCTION.bits() / Byte.SIZE;
21 |
22 | private static final byte[] hash(byte[] systemHash, byte[] data) {
23 | return HASH_FUNCTION.newHasher().putBytes(systemHash).putBytes(data).hash().asBytes();
24 | }
25 |
26 | public static ObfuscationRequest fromChunk(ChunkStruct struct, OrebfuscatorConfig config,
27 | ObfuscationTaskDispatcher dispatcher) {
28 | ChunkPosition position = new ChunkPosition(struct.world, struct.chunkX, struct.chunkZ);
29 | byte[] hash = config.cache().enabled() ? hash(config.systemHash(), struct.data) : EMPTY_HASH;
30 | return new ObfuscationRequest(dispatcher, position, hash, struct);
31 | }
32 |
33 | private final CompletableFuture future = new CompletableFuture<>();
34 |
35 | private final ObfuscationTaskDispatcher dispatcher;
36 | private final ChunkPosition position;
37 | private final byte[] chunkHash;
38 | private final ChunkStruct chunkStruct;
39 |
40 | private ObfuscationRequest(ObfuscationTaskDispatcher dispatcher, ChunkPosition position, byte[] chunkHash,
41 | ChunkStruct chunkStruct) {
42 | this.dispatcher = dispatcher;
43 | this.position = position;
44 | this.chunkHash = chunkHash;
45 | this.chunkStruct = chunkStruct;
46 | }
47 |
48 | public CompletableFuture getFuture() {
49 | return future;
50 | }
51 |
52 | public ChunkPosition getPosition() {
53 | return position;
54 | }
55 |
56 | public byte[] getChunkHash() {
57 | return chunkHash;
58 | }
59 |
60 | public ChunkStruct getChunkStruct() {
61 | return chunkStruct;
62 | }
63 |
64 | public CompletableFuture submitForObfuscation() {
65 | this.dispatcher.submitRequest(this);
66 | return this.future;
67 | }
68 |
69 | public ObfuscationResult createResult(byte[] data, Set blockEntities, List proximityBlocks) {
70 | return new ObfuscationResult(this.position, this.chunkHash, data, blockEntities, proximityBlocks);
71 | }
72 |
73 | public CompletableFuture complete(ObfuscationResult result) {
74 | this.future.complete(result);
75 | return this.future;
76 | }
77 |
78 | public CompletableFuture completeExceptionally(Throwable throwable) {
79 | this.future.completeExceptionally(throwable);
80 | return this.future;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationResult.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashSet;
5 | import java.util.List;
6 | import java.util.Set;
7 |
8 | import net.imprex.orebfuscator.util.BlockPos;
9 | import net.imprex.orebfuscator.util.ChunkPosition;
10 |
11 | public class ObfuscationResult {
12 |
13 | private final ChunkPosition position;
14 |
15 | private final byte[] hash;
16 | private final byte[] data;
17 |
18 | private final Set blockEntities;
19 | private final List proximityBlocks;
20 |
21 | public ObfuscationResult(ChunkPosition position, byte[] hash, byte[] data) {
22 | this(position, hash, data, new HashSet<>(), new ArrayList<>());
23 | }
24 |
25 | public ObfuscationResult(ChunkPosition position, byte[] hash, byte[] data,
26 | Set blockEntities, List proximityBlocks) {
27 | this.position = position;
28 | this.hash = hash;
29 | this.data = data;
30 | this.blockEntities = blockEntities;
31 | this.proximityBlocks = proximityBlocks;
32 | }
33 |
34 | public ChunkPosition getPosition() {
35 | return position;
36 | }
37 |
38 | public byte[] getHash() {
39 | return hash;
40 | }
41 |
42 | public byte[] getData() {
43 | return data;
44 | }
45 |
46 | public Set getBlockEntities() {
47 | return blockEntities;
48 | }
49 |
50 | public List getProximityBlocks() {
51 | return proximityBlocks;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationSystem.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.Collection;
4 | import java.util.concurrent.CompletableFuture;
5 |
6 | import org.bukkit.block.Block;
7 |
8 | import net.imprex.orebfuscator.Orebfuscator;
9 | import net.imprex.orebfuscator.cache.ObfuscationCache;
10 | import net.imprex.orebfuscator.chunk.ChunkStruct;
11 | import net.imprex.orebfuscator.config.OrebfuscatorConfig;
12 |
13 | public class ObfuscationSystem {
14 |
15 | private final Orebfuscator orebfuscator;
16 | private final OrebfuscatorConfig config;
17 | private final ObfuscationCache cache;
18 |
19 | private final ObfuscationProcessor processor;
20 | private final ObfuscationTaskDispatcher dispatcher;
21 | private ObfuscationListener listener;
22 |
23 | private final DeobfuscationWorker deobfuscationWorker;
24 |
25 | public ObfuscationSystem(Orebfuscator orebfuscator) {
26 | this.orebfuscator = orebfuscator;
27 | this.config = orebfuscator.getOrebfuscatorConfig();
28 | this.cache = orebfuscator.getObfuscationCache();
29 |
30 | this.processor = new ObfuscationProcessor(orebfuscator);
31 | this.dispatcher = new ObfuscationTaskDispatcher(orebfuscator, this.processor);
32 |
33 | this.deobfuscationWorker = new DeobfuscationWorker(orebfuscator);
34 | DeobfuscationListener.createAndRegister(orebfuscator, this.deobfuscationWorker);
35 | }
36 |
37 | public void registerChunkListener() {
38 | this.listener = new ObfuscationListener(orebfuscator);
39 | }
40 |
41 | public CompletableFuture obfuscate(ChunkStruct chunkStruct) {
42 | ObfuscationRequest request = ObfuscationRequest.fromChunk(chunkStruct, this.config, this.dispatcher);
43 | if (this.config.cache().enabled()) {
44 | return this.cache.get(request);
45 | } else {
46 | return request.submitForObfuscation();
47 | }
48 | }
49 |
50 | public void deobfuscate(Collection extends Block> blocks) {
51 | this.deobfuscationWorker.deobfuscate(blocks, false);
52 | }
53 |
54 | public void shutdown() {
55 | this.listener.unregister();
56 | this.dispatcher.shutdown();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTask.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.List;
4 | import java.util.Set;
5 | import java.util.concurrent.CompletableFuture;
6 |
7 | import org.bukkit.World;
8 |
9 | import net.imprex.orebfuscator.OrebfuscatorCompatibility;
10 | import net.imprex.orebfuscator.chunk.ChunkStruct;
11 | import net.imprex.orebfuscator.nms.ReadOnlyChunk;
12 | import net.imprex.orebfuscator.util.BlockPos;
13 | import net.imprex.orebfuscator.util.ChunkDirection;
14 | import net.imprex.orebfuscator.util.ChunkPosition;
15 |
16 | public class ObfuscationTask {
17 |
18 | public static CompletableFuture fromRequest(ObfuscationRequest request) {
19 | World world = request.getChunkStruct().world;
20 | ChunkPosition position = request.getPosition();
21 |
22 | return OrebfuscatorCompatibility.getNeighboringChunks(world, position)
23 | .thenApply(chunks -> new ObfuscationTask(request, chunks));
24 | }
25 |
26 | private final ObfuscationRequest request;
27 | private final ReadOnlyChunk[] neighboringChunks;
28 |
29 | private ObfuscationTask(ObfuscationRequest request, ReadOnlyChunk[] neighboringChunks) {
30 | if (neighboringChunks == null || neighboringChunks.length != 4) {
31 | throw new IllegalArgumentException("neighboringChunks missing or invalid length");
32 | }
33 |
34 | this.request = request;
35 | this.neighboringChunks = neighboringChunks;
36 | }
37 |
38 | public ChunkStruct getChunkStruct() {
39 | return this.request.getChunkStruct();
40 | }
41 |
42 | public void complete(byte[] data, Set blockEntities, List proximityBlocks) {
43 | this.request.complete(this.request.createResult(data, blockEntities, proximityBlocks));
44 | }
45 |
46 | public void completeExceptionally(Throwable throwable) {
47 | this.request.completeExceptionally(throwable);
48 | }
49 |
50 | public int getBlockState(int x, int y, int z) {
51 | ChunkDirection direction = ChunkDirection.fromPosition(request.getPosition(), x, z);
52 | return this.neighboringChunks[direction.ordinal()].getBlockState(x, y, z);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskDispatcher.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.Queue;
4 | import java.util.concurrent.ConcurrentLinkedQueue;
5 | import java.util.concurrent.locks.LockSupport;
6 |
7 | import net.imprex.orebfuscator.Orebfuscator;
8 | import net.imprex.orebfuscator.config.AdvancedConfig;
9 |
10 | class ObfuscationTaskDispatcher {
11 |
12 | private final Queue tasks = new ConcurrentLinkedQueue<>();
13 |
14 | private final ObfuscationProcessor processor;
15 | private final ObfuscationTaskWorker[] worker;
16 |
17 | public ObfuscationTaskDispatcher(Orebfuscator orebfuscator, ObfuscationProcessor processor) {
18 | this.processor = processor;
19 |
20 | AdvancedConfig config = orebfuscator.getOrebfuscatorConfig().advanced();
21 | this.worker = new ObfuscationTaskWorker[config.obfuscationThreads()];
22 | for (int i = 0; i < this.worker.length; i++) {
23 | this.worker[i] = new ObfuscationTaskWorker(this, this.processor);
24 | }
25 |
26 | orebfuscator.getStatistics().setObfuscationQueueLengthSupplier(() -> this.tasks.size());
27 | }
28 |
29 | public void submitRequest(ObfuscationRequest request) {
30 | ObfuscationTask.fromRequest(request).whenComplete((task, throwable) -> {
31 | if (throwable != null) {
32 | request.completeExceptionally(throwable);
33 | } else {
34 | this.tasks.offer(task);
35 | }
36 | });
37 | }
38 |
39 | public ObfuscationTask retrieveTask() throws InterruptedException {
40 | ObfuscationTask task;
41 |
42 | while ((task = this.tasks.poll()) == null) {
43 | // sleep for 1 tick = 50ms
44 | LockSupport.parkNanos(this, 50000000L);
45 | if (Thread.interrupted()) {
46 | throw new InterruptedException();
47 | }
48 | }
49 |
50 | return task;
51 | }
52 |
53 | public void shutdown() {
54 | for (ObfuscationTaskWorker worker : this.worker) {
55 | worker.shutdown();
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/obfuscation/ObfuscationTaskWorker.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.obfuscation;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 | import java.util.concurrent.locks.LockSupport;
5 |
6 | import net.imprex.orebfuscator.Orebfuscator;
7 |
8 | class ObfuscationTaskWorker implements Runnable {
9 |
10 | private static final AtomicInteger WORKER_ID = new AtomicInteger();
11 |
12 | private final ObfuscationTaskDispatcher dispatcher;
13 | private final ObfuscationProcessor processor;
14 |
15 | private final Thread thread;
16 | private volatile boolean running = true;
17 |
18 | public ObfuscationTaskWorker(ObfuscationTaskDispatcher dispatcher, ObfuscationProcessor processor) {
19 | this.dispatcher = dispatcher;
20 | this.processor = processor;
21 |
22 | this.thread = new Thread(Orebfuscator.THREAD_GROUP, this, "ofc-task-worker-" + WORKER_ID.getAndIncrement());
23 | this.thread.setDaemon(true);
24 | this.thread.start();
25 | }
26 |
27 | public boolean unpark() {
28 | if (LockSupport.getBlocker(this.thread) != null) {
29 | LockSupport.unpark(this.thread);
30 | return true;
31 | }
32 | return false;
33 | }
34 |
35 | @Override
36 | public void run() {
37 | while (this.running) {
38 | try {
39 | this.processor.process(this.dispatcher.retrieveTask());
40 | } catch (InterruptedException e) {
41 | break;
42 | }
43 | }
44 | }
45 |
46 | public void shutdown() {
47 | this.running = false;
48 | this.thread.interrupt();
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/player/OrebfuscatorPlayerChunk.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.player;
2 |
3 | import java.util.Iterator;
4 | import java.util.List;
5 | import java.util.NoSuchElementException;
6 |
7 | import net.imprex.orebfuscator.util.BlockPos;
8 |
9 | public class OrebfuscatorPlayerChunk {
10 |
11 | private final int chunkX;
12 | private final int chunkZ;
13 |
14 | private int proximitySize;
15 | private final int[] proximityBlocks;
16 |
17 | public OrebfuscatorPlayerChunk(int chunkX, int chunkZ, List proximityBlocks) {
18 | this.chunkX = chunkX;
19 | this.chunkZ = chunkZ;
20 |
21 | this.proximitySize = proximityBlocks.size();
22 | this.proximityBlocks = new int[proximityBlocks.size()];
23 |
24 | for (int i = 0; i < proximityBlocks.size(); i++) {
25 | this.proximityBlocks[i] = proximityBlocks.get(i).toSectionPos();
26 | }
27 | }
28 |
29 | public boolean isEmpty() {
30 | return proximitySize <= 0;
31 | }
32 |
33 | public Iterator proximityIterator() {
34 | return new ProximityItr();
35 | }
36 |
37 | private class ProximityItr implements Iterator {
38 |
39 | private final int x = chunkX << 4;
40 | private final int z = chunkZ << 4;
41 |
42 | private int cursor;
43 | private int returnCursor = -1;
44 |
45 | @Override
46 | public boolean hasNext() {
47 | return cursor < proximitySize;
48 | }
49 |
50 | @Override
51 | public BlockPos next() {
52 | if (cursor >= proximitySize)
53 | throw new NoSuchElementException();
54 |
55 | int sectionPos = proximityBlocks[returnCursor = cursor];
56 | cursor++;
57 |
58 | return BlockPos.fromSectionPos(x, z, sectionPos);
59 | }
60 |
61 | @Override
62 | public void remove() {
63 | if (returnCursor < 0)
64 | throw new IllegalStateException();
65 |
66 | // remove entry
67 | final int index = returnCursor;
68 | final int newSize;
69 | if ((newSize = proximitySize - 1) > index)
70 | System.arraycopy(proximityBlocks, index + 1, proximityBlocks, index, newSize - index);
71 | proximityBlocks[proximitySize = newSize] = 0xFFFFFFFF;
72 |
73 | // update cursor positions
74 | cursor = returnCursor;
75 | returnCursor = -1;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/player/OrebfuscatorPlayerMap.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.player;
2 |
3 | import java.util.concurrent.ConcurrentHashMap;
4 | import java.util.concurrent.ConcurrentMap;
5 |
6 | import org.bukkit.Bukkit;
7 | import org.bukkit.entity.Player;
8 | import org.bukkit.event.EventHandler;
9 | import org.bukkit.event.Listener;
10 | import org.bukkit.event.player.PlayerJoinEvent;
11 | import org.bukkit.event.player.PlayerQuitEvent;
12 |
13 | import net.imprex.orebfuscator.Orebfuscator;
14 |
15 | public class OrebfuscatorPlayerMap implements Listener {
16 |
17 | private final Orebfuscator orebfuscator;
18 |
19 | private final ConcurrentMap internalMap = new ConcurrentHashMap<>();
20 |
21 | public OrebfuscatorPlayerMap(Orebfuscator orebfuscator) {
22 | this.orebfuscator = orebfuscator;
23 | if (orebfuscator.getOrebfuscatorConfig().proximityEnabled()) {
24 | Bukkit.getPluginManager().registerEvents(this, orebfuscator);
25 |
26 | for (Player player : Bukkit.getOnlinePlayers()) {
27 | this.addPlayer(player);
28 | }
29 | }
30 | }
31 |
32 | private void addPlayer(Player player) {
33 | this.internalMap.put(player, new OrebfuscatorPlayer(orebfuscator, player));
34 | }
35 |
36 | @EventHandler
37 | public void onJoin(PlayerJoinEvent event) {
38 | this.addPlayer(event.getPlayer());
39 | }
40 |
41 | @EventHandler
42 | public void onQuit(PlayerQuitEvent event) {
43 | this.internalMap.remove(event.getPlayer());
44 | }
45 |
46 | public OrebfuscatorPlayer get(Player player) {
47 | OrebfuscatorPlayer orebfuscatorPlayer = this.internalMap.get(player);
48 | if (orebfuscatorPlayer != null) {
49 | orebfuscatorPlayer.updateWorld();
50 | }
51 | return orebfuscatorPlayer;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityPacketListener.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.proximity;
2 |
3 | import org.bukkit.World;
4 | import org.bukkit.entity.Player;
5 |
6 | import com.comphenix.protocol.PacketType;
7 | import com.comphenix.protocol.ProtocolLibrary;
8 | import com.comphenix.protocol.ProtocolManager;
9 | import com.comphenix.protocol.events.PacketAdapter;
10 | import com.comphenix.protocol.events.PacketContainer;
11 | import com.comphenix.protocol.events.PacketEvent;
12 | import com.comphenix.protocol.reflect.StructureModifier;
13 | import com.comphenix.protocol.wrappers.ChunkCoordIntPair;
14 |
15 | import net.imprex.orebfuscator.Orebfuscator;
16 | import net.imprex.orebfuscator.chunk.ChunkCapabilities;
17 | import net.imprex.orebfuscator.config.OrebfuscatorConfig;
18 | import net.imprex.orebfuscator.config.ProximityConfig;
19 | import net.imprex.orebfuscator.player.OrebfuscatorPlayer;
20 | import net.imprex.orebfuscator.player.OrebfuscatorPlayerMap;
21 | import net.imprex.orebfuscator.util.PermissionUtil;
22 |
23 | public class ProximityPacketListener extends PacketAdapter {
24 |
25 | private final ProtocolManager protocolManager;
26 |
27 | private final OrebfuscatorConfig config;
28 | private final OrebfuscatorPlayerMap playerMap;
29 |
30 | public ProximityPacketListener(Orebfuscator orebfuscator) {
31 | super(orebfuscator, PacketType.Play.Server.UNLOAD_CHUNK);
32 |
33 | this.protocolManager = ProtocolLibrary.getProtocolManager();
34 | this.protocolManager.addPacketListener(this);
35 |
36 | this.config = orebfuscator.getOrebfuscatorConfig();
37 | this.playerMap = orebfuscator.getPlayerMap();
38 | }
39 |
40 | public void unregister() {
41 | this.protocolManager.removePacketListener(this);
42 | }
43 |
44 | @Override
45 | public void onPacketSending(PacketEvent event) {
46 | Player player = event.getPlayer();
47 | if (PermissionUtil.canBypassObfuscate(player)) {
48 | return;
49 | }
50 |
51 | World world = player.getWorld();
52 | ProximityConfig proximityConfig = config.world(world).proximity();
53 | if (proximityConfig == null || !proximityConfig.isEnabled()) {
54 | return;
55 | }
56 |
57 | OrebfuscatorPlayer orebfuscatorPlayer = this.playerMap.get(player);
58 | if (orebfuscatorPlayer != null) {
59 | PacketContainer packet = event.getPacket();
60 | if (ChunkCapabilities.hasChunkPosFieldUnloadPacket()) {
61 | ChunkCoordIntPair chunkPos = packet.getChunkCoordIntPairs().read(0);
62 | orebfuscatorPlayer.removeChunk(chunkPos.getChunkX(), chunkPos.getChunkZ());
63 | } else {
64 | StructureModifier ints = packet.getIntegers();
65 | orebfuscatorPlayer.removeChunk(ints.read(0), ints.read(1));
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/proximity/ProximityWorkerThread.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.proximity;
2 |
3 | import java.util.List;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | import org.bukkit.entity.Player;
7 |
8 | import net.imprex.orebfuscator.Orebfuscator;
9 |
10 | public class ProximityWorkerThread extends Thread {
11 |
12 | private static final AtomicInteger NEXT_ID = new AtomicInteger();
13 |
14 | private final ProximityDirectorThread directorThread;
15 | private final ProximityWorker worker;
16 |
17 | public ProximityWorkerThread(ProximityDirectorThread directorThread, ProximityWorker worker) {
18 | super(Orebfuscator.THREAD_GROUP, "ofc-proximity-worker-" + NEXT_ID.getAndIncrement());
19 | this.setDaemon(true);
20 |
21 | this.directorThread = directorThread;
22 | this.worker = worker;
23 | }
24 |
25 | @Override
26 | public void run() {
27 | while (this.directorThread.isRunning()) {
28 | try {
29 | List bucket = this.directorThread.nextBucket();
30 |
31 | this.worker.process(bucket);
32 |
33 | this.directorThread.finishBucketProcessing();
34 | } catch (InterruptedException e) {
35 | continue;
36 | } catch (Exception e) {
37 | e.printStackTrace();
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/java/net/imprex/orebfuscator/util/PermissionUtil.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.util;
2 |
3 | import org.bukkit.permissions.Permissible;
4 |
5 | public class PermissionUtil {
6 |
7 | public static boolean canBypassObfuscate(Permissible permissible) {
8 | try {
9 | return permissible.hasPermission("orebfuscator.bypass");
10 | } catch (UnsupportedOperationException e) {
11 | // fix #131: catch TemporaryPlayer not implementing hasPermission
12 | return false;
13 | }
14 | }
15 |
16 | public static boolean canAccessAdminTools(Permissible permissible) {
17 | return permissible.isOp() || permissible.hasPermission("orebfuscator.admin");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | api-version: 1.16
2 | folia-supported: true
3 |
4 | name: ${project.parent.name}
5 | version: ${project.version}
6 | description: '${project.parent.description}'
7 |
8 | author: Ingrim4
9 | authors: [NgLoader, lishid, SydMontague, ProgrammerDan, Aleksey-Terzi]
10 |
11 | main: net.imprex.orebfuscator.Orebfuscator
12 | depend: [ProtocolLib]
13 |
14 | commands:
15 | orebfuscator:
16 | aliases: [ofc]
17 | description: Performs administrative tasks regarding Orebfuscator.
18 | usage: / [dump]
19 | permission: orebfuscator.admin
20 | permission-message: You don't have
21 |
22 | permissions:
23 | orebfuscator.*:
24 | default: false
25 | description: Access to all of Orebfuscator's features
26 | children:
27 | orebfuscator.admin: true
28 | orebfuscator.bypass: true
29 | orebfuscator.admin:
30 | default: op
31 | description: Access to update notifications and commands
32 | orebfuscator.bypass:
33 | default: false
34 | description: Bypass the obfuscation
35 |
--------------------------------------------------------------------------------
/orebfuscator-plugin/src/test/java/net/imprex/orebfuscator/config/ProximityHeightConditionTest.java:
--------------------------------------------------------------------------------
1 | package net.imprex.orebfuscator.config;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import org.junit.jupiter.api.Test;
8 |
9 | public class ProximityHeightConditionTest {
10 |
11 | private static final int TEST_MIN = ProximityHeightCondition.clampY(-0xFFF);
12 | private static final int TEST_MAX = ProximityHeightCondition.clampY(0xFFF);
13 |
14 | @Test
15 | public void testCreateRemove() {
16 | final int minY = -10;
17 | final int maxY = 10;
18 |
19 | int flag = 0b101;
20 | assertFalse(ProximityHeightCondition.isPresent(flag));
21 |
22 | flag |= ProximityHeightCondition.create(minY, maxY);
23 | assertTrue(ProximityHeightCondition.isPresent(flag));
24 | assertEquals(minY, ProximityHeightCondition.getMinY(flag));
25 | assertEquals(maxY, ProximityHeightCondition.getMaxY(flag));
26 |
27 | for (int y = TEST_MIN; y <= TEST_MAX; y++) {
28 | boolean expected = minY <= y && maxY >= y;
29 | assertEquals(expected, ProximityHeightCondition.match(flag, y), "failed for " + y);
30 | }
31 |
32 | int other = ProximityHeightCondition.create(minY, maxY);
33 | assertTrue(ProximityHeightCondition.equals(flag, other));
34 |
35 | flag = ProximityHeightCondition.remove(flag);
36 | assertEquals(0b101, flag);
37 | }
38 |
39 | @Test
40 | public void testReadWrite() {
41 | for (int minY = TEST_MIN; minY <= TEST_MAX; minY++) {
42 | for (int maxY = minY; maxY <= TEST_MAX; maxY++) {
43 | int flag = ProximityHeightCondition.create(minY, maxY);
44 |
45 | assertTrue(ProximityHeightCondition.isPresent(flag));
46 | assertEquals(minY, ProximityHeightCondition.getMinY(flag));
47 | assertEquals(maxY, ProximityHeightCondition.getMaxY(flag));
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------