Skip to content

Commit 73e79ce

Browse files
committed
Minor tweaks and added example config file with enabled worlds
1 parent b4e5850 commit 73e79ce

File tree

5 files changed

+171
-29
lines changed

5 files changed

+171
-29
lines changed

Plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.lishid</groupId>
66
<artifactId>orebfuscator</artifactId>
7-
<version>4.3.2-SNAPSHOT</version>
7+
<version>4.3.3-SNAPSHOT</version>
88
<packaging>jar</packaging>
99

1010
<name>Orebfuscator4</name>

Plugin/src/main/java/com/lishid/orebfuscator/Orebfuscator.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.lishid.orebfuscator;
1818

19-
import java.io.IOException;
19+
import java.io.*;
2020
import java.util.logging.Logger;
2121

2222
import org.bukkit.ChatColor;
@@ -69,6 +69,8 @@ public void onEnable() {
6969

7070
// Load configurations
7171
loadOrebfuscatorConfig();
72+
73+
makeConfigExample();
7274

7375
this.isProtocolLibFound = pm.getPlugin("ProtocolLib") != null;
7476

@@ -108,6 +110,28 @@ public void loadOrebfuscatorConfig() {
108110
e.printStackTrace();
109111
}
110112
}
113+
114+
private void makeConfigExample() {
115+
File outputFile = new File(getDataFolder(), "config.example_enabledworlds.yml");
116+
117+
if(outputFile.exists()) return;
118+
119+
InputStream configStream = Orebfuscator.class.getResourceAsStream("/resources/config.example_enabledworlds.yml");
120+
StringBuilder content = new StringBuilder();
121+
122+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(configStream));
123+
PrintWriter writer = new PrintWriter(outputFile)
124+
)
125+
{
126+
String line;
127+
128+
while ((line = reader.readLine()) != null) {
129+
writer.println(line);
130+
}
131+
} catch (IOException e) {
132+
e.printStackTrace();
133+
}
134+
}
111135

112136
public void reloadOrebfuscatorConfig() {
113137
reloadConfig();

Plugin/src/main/java/com/lishid/orebfuscator/hook/ProtocolLibHook.java

+28-16
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,35 @@ public void register(Plugin plugin) {
4848
this.manager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
4949
@Override
5050
public void onPacketSending(PacketEvent event) {
51-
PacketContainer packet = event.getPacket();
52-
53-
StructureModifier<Integer> ints = packet.getIntegers();
54-
StructureModifier<byte[]> byteArray = packet.getByteArrays();
55-
StructureModifier<Boolean> bools = packet.getBooleans();
56-
57-
ChunkData chunkData = new ChunkData();
58-
chunkData.chunkX = ints.read(0);
59-
chunkData.chunkZ = ints.read(1);
60-
chunkData.groundUpContinuous = bools.read(0);
61-
chunkData.primaryBitMask = ints.read(2);
62-
chunkData.data = byteArray.read(0);
63-
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
64-
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
65-
6651
try {
67-
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, event.getPlayer());
52+
Player player = event.getPlayer();
53+
54+
if (!Orebfuscator.config.isEnabled() || !Orebfuscator.config.obfuscateForPlayer(player)) {
55+
return;
56+
}
57+
58+
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
59+
60+
if(!worldConfig.isEnabled()) {
61+
return;
62+
}
63+
64+
PacketContainer packet = event.getPacket();
65+
66+
StructureModifier<Integer> ints = packet.getIntegers();
67+
StructureModifier<byte[]> byteArray = packet.getByteArrays();
68+
StructureModifier<Boolean> bools = packet.getBooleans();
69+
70+
ChunkData chunkData = new ChunkData();
71+
chunkData.chunkX = ints.read(0);
72+
chunkData.chunkZ = ints.read(1);
73+
chunkData.groundUpContinuous = bools.read(0);
74+
chunkData.primaryBitMask = ints.read(2);
75+
chunkData.data = byteArray.read(0);
76+
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
77+
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
78+
79+
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, player, worldConfig);
6880

6981
if(newData != null) {
7082
byteArray.write(0, newData);

Plugin/src/main/java/com/lishid/orebfuscator/obfuscation/Calculations.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,9 @@
4242
public class Calculations {
4343
private static Random random = new Random();
4444

45-
public static byte[] obfuscateOrUseCache(ChunkData chunkData, Player player) throws IOException {
45+
public static byte[] obfuscateOrUseCache(ChunkData chunkData, Player player, WorldConfig worldConfig) throws IOException {
4646
if(chunkData.primaryBitMask == 0) return null;
4747

48-
if (!Orebfuscator.config.isEnabled() || !Orebfuscator.config.obfuscateForPlayer(player)) {
49-
return null;
50-
}
51-
52-
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
53-
54-
if(!worldConfig.isEnabled()) {
55-
return null;
56-
}
57-
5848
byte[] output;
5949

6050
ObfuscatedCachedChunk cache = tryUseCache(chunkData, player);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
ConfigVersion: 13
2+
Booleans:
3+
UseCache: true
4+
Enabled: true
5+
UpdateOnDamage: true
6+
NoObfuscationForMetadata: true
7+
NoObfuscationForOps: false
8+
NoObfuscationForPermission: false
9+
LoginNotification: true
10+
Integers:
11+
MaxLoadedCacheFiles: 64
12+
DeleteCacheFilesAfterDays: 0
13+
EngineMode: 2
14+
InitialRadius: 1
15+
UpdateRadius: 2
16+
Strings:
17+
CacheLocation: orebfuscator_cache
18+
NoObfuscationForMetadataTagName: NPC
19+
Lists:
20+
TransparentBlocks: []
21+
NonTransparentBlocks: []
22+
Worlds:
23+
Default:
24+
Types:
25+
- DEFAULT
26+
Enabled: false
27+
AntiTexturePackAndFreecam: true
28+
AirGeneratorMaxChance: 43
29+
DarknessHideBlocks: false
30+
BypassObfuscationForSignsWithText: false
31+
DarknessBlocks:
32+
- MOB_SPAWNER
33+
- CHEST
34+
Mode1Block: STONE
35+
RandomBlocks: []
36+
ObfuscateBlocks: []
37+
ProximityHider:
38+
Enabled: true
39+
Distance: 8
40+
SpecialBlock: STONE
41+
Y: 255
42+
UseSpecialBlock: true
43+
ObfuscateAboveY: false
44+
ProximityHiderBlocks:
45+
- DISPENSER
46+
- MOB_SPAWNER
47+
- CHEST
48+
- DIAMOND_ORE
49+
- WORKBENCH
50+
- FURNACE
51+
- BURNING_FURNACE
52+
- ENCHANTMENT_TABLE
53+
- EMERALD_ORE
54+
- ENDER_CHEST
55+
- ANVIL
56+
- TRAPPED_CHEST
57+
UseFastGazeCheck: true
58+
Normal:
59+
Types:
60+
- NORMAL
61+
Mode1Block: STONE
62+
RandomBlocks:
63+
- STONE
64+
- COBBLESTONE
65+
- WOOD
66+
- GOLD_ORE
67+
- IRON_ORE
68+
- COAL_ORE
69+
- LAPIS_ORE
70+
- TNT
71+
- MOSSY_COBBLESTONE
72+
- OBSIDIAN
73+
- DIAMOND_ORE
74+
- REDSTONE_ORE
75+
- CLAY
76+
- EMERALD_ORE
77+
ObfuscateBlocks:
78+
- GOLD_ORE
79+
- IRON_ORE
80+
- COAL_ORE
81+
- LAPIS_ORE
82+
- CHEST
83+
- DIAMOND_ORE
84+
- REDSTONE_ORE
85+
- GLOWING_REDSTONE_ORE
86+
- EMERALD_ORE
87+
- ENDER_CHEST
88+
TheEnd:
89+
Types:
90+
- THE_END
91+
Mode1Block: ENDER_STONE
92+
RandomBlocks:
93+
- BEDROCK
94+
- OBSIDIAN
95+
- ENDER_STONE
96+
- PURPUR_BLOCK
97+
- END_BRICKS
98+
ObfuscateBlocks:
99+
- ENDER_STONE
100+
Nether:
101+
Types:
102+
- NETHER
103+
Mode1Block: NETHERRACK
104+
RandomBlocks:
105+
- GRAVEL
106+
- NETHERRACK
107+
- SOUL_SAND
108+
- NETHER_BRICK
109+
- QUARTZ_ORE
110+
ObfuscateBlocks:
111+
- NETHERRACK
112+
- QUARTZ_ORE
113+
EnabledWorlds:
114+
Names:
115+
- world
116+
Enabled: true

0 commit comments

Comments
 (0)