Skip to content

Commit

Permalink
[#307] Add layer obfuscation (#336)
Browse files Browse the repository at this point in the history
* feat: add layer obfuscation

* chore: update config defaults
  • Loading branch information
Ingrim4 authored Nov 25, 2023
1 parent 473c438 commit 87fc5a4
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

public interface ObfuscationConfig extends WorldConfig {

boolean layerObfuscation();

Iterable<BlockProperties> hiddenBlocks();
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 87fc5a4

Please sign in to comment.