Merge pull request #167 from DevotedMC/master

Merging in downstream gazecheck feature, world fixes and example configs.
master
Daniel Boston 2017-08-05 11:54:05 -04:00 committed by GitHub
commit 90852aa552
12 changed files with 328 additions and 82 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.3.0-SNAPSHOT</version>
<version>4.3.3-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Orebfuscator4</name>
@ -130,8 +130,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>

View File

@ -16,7 +16,7 @@
package com.lishid.orebfuscator;
import java.io.IOException;
import java.io.*;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@ -69,6 +69,8 @@ public class Orebfuscator extends JavaPlugin {
// Load configurations
loadOrebfuscatorConfig();
makeConfigExample();
this.isProtocolLibFound = pm.getPlugin("ProtocolLib") != null;
@ -96,7 +98,7 @@ public class Orebfuscator extends JavaPlugin {
}
configManager.load();
ObfuscatedDataCache.resetCacheFolder();
nms.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());
@ -108,6 +110,28 @@ public class Orebfuscator extends JavaPlugin {
e.printStackTrace();
}
}
private void makeConfigExample() {
File outputFile = new File(getDataFolder(), "config.example_enabledworlds.yml");
if(outputFile.exists()) return;
InputStream configStream = Orebfuscator.class.getResourceAsStream("/resources/config.example_enabledworlds.yml");
StringBuilder content = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(configStream));
PrintWriter writer = new PrintWriter(outputFile)
)
{
String line;
while ((line = reader.readLine()) != null) {
writer.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void reloadOrebfuscatorConfig() {
reloadConfig();

View File

@ -18,9 +18,10 @@ package com.lishid.orebfuscator.commands;
import java.io.IOException;
import net.md_5.bungee.api.ChatColor;
import com.lishid.orebfuscator.config.WorldConfig;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
@ -150,20 +151,13 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.message(sender, "Initial Obfuscation Radius: " + Orebfuscator.config.getInitialRadius());
Orebfuscator.message(sender, "Update Radius: " + Orebfuscator.config.getUpdateRadius());
String worlds = "";
for(String name : Orebfuscator.config.getWorlds().keySet()) {
if(worlds.length() > 0) {
name += ", ";
}
worlds += name;
}
Orebfuscator.message(sender, "Worlds: " + (worlds.equals("") ? "None" : worlds));
Orebfuscator.message(sender, "Use worlds as: " + (Orebfuscator.config.getDefaultWorld().isEnabled() ? "Blacklist" : "Whitelist"));
Orebfuscator.message(sender, "World by Default: " + (Orebfuscator.config.getDefaultWorld().isEnabled() ? "Enabled" : "Disabled"));
String worldNames = Orebfuscator.config.getWorldNames();
Orebfuscator.message(sender, "Worlds in List: " + (worldNames.equals("") ? "None" : worldNames));
return true;
}

View File

@ -57,7 +57,7 @@ public class ConfigManager {
break;
}
WorldConfig cfg = this.orebfuscatorConfig.getWorlds().get(world.getName().toLowerCase());
WorldConfig cfg = this.orebfuscatorConfig.getWorld(world.getName());
if(cfg == null) {
return baseCfg;
@ -130,8 +130,8 @@ public class ConfigManager {
this.orebfuscatorConfig.setProximityHiderEnabled();
logger.info(Globals.LogPrefix + "Proximity Hider is " + (this.orebfuscatorConfig.isProximityHiderEnabled() ? "Enabled": "Disabled"));
this.logger.info(Globals.LogPrefix + "Proximity Hider is " + (this.orebfuscatorConfig.isProximityHiderEnabled() ? "Enabled": "Disabled"));
save();
}

View File

@ -7,6 +7,7 @@ package com.lishid.orebfuscator.config;
import java.util.Map;
import com.lishid.orebfuscator.utils.Globals;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
@ -199,10 +200,24 @@ public class OrebfuscatorConfig {
this.netherWorld = value;
}
public Map<String, WorldConfig> getWorlds() {
return this.worlds;
public String getWorldNames() {
String worldNames = "";
for(WorldConfig world : this.worlds.values()) {
if(worldNames.length() > 0) {
worldNames += ", ";
}
worldNames += world.getName();
}
return worldNames;
}
public WorldConfig getWorld(String name) {
return this.worlds.get(name.toLowerCase());
}
public void setWorlds(Map<String, WorldConfig> value) {
this.worlds = value;
}

View File

@ -31,6 +31,7 @@ public class ProximityHiderConfig {
private Integer y;
private Boolean useSpecialBlock;
private Boolean obfuscateAboveY;
private Boolean useFastGazeCheck;
private Integer[] proximityHiderBlockIds;
private BlockSetting[] proximityHiderBlockSettings;
private int[] proximityHiderBlockMatrix;
@ -43,6 +44,7 @@ public class ProximityHiderConfig {
this.y = 255;
this.useSpecialBlock = true;
this.obfuscateAboveY = false;
this.useFastGazeCheck = true;
this.proximityHiderBlockIds = defaultProximityHiderBlockIds;
}
@ -80,6 +82,10 @@ public class ProximityHiderConfig {
this.proximityHiderBlockSettings = baseCfg.proximityHiderBlockSettings.clone();
}
if (this.useFastGazeCheck == null) {
this.useFastGazeCheck = baseCfg.useFastGazeCheck;
}
setProximityHiderBlockMatrix();
}
@ -171,6 +177,14 @@ public class ProximityHiderConfig {
}
}
}
public Boolean isUseFastGazeCheck() {
return this.useFastGazeCheck;
}
public void setUseFastGazeCheck(Boolean value) {
this.useFastGazeCheck = value;
}
// Help methods

View File

@ -12,6 +12,7 @@ import java.util.HashSet;
import java.util.List;
public class WorldConfig {
private String name;
private Boolean enabled;
private Boolean darknessHideBlocks;
private Boolean antiTexturePackAndFreecam;
@ -107,6 +108,14 @@ public class WorldConfig {
public boolean isInitialized() {
return this.initialized;
}
public String getName() {
return this.name;
}
public void setName(String value) {
this.name = value;
}
public Boolean isEnabled() {
return this.enabled;
@ -218,10 +227,6 @@ public class WorldConfig {
return this.randomBlocks;
}
public Integer[] getRandomBlocks2() {
return this.randomBlocks2;
}
public void setRandomBlocks(Integer[] values) {
this.randomBlocks = values;
this.randomBlocks2 = values;
@ -279,10 +284,6 @@ public class WorldConfig {
public ProximityHiderConfig getProximityHiderConfig() {
return this.proximityHiderConfig;
}
public void setProximityHiderConfig(ProximityHiderConfig value) {
this.proximityHiderConfig = value;
}
// Helper methods

View File

@ -5,13 +5,7 @@
package com.lishid.orebfuscator.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -63,7 +57,7 @@ public class WorldReader {
this.endWorld = readWorldByType(keys, WorldType.TheEnd, this.defaultWorld);
this.netherWorld = readWorldByType(keys, WorldType.Nether, this.defaultWorld);
this.worlds = new WeakHashMap<String, WorldConfig>();
this.worlds = new HashMap<String, WorldConfig>();
for(String key : keys) {
readWorldsByName("Worlds." + key);
@ -105,6 +99,8 @@ public class WorldReader {
}
world = readWorld(worldPath, world, worldType, worldType == WorldType.Default);
this.logger.log(Level.INFO, Globals.LogPrefix + "World type '" + worldType + "' has been read.");
break;
}
}
@ -124,6 +120,8 @@ public class WorldReader {
world = createNetherWorld(createPath("Worlds", "Nether", getConfig()));
break;
}
this.logger.log(Level.WARNING, Globals.LogPrefix + "World type '" + worldType + "' has been created.");
}
world.init(baseWorld);
@ -142,7 +140,12 @@ public class WorldReader {
String key = name.toLowerCase();
if(!this.worlds.containsKey(key)) {
this.worlds.put(key, readWorld(worldPath, null, WorldType.Default, false));
WorldConfig world = readWorld(worldPath, null, WorldType.Default, false);
world.setName(name);
this.worlds.put(key, world);
this.logger.log(Level.INFO, Globals.LogPrefix + "World name '" + name + "' has been read.");
}
}
}
@ -228,6 +231,7 @@ public class WorldReader {
Boolean useYLocationProximity = getBoolean(sectionPath + ".ObfuscateAboveY", cfg.isObfuscateAboveY(), withSave);
Integer[] proximityHiderBlockIds = this.materialReader.getMaterialIdsByPath(sectionPath + ".ProximityHiderBlocks", cfg.getProximityHiderBlockIds(), withSave);
ProximityHiderConfig.BlockSetting[] proximityHiderBlockSettings = readProximityHiderBlockSettings(sectionPath + ".ProximityHiderBlockSettings", cfg.getProximityHiderBlockSettings());
Boolean useFastGazeCheck = getBoolean(sectionPath + ".UseFastGazeCheck", cfg.isUseFastGazeCheck(), withSave);
cfg.setEnabled(enabled);
cfg.setDistance(distance);
@ -237,6 +241,7 @@ public class WorldReader {
cfg.setObfuscateAboveY(useYLocationProximity);
cfg.setProximityHiderBlockIds(proximityHiderBlockIds);
cfg.setProximityHiderBlockSettings(proximityHiderBlockSettings);
cfg.setUseFastGazeCheck(useFastGazeCheck);
}
private ProximityHiderConfig.BlockSetting[] readProximityHiderBlockSettings(

View File

@ -48,23 +48,35 @@ public class ProtocolLibHook {
this.manager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
@Override
public void onPacketSending(PacketEvent event) {
PacketContainer packet = event.getPacket();
StructureModifier<Integer> ints = packet.getIntegers();
StructureModifier<byte[]> byteArray = packet.getByteArrays();
StructureModifier<Boolean> bools = packet.getBooleans();
ChunkData chunkData = new ChunkData();
chunkData.chunkX = ints.read(0);
chunkData.chunkZ = ints.read(1);
chunkData.groundUpContinuous = bools.read(0);
chunkData.primaryBitMask = ints.read(2);
chunkData.data = byteArray.read(0);
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
try {
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, event.getPlayer());
Player player = event.getPlayer();
if (!Orebfuscator.config.isEnabled() || !Orebfuscator.config.obfuscateForPlayer(player)) {
return;
}
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
if(!worldConfig.isEnabled()) {
return;
}
PacketContainer packet = event.getPacket();
StructureModifier<Integer> ints = packet.getIntegers();
StructureModifier<byte[]> byteArray = packet.getByteArrays();
StructureModifier<Boolean> bools = packet.getBooleans();
ChunkData chunkData = new ChunkData();
chunkData.chunkX = ints.read(0);
chunkData.chunkZ = ints.read(1);
chunkData.groundUpContinuous = bools.read(0);
chunkData.primaryBitMask = ints.read(2);
chunkData.data = byteArray.read(0);
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, player, worldConfig);
if(newData != null) {
byteArray.write(0, newData);

View File

@ -42,19 +42,9 @@ import com.lishid.orebfuscator.types.BlockState;
public class Calculations {
private static Random random = new Random();
public static byte[] obfuscateOrUseCache(ChunkData chunkData, Player player) throws IOException {
public static byte[] obfuscateOrUseCache(ChunkData chunkData, Player player, WorldConfig worldConfig) throws IOException {
if(chunkData.primaryBitMask == 0) return null;
if (!Orebfuscator.config.isEnabled() || !Orebfuscator.config.obfuscateForPlayer(player)) {
return null;
}
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
if(!worldConfig.isEnabled()) {
return null;
}
byte[] output;
ObfuscatedCachedChunk cache = tryUseCache(chunkData, player);

View File

@ -145,6 +145,9 @@ public class ProximityHider extends Thread implements Runnable {
ArrayList<BlockCoord> removedBlocks = new ArrayList<BlockCoord>();
Location playerLocation = p.getLocation();
// 4.3.1 -- GAZE CHECK
Location playerEyes = p.getEyeLocation();
// 4.3.1 -- GAZE CHECK END
int minChunkX = (playerLocation.getBlockX() >> 4) - checkRadius;
int maxChunkX = minChunkX + (checkRadius << 1);
int minChunkZ = (playerLocation.getBlockZ() >> 4) - checkRadius;
@ -167,19 +170,23 @@ public class ProximityHider extends Thread implements Runnable {
Location blockLocation = new Location(localPlayerInfo.getWorld(), b.x, b.y, b.z);
if (proximityHider.isObfuscateAboveY() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
removedBlocks.add(b);
BlockState blockState = Orebfuscator.nms.getBlockState(localPlayerInfo.getWorld(), b.x, b.y, b.z);
if (blockState != null) {
DeprecatedMethods.sendBlockChange(p, blockLocation, blockState);
final BlockCoord block = b;
final Player player = p;
Orebfuscator.instance.runTask(new Runnable() {
public void run() {
Orebfuscator.nms.updateBlockTileEntity(block, player);
}
});
// 4.3.1 -- GAZE CHECK
if (!proximityHider.isUseFastGazeCheck() || doFastCheck(blockLocation, playerEyes, localPlayerInfo.getWorld())) {
// 4.3.1 -- GAZE CHECK END
removedBlocks.add(b);
BlockState blockState = Orebfuscator.nms.getBlockState(localPlayerInfo.getWorld(), b.x, b.y, b.z);
if (blockState != null) {
DeprecatedMethods.sendBlockChange(p, blockLocation, blockState);
final BlockCoord block = b;
final Player player = p;
Orebfuscator.instance.runTask(new Runnable() {
public void run() {
Orebfuscator.nms.updateBlockTileEntity(block, player);
}
});
}
}
}
}
@ -199,6 +206,74 @@ public class ProximityHider extends Thread implements Runnable {
running = false;
}
/**
* Basic idea here is to take some rays from the considered block to the player's eyes, and decide if
* any of those rays can reach the eyes unimpeded.
*
* @param block the starting block
* @param eyes the destination eyes
* @param player the player world we are testing for
* @return true if unimpeded path, false otherwise
*/
private boolean doFastCheck(Location block, Location eyes, World player) {
double ex = eyes.getX();
double ey = eyes.getY();
double ez = eyes.getZ();
double x = block.getBlockX();
double y = block.getBlockY();
double z = block.getBlockZ();
return // midfaces
fastAABBRayCheck(x, y, z, x , y+0.5, z+0.5, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+0.5, y , z+0.5, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+0.5, y+0.5, z , ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+0.5, y+1.0, z+0.5, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+0.5, y+0.5, z+1.0, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+1.0, y+0.5, z+0.5, ex, ey, ez, player) ||
// corners
fastAABBRayCheck(x, y, z, x , y , z , ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+1, y , z , ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x , y+1, z , ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+1, y+1, z , ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x , y , z+1, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+1, y , z+1, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x , y+1, z+1, ex, ey, ez, player) ||
fastAABBRayCheck(x, y, z, x+1, y+1, z+1, ex, ey, ez, player);
}
private boolean fastAABBRayCheck(double bx, double by, double bz, double x, double y, double z, double ex, double ey, double ez, World world) {
double fx = ex - x;
double fy = ey - y;
double fz = ez - z;
double absFx = Math.abs(fx);
double absFy = Math.abs(fy);
double absFz = Math.abs(fz);
double s = Math.max(absFx, Math.max(absFy, absFz));
if (s < 1) return true; // on top / inside
double lx, ly, lz;
fx = fx / s; // units of change along vector
fy = fy / s;
fz = fz / s;
while (s > 0) {
ex = ex - fx; // move along vector, we start _at_ the eye and move towards b
ey = ey - fy;
ez = ez - fz;
lx = Math.floor(ex);
ly = Math.floor(ey);
lz = Math.floor(ez);
if (lx == bx && ly == by && lz == bz) return true; // we've reached our starting block, don't test it.
int between = Orebfuscator.nms.getBlockId(world, (int) lx, (int) ly, (int) lz);
if (between > 0 && !Orebfuscator.config.isBlockTransparent(between)) { // -1 is null, 0 is air, above that? check with config.
return false; // fail on first hit, this ray is "blocked"
}
s--; // we stop
}
return true;
}
private static void restart() {
synchronized (thread) {

View File

@ -0,0 +1,116 @@
ConfigVersion: 13
Booleans:
UseCache: true
Enabled: true
UpdateOnDamage: true
NoObfuscationForMetadata: true
NoObfuscationForOps: false
NoObfuscationForPermission: false
LoginNotification: true
Integers:
MaxLoadedCacheFiles: 64
DeleteCacheFilesAfterDays: 0
EngineMode: 2
InitialRadius: 1
UpdateRadius: 2
Strings:
CacheLocation: orebfuscator_cache
NoObfuscationForMetadataTagName: NPC
Lists:
TransparentBlocks: []
NonTransparentBlocks: []
Worlds:
Default:
Types:
- DEFAULT
Enabled: false
AntiTexturePackAndFreecam: true
AirGeneratorMaxChance: 43
DarknessHideBlocks: false
BypassObfuscationForSignsWithText: false
DarknessBlocks:
- MOB_SPAWNER
- CHEST
Mode1Block: STONE
RandomBlocks: []
ObfuscateBlocks: []
ProximityHider:
Enabled: true
Distance: 8
SpecialBlock: STONE
Y: 255
UseSpecialBlock: true
ObfuscateAboveY: false
ProximityHiderBlocks:
- DISPENSER
- MOB_SPAWNER
- CHEST
- DIAMOND_ORE
- WORKBENCH
- FURNACE
- BURNING_FURNACE
- ENCHANTMENT_TABLE
- EMERALD_ORE
- ENDER_CHEST
- ANVIL
- TRAPPED_CHEST
UseFastGazeCheck: true
Normal:
Types:
- NORMAL
Mode1Block: STONE
RandomBlocks:
- STONE
- COBBLESTONE
- WOOD
- GOLD_ORE
- IRON_ORE
- COAL_ORE
- LAPIS_ORE
- TNT
- MOSSY_COBBLESTONE
- OBSIDIAN
- DIAMOND_ORE
- REDSTONE_ORE
- CLAY
- EMERALD_ORE
ObfuscateBlocks:
- GOLD_ORE
- IRON_ORE
- COAL_ORE
- LAPIS_ORE
- CHEST
- DIAMOND_ORE
- REDSTONE_ORE
- GLOWING_REDSTONE_ORE
- EMERALD_ORE
- ENDER_CHEST
TheEnd:
Types:
- THE_END
Mode1Block: ENDER_STONE
RandomBlocks:
- BEDROCK
- OBSIDIAN
- ENDER_STONE
- PURPUR_BLOCK
- END_BRICKS
ObfuscateBlocks:
- ENDER_STONE
Nether:
Types:
- NETHER
Mode1Block: NETHERRACK
RandomBlocks:
- GRAVEL
- NETHERRACK
- SOUL_SAND
- NETHER_BRICK
- QUARTZ_ORE
ObfuscateBlocks:
- NETHERRACK
- QUARTZ_ORE
EnabledWorlds:
Names:
- world
Enabled: true