diff --git a/pom.xml b/pom.xml
index 6e78221d..21ac04d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.lishid
orebfuscator
- 4.0.5-SNAPSHOT
+ 4.0.7-SNAPSHOT
jar
Orebfuscator4
diff --git a/src/main/java/com/lishid/orebfuscator/Orebfuscator.java b/src/main/java/com/lishid/orebfuscator/Orebfuscator.java
index aa4ccef2..7f08ffcf 100644
--- a/src/main/java/com/lishid/orebfuscator/Orebfuscator.java
+++ b/src/main/java/com/lishid/orebfuscator/Orebfuscator.java
@@ -16,9 +16,6 @@
package com.lishid.orebfuscator;
-import java.io.File;
-import java.io.IOException;
-import java.util.Objects;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@@ -34,7 +31,6 @@
import com.lishid.orebfuscator.listeners.OrebfuscatorBlockListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorEntityListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorPlayerListener;
-import com.lishid.orebfuscator.utils.FileHelper;
/**
* Orebfuscator Anti X-RAY
@@ -45,8 +41,11 @@ public class Orebfuscator extends JavaPlugin {
public static final Logger logger = Logger.getLogger("Minecraft.OFC");
public static Orebfuscator instance;
- public static boolean usePL = false;
- public static boolean useSpigot = false;
+
+ private boolean isProtocolLibFound;
+ public boolean getIsProtocolLibFound() {
+ return this.isProtocolLibFound;
+ }
@Override
public void onEnable() {
@@ -57,49 +56,24 @@ public void onEnable() {
// Load configurations
OrebfuscatorConfig.load();
- //Make sure cache is cleared if config was changed since last start
- checkCacheAndConfigSynchronized();
+ this.isProtocolLibFound = pm.getPlugin("ProtocolLib") != null;
+
+ if (!this.isProtocolLibFound) {
+ Orebfuscator.log("ProtocolLib is not found! Plugin cannot be enabled.");
+ return;
+ }
// Orebfuscator events
pm.registerEvents(new OrebfuscatorPlayerListener(), this);
pm.registerEvents(new OrebfuscatorEntityListener(), this);
pm.registerEvents(new OrebfuscatorBlockListener(), this);
- if (pm.getPlugin("ProtocolLib") != null) {
- Orebfuscator.log("ProtocolLib found! Hooking into ProtocolLib.");
- (new ProtocolLibHook()).register(this);
- usePL = true;
- }
- }
-
- private void checkCacheAndConfigSynchronized() {
- String configContent = getConfig().saveToString();
-
- File cacheFolder = OrebfuscatorConfig.getCacheFolder();
- File cacheConfigFile = new File(cacheFolder, "cache_config.yml");
-
- try {
- String cacheConfigContent = FileHelper.readFile(cacheConfigFile);
-
- if(Objects.equals(configContent, cacheConfigContent)) return;
-
- Orebfuscator.log("Clear cache.");
-
- if(cacheFolder.exists()) {
- FileHelper.delete(cacheFolder);
- }
-
- cacheFolder.mkdirs();
-
- getConfig().save(cacheConfigFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ (new ProtocolLibHook()).register(this);
}
@Override
public void onDisable() {
- ObfuscatedDataCache.clearCache();
+ ObfuscatedDataCache.closeCacheFiles();
BlockHitManager.clearAll();
getServer().getScheduler().cancelTasks(this);
}
diff --git a/src/main/java/com/lishid/orebfuscator/OrebfuscatorConfig.java b/src/main/java/com/lishid/orebfuscator/OrebfuscatorConfig.java
index 1391b6a8..2d41951e 100644
--- a/src/main/java/com/lishid/orebfuscator/OrebfuscatorConfig.java
+++ b/src/main/java/com/lishid/orebfuscator/OrebfuscatorConfig.java
@@ -29,7 +29,6 @@
import org.bukkit.Bukkit;
import org.bukkit.World;
-import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@@ -37,7 +36,7 @@
public class OrebfuscatorConfig {
// Constant/persistent data
- private static final int CONFIG_VERSION = 10;
+ private static final int CONFIG_VERSION = 12;
private static Random random = new Random();
private static int AvailableProcessors = Runtime.getRuntime().availableProcessors();
@@ -186,7 +185,7 @@ public static boolean skipProximityHiderCheck(int y) {
return UseYLocationProximity && y < ProximityHiderEnd;
}
- public static boolean proximityHiderDeobfuscate(int playerY, Block block) {
+ public static boolean proximityHiderDeobfuscate() {
return UseYLocationProximity;
}
@@ -378,24 +377,6 @@ public static void load() {
// Version check
int version = getInt("ConfigVersion", CONFIG_VERSION);
if (version < CONFIG_VERSION) {
- // Orebfuscator.log("Configuration out of date. Recreating new configuration file.");
- // File configFile = new File(Orebfuscator.instance.getDataFolder(), "config.yml");
- // File destination = new File(Orebfuscator.instance.getDataFolder(), "config_old.yml");
- // if (destination.exists())
- // {
- // try
- // {
- // destination.delete();
- // }
- // catch (Exception e)
- // {
- // Orebfuscator.log(e);
- // }
- // }
- // configFile.renameTo(destination);
- // reload();
-
- ObfuscatedDataCache.ClearCache();
setData("ConfigVersion", CONFIG_VERSION);
}
@@ -460,6 +441,13 @@ public static void load() {
save();
createPaletteBlocks();
+
+ //Make sure cache is cleared if config was changed since last start
+ try {
+ ObfuscatedDataCache.checkCacheAndConfigSynchronized();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
private static void createPaletteBlocks() {
diff --git a/src/main/java/com/lishid/orebfuscator/cache/ObfuscatedDataCache.java b/src/main/java/com/lishid/orebfuscator/cache/ObfuscatedDataCache.java
index 0820d705..3792a5f6 100644
--- a/src/main/java/com/lishid/orebfuscator/cache/ObfuscatedDataCache.java
+++ b/src/main/java/com/lishid/orebfuscator/cache/ObfuscatedDataCache.java
@@ -16,15 +16,19 @@
package com.lishid.orebfuscator.cache;
-import com.lishid.orebfuscator.Orebfuscator;
-import com.lishid.orebfuscator.OrebfuscatorConfig;
-import com.lishid.orebfuscator.internal.ChunkCache;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.IOException;
+import java.util.Objects;
+
+import com.lishid.orebfuscator.Orebfuscator;
+import com.lishid.orebfuscator.OrebfuscatorConfig;
+import com.lishid.orebfuscator.internal.ChunkCache;
+import com.lishid.orebfuscator.utils.FileHelper;
public class ObfuscatedDataCache {
+ private static final String cacheFileName = "cache_config.yml";
private static ChunkCache internalCache;
private static ChunkCache getInternalCache() {
@@ -34,8 +38,37 @@ private static ChunkCache getInternalCache() {
return internalCache;
}
- public static void clearCache() {
- getInternalCache().clearCache();
+ public static void closeCacheFiles() {
+ getInternalCache().closeCacheFiles();
+ }
+
+ public static void checkCacheAndConfigSynchronized() throws IOException {
+ String configContent = Orebfuscator.instance.getConfig().saveToString();
+
+ File cacheFolder = OrebfuscatorConfig.getCacheFolder();
+ File cacheConfigFile = new File(cacheFolder, cacheFileName);
+ String cacheConfigContent = FileHelper.readFile(cacheConfigFile);
+
+ if(Objects.equals(configContent, cacheConfigContent)) return;
+
+ clearCache();
+ }
+
+ public static void clearCache() throws IOException {
+ closeCacheFiles();
+
+ File cacheFolder = OrebfuscatorConfig.getCacheFolder();
+ File cacheConfigFile = new File(cacheFolder, cacheFileName);
+
+ if(cacheFolder.exists()) {
+ FileHelper.delete(cacheFolder);
+ }
+
+ Orebfuscator.log("Cache cleared.");
+
+ cacheFolder.mkdirs();
+
+ Orebfuscator.instance.getConfig().save(cacheConfigFile);
}
public static DataInputStream getInputStream(File folder, int x, int z) {
@@ -45,28 +78,4 @@ public static DataInputStream getInputStream(File folder, int x, int z) {
public static DataOutputStream getOutputStream(File folder, int x, int z) {
return getInternalCache().getOutputStream(folder, x, z);
}
-
- public static void ClearCache() {
- getInternalCache().clearCache();
- try {
- DeleteDir(OrebfuscatorConfig.getCacheFolder());
- } catch (Exception e) {
- Orebfuscator.log(e);
- }
- }
-
- private static void DeleteDir(File dir) {
- try {
- if (!dir.exists())
- return;
-
- if (dir.isDirectory())
- for (File f : dir.listFiles())
- DeleteDir(f);
-
- dir.delete();
- } catch (Exception e) {
- Orebfuscator.log(e);
- }
- }
}
\ No newline at end of file
diff --git a/src/main/java/com/lishid/orebfuscator/chunkmap/ChunkMapManager.java b/src/main/java/com/lishid/orebfuscator/chunkmap/ChunkMapManager.java
index 81b5cbfd..2275d9ea 100644
--- a/src/main/java/com/lishid/orebfuscator/chunkmap/ChunkMapManager.java
+++ b/src/main/java/com/lishid/orebfuscator/chunkmap/ChunkMapManager.java
@@ -90,6 +90,10 @@ public static int getBlockIdFromData(int blockData) {
return blockData >>> 4;
}
+ public static int getBlockMetaFromData(int blockData) {
+ return blockData & 0xf;
+ }
+
public static int blockStateToData(BlockState blockState) {
return (blockState.id << 4) | blockState.meta;
}
diff --git a/src/main/java/com/lishid/orebfuscator/commands/OrebfuscatorCommandExecutor.java b/src/main/java/com/lishid/orebfuscator/commands/OrebfuscatorCommandExecutor.java
index e0b4f897..f1ed8a23 100644
--- a/src/main/java/com/lishid/orebfuscator/commands/OrebfuscatorCommandExecutor.java
+++ b/src/main/java/com/lishid/orebfuscator/commands/OrebfuscatorCommandExecutor.java
@@ -16,6 +16,8 @@
package com.lishid.orebfuscator.commands;
+import java.io.IOException;
+
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -165,11 +167,16 @@ else if (args[0].equalsIgnoreCase("reload")) {
}
else if (args[0].equalsIgnoreCase("status")) {
- Orebfuscator.message(sender, "Orebfuscator " + Orebfuscator.instance.getDescription().getVersion() + " is: " + (OrebfuscatorConfig.Enabled ? "Enabled" : "Disabled"));
+ String status = Orebfuscator.instance.getIsProtocolLibFound()
+ ? (OrebfuscatorConfig.Enabled ? "Enabled" : "Disabled")
+ : "ProtocolLib is not found! Plugin cannot be enabled.";
+
+ Orebfuscator.message(sender, "Orebfuscator " + Orebfuscator.instance.getDescription().getVersion() + " is: " + status);
Orebfuscator.message(sender, "EngineMode: " + OrebfuscatorConfig.EngineMode);
Orebfuscator.message(sender, "Caching: " + (OrebfuscatorConfig.UseCache ? "Enabled" : "Disabled"));
Orebfuscator.message(sender, "ProximityHider: " + (OrebfuscatorConfig.UseProximityHider ? "Enabled" : "Disabled"));
+ Orebfuscator.message(sender, "DarknessHideBlocks: " + (OrebfuscatorConfig.DarknessHideBlocks ? "Enabled": "Disabled"));
Orebfuscator.message(sender, "Initial Obfuscation Radius: " + OrebfuscatorConfig.InitialRadius);
Orebfuscator.message(sender, "Update Radius: " + OrebfuscatorConfig.UpdateRadius);
@@ -179,8 +186,12 @@ else if (args[0].equalsIgnoreCase("status")) {
}
else if (args[0].equalsIgnoreCase("clearcache")) {
- ObfuscatedDataCache.ClearCache();
- Orebfuscator.message(sender, "Cache cleared.");
+ try {
+ ObfuscatedDataCache.clearCache();
+ Orebfuscator.message(sender, "Cache cleared.");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
else if (args[0].equalsIgnoreCase("debug")) {
diff --git a/src/main/java/com/lishid/orebfuscator/hook/ProtocolLibHook.java b/src/main/java/com/lishid/orebfuscator/hook/ProtocolLibHook.java
index 86c5a18f..590fefde 100644
--- a/src/main/java/com/lishid/orebfuscator/hook/ProtocolLibHook.java
+++ b/src/main/java/com/lishid/orebfuscator/hook/ProtocolLibHook.java
@@ -28,7 +28,6 @@
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
-import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.chunkmap.ChunkData;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.obfuscation.Calculations;
diff --git a/src/main/java/com/lishid/orebfuscator/internal/ChunkCache.java b/src/main/java/com/lishid/orebfuscator/internal/ChunkCache.java
index b535dce1..01840f24 100644
--- a/src/main/java/com/lishid/orebfuscator/internal/ChunkCache.java
+++ b/src/main/java/com/lishid/orebfuscator/internal/ChunkCache.java
@@ -44,7 +44,7 @@ private synchronized RegionFile getRegionFile(File folder, int x, int z) {
}
if (cachedRegionFiles.size() >= OrebfuscatorConfig.MaxLoadedCacheFiles) {
- clearCache();
+ closeCacheFiles();
}
regionFile = new RegionFile(file);
@@ -73,7 +73,7 @@ public DataOutputStream getOutputStream(File folder, int x, int z) {
return regionFile.b(x & 0x1F, z & 0x1F);
}
- public synchronized void clearCache() {
+ public synchronized void closeCacheFiles() {
for (RegionFile regionFile : cachedRegionFiles.values()) {
try {
if (regionFile != null)
diff --git a/src/main/java/com/lishid/orebfuscator/internal/MinecraftInternals.java b/src/main/java/com/lishid/orebfuscator/internal/MinecraftInternals.java
index 421b83b0..077ecf5a 100644
--- a/src/main/java/com/lishid/orebfuscator/internal/MinecraftInternals.java
+++ b/src/main/java/com/lishid/orebfuscator/internal/MinecraftInternals.java
@@ -21,6 +21,7 @@
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.TileEntity;
+import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_9_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.block.CraftBlock;
@@ -30,8 +31,8 @@
//Volatile
public class MinecraftInternals {
- public static void updateBlockTileEntity(org.bukkit.block.Block block, Player player) {
- CraftWorld world = (CraftWorld) block.getWorld();
+ public static void updateBlockTileEntity(Block block, Player player) {
+ CraftWorld world = (CraftWorld) player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (tileEntity == null) {
return;
diff --git a/src/main/java/com/lishid/orebfuscator/listeners/OrebfuscatorBlockListener.java b/src/main/java/com/lishid/orebfuscator/listeners/OrebfuscatorBlockListener.java
index bed0c608..4b6ad1e7 100644
--- a/src/main/java/com/lishid/orebfuscator/listeners/OrebfuscatorBlockListener.java
+++ b/src/main/java/com/lishid/orebfuscator/listeners/OrebfuscatorBlockListener.java
@@ -16,15 +16,20 @@
package com.lishid.orebfuscator.listeners;
-import com.lishid.orebfuscator.OrebfuscatorConfig;
-import com.lishid.orebfuscator.hithack.BlockHitManager;
-import com.lishid.orebfuscator.obfuscation.BlockUpdate;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
-import org.bukkit.event.block.*;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.BlockDamageEvent;
+import org.bukkit.event.block.BlockPhysicsEvent;
+import org.bukkit.event.block.BlockPistonExtendEvent;
+import org.bukkit.event.block.BlockPistonRetractEvent;
+
+import com.lishid.orebfuscator.OrebfuscatorConfig;
+import com.lishid.orebfuscator.hithack.BlockHitManager;
+import com.lishid.orebfuscator.obfuscation.BlockUpdate;
public class OrebfuscatorBlockListener implements Listener {
diff --git a/src/main/java/com/lishid/orebfuscator/obfuscation/Calculations.java b/src/main/java/com/lishid/orebfuscator/obfuscation/Calculations.java
index 7aae6964..0a3aa023 100644
--- a/src/main/java/com/lishid/orebfuscator/obfuscation/Calculations.java
+++ b/src/main/java/com/lishid/orebfuscator/obfuscation/Calculations.java
@@ -100,13 +100,14 @@ public static byte[] ObfuscateOrUseCache(ChunkData chunkData, Player player) thr
if(chunkData.useCache) {
// Save cache
int[] proximityList = new int[proximityBlocks.size() * 3];
+ int index = 0;
for (int i = 0; i < proximityBlocks.size(); i++) {
- Block b = proximityBlocks.get(i);
+ Block b = proximityBlocks.get(i);
if (b != null) {
- proximityList[i * 3] = b.getX();
- proximityList[i * 3 + 1] = b.getY();
- proximityList[i * 3 + 2] = b.getZ();
+ proximityList[index++] = b.getX();
+ proximityList[index++] = b.getY();
+ proximityList[index++] = b.getZ();
}
}
@@ -175,7 +176,7 @@ private static byte[] Obfuscate(ChunkData chunkData, Player player, ArrayList= world.getMaxHeight() || y < 0)
return true;
- ChunkData chunkData = manager.getChunkData();
- int blockData = manager.get(x, y, z);
- int id;
-
- if (blockData < 0) {
- if (CalculationsUtil.isChunkLoaded(world, chunkData.chunkX, chunkData.chunkZ)) {
- id = world.getBlockTypeIdAt(x, y, z);
- } else {
- id = 1;
- chunkData.useCache = false;
- }
- } else {
- id = ChunkMapManager.getBlockIdFromData(blockData);
- }
-
- if (id != currentBlockID && OrebfuscatorConfig.isBlockTransparent(id)) {
- return true;
+ if(checkCurrentBlock) {
+ ChunkData chunkData = manager.getChunkData();
+ int blockData = manager.get(x, y, z);
+ int id;
+
+ if (blockData < 0) {
+ if (CalculationsUtil.isChunkLoaded(world, chunkData.chunkX, chunkData.chunkZ)) {
+ id = world.getBlockTypeIdAt(x, y, z);
+ } else {
+ id = 1;
+ chunkData.useCache = false;
+ }
+ } else {
+ id = ChunkMapManager.getBlockIdFromData(blockData);
+ }
+
+ if (OrebfuscatorConfig.isBlockTransparent(id)) {
+ return true;
+ }
}
if (countdown == 0)
return false;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x, y + 1, z, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x, y + 1, z, countdown - 1))
return true;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x, y - 1, z, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x, y - 1, z, countdown - 1))
return true;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x + 1, y, z, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x + 1, y, z, countdown - 1))
return true;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x - 1, y, z, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x - 1, y, z, countdown - 1))
return true;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x, y, z + 1, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x, y, z + 1, countdown - 1))
return true;
- if (areAjacentBlocksTransparent(manager, world, currentBlockID, x, y, z - 1, countdown - 1))
+ if (areAjacentBlocksTransparent(manager, world, true, x, y, z - 1, countdown - 1))
return true;
return false;
diff --git a/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHider.java b/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHider.java
index 8b70cbc3..fb70f6b9 100644
--- a/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHider.java
+++ b/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHider.java
@@ -18,14 +18,12 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.bukkit.Location;
+import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@@ -39,7 +37,7 @@ public class ProximityHider extends Thread implements Runnable {
private static ProximityHider thread = new ProximityHider();
- private Map> proximityHiderTrackerLocal = new WeakHashMap>();
+ private Map proximityHiderTrackerLocal = new WeakHashMap();
private long lastExecute = System.currentTimeMillis();
private AtomicBoolean kill = new AtomicBoolean(false);
private static boolean running = false;
@@ -75,6 +73,12 @@ public void run() {
return;
}
+ int checkRadius = OrebfuscatorConfig.ProximityHiderDistance >> 4;
+
+ if((OrebfuscatorConfig.ProximityHiderDistance & 0xf) != 0) {
+ checkRadius++;
+ }
+
HashMap checkPlayers = new HashMap();
synchronized (playersToCheck) {
@@ -107,59 +111,82 @@ public void run() {
continue;
}
}
-
- Set blocks = proximityHiderTrackerLocal.get(p);
- Set removedBlocks = new HashSet();
- if (blocks == null) {
- blocks = new HashSet();
- proximityHiderTrackerLocal.put(p, blocks);
+
+ ProximityHiderPlayer localPlayerInfo = proximityHiderTrackerLocal.get(p);
+
+ if(localPlayerInfo == null) {
+ proximityHiderTrackerLocal.put(p, localPlayerInfo = new ProximityHiderPlayer(p.getWorld()));
}
int y = (int) Math.floor(p.getLocation().getY());
- boolean skip = OrebfuscatorConfig.skipProximityHiderCheck(y);
-
synchronized (proximityHiderTracker) {
- Set synchronizedBlocks = proximityHiderTracker.get(p).blocks;
-
- if (synchronizedBlocks != null) {
- blocks.addAll(synchronizedBlocks);
- synchronizedBlocks.clear();
+ ProximityHiderPlayer playerInfo = proximityHiderTracker.get(p);
+
+ if (playerInfo != null) {
+ if(!localPlayerInfo.getWorld().equals(playerInfo.getWorld())) {
+ localPlayerInfo.setWorld(playerInfo.getWorld());
+ localPlayerInfo.clearChunks();
+ }
+
+ localPlayerInfo.copyChunks(playerInfo);
+ playerInfo.clearChunks();
}
}
- if (!skip) {
- for (Block b : blocks) {
- if (b == null || b.getWorld() == null || p.getWorld() == null) {
- removedBlocks.add(b);
- continue;
- }
-
- if (!p.getWorld().equals(b.getWorld())) {
- removedBlocks.add(b);
- continue;
- }
-
- if (OrebfuscatorConfig.proximityHiderDeobfuscate(y, b) || p.getLocation().distanceSquared(b.getLocation()) < distanceSquared) {
- removedBlocks.add(b);
-
- if (CalculationsUtil.isChunkLoaded(b.getWorld(), b.getChunk().getX(), b.getChunk().getZ())) {
- p.sendBlockChange(b.getLocation(), b.getTypeId(), b.getData());
- final Block block = b;
- final Player player = p;
- Orebfuscator.instance.runTask(new Runnable() {
- @Override
- public void run() {
- MinecraftInternals.updateBlockTileEntity(block, player);
- }
- });
- }
- }
- }
-
- for (Block b : removedBlocks) {
- blocks.remove(b);
- }
+ if (OrebfuscatorConfig.skipProximityHiderCheck(y)) continue;
+
+ if(localPlayerInfo.getWorld() == null || p.getWorld() == null || !p.getWorld().equals(localPlayerInfo.getWorld())) {
+ localPlayerInfo.clearChunks();
+ continue;
+ }
+
+ ArrayList removedBlocks = new ArrayList();
+ Location playerLocation = p.getLocation();
+ int minChunkX = (playerLocation.getBlockX() >> 4) - checkRadius;
+ int maxChunkX = minChunkX + (checkRadius << 1);
+ int minChunkZ = (playerLocation.getBlockZ() >> 4) - checkRadius;
+ int maxChunkZ = minChunkZ + (checkRadius << 1);
+
+ for(int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
+ for(int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
+ ArrayList blocks = localPlayerInfo.getBlocks(chunkX, chunkZ);
+
+ if(blocks == null) continue;
+
+ removedBlocks.clear();
+
+ for (Block b : blocks) {
+ if (b == null) {
+ removedBlocks.add(b);
+ continue;
+ }
+
+ Location blockLocation = b.getLocation();
+
+ if (OrebfuscatorConfig.proximityHiderDeobfuscate() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
+ removedBlocks.add(b);
+
+ if (CalculationsUtil.isChunkLoaded(localPlayerInfo.getWorld(), b.getChunk().getX(), b.getChunk().getZ())) {
+ p.sendBlockChange(blockLocation, b.getTypeId(), (byte)b.getData());
+ final Block block = b;
+ final Player player = p;
+ Orebfuscator.instance.runTask(new Runnable() {
+ @Override
+ public void run() {
+ MinecraftInternals.updateBlockTileEntity(block, player);
+ }
+ });
+ }
+ }
+ }
+
+ if(blocks.size() == removedBlocks.size()) {
+ localPlayerInfo.removeChunk(chunkX, chunkZ);
+ } else {
+ blocks.removeAll(removedBlocks);
+ }
+ }
}
}
} catch (Exception e) {
@@ -182,28 +209,26 @@ public static void restart() {
}
}
- public static void addProximityBlocks(Player player, ArrayList blocks) {
+ public static void addProximityBlocks(Player player, int chunkX, int chunkZ, ArrayList blocks) {
if (!OrebfuscatorConfig.UseProximityHider) return;
restart();
synchronized (proximityHiderTracker) {
- ProximityHiderPlayer playerInfo;
- UUID worldUID = player.getWorld().getUID();
+ ProximityHiderPlayer playerInfo = proximityHiderTracker.get(player);
+ World world = player.getWorld();
- if (!proximityHiderTracker.containsKey(player)) {
- proximityHiderTracker.put(player, playerInfo = new ProximityHiderPlayer(worldUID));
- } else {
- playerInfo = proximityHiderTracker.get(player);
-
- if(!playerInfo.worldUID.equals(worldUID)) {
- playerInfo.worldUID = worldUID;
- playerInfo.blocks.clear();
- }
+ if (playerInfo == null) {
+ proximityHiderTracker.put(player, playerInfo = new ProximityHiderPlayer(world));
+ } else if(!playerInfo.getWorld().equals(world)) {
+ playerInfo.setWorld(world);
+ playerInfo.clearChunks();
}
- for (Block b : blocks) {
- playerInfo.blocks.add(b);
+ if(blocks.size() > 0) {
+ playerInfo.putBlocks(chunkX, chunkZ, blocks);
+ } else {
+ playerInfo.removeChunk(chunkX, chunkZ);
}
}
}
@@ -216,13 +241,14 @@ public static void clearPlayer(Player player) {
public static void clearBlocksForOldWorld(Player player) {
synchronized (ProximityHider.proximityHiderTracker) {
- if(ProximityHider.proximityHiderTracker.containsKey(player)) {
- ProximityHiderPlayer playerInfo = ProximityHider.proximityHiderTracker.get(player);
- UUID worldUID = player.getWorld().getUID();
+ ProximityHiderPlayer playerInfo = ProximityHider.proximityHiderTracker.get(player);
+
+ if(playerInfo != null) {
+ World world = player.getWorld();
- if(!playerInfo.worldUID.equals(worldUID)) {
- playerInfo.worldUID = worldUID;
- playerInfo.blocks.clear();
+ if(!playerInfo.getWorld().equals(world)) {
+ playerInfo.setWorld(world);
+ playerInfo.clearChunks();
}
}
}
diff --git a/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHiderPlayer.java b/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHiderPlayer.java
index e50a5d11..aa89d21f 100644
--- a/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHiderPlayer.java
+++ b/src/main/java/com/lishid/orebfuscator/obfuscation/ProximityHiderPlayer.java
@@ -5,18 +5,54 @@
package com.lishid.orebfuscator.obfuscation;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.World;
import org.bukkit.block.Block;
public class ProximityHiderPlayer {
- public UUID worldUID;
- public Set blocks;
+ private World world;
+ private Map> chunks;
- public ProximityHiderPlayer(UUID worldUID) {
- this.worldUID = worldUID;
- this.blocks = new HashSet();
+ public ProximityHiderPlayer(World world) {
+ this.world = world;
+ this.chunks = new HashMap>();
+ }
+
+ public World getWorld() {
+ return this.world;
+ }
+
+ public void setWorld(World world) {
+ this.world = world;
+ }
+
+ public void clearChunks() {
+ this.chunks.clear();
+ }
+
+ public void putBlocks(int chunkX, int chunkZ, ArrayList blocks) {
+ long key = getKey(chunkX, chunkZ);
+ this.chunks.put(key, blocks);
+ }
+
+ public ArrayList getBlocks(int chunkX, int chunkZ) {
+ long key = getKey(chunkX, chunkZ);
+ return this.chunks.get(key);
+ }
+
+ public void copyChunks(ProximityHiderPlayer playerInfo) {
+ this.chunks.putAll(playerInfo.chunks);
+ }
+
+ public void removeChunk(int chunkX, int chunkZ) {
+ long key = getKey(chunkX, chunkZ);
+ this.chunks.remove(key);
+ }
+
+ private static long getKey(int chunkX, int chunkZ) {
+ return ((chunkZ & 0xffffffffL) << 32) | (chunkX & 0xffffffffL);
}
}
diff --git a/src/main/resources/resources/transparent_blocks.txt b/src/main/resources/resources/transparent_blocks.txt
index b2d14fbc..617ac88a 100644
--- a/src/main/resources/resources/transparent_blocks.txt
+++ b/src/main/resources/resources/transparent_blocks.txt
@@ -9,7 +9,7 @@
8:true //minecraft:flowing_water
9:true //minecraft:water
10:true //minecraft:flowing_lava
-11:false //minecraft:lava
+11:true //minecraft:lava
12:false //minecraft:sand
13:false //minecraft:gravel
14:false //minecraft:gold_ore
@@ -118,7 +118,7 @@
117:true //minecraft:brewing_stand
118:true //minecraft:cauldron
119:true //minecraft:end_portal
-120:false //minecraft:end_portal_frame
+120:true //minecraft:end_portal_frame
121:false //minecraft:end_stone
122:true //minecraft:dragon_egg
123:false //minecraft:redstone_lamp
@@ -164,7 +164,7 @@
163:true //minecraft:acacia_stairs
164:true //minecraft:dark_oak_stairs
165:true //minecraft:slime
-166:false //minecraft:barrier
+166:true //minecraft:barrier
167:true //minecraft:iron_trapdoor
168:false //minecraft:prismarine
169:false //minecraft:sea_lantern
@@ -206,8 +206,8 @@
205:true //minecraft:purpur_slab
206:false //minecraft:end_bricks
207:true //minecraft:beetroots
-208:false //minecraft:grass_path
-209:false //minecraft:end_gateway
+208:true //minecraft:grass_path
+209:true //minecraft:end_gateway
210:false //minecraft:repeating_command_block
211:false //minecraft:chain_command_block
212:true //minecraft:frosted_ice