Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#307] Add layer obfuscation #336

Merged
merged 2 commits into from Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,5 +4,7 @@

public interface ObfuscationConfig extends WorldConfig {

boolean layerObfuscation();

Iterable<BlockProperties> hiddenBlocks();
}
Expand Up @@ -16,17 +16,23 @@ public BukkitScheduler(Plugin plugin) {

@Override
public void runForPlayer(Player player, Runnable runnable) {
Bukkit.getScheduler().runTask(this.plugin, runnable);
if (this.plugin.isEnabled()) {
Bukkit.getScheduler().runTask(this.plugin, runnable);
}
}

@Override
public void runAsyncNow(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, runnable);
if (this.plugin.isEnabled()) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, runnable);
}
}

@Override
public void runAsyncAtFixedRate(Runnable runnable, long delay, long period) {
Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, delay, period);
if (this.plugin.isEnabled()) {
Bukkit.getScheduler().runTaskTimerAsynchronously(this.plugin, runnable, delay, period);
}
}

@Override
Expand Down
Expand Up @@ -18,18 +18,24 @@ public FoliaScheduler(Plugin plugin) {

@Override
public void runForPlayer(Player player, Runnable runnable) {
player.getScheduler().run(this.plugin, task -> runnable.run(), null);
if (this.plugin.isEnabled()) {
player.getScheduler().run(this.plugin, task -> runnable.run(), null);
}
}

@Override
public void runAsyncNow(Runnable runnable) {
Bukkit.getAsyncScheduler().runNow(this.plugin, task -> runnable.run());
if (this.plugin.isEnabled()) {
Bukkit.getAsyncScheduler().runNow(this.plugin, task -> runnable.run());
}
}

@Override
public void runAsyncAtFixedRate(Runnable runnable, long delay, long period) {
Bukkit.getAsyncScheduler().runAtFixedRate(this.plugin, task -> runnable.run(),
delay * 50, period * 50, TimeUnit.MILLISECONDS);
if (this.plugin.isEnabled()) {
Bukkit.getAsyncScheduler().runAtFixedRate(this.plugin, task -> runnable.run(),
delay * 50, period * 50, TimeUnit.MILLISECONDS);
}
}

@Override
Expand Down
Expand Up @@ -13,19 +13,23 @@

public class OrebfuscatorObfuscationConfig extends AbstractWorldConfig implements ObfuscationConfig {

private boolean layerObfuscation = false;

private final Set<BlockProperties> hiddenBlocks = new LinkedHashSet<>();

OrebfuscatorObfuscationConfig(ConfigurationSection section) {
super(section.getName());
this.deserializeBase(section);
this.deserializeWorlds(section, "worlds");
this.layerObfuscation = section.getBoolean("layerObfuscation", false);
this.deserializeHiddenBlocks(section, "hiddenBlocks");
this.deserializeRandomBlocks(section, "randomBlocks");
}

void serialize(ConfigurationSection section) {
this.serializeBase(section);
this.serializeWorlds(section, "worlds");
section.set("layerObfuscation", this.layerObfuscation);
this.serializeHiddenBlocks(section, "hiddenBlocks");
this.serializeRandomBlocks(section, "randomBlocks");
}
Expand Down Expand Up @@ -58,6 +62,11 @@ private void serializeHiddenBlocks(ConfigurationSection section, String path) {
section.set(path, blockNames);
}

@Override
public boolean layerObfuscation() {
return this.layerObfuscation;
}

@Override
public Iterable<BlockProperties> hiddenBlocks() {
return this.hiddenBlocks;
Expand Down
Expand Up @@ -44,6 +44,9 @@ public void process(ObfuscationTask task) {
int baseX = chunkStruct.chunkX << 4;
int baseZ = chunkStruct.chunkZ << 4;

int layerY = Integer.MIN_VALUE;
int layerYBlockState = -1;

try (Chunk chunk = Chunk.fromChunkStruct(chunkStruct)) {
for (int sectionIndex = Math.max(0, bundle.minSectionIndex()); sectionIndex <= Math
.min(chunk.getSectionCount() - 1, bundle.maxSectionIndex()); sectionIndex++) {
Expand Down Expand Up @@ -74,7 +77,15 @@ public void process(ObfuscationTask task) {

// should current block be obfuscated
if (isObfuscateBitSet && obfuscationConfig.shouldObfuscate(y) && shouldObfuscate(task, chunk, x, y, z)) {
blockState = bundle.nextRandomObfuscationBlock(y);
if (obfuscationConfig.layerObfuscation()) {
if (layerY != y) {
layerY = y;
layerYBlockState = bundle.nextRandomObfuscationBlock(y);
}
blockState = layerYBlockState;
} else {
blockState = bundle.nextRandomObfuscationBlock(y);
}
obfuscated = true;
}

Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.10.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -75,6 +76,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -106,6 +108,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.11.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -91,6 +92,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -138,6 +140,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.12.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -91,6 +92,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -138,6 +140,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.13.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -92,6 +93,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -140,6 +142,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.14.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -92,6 +93,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -140,6 +142,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.15.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -92,6 +93,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -140,6 +142,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.16.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -92,6 +93,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down Expand Up @@ -147,6 +149,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.17.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:emerald_ore
- minecraft:deepslate_emerald_ore
Expand Down Expand Up @@ -119,6 +120,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:netherrack
- minecraft:nether_quartz_ore
Expand Down Expand Up @@ -174,6 +176,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:spawner
- minecraft:chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.18.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:emerald_ore
- minecraft:deepslate_emerald_ore
Expand Down Expand Up @@ -121,6 +122,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:netherrack
- minecraft:nether_quartz_ore
Expand Down Expand Up @@ -175,6 +177,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.19.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:emerald_ore
- minecraft:deepslate_emerald_ore
Expand Down Expand Up @@ -121,6 +122,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:netherrack
- minecraft:nether_quartz_ore
Expand Down Expand Up @@ -175,6 +177,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down
3 changes: 3 additions & 0 deletions orebfuscator-plugin/src/main/resources/config/config-1.20.yml
Expand Up @@ -32,6 +32,7 @@ obfuscation:
maxY: 2031
worlds:
- world
layerObfuscation: false
hiddenBlocks:
- minecraft:emerald_ore
- minecraft:deepslate_emerald_ore
Expand Down Expand Up @@ -121,6 +122,7 @@ obfuscation:
maxY: 2031
worlds:
- world_nether
layerObfuscation: false
hiddenBlocks:
- minecraft:netherrack
- minecraft:nether_quartz_ore
Expand Down Expand Up @@ -175,6 +177,7 @@ obfuscation:
maxY: 2031
worlds:
- world_the_end
layerObfuscation: false
hiddenBlocks:
- minecraft:chest
- minecraft:ender_chest
Expand Down