Config is refactored

master
Aleksey-Terzi 2016-10-11 18:43:12 +03:00
parent 63be95ee87
commit 6082d4e743
19 changed files with 1470 additions and 920 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.lishid</groupId>
<artifactId>orebfuscator</artifactId>
<version>4.1.10-SNAPSHOT</version>
<version>4.1.11-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Orebfuscator4</name>

View File

@ -16,6 +16,7 @@
package com.lishid.orebfuscator;
import java.io.IOException;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
@ -27,6 +28,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.orebfuscator.cache.CacheCleaner;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.commands.OrebfuscatorCommandExecutor;
import com.lishid.orebfuscator.config.ConfigManager12;
import com.lishid.orebfuscator.config.OrebfuscatorConfig;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.hook.ProtocolLibHook;
import com.lishid.orebfuscator.listeners.OrebfuscatorBlockListener;
@ -44,6 +47,8 @@ public class Orebfuscator extends JavaPlugin {
public static final Logger logger = Logger.getLogger("Minecraft.OFC");
public static Orebfuscator instance;
public static OrebfuscatorConfig config;
public static ConfigManager12 configManager;
public static INmsManager nms;
@ -62,7 +67,7 @@ public class Orebfuscator extends JavaPlugin {
nms = createNmsManager();
// Load configurations
OrebfuscatorConfig.load();
loadOrebfuscatorConfig();
this.isProtocolLibFound = pm.getPlugin("ProtocolLib") != null;
@ -80,9 +85,34 @@ public class Orebfuscator extends JavaPlugin {
(new ProtocolLibHook()).register(this);
// Run CacheCleaner
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new CacheCleaner(), 0, OrebfuscatorConfig.CacheCleanRate);
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new CacheCleaner(), 0, config.getCacheCleanRate());
}
public void loadOrebfuscatorConfig() {
if(config == null) {
config = new OrebfuscatorConfig();
configManager = new ConfigManager12(this, logger, config);
}
configManager.load();
ObfuscatedDataCache.resetCacheFolder();
nms.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());
//Make sure cache is cleared if config was changed since last start
try {
ObfuscatedDataCache.checkCacheAndConfigSynchronized();
} catch (IOException e) {
e.printStackTrace();
}
}
public void reloadOrebfuscatorConfig() {
reloadConfig();
loadOrebfuscatorConfig();
}
private static INmsManager createNmsManager() {
String serverVersion = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];

View File

@ -1,704 +0,0 @@
/*
* Copyright (C) 2011-2014 lishid. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lishid.orebfuscator;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
public class OrebfuscatorConfig {
private static class MaterialResult {
public int id;
public String name;
public MaterialResult(int id, String name) {
this.id = id;
this.name = name;
}
}
// Constant/persistent data
private static final int CONFIG_VERSION = 12;
private static Random random = new Random();
// Main engine config
public static boolean Enabled = true;
public static boolean UpdateOnDamage = true;
public static int EngineMode = 2;
public static int InitialRadius = 1;
public static int UpdateRadius = 2;
public static boolean UseWorldsAsBlacklist = true;
public static boolean NoObfuscationForMetadata = true;
public static String NoObfuscationForMetadataTagName = "NPC";
// Darkness
public static boolean DarknessHideBlocks = false;
// Caching
public static boolean UseCache = true;
public static int MaxLoadedCacheFiles = 64;
public static String CacheLocation = "orebfuscator_cache";
public static File CacheFolder = new File(Bukkit.getServer().getWorldContainer(), CacheLocation);
public static int DeleteCacheFilesAfterDays = 0;
// ProximityHider
public static int ProximityHiderRate = 500;
public static int ProximityHiderDistance = 8;
public static int ProximityHiderID = 1;
public static int ProximityHiderEnd = 255;
public static boolean UseProximityHider = true;
public static boolean UseSpecialBlockForProximityHider = true;
public static boolean UseYLocationProximity = false;
// AntiTexturePackAndFreecam
public static boolean AntiTexturePackAndFreecam = true;
public static int AirGeneratorMaxChance = 43;
// Misc
public static boolean NoObfuscationForOps = false;
public static boolean NoObfuscationForPermission = false;
public static boolean LoginNotification = true;
// Anti Hit Hack
public static int AntiHitHackDecrementFactor = 1000;
public static int AntiHitHackMaxViolation = 15;
// Utilities
private static boolean[] ObfuscateBlocks = new boolean[256];
private static boolean[] NetherObfuscateBlocks = new boolean[256];
private static boolean[] DarknessBlocks = new boolean[256];
private static boolean[] ProximityHiderBlocks = new boolean[256];
private static Integer[] RandomBlocks = new Integer[]{1, 4, 5, 14, 15, 16, 21, 46, 48, 49, 56, 73, 82, 129};
private static Integer[] NetherRandomBlocks = new Integer[]{13, 87, 88, 112, 153};
private static Integer[] RandomBlocks2 = RandomBlocks;
private static List<String> Worlds = new ArrayList<String>();
// Palette
public static int[] NetherPaletteBlocks;
public static int[] NormalPaletteBlocks;
// ChunkReloader
public static int ChunkReloaderRate = 500;
public static boolean UseChunkReloader = false;
// CacheCleaner
public static long CacheCleanRate = 60 * 60 * 20;//once per hour
public static File getCacheFolder() {
// Try to make the folder
if (!CacheFolder.exists()) {
CacheFolder.mkdirs();
}
// Can't make folder? Use default
if (!CacheFolder.exists()) {
CacheFolder = new File("orebfuscator_cache");
}
return CacheFolder;
}
private static boolean[] TransparentBlocks;
private static boolean[] TransparentBlocksMode1;
private static boolean[] TransparentBlocksMode2;
public static boolean isBlockTransparent(int id) {
if (id < 0)
id += 256;
if (id >= 256) {
return false;
}
return TransparentBlocks[id];
}
private static void generateTransparentBlocks() {
if(TransparentBlocks == null) {
readInitialTransparentBlocks();
}
boolean[] transparentBlocks = EngineMode == 1
? TransparentBlocksMode1
: TransparentBlocksMode2;
System.arraycopy(transparentBlocks, 0, TransparentBlocks, 0, TransparentBlocks.length);
List<Integer> customTransparentBlocks = getMaterialIdsByPath("Lists.TransparentBlocks", new Integer[]{ });
for(int blockId : customTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
TransparentBlocks[blockId] = true;
}
}
List<Integer> customNonTransparentBlocks = getMaterialIdsByPath("Lists.NonTransparentBlocks", new Integer[]{ });
for(int blockId : customNonTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
TransparentBlocks[blockId] = false;
}
}
}
private static void readInitialTransparentBlocks() {
TransparentBlocks = new boolean[256];
Arrays.fill(TransparentBlocks, false);
InputStream mainStream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks.txt");
readTransparentBlocks(TransparentBlocks, mainStream);
TransparentBlocksMode1 = new boolean[256];
System.arraycopy(TransparentBlocks, 0, TransparentBlocksMode1, 0, TransparentBlocksMode1.length);
InputStream mode1Stream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks_mode1.txt");
if(mode1Stream != null) readTransparentBlocks(TransparentBlocksMode1, mode1Stream);
TransparentBlocksMode2 = new boolean[256];
System.arraycopy(TransparentBlocks, 0, TransparentBlocksMode2, 0, TransparentBlocksMode2.length);
InputStream mode2Stream = Orebfuscator.class.getResourceAsStream("/resources/transparent_blocks_mode2.txt");
if(mode2Stream != null) readTransparentBlocks(TransparentBlocksMode2, mode2Stream);
}
private static void readTransparentBlocks(boolean[] transparentBlocks, InputStream stream) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null) {
int index1 = line.indexOf(":");
int index2 = line.indexOf(" ", index1);
int blockId = Integer.parseInt(line.substring(0, index1));
boolean isTransparent = line.substring(index1 + 1, index2).equals("true");
transparentBlocks[blockId] = isTransparent;
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean isObfuscated(int id, World.Environment environment) {
if (id < 0)
id += 256;
// Nether case
if (environment == World.Environment.NETHER) {
return id == 87 || NetherObfuscateBlocks[id];
}
// Normal case
return id == 1 || ObfuscateBlocks[id];
}
public static boolean isDarknessObfuscated(int id) {
if (id < 0)
id += 256;
return DarknessBlocks[id];
}
public static boolean isProximityObfuscated(int y, int id) {
if (id < 0)
id += 256;
return ProximityHiderBlocks[id];
}
public static boolean isProximityHiderOn(int y, int id) {
return (UseYLocationProximity && y >= ProximityHiderEnd) ||
(!UseYLocationProximity && y <= ProximityHiderEnd);
}
public static boolean skipProximityHiderCheck(int y) {
return UseYLocationProximity && y < ProximityHiderEnd;
}
public static boolean proximityHiderDeobfuscate() {
return UseYLocationProximity;
}
public static boolean isWorldDisabled(String name) {
for (String world : Worlds) {
if (world.equalsIgnoreCase(name)) {
return UseWorldsAsBlacklist;
}
}
return !UseWorldsAsBlacklist;
}
public static String getWorlds() {
String retval = "";
for (String world : Worlds) {
retval += world + ", ";
}
return retval.length() > 1 ? retval.substring(0, retval.length() - 2) : retval;
}
public static int getRandomBlock(int index, boolean alternate, World.Environment environment) {
if (environment == World.Environment.NETHER)
return (int) (NetherRandomBlocks[index]);
return (int) (alternate ? RandomBlocks2[index] : RandomBlocks[index]);
}
public static Integer[] getRandomBlocks(boolean alternate, World.Environment environment) {
if (environment == World.Environment.NETHER)
return NetherRandomBlocks;
return (alternate ? RandomBlocks2 : RandomBlocks);
}
public static void shuffleRandomBlocks() {
synchronized (RandomBlocks) {
Collections.shuffle(Arrays.asList(RandomBlocks));
Collections.shuffle(Arrays.asList(RandomBlocks2));
}
}
public static int random(int max) {
return random.nextInt(max);
}
// Set
public static void setEngineMode(int data) {
setData("Integers.EngineMode", data);
EngineMode = data;
}
public static void setUpdateRadius(int data) {
setData("Integers.UpdateRadius", data);
UpdateRadius = data;
}
public static void setInitialRadius(int data) {
setData("Integers.InitialRadius", data);
InitialRadius = data;
}
public static void setProximityHiderDistance(int data) {
setData("Integers.ProximityHiderDistance", data);
ProximityHiderDistance = data;
}
public static void setAirGeneratorMaxChance(int data) {
setData("Integers.AirGeneratorMaxChance", data);
AirGeneratorMaxChance = data;
}
public static void setUseProximityHider(boolean data) {
setData("Booleans.UseProximityHider", data);
UseProximityHider = data;
}
public static void setDarknessHideBlocks(boolean data) {
setData("Booleans.DarknessHideBlocks", data);
DarknessHideBlocks = data;
}
public static void setNoObfuscationForOps(boolean data) {
setData("Booleans.NoObfuscationForOps", data);
NoObfuscationForOps = data;
}
public static void setNoObfuscationForPermission(boolean data) {
setData("Booleans.NoObfuscationForPermission", data);
NoObfuscationForPermission = data;
}
public static void setLoginNotification(boolean data) {
setData("Booleans.LoginNotification", data);
LoginNotification = data;
}
public static void setAntiTexturePackAndFreecam(boolean data) {
setData("Booleans.AntiTexturePackAndFreecam", data);
AntiTexturePackAndFreecam = data;
}
public static void setUseCache(boolean data) {
setData("Booleans.UseCache", data);
UseCache = data;
}
public static void setEnabled(boolean data) {
setData("Booleans.Enabled", data);
Enabled = data;
}
public static void setUseWorldsAsBlacklist(boolean data) {
setData("Booleans.UseWorldsAsBlacklist", data);
UseWorldsAsBlacklist = data;
}
public static void setWorldEnabled(String name, boolean enabled) {
if (enabled && !UseWorldsAsBlacklist || !enabled && UseWorldsAsBlacklist) {
Worlds.add(name);
} else {
Worlds.remove(name);
}
setData("Lists.Worlds", Worlds);
}
private static boolean getBoolean(String path, boolean defaultData) {
if (getConfig().get(path) == null)
setData(path, defaultData);
return getConfig().getBoolean(path, defaultData);
}
private static String getString(String path, String defaultData) {
if (getConfig().get(path) == null)
setData(path, defaultData);
return getConfig().getString(path, defaultData);
}
private static int getInt(String path, int defaultData) {
if (getConfig().get(path) == null)
setData(path, defaultData);
return getConfig().getInt(path, defaultData);
}
private static List<String> getStringList(String path, List<String> defaultData) {
if (getConfig().get(path) == null)
setData(path, defaultData);
return getConfig().getStringList(path);
}
private static void setData(String path, Object data) {
try {
getConfig().set(path, data);
save();
} catch (Exception e) {
Orebfuscator.log(e);
}
}
private static void setBlockValues(boolean[] boolArray, List<Integer> blocks, boolean transparent) {
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blocks.contains(i);
// If block is transparent while we don't want them to, or the other way around
if (transparent != isBlockTransparent((short) i)) {
// Remove it
boolArray[i] = false;
}
}
}
private static void setBlockValues(boolean[] boolArray, List<Integer> blocks) {
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blocks.contains(i);
}
}
public static void load() {
// Version check
int version = getInt("ConfigVersion", CONFIG_VERSION);
if (version < CONFIG_VERSION) {
setData("ConfigVersion", CONFIG_VERSION);
}
EngineMode = getInt("Integers.EngineMode", EngineMode);
if (EngineMode != 1 && EngineMode != 2) {
EngineMode = 2;
Orebfuscator.log("EngineMode must be 1 or 2.");
}
InitialRadius = clamp(getInt("Integers.InitialRadius", InitialRadius), 0, 2);
if (InitialRadius == 0) {
Orebfuscator.log("Warning, InitialRadius is 0. This will cause all exposed blocks to be obfuscated.");
}
UpdateRadius = clamp(getInt("Integers.UpdateRadius", UpdateRadius), 1, 5);
MaxLoadedCacheFiles = clamp(getInt("Integers.MaxLoadedCacheFiles", MaxLoadedCacheFiles), 16, 128);
ProximityHiderDistance = clamp(getInt("Integers.ProximityHiderDistance", ProximityHiderDistance), 2, 64);
ProximityHiderID = getMaterialIdByPath("Integers.ProximityHiderID", ProximityHiderID);
ProximityHiderEnd = clamp(getInt("Integers.ProximityHiderEnd", ProximityHiderEnd), 0, 255);
AirGeneratorMaxChance = clamp(getInt("Integers.AirGeneratorMaxChance", AirGeneratorMaxChance), 40, 100);
UseProximityHider = getBoolean("Booleans.UseProximityHider", UseProximityHider);
UseSpecialBlockForProximityHider = getBoolean("Booleans.UseSpecialBlockForProximityHider", UseSpecialBlockForProximityHider);
UseYLocationProximity = getBoolean("Booleans.UseYLocationProximity", UseYLocationProximity);
UpdateOnDamage = getBoolean("Booleans.UpdateOnDamage", UpdateOnDamage);
DarknessHideBlocks = getBoolean("Booleans.DarknessHideBlocks", DarknessHideBlocks);
NoObfuscationForOps = getBoolean("Booleans.NoObfuscationForOps", NoObfuscationForOps);
NoObfuscationForPermission = getBoolean("Booleans.NoObfuscationForPermission", NoObfuscationForPermission);
UseCache = getBoolean("Booleans.UseCache", UseCache);
LoginNotification = getBoolean("Booleans.LoginNotification", LoginNotification);
AntiTexturePackAndFreecam = getBoolean("Booleans.AntiTexturePackAndFreecam", AntiTexturePackAndFreecam);
UseWorldsAsBlacklist = getBoolean("Booleans.UseWorldsAsBlacklist", UseWorldsAsBlacklist);
Enabled = getBoolean("Booleans.Enabled", Enabled);
NoObfuscationForMetadata = getBoolean("Booleans.NoObfuscationForMetadata", NoObfuscationForMetadata);
NoObfuscationForMetadataTagName = getString("Strings.NoObfuscationForMetadataTagName", NoObfuscationForMetadataTagName);
DeleteCacheFilesAfterDays = getInt("Integers.DeleteCacheFilesAfterDays", DeleteCacheFilesAfterDays);
//UseChunkReloader = getBoolean("Booleans.UseChunkReloader", UseChunkReloader);
generateTransparentBlocks();
// Read block lists
setBlockValues(ObfuscateBlocks, getMaterialIdsByPath("Lists.ObfuscateBlocks", new Integer[]{14, 15, 16, 21, 54, 56, 73, 74, 129, 130}), false);
setBlockValues(NetherObfuscateBlocks, getMaterialIdsByPath("Lists.NetherObfuscateBlocks", new Integer[]{87, 153}), false);
setBlockValues(DarknessBlocks, getMaterialIdsByPath("Lists.DarknessBlocks", new Integer[]{52, 54}));
setBlockValues(ProximityHiderBlocks, getMaterialIdsByPath("Lists.ProximityHiderBlocks", new Integer[]{23, 52, 54, 56, 58, 61, 62, 116, 129, 130, 145, 146}));
//Support old DisabledWorlds value
if(getConfig().get("Lists.DisabledWorlds") != null) {
Worlds = getConfig().getStringList("Lists.DisabledWorlds");
getConfig().set("Lists.DisabledWorlds", null);
}
// List of worlds (either disabled or enabled depending on WorldsAsBlacklist value).
Worlds = getStringList("Lists.Worlds", Worlds);
// Read the cache location
CacheLocation = getString("Strings.CacheLocation", CacheLocation);
CacheFolder = new File(CacheLocation);
RandomBlocks = getMaterialIdsByPath("Lists.RandomBlocks", RandomBlocks).toArray(new Integer[0]);
NetherRandomBlocks = getMaterialIdsByPath("Lists.NetherRandomBlocks", NetherRandomBlocks).toArray(new Integer[0]);
// Validate RandomBlocks
for (int i = 0; i < RandomBlocks.length; i++) {
// Don't want people to put chests and other stuff that lags the hell out of players.
if (RandomBlocks[i] == null || OrebfuscatorConfig.isBlockTransparent((short) (int) RandomBlocks[i])) {
RandomBlocks[i] = 1;
}
}
RandomBlocks2 = RandomBlocks;
save();
createPaletteBlocks();
Orebfuscator.nms.setMaxLoadedCacheFiles(MaxLoadedCacheFiles);
//Make sure cache is cleared if config was changed since last start
try {
ObfuscatedDataCache.checkCacheAndConfigSynchronized();
} catch (IOException e) {
e.printStackTrace();
}
}
private static int getMaterialIdByPath(String path, int defaultMaterialId) {
String materialName = getConfig().get(path) != null ? getConfig().getString(path): Integer.toString(defaultMaterialId);
MaterialResult material = getMaterial(materialName, defaultMaterialId);
setData(path, material.name);
return material.id;
}
private static List<Integer> getMaterialIdsByPath(String path, Integer[] defaultMaterials) {
List<String> list;
if(getConfig().get(path) != null) {
list = getConfig().getStringList(path);
} else {
list = new ArrayList<String>();
for(int materialId : defaultMaterials) {
list.add(DeprecatedMethods.getMaterial(materialId).name());
}
}
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i < list.size(); i++) {
MaterialResult material = getMaterial(list.get(i), null);
if(material != null) {
list.set(i, material.name);
result.add(material.id);
}
}
setData(path, list);
return result;
}
private static MaterialResult getMaterial(String materialName, Integer defaultMaterialId) {
Integer materialId;
String defaultMaterialName = defaultMaterialId != null ? DeprecatedMethods.getMaterial(defaultMaterialId).name(): null;
try {
if(Character.isDigit(materialName.charAt(0))) {
materialId = Integer.parseInt(materialName);
Material obj = DeprecatedMethods.getMaterial(materialId);
if(obj != null) {
materialName = obj.name();
} else {
if(defaultMaterialId != null) {
Orebfuscator.log("Material with ID = " + materialId + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
Orebfuscator.log("Material with ID = " + materialId + " is not found. Skipped.");
materialId = null;
}
}
} else {
Material obj = Material.getMaterial(materialName.toUpperCase());
if(obj != null) {
materialId = DeprecatedMethods.getMaterialId(obj);
} else {
if(defaultMaterialId != null) {
Orebfuscator.log("Material " + materialName + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
Orebfuscator.log("Material " + materialName + " is not found. Skipped.");
materialId = null;
}
}
}
} catch (Exception e) {
if(defaultMaterialId != null) {
Orebfuscator.log("Invalid material ID or name: " + materialName + ". Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
Orebfuscator.log("Invalid material ID or name: " + materialName + ". Skipped.");
materialId = null;
}
}
return materialId != null ? new MaterialResult(materialId, materialName): null;
}
private static void createPaletteBlocks() {
//Nether
ArrayList<Integer> nether = new ArrayList<Integer>();
nether.add(0);
nether.add(87);
if(ProximityHiderID != 0 && ProximityHiderID != 87) {
nether.add(ProximityHiderID);
}
for(Integer id : NetherRandomBlocks) {
if(id != null && nether.indexOf(id) < 0) {
nether.add(id);
}
}
NetherPaletteBlocks = new int[nether.size()];
for(int i = 0; i < NetherPaletteBlocks.length; i++) NetherPaletteBlocks[i] = nether.get(i);
//Normal
ArrayList<Integer> normal = new ArrayList<Integer>();
normal.add(0);
normal.add(1);
if(ProximityHiderID != 0 && ProximityHiderID != 1) {
normal.add(ProximityHiderID);
}
for(Integer id : RandomBlocks) {
if(id != null && normal.indexOf(id) < 0) {
normal.add(id);
}
}
for(Integer id : RandomBlocks2) {
if(id != null && normal.indexOf(id) < 0) {
normal.add(id);
}
}
NormalPaletteBlocks = new int[normal.size()];
for(int i = 0; i < NormalPaletteBlocks.length; i++) NormalPaletteBlocks[i] = normal.get(i);
}
public static void reload() {
Orebfuscator.instance.reloadConfig();
load();
}
public static void save() {
Orebfuscator.instance.saveConfig();
}
public static boolean obfuscateForPlayer(Player player) {
return !(playerBypassOp(player) || playerBypassPerms(player) || playerBypassMetadata(player));
}
public static boolean playerBypassOp(Player player) {
boolean ret = false;
try {
ret = OrebfuscatorConfig.NoObfuscationForOps && player.isOp();
} catch (Exception e) {
Orebfuscator.log("Error while obtaining Operator status for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
public static boolean playerBypassPerms(Player player) {
boolean ret = false;
try {
ret = OrebfuscatorConfig.NoObfuscationForPermission && player.hasPermission("Orebfuscator.deobfuscate");
} catch (Exception e) {
Orebfuscator.log("Error while obtaining permissions for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
public static boolean playerBypassMetadata(Player player) {
boolean ret = false;
try {
ret = OrebfuscatorConfig.NoObfuscationForMetadata
&& player.hasMetadata(OrebfuscatorConfig.NoObfuscationForMetadataTagName)
&& player.getMetadata(OrebfuscatorConfig.NoObfuscationForMetadataTagName).get(0).asBoolean();
} catch (Exception e) {
Orebfuscator.log("Error while obtaining metadata for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
private static FileConfiguration getConfig() {
return Orebfuscator.instance.getConfig();
}
private static int clamp(int value, int min, int max) {
if (value < min)
value = min;
if (value > max)
value = max;
return value;
}
}

View File

@ -6,17 +6,16 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
public class CacheCleaner implements Runnable {
public void run() {
if(!OrebfuscatorConfig.Enabled || OrebfuscatorConfig.DeleteCacheFilesAfterDays <= 0) return;
if(!Orebfuscator.config.isEnabled() || Orebfuscator.config.getDeleteCacheFilesAfterDays() <= 0) return;
int count = 0;
for(World world : Bukkit.getWorlds()) {
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), world.getName());
count += ObfuscatedDataCache.deleteFiles(cacheFolder, OrebfuscatorConfig.DeleteCacheFilesAfterDays);
File cacheFolder = new File(ObfuscatedDataCache.getCacheFolder(), world.getName());
count += ObfuscatedDataCache.deleteFiles(cacheFolder, Orebfuscator.config.getDeleteCacheFilesAfterDays());
}
Orebfuscator.log("Cache cleaner completed, deleted files: " + count);

View File

@ -21,7 +21,6 @@ import java.io.DataOutputStream;
import java.io.File;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.nms.INBT;
public class ObfuscatedCachedChunk {
@ -78,8 +77,6 @@ public class ObfuscatedCachedChunk {
// Check if statuses makes sense
if (nbt.getInt("X") != x || nbt.getInt("Z") != z)
return;
if (OrebfuscatorConfig.UseProximityHider != nbt.getBoolean("PH") || OrebfuscatorConfig.InitialRadius != nbt.getInt("IR"))
return;
// Get Hash
hash = nbt.getLong("Hash");
@ -104,8 +101,6 @@ public class ObfuscatedCachedChunk {
// Set status indicator
nbt.setInt("X", x);
nbt.setInt("Z", z);
nbt.setInt("IR", OrebfuscatorConfig.InitialRadius);
nbt.setBoolean("PH", OrebfuscatorConfig.UseProximityHider);
// Set hash
nbt.setLong("Hash", hash);

View File

@ -23,13 +23,15 @@ import java.io.IOException;
import java.util.Date;
import java.util.Objects;
import org.bukkit.Bukkit;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.nms.IChunkCache;
import com.lishid.orebfuscator.utils.FileHelper;
public class ObfuscatedDataCache {
private static final String cacheFileName = "cache_config.yml";
private static File cacheFolder;
private static IChunkCache internalCache;
private static IChunkCache getInternalCache() {
@ -38,6 +40,26 @@ public class ObfuscatedDataCache {
}
return internalCache;
}
public static void resetCacheFolder() {
cacheFolder = null;
}
public static File getCacheFolder() {
if(cacheFolder == null) {
cacheFolder = new File(Bukkit.getServer().getWorldContainer(), Orebfuscator.config.getCacheLocation());
}
// Try to make the folder
if (!cacheFolder.exists()) {
cacheFolder.mkdirs();
}
// Can't make folder? Use default
if (!cacheFolder.exists()) {
cacheFolder = new File("orebfuscator_cache");
}
return cacheFolder;
}
public static void closeCacheFiles() {
getInternalCache().closeCacheFiles();
@ -46,7 +68,7 @@ public class ObfuscatedDataCache {
public static void checkCacheAndConfigSynchronized() throws IOException {
String configContent = Orebfuscator.instance.getConfig().saveToString();
File cacheFolder = OrebfuscatorConfig.getCacheFolder();
File cacheFolder = getCacheFolder();
File cacheConfigFile = new File(cacheFolder, cacheFileName);
String cacheConfigContent = FileHelper.readFile(cacheConfigFile);
@ -58,7 +80,7 @@ public class ObfuscatedDataCache {
public static void clearCache() throws IOException {
closeCacheFiles();
File cacheFolder = OrebfuscatorConfig.getCacheFolder();
File cacheFolder = getCacheFolder();
File cacheConfigFile = new File(cacheFolder, cacheFileName);
if(cacheFolder.exists()) {

View File

@ -18,12 +18,12 @@ package com.lishid.orebfuscator.commands;
import java.io.IOException;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
public class OrebfuscatorCommandExecutor {
@ -39,7 +39,7 @@ public class OrebfuscatorCommandExecutor {
}
if (args[0].equalsIgnoreCase("engine") && args.length > 1) {
int engine = OrebfuscatorConfig.EngineMode;
int engine = Orebfuscator.config.getEngineMode();
try {
engine = new Integer(args[1]);
}
@ -52,14 +52,14 @@ public class OrebfuscatorCommandExecutor {
return true;
}
else {
OrebfuscatorConfig.setEngineMode(engine);
Orebfuscator.configManager.setEngineMode(engine);
Orebfuscator.message(sender, "Engine set to: " + engine);
return true;
}
}
else if (args[0].equalsIgnoreCase("updateradius") && args.length > 1) {
int radius = OrebfuscatorConfig.UpdateRadius;
int radius = Orebfuscator.config.getUpdateRadius();
try {
radius = new Integer(args[1]);
}
@ -67,13 +67,13 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
OrebfuscatorConfig.setUpdateRadius(radius);
Orebfuscator.message(sender, "UpdateRadius set to: " + OrebfuscatorConfig.UpdateRadius);
Orebfuscator.configManager.setUpdateRadius(radius);
Orebfuscator.message(sender, "UpdateRadius set to: " + Orebfuscator.config.getUpdateRadius());
return true;
}
else if (args[0].equalsIgnoreCase("initialradius") && args.length > 1) {
int radius = OrebfuscatorConfig.InitialRadius;
int radius = Orebfuscator.config.getInitialRadius();
try {
radius = new Integer(args[1]);
}
@ -81,13 +81,13 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
OrebfuscatorConfig.setInitialRadius(radius);
Orebfuscator.configManager.setInitialRadius(radius);
Orebfuscator.message(sender, "InitialRadius set to: " + radius);
return true;
}
else if (args[0].equalsIgnoreCase("airgen") && args.length > 1) {
int airgen = OrebfuscatorConfig.AirGeneratorMaxChance;
int airgen = Orebfuscator.config.getDefaultWorld().getAirGeneratorMaxChance();
try {
airgen = new Integer(args[1]);
}
@ -95,13 +95,13 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
OrebfuscatorConfig.setAirGeneratorMaxChance(airgen);
Orebfuscator.configManager.setAirGeneratorMaxChance(airgen);
Orebfuscator.message(sender, "AirGeneratorMaxChance set to: " + airgen);
return true;
}
else if ((args[0].equalsIgnoreCase("proximity") | args[0].equalsIgnoreCase("proximityhider")) && args.length > 1) {
int ProximityHiderDistance = OrebfuscatorConfig.ProximityHiderDistance;
int ProximityHiderDistance = Orebfuscator.config.getDefaultWorld().getProximityHiderConfig().getDistance();
try {
ProximityHiderDistance = new Integer(args[1]);
}
@ -109,7 +109,7 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
OrebfuscatorConfig.setProximityHiderDistance(ProximityHiderDistance);
Orebfuscator.configManager.setProximityHiderDistance(ProximityHiderDistance);
Orebfuscator.message(sender, "ProximityHider Distance set to: " + ProximityHiderDistance);
return true;
}
@ -118,42 +118,42 @@ public class OrebfuscatorCommandExecutor {
boolean data = args[0].equalsIgnoreCase("enable");
if (args[0].equalsIgnoreCase("enable") && args.length == 1) {
OrebfuscatorConfig.setEnabled(true);
Orebfuscator.configManager.setEnabled(true);
Orebfuscator.message(sender, "Enabled.");
}
else if (args[0].equalsIgnoreCase("disable") && args.length == 1) {
OrebfuscatorConfig.setEnabled(false);
Orebfuscator.configManager.setEnabled(false);
Orebfuscator.message(sender, "Disabled.");
}
else if (args.length > 1) {
if (args[1].equalsIgnoreCase("darknesshide")) {
OrebfuscatorConfig.setDarknessHideBlocks(data);
Orebfuscator.configManager.setDarknessHideBlocks(data);
Orebfuscator.message(sender, "Darkness obfuscation " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("op")) {
OrebfuscatorConfig.setNoObfuscationForOps(data);
Orebfuscator.configManager.setNoObfuscationForOps(data);
Orebfuscator.message(sender, "Ops No-Obfuscation " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("perms") || args[1].equalsIgnoreCase("permissions")) {
OrebfuscatorConfig.setNoObfuscationForPermission(data);
Orebfuscator.configManager.setNoObfuscationForPermission(data);
Orebfuscator.message(sender, "Permissions No-Obfuscation " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("cache")) {
OrebfuscatorConfig.setUseCache(data);
Orebfuscator.configManager.setUseCache(data);
Orebfuscator.message(sender, "Cache " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("axr")) {
OrebfuscatorConfig.setAntiTexturePackAndFreecam(data);
Orebfuscator.configManager.setAntiTexturePackAndFreecam(data);
Orebfuscator.message(sender, "AntiTexturePackAndFreecam " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("notification")) {
OrebfuscatorConfig.setLoginNotification(data);
Orebfuscator.configManager.setLoginNotification(data);
Orebfuscator.message(sender, "Login Notification " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("world") && args.length > 2) {
OrebfuscatorConfig.setWorldEnabled(args[2], data);
Orebfuscator.configManager.setWorldEnabled(args[2], data);
Orebfuscator.message(sender, "World \"" + args[2] + "\" obfuscation " + (data ? "enabled" : "disabled") + ".");
}
}
@ -161,38 +161,47 @@ public class OrebfuscatorCommandExecutor {
else if (args[0].equalsIgnoreCase("use") && args.length > 1) {
if (args[1].equalsIgnoreCase("blacklist")) {
OrebfuscatorConfig.setUseWorldsAsBlacklist(true);
Orebfuscator.configManager.setUseWorldsAsBlacklist(true);
Orebfuscator.message(sender, "Use worlds as blacklist.");
}
else if (args[1].equalsIgnoreCase("whitelist")) {
OrebfuscatorConfig.setUseWorldsAsBlacklist(false);
Orebfuscator.configManager.setUseWorldsAsBlacklist(false);
Orebfuscator.message(sender, "Use worlds as whitelist.");
}
}
else if (args[0].equalsIgnoreCase("reload")) {
OrebfuscatorConfig.reload();
Orebfuscator.instance.reloadOrebfuscatorConfig();
Orebfuscator.message(sender, "Reload complete.");
}
else if (args[0].equalsIgnoreCase("status")) {
String status = Orebfuscator.instance.getIsProtocolLibFound()
? (OrebfuscatorConfig.Enabled ? "Enabled" : "Disabled")
? (Orebfuscator.config.isEnabled() ? "Enabled" : "Disabled")
: "ProtocolLib is not found! Plugin cannot be enabled.";
Orebfuscator.message(sender, "Orebfuscator " + Orebfuscator.instance.getDescription().getVersion() + " is: " + status);
Orebfuscator.message(sender, "Engine Mode: " + OrebfuscatorConfig.EngineMode);
Orebfuscator.message(sender, "Engine Mode: " + Orebfuscator.config.getEngineMode());
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, "Caching: " + (Orebfuscator.config.isUseCache() ? "Enabled" : "Disabled"));
Orebfuscator.message(sender, "ProximityHider: " + (Orebfuscator.config.isProximityHiderEnabled() ? "Enabled" : "Disabled"));
Orebfuscator.message(sender, "DarknessHideBlocks: " + (Orebfuscator.config.getDefaultWorld().isDarknessHideBlocks() ? "Enabled": "Disabled"));
Orebfuscator.message(sender, "Initial Obfuscation Radius: " + OrebfuscatorConfig.InitialRadius);
Orebfuscator.message(sender, "Update Radius: " + OrebfuscatorConfig.UpdateRadius);
Orebfuscator.message(sender, "Initial Obfuscation Radius: " + Orebfuscator.config.getInitialRadius());
Orebfuscator.message(sender, "Update Radius: " + Orebfuscator.config.getUpdateRadius());
String worlds = "";
String worlds = OrebfuscatorConfig.getWorlds();
for(World world : Orebfuscator.config.getWorlds().keySet()) {
if(worlds.length() > 0) {
worlds += ", ";
}
worlds += world.getName();
}
Orebfuscator.message(sender, "Worlds: " + (worlds.equals("") ? "None" : worlds));
Orebfuscator.message(sender, "Use worlds as: " + (OrebfuscatorConfig.UseWorldsAsBlacklist ? "Blacklist" : "Whitelist"));
Orebfuscator.message(sender, "Use worlds as: " + (Orebfuscator.config.getDefaultWorld().isEnabled() ? "Blacklist" : "Whitelist"));
}
else if (args[0].equalsIgnoreCase("clearcache")) {

View File

@ -0,0 +1,631 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.orebfuscator.DeprecatedMethods;
public class ConfigManager12 {
private static final int CONFIG_VERSION = 12;
private boolean[] transparentBlocks;
private boolean[] transparentBlocksMode1;
private boolean[] transparentBlocksMode2;
private JavaPlugin plugin;
private Logger logger;
private OrebfuscatorConfig orebfuscatorConfig;
public ConfigManager12(JavaPlugin plugin, Logger logger, OrebfuscatorConfig orebfuscatorConfig) {
this.plugin = plugin;
this.logger = logger;
this.orebfuscatorConfig = orebfuscatorConfig;
}
public void load() {
// Version check
int version = getInt("ConfigVersion", CONFIG_VERSION);
if (version < CONFIG_VERSION) {
getConfig().set("ConfigVersion", CONFIG_VERSION);
}
boolean useCache = getBoolean("Booleans.UseCache", true);
int maxLoadedCacheFiles = getInt("Integers.MaxLoadedCacheFiles", 64, 16, 128);
String cacheLocation = getString("Strings.CacheLocation", "orebfuscator_cache");
int deleteCacheFilesAfterDays = getInt("Integers.DeleteCacheFilesAfterDays", 0);
boolean enabled = getBoolean("Booleans.Enabled", true);
boolean updateOnDamage = getBoolean("Booleans.UpdateOnDamage", true);
int engineMode = getInt("Integers.EngineMode", 2);
if (engineMode != 1 && engineMode != 2) {
engineMode = 2;
logger.info("EngineMode must be 1 or 2.");
}
int initialRadius = getInt("Integers.InitialRadius", 1, 0, 2);
if (initialRadius == 0) {
logger.info("Warning, InitialRadius is 0. This will cause all exposed blocks to be obfuscated.");
}
int updateRadius = getInt("Integers.UpdateRadius", 2, 1, 5);
boolean noObfuscationForMetadata = getBoolean("Booleans.NoObfuscationForMetadata", true);
String noObfuscationForMetadataTagName = getString("Strings.NoObfuscationForMetadataTagName", "NPC");
boolean noObfuscationForOps = getBoolean("Booleans.NoObfuscationForOps", false);
boolean noObfuscationForPermission = getBoolean("Booleans.NoObfuscationForPermission", false);
boolean loginNotification = getBoolean("Booleans.LoginNotification", true);
generateTransparentBlocks(engineMode);
WorldConfig defaultWorld = readDefaultWorld();
WorldConfig normalWorld = readNormalWorld(defaultWorld);
WorldConfig netherWorld = readNetherWorld(defaultWorld);
Map<World, WorldConfig> worlds = readWorldList(normalWorld, netherWorld);
this.orebfuscatorConfig.setUseCache(useCache);
this.orebfuscatorConfig.setMaxLoadedCacheFiles(maxLoadedCacheFiles);
this.orebfuscatorConfig.setCacheLocation(cacheLocation);
this.orebfuscatorConfig.setDeleteCacheFilesAfterDays(deleteCacheFilesAfterDays);
this.orebfuscatorConfig.setEnabled(enabled);
this.orebfuscatorConfig.setUpdateOnDamage(updateOnDamage);
this.orebfuscatorConfig.setEngineMode(engineMode);
this.orebfuscatorConfig.setInitialRadius(initialRadius);
this.orebfuscatorConfig.setUpdateRadius(updateRadius);
this.orebfuscatorConfig.setNoObfuscationForMetadata(noObfuscationForMetadata);
this.orebfuscatorConfig.setNoObfuscationForMetadataTagName(noObfuscationForMetadataTagName);
this.orebfuscatorConfig.setNoObfuscationForOps(noObfuscationForOps);
this.orebfuscatorConfig.setNoObfuscationForPermission(noObfuscationForPermission);
this.orebfuscatorConfig.setLoginNotification(loginNotification);
this.orebfuscatorConfig.setTransparentBlocks(this.transparentBlocks);
this.orebfuscatorConfig.setDefaultWorld(defaultWorld);
this.orebfuscatorConfig.setNormalWorld(normalWorld);
this.orebfuscatorConfig.setEndWorld(normalWorld.clone());
this.orebfuscatorConfig.setNetherWorld(netherWorld);
this.orebfuscatorConfig.setWorlds(worlds);
this.orebfuscatorConfig.setProximityHiderEnabled();
save();
}
public void setEngineMode(int value) {
getConfig().set("Integers.EngineMode", value);
save();
this.orebfuscatorConfig.setEngineMode(value);
}
public void setUpdateRadius(int value) {
getConfig().set("Integers.UpdateRadius", value);
save();
this.orebfuscatorConfig.setUpdateRadius(value);
}
public void setInitialRadius(int value) {
getConfig().set("Integers.InitialRadius", value);
save();
this.orebfuscatorConfig.setInitialRadius(value);
}
public void setProximityHiderDistance(int value) {
getConfig().set("Integers.ProximityHiderDistance", value);
save();
this.orebfuscatorConfig.getDefaultWorld().getProximityHiderConfig().setDistance(value);
}
public void setAirGeneratorMaxChance(int value) {
getConfig().set("Integers.AirGeneratorMaxChance", value);
save();
this.orebfuscatorConfig.getDefaultWorld().setAirGeneratorMaxChance(value);
this.orebfuscatorConfig.getNormalWorld().setAirGeneratorMaxChance(value);
this.orebfuscatorConfig.getEndWorld().setAirGeneratorMaxChance(value);
this.orebfuscatorConfig.getNetherWorld().setAirGeneratorMaxChance(value);
for(WorldConfig world : this.orebfuscatorConfig.getWorlds().values()) {
world.setAirGeneratorMaxChance(value);
}
}
public void setUseProximityHider(boolean value) {
getConfig().set("Booleans.UseProximityHider", value);
save();
this.orebfuscatorConfig.getDefaultWorld().getProximityHiderConfig().setEnabled(value);
this.orebfuscatorConfig.setProximityHiderEnabled();
}
public void setDarknessHideBlocks(boolean value) {
getConfig().set("Booleans.DarknessHideBlocks", value);
save();
this.orebfuscatorConfig.getDefaultWorld().setDarknessHideBlocks(value);
this.orebfuscatorConfig.getNormalWorld().setDarknessHideBlocks(value);
this.orebfuscatorConfig.getEndWorld().setDarknessHideBlocks(value);
this.orebfuscatorConfig.getNetherWorld().setDarknessHideBlocks(value);
for(WorldConfig world : this.orebfuscatorConfig.getWorlds().values()) {
world.setDarknessHideBlocks(value);
}
}
public void setNoObfuscationForOps(boolean value) {
getConfig().set("Booleans.NoObfuscationForOps", value);
save();
this.orebfuscatorConfig.setNoObfuscationForOps(value);
}
public void setNoObfuscationForPermission(boolean value) {
getConfig().set("Booleans.NoObfuscationForPermission", value);
save();
this.orebfuscatorConfig.setNoObfuscationForPermission(value);
}
public void setLoginNotification(boolean value) {
getConfig().set("Booleans.LoginNotification", value);
save();
this.orebfuscatorConfig.setLoginNotification(value);
}
public void setAntiTexturePackAndFreecam(boolean value) {
getConfig().set("Booleans.AntiTexturePackAndFreecam", value);
save();
this.orebfuscatorConfig.getDefaultWorld().setAntiTexturePackAndFreecam(value);
this.orebfuscatorConfig.getNormalWorld().setAntiTexturePackAndFreecam(value);
this.orebfuscatorConfig.getEndWorld().setAntiTexturePackAndFreecam(value);
this.orebfuscatorConfig.getNetherWorld().setAntiTexturePackAndFreecam(value);
for(WorldConfig world : this.orebfuscatorConfig.getWorlds().values()) {
world.setAntiTexturePackAndFreecam(value);
}
}
public void setUseCache(boolean value) {
getConfig().set("Booleans.UseCache", value);
save();
this.orebfuscatorConfig.setUseCache(value);
}
public void setEnabled(boolean value) {
getConfig().set("Booleans.Enabled", value);
save();
this.orebfuscatorConfig.setEnabled(value);
}
public void setUseWorldsAsBlacklist(boolean value) {
getConfig().set("Booleans.UseWorldsAsBlacklist", value);
save();
this.orebfuscatorConfig.getDefaultWorld().setEnabled(value);
this.orebfuscatorConfig.getNormalWorld().setEnabled(value);
this.orebfuscatorConfig.getEndWorld().setEnabled(value);
this.orebfuscatorConfig.getNetherWorld().setEnabled(value);
for(WorldConfig world : this.orebfuscatorConfig.getWorlds().values()) {
world.setEnabled(!value);
}
}
public void setWorldEnabled(String name, boolean enabled) {
World world = Bukkit.getServer().getWorld(name);
if(world == null) return;
boolean useWorldsAsBlacklist = this.orebfuscatorConfig.getDefaultWorld().isEnabled();
if (enabled && !useWorldsAsBlacklist || !enabled && useWorldsAsBlacklist) {
WorldConfig defaultConfig = world.getEnvironment() == Environment.NETHER
? this.orebfuscatorConfig.getNetherWorld()
: this.orebfuscatorConfig.getNormalWorld();
WorldConfig cfg = defaultConfig.clone();
cfg.setEnabled(!cfg.isEnabled());
this.orebfuscatorConfig.getWorlds().put(world, cfg);
} else {
this.orebfuscatorConfig.getWorlds().remove(world);
}
List<String> worldNames = new ArrayList<String>();
for(World current : this.orebfuscatorConfig.getWorlds().keySet()) {
worldNames.add(current.getName());
}
getConfig().set("Lists.Worlds", worldNames);
save();
}
private FileConfiguration getConfig() {
return this.plugin.getConfig();
}
private void save() {
this.plugin.saveConfig();
}
private WorldConfig readDefaultWorld() {
boolean enabled = getBoolean("Booleans.UseWorldsAsBlacklist", true);
boolean darknessHideBlocks = getBoolean("Booleans.DarknessHideBlocks", false);
boolean antiTexturePackAndFreecam = getBoolean("Booleans.AntiTexturePackAndFreecam", true);
int airGeneratorMaxChance = getInt("Integers.AirGeneratorMaxChance", 43, 40, 100);
boolean[] darknessBlocks = new boolean[256];
ProximityHiderConfig proximityHiderConfig = readProxmityHider();
setBlockValues(darknessBlocks, getMaterialIdsByPath("Lists.DarknessBlocks", new Integer[]{52, 54}));
WorldConfig cfg = new WorldConfig();
cfg.setEnabled(enabled);
cfg.setDarknessHideBlocks(darknessHideBlocks);
cfg.setAntiTexturePackAndFreecam(antiTexturePackAndFreecam);
cfg.setAirGeneratorMaxChance(airGeneratorMaxChance);
cfg.setObfuscateBlocks(null);
cfg.setDarknessBlocks(darknessBlocks);
cfg.setRandomBlocks(null);
cfg.setPaletteBlocks(null);
cfg.setProximityHiderConfig(proximityHiderConfig);
return cfg;
}
private ProximityHiderConfig readProxmityHider() {
boolean enabled = getBoolean("Booleans.UseProximityHider", true);
int distance = getInt("Integers.ProximityHiderDistance", 8, 2, 64);
int specialBlockID = getMaterialIdByPath("Integers.ProximityHiderID", 1);
int endY = getInt("Integers.ProximityHiderEnd", 255, 0, 255);
boolean useSpecialBlock = getBoolean("Booleans.UseSpecialBlockForProximityHider", true);
boolean useYLocationProximity = getBoolean("Booleans.UseYLocationProximity", false);
boolean[] proximityHiderBlocks = new boolean[256];
setBlockValues(proximityHiderBlocks, getMaterialIdsByPath("Lists.ProximityHiderBlocks", new Integer[]{23, 52, 54, 56, 58, 61, 62, 116, 129, 130, 145, 146}));
ProximityHiderConfig cfg = new ProximityHiderConfig();
cfg.setEnabled(enabled);
cfg.setDistance(distance);
cfg.setSpecialBlockID(specialBlockID);
cfg.setEndY(endY);
cfg.setUseSpecialBlock(useSpecialBlock);
cfg.setUseYLocationProximity(useYLocationProximity);
cfg.setProximityHiderBlocks(proximityHiderBlocks);
return cfg;
}
private WorldConfig readNormalWorld(WorldConfig defaultConfig) {
boolean[] obfuscateBlocks = new boolean[256];
Integer[] randomBlocks = getMaterialIdsByPath("Lists.RandomBlocks", new Integer[]{1, 4, 5, 14, 15, 16, 21, 46, 48, 49, 56, 73, 82, 129}).toArray(new Integer[0]);
setBlockValues(obfuscateBlocks, getMaterialIdsByPath("Lists.ObfuscateBlocks", new Integer[]{14, 15, 16, 21, 54, 56, 73, 74, 129, 130}), false);
obfuscateBlocks[1] = true;
WorldConfig cfg = defaultConfig.clone();
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setRandomBlocks(randomBlocks);
cfg.setMode1BlockId(1);
createPaletteBlocks(cfg);
return cfg;
}
private WorldConfig readNetherWorld(WorldConfig defaultConfig) {
boolean[] obfuscateBlocks = new boolean[256];
Integer[] randomBlocks = getMaterialIdsByPath("Lists.NetherRandomBlocks", new Integer[]{13, 87, 88, 112, 153}).toArray(new Integer[0]);
setBlockValues(obfuscateBlocks, getMaterialIdsByPath("Lists.NetherObfuscateBlocks", new Integer[]{87, 153}), false);
obfuscateBlocks[87] = true;
WorldConfig cfg = defaultConfig.clone();
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setRandomBlocks(randomBlocks);
cfg.setMode1BlockId(87);
createPaletteBlocks(cfg);
return cfg;
}
private Map<World, WorldConfig> readWorldList(WorldConfig normalWorld, WorldConfig netherWorld) {
Map<World, WorldConfig> worlds = new HashMap<World, WorldConfig>();
List<String> worldNames = new ArrayList<String>();
Server server = Bukkit.getServer();
//Support old DisabledWorlds value
if(getConfig().get("Lists.DisabledWorlds") != null) {
worldNames = getConfig().getStringList("Lists.DisabledWorlds");
getConfig().set("Lists.DisabledWorlds", null);
}
// List of worlds (either disabled or enabled depending on WorldsAsBlacklist value).
worldNames = getStringList("Lists.Worlds", new ArrayList<String>());
for(String worldName : worldNames) {
World world = server.getWorld(worldName);
if(world == null || worlds.containsKey(world)) continue;
WorldConfig defaultConfig = world.getEnvironment() == Environment.NETHER ? netherWorld: normalWorld;
WorldConfig cfg = defaultConfig.clone();
cfg.setEnabled(!cfg.isEnabled());
worlds.put(world, cfg);
}
return worlds;
}
private static void setBlockValues(boolean[] boolArray, List<Integer> blocks) {
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blocks.contains(i);
}
}
private void setBlockValues(boolean[] boolArray, List<Integer> blocks, boolean transparent) {
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blocks.contains(i);
// If block is transparent while we don't want them to, or the other way around
if (transparent != isBlockTransparent((short) i)) {
// Remove it
boolArray[i] = false;
}
}
}
private void createPaletteBlocks(WorldConfig cfg) {
HashSet<Integer> map = new HashSet<Integer>();
map.add(0);
if(cfg.getProximityHiderConfig().isUseSpecialBlock()) {
map.add(cfg.getProximityHiderConfig().getSpecialBlockID());
}
for(Integer id : cfg.getRandomBlocks()) {
if(id != null) {
map.add(id);
}
}
int[] paletteBlocks = new int[map.size()];
int index = 0;
for(Integer id : map) {
paletteBlocks[index++] = id;
}
cfg.setPaletteBlocks(paletteBlocks);
}
private String getString(String path, String defaultData) {
if (getConfig().get(path) == null)
getConfig().set(path, defaultData);
return getConfig().getString(path, defaultData);
}
private int getInt(String path, int defaultData) {
if (getConfig().get(path) == null)
getConfig().set(path, defaultData);
return getConfig().getInt(path, defaultData);
}
private int getInt(String path, int defaultData, int min, int max) {
if (getConfig().get(path) == null)
getConfig().set(path, defaultData);
int value = getConfig().getInt(path, defaultData);
if(value < min) {
value = min;
}
else if(value > max) {
value = max;
}
return value;
}
private boolean getBoolean(String path, boolean defaultData) {
if (getConfig().get(path) == null)
getConfig().set(path, defaultData);
return getConfig().getBoolean(path, defaultData);
}
private List<String> getStringList(String path, List<String> defaultData) {
if (getConfig().get(path) == null)
getConfig().set(path, defaultData);
return getConfig().getStringList(path);
}
private int getMaterialIdByPath(String path, int defaultMaterialId) {
String materialName = getConfig().get(path) != null ? getConfig().getString(path): Integer.toString(defaultMaterialId);
MaterialResult material = getMaterial(materialName, defaultMaterialId);
getConfig().set(path, material.name);
return material.id;
}
private List<Integer> getMaterialIdsByPath(String path, Integer[] defaultMaterials) {
List<String> list;
if(getConfig().get(path) != null) {
list = getConfig().getStringList(path);
} else {
list = new ArrayList<String>();
for(int materialId : defaultMaterials) {
list.add(DeprecatedMethods.getMaterial(materialId).name());
}
}
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i < list.size(); i++) {
MaterialResult material = getMaterial(list.get(i), null);
if(material != null) {
list.set(i, material.name);
result.add(material.id);
}
}
getConfig().set(path, list);
return result;
}
private MaterialResult getMaterial(String materialName, Integer defaultMaterialId) {
Integer materialId;
String defaultMaterialName = defaultMaterialId != null ? DeprecatedMethods.getMaterial(defaultMaterialId).name(): null;
try {
if(Character.isDigit(materialName.charAt(0))) {
materialId = Integer.parseInt(materialName);
Material obj = DeprecatedMethods.getMaterial(materialId);
if(obj != null) {
materialName = obj.name();
} else {
if(defaultMaterialId != null) {
this.logger.info("Material with ID = " + materialId + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info("Material with ID = " + materialId + " is not found. Skipped.");
materialId = null;
}
}
} else {
Material obj = Material.getMaterial(materialName.toUpperCase());
if(obj != null) {
materialId = DeprecatedMethods.getMaterialId(obj);
} else {
if(defaultMaterialId != null) {
this.logger.info("Material " + materialName + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info("Material " + materialName + " is not found. Skipped.");
materialId = null;
}
}
}
} catch (Exception e) {
if(defaultMaterialId != null) {
this.logger.info("Invalid material ID or name: " + materialName + ". Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info("Invalid material ID or name: " + materialName + ". Skipped.");
materialId = null;
}
}
return materialId != null ? new MaterialResult(materialId, materialName): null;
}
private boolean isBlockTransparent(int id) {
if (id < 0)
id += 256;
if (id >= 256) {
return false;
}
return this.transparentBlocks[id];
}
private void generateTransparentBlocks(int engineMode) {
if(this.transparentBlocks == null) {
readInitialTransparentBlocks();
}
boolean[] transparentBlocks = engineMode == 1
? this.transparentBlocksMode1
: this.transparentBlocksMode2;
System.arraycopy(transparentBlocks, 0, this.transparentBlocks, 0, this.transparentBlocks.length);
List<Integer> customTransparentBlocks = getMaterialIdsByPath("Lists.TransparentBlocks", new Integer[]{ });
for(int blockId : customTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
this.transparentBlocks[blockId] = true;
}
}
List<Integer> customNonTransparentBlocks = getMaterialIdsByPath("Lists.NonTransparentBlocks", new Integer[]{ });
for(int blockId : customNonTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
this.transparentBlocks[blockId] = false;
}
}
}
private void readInitialTransparentBlocks() {
this.transparentBlocks = new boolean[256];
Arrays.fill(this.transparentBlocks, false);
InputStream mainStream = ConfigManager12.class.getResourceAsStream("/resources/transparent_blocks.txt");
readTransparentBlocks(this.transparentBlocks, mainStream);
this.transparentBlocksMode1 = new boolean[256];
System.arraycopy(this.transparentBlocks, 0, this.transparentBlocksMode1, 0, this.transparentBlocksMode1.length);
InputStream mode1Stream = ConfigManager12.class.getResourceAsStream("/resources/transparent_blocks_mode1.txt");
if(mode1Stream != null) readTransparentBlocks(this.transparentBlocksMode1, mode1Stream);
this.transparentBlocksMode2 = new boolean[256];
System.arraycopy(this.transparentBlocks, 0, this.transparentBlocksMode2, 0, this.transparentBlocksMode2.length);
InputStream mode2Stream = ConfigManager12.class.getResourceAsStream("/resources/transparent_blocks_mode2.txt");
if(mode2Stream != null) readTransparentBlocks(this.transparentBlocksMode2, mode2Stream);
}
private void readTransparentBlocks(boolean[] transparentBlocks, InputStream stream) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null) {
int index1 = line.indexOf(":");
int index2 = line.indexOf(" ", index1);
int blockId = Integer.parseInt(line.substring(0, index1));
boolean isTransparent = line.substring(index1 + 1, index2).equals("true");
transparentBlocks[blockId] = isTransparent;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,16 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
public class MaterialResult {
public int id;
public String name;
public MaterialResult(int id, String name) {
this.id = id;
this.name = name;
}
}

View File

@ -0,0 +1,329 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.util.Map;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
public class OrebfuscatorConfig {
// Caching
private boolean useCache;
private int maxLoadedCacheFiles;
private String cacheLocation;
private int deleteCacheFilesAfterDays;
// Main engine config
private boolean enabled;
private boolean updateOnDamage;
private int engineMode;
private int initialRadius;
private int updateRadius;
private boolean noObfuscationForMetadata;
private String noObfuscationForMetadataTagName;
private boolean noObfuscationForOps;
private boolean noObfuscationForPermission;
private boolean loginNotification;
private boolean[] transparentBlocks;
private WorldConfig defaultWorld;
private WorldConfig normalWorld;
private WorldConfig endWorld;
private WorldConfig netherWorld;
private Map<World, WorldConfig> worlds;
private boolean proximityHiderEnabled;
private static final int antiHitHackDecrementFactor = 1000;
private static final int antiHitHackMaxViolation = 15;
private static final int proximityHiderRate = 500;
private static final int chunkReloaderRate = 500;
private static final boolean useChunkReloader = false;
private static final long cacheCleanRate = 60 * 60 * 20;//once per hour
public WorldConfig getWorld(World world) {
if(world == null) {
return null;
}
WorldConfig cfg = this.worlds.get(world);
if(cfg != null) {
return cfg;
}
if(world.getEnvironment() == Environment.THE_END) {
return this.endWorld;
}
if(world.getEnvironment() == Environment.NETHER) {
return this.netherWorld;
}
return this.normalWorld;
}
public boolean isUseCache() {
return this.useCache;
}
public void setUseCache(boolean value) {
this.useCache = value;
}
public int getMaxLoadedCacheFiles() {
return this.maxLoadedCacheFiles;
}
public void setMaxLoadedCacheFiles(int value) {
this.maxLoadedCacheFiles = value;
}
public String getCacheLocation() {
return this.cacheLocation;
}
public void setCacheLocation(String value) {
this.cacheLocation = value;
}
public int getDeleteCacheFilesAfterDays() {
return this.deleteCacheFilesAfterDays;
}
public void setDeleteCacheFilesAfterDays(int value) {
this.deleteCacheFilesAfterDays = value;
}
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean value) {
this.enabled = value;
}
public boolean isUpdateOnDamage() {
return this.updateOnDamage;
}
public void setUpdateOnDamage(boolean value) {
this.updateOnDamage = value;
}
public int getEngineMode() {
return this.engineMode;
}
public void setEngineMode(int value) {
this.engineMode = value;
}
public int getInitialRadius() {
return this.initialRadius;
}
public void setInitialRadius(int value) {
this.initialRadius = value;
}
public int getUpdateRadius() {
return this.updateRadius;
}
public void setUpdateRadius(int value) {
this.updateRadius = value;
}
public boolean isNoObfuscationForMetadata() {
return this.noObfuscationForMetadata;
}
public void setNoObfuscationForMetadata(boolean value) {
this.noObfuscationForMetadata = value;
}
public String getNoObfuscationForMetadataTagName() {
return this.noObfuscationForMetadataTagName;
}
public void setNoObfuscationForMetadataTagName(String value) {
this.noObfuscationForMetadataTagName = value;
}
public boolean isNoObfuscationForOps() {
return this.noObfuscationForOps;
}
public void setNoObfuscationForOps(boolean value) {
this.noObfuscationForOps = value;
}
public boolean isNoObfuscationForPermission() {
return this.noObfuscationForPermission;
}
public void setNoObfuscationForPermission(boolean value) {
this.noObfuscationForPermission = value;
}
public boolean isLoginNotification() {
return this.loginNotification;
}
public void setLoginNotification(boolean value) {
this.loginNotification = value;
}
public boolean[] getTransparentBlocks() {
return this.transparentBlocks;
}
public void setTransparentBlocks(boolean[] value) {
this.transparentBlocks = value;
}
public WorldConfig getDefaultWorld() {
return this.defaultWorld;
}
public void setDefaultWorld(WorldConfig value) {
this.defaultWorld = value;
}
public WorldConfig getNormalWorld() {
return this.normalWorld;
}
public void setNormalWorld(WorldConfig value) {
this.normalWorld = value;
}
public WorldConfig getEndWorld() {
return this.endWorld;
}
public void setEndWorld(WorldConfig value) {
this.endWorld = value;
}
public WorldConfig getNetherWorld() {
return this.netherWorld;
}
public void setNetherWorld(WorldConfig value) {
this.netherWorld = value;
}
public Map<World, WorldConfig> getWorlds() {
return this.worlds;
}
public void setWorlds(Map<World, WorldConfig> value) {
this.worlds = value;
}
public boolean isProximityHiderEnabled() {
return this.proximityHiderEnabled;
}
public void setProximityHiderEnabled() {
this.proximityHiderEnabled = this.normalWorld.getProximityHiderConfig().isEnabled()
|| this.endWorld.getProximityHiderConfig().isEnabled()
|| this.netherWorld.getProximityHiderConfig().isEnabled()
;
if(!this.proximityHiderEnabled) {
for(WorldConfig world : this.worlds.values()) {
if(world.getProximityHiderConfig().isEnabled()) {
this.proximityHiderEnabled = true;
break;
}
}
}
}
public int getAntiHitHackDecrementFactor() {
return antiHitHackDecrementFactor;
}
public int getAntiHitHackMaxViolation() {
return antiHitHackMaxViolation;
}
public int getProximityHiderRate() {
return proximityHiderRate;
}
public int getChunkReloaderRate() {
return chunkReloaderRate;
}
public boolean isUseChunkReloader() {
return useChunkReloader;
}
public long getCacheCleanRate() {
return cacheCleanRate;
}
// Helper methods
public boolean isBlockTransparent(int id) {
if (id < 0)
id += 256;
if (id >= 256) {
return false;
}
return this.transparentBlocks[id];
}
public boolean obfuscateForPlayer(Player player) {
return !(playerBypassOp(player) || playerBypassPerms(player) || playerBypassMetadata(player));
}
public boolean playerBypassOp(Player player) {
boolean ret = false;
try {
ret = this.noObfuscationForOps && player.isOp();
} catch (Exception e) {
Orebfuscator.log("Error while obtaining Operator status for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
public boolean playerBypassPerms(Player player) {
boolean ret = false;
try {
ret = this.noObfuscationForPermission && player.hasPermission("Orebfuscator.deobfuscate");
} catch (Exception e) {
Orebfuscator.log("Error while obtaining permissions for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
public boolean playerBypassMetadata(Player player) {
boolean ret = false;
try {
ret = this.noObfuscationForMetadata
&& player.hasMetadata(this.noObfuscationForMetadataTagName)
&& player.getMetadata(this.noObfuscationForMetadataTagName).get(0).asBoolean();
} catch (Exception e) {
Orebfuscator.log("Error while obtaining metadata for player" + player.getName() + ": " + e.getMessage());
e.printStackTrace();
}
return ret;
}
}

View File

@ -0,0 +1,102 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
public class ProximityHiderConfig {
private boolean enabled;
private int distance;
private int specialBlockID;
private int endY;
private boolean useSpecialBlock;
private boolean useYLocationProximity;
private boolean[] proximityHiderBlocks;
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean value) {
this.enabled = value;
}
public int getDistance() {
return this.distance;
}
public void setDistance(int value) {
this.distance = value;
}
public int getSpecialBlockID() {
return this.specialBlockID;
}
public void setSpecialBlockID(int value) {
this.specialBlockID = value;
}
public int getEndY() {
return this.endY;
}
public void setEndY(int value) {
this.endY = value;
}
public boolean isUseSpecialBlock() {
return this.useSpecialBlock;
}
public void setUseSpecialBlock(boolean value) {
this.useSpecialBlock = value;
}
public boolean isUseYLocationProximity() {
return this.useYLocationProximity;
}
public void setUseYLocationProximity(boolean value) {
this.useYLocationProximity = value;
}
public boolean[] getProximityHiderBlocks() {
return this.proximityHiderBlocks;
}
public void setProximityHiderBlocks(boolean[] values) {
this.proximityHiderBlocks = values;
}
public ProximityHiderConfig clone() {
ProximityHiderConfig cfg = new ProximityHiderConfig();
cfg.enabled = this.enabled;
cfg.distance = this.distance;
cfg.specialBlockID = this.specialBlockID;
cfg.endY = this.endY;
cfg.useSpecialBlock = this.useSpecialBlock;
cfg.useYLocationProximity = this.useYLocationProximity;
cfg.proximityHiderBlocks = this.proximityHiderBlocks;
return cfg;
}
// Help methods
public boolean isProximityObfuscated(int y, int id) {
if (id < 0)
id += 256;
return this.proximityHiderBlocks[id]
&& (
this.useYLocationProximity && y >= this.endY
|| !this.useYLocationProximity && y <= this.endY
);
}
public boolean skipProximityHiderCheck(int y) {
return this.useYLocationProximity && y < this.endY;
}
}

View File

@ -0,0 +1,151 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.util.Arrays;
import java.util.Collections;
public class WorldConfig {
private boolean enabled;
private boolean darknessHideBlocks;
private boolean antiTexturePackAndFreecam;
private int airGeneratorMaxChance;
private boolean[] obfuscateBlocks;
private boolean[] darknessBlocks;
private Integer[] randomBlocks;
private Integer[] randomBlocks2;
private int mode1BlockId;
private int[] paletteBlocks;
private ProximityHiderConfig proximityHiderConfig;
public boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean value) {
this.enabled = value;
}
public boolean isDarknessHideBlocks() {
return this.darknessHideBlocks;
}
public void setDarknessHideBlocks(boolean value) {
this.darknessHideBlocks = value;
}
public boolean isAntiTexturePackAndFreecam() {
return this.antiTexturePackAndFreecam;
}
public void setAntiTexturePackAndFreecam(boolean value) {
this.antiTexturePackAndFreecam = value;
}
public int getAirGeneratorMaxChance() {
return this.airGeneratorMaxChance;
}
public void setAirGeneratorMaxChance(int value) {
this.airGeneratorMaxChance = value;
}
public boolean[] getObfuscateBlocks() {
return this.obfuscateBlocks;
}
public void setObfuscateBlocks(boolean[] values) {
this.obfuscateBlocks = values;
}
public boolean[] getDarknessBlocks() {
return this.darknessBlocks;
}
public void setDarknessBlocks(boolean[] values) {
this.darknessBlocks = values;
}
public Integer[] getRandomBlocks() {
return this.randomBlocks;
}
public Integer[] getRandomBlocks2() {
return this.randomBlocks2;
}
public void setRandomBlocks(Integer[] values) {
this.randomBlocks = values;
this.randomBlocks2 = values;
}
public void shuffleRandomBlocks() {
synchronized (this.randomBlocks) {
Collections.shuffle(Arrays.asList(this.randomBlocks));
Collections.shuffle(Arrays.asList(this.randomBlocks2));
}
}
public int getMode1BlockId() {
return this.mode1BlockId;
}
public void setMode1BlockId(int value) {
this.mode1BlockId = value;
}
public int[] getPaletteBlocks() {
return this.paletteBlocks;
}
public void setPaletteBlocks(int[] values) {
this.paletteBlocks = values;
}
public ProximityHiderConfig getProximityHiderConfig() {
return this.proximityHiderConfig;
}
public void setProximityHiderConfig(ProximityHiderConfig value) {
this.proximityHiderConfig = value;
}
public WorldConfig clone() {
WorldConfig cfg = new WorldConfig();
cfg.enabled = this.enabled;
cfg.darknessHideBlocks = this.darknessHideBlocks;
cfg.antiTexturePackAndFreecam = this.antiTexturePackAndFreecam;
cfg.airGeneratorMaxChance = this.airGeneratorMaxChance;
cfg.obfuscateBlocks = this.obfuscateBlocks;
cfg.darknessBlocks = this.darknessBlocks;
cfg.randomBlocks = this.randomBlocks;
cfg.randomBlocks2 = this.randomBlocks2;
cfg.paletteBlocks = this.paletteBlocks;
cfg.proximityHiderConfig = this.proximityHiderConfig;
return cfg;
}
// Helper methods
public boolean isObfuscated(int id) {
if (id < 0)
id += 256;
return this.obfuscateBlocks[id];
}
public boolean isDarknessObfuscated(int id) {
if (id < 0)
id += 256;
return this.darknessBlocks[id];
}
public int getRandomBlock(int index, boolean alternate) {
return (int)(alternate ? this.randomBlocks2[index] : this.randomBlocks[index]);
}
}

View File

@ -22,7 +22,7 @@ import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.Orebfuscator;
public class BlockHitManager {
private static HashMap<Player, PlayerBlockTracking> playersBlockTrackingStatus = new HashMap<Player, PlayerBlockTracking>();
@ -42,13 +42,13 @@ public class BlockHitManager {
playerBlockTracking.setBlock(block);
playerBlockTracking.updateTime();
int decrement = (int) (time / OrebfuscatorConfig.AntiHitHackDecrementFactor);
int decrement = (int) (time / Orebfuscator.config.getAntiHitHackDecrementFactor());
playerBlockTracking.decrementHackingIndicator(decrement);
if (playerBlockTracking.getHackingIndicator() == OrebfuscatorConfig.AntiHitHackMaxViolation)
playerBlockTracking.incrementHackingIndicator(OrebfuscatorConfig.AntiHitHackMaxViolation);
if (playerBlockTracking.getHackingIndicator() == Orebfuscator.config.getAntiHitHackMaxViolation())
playerBlockTracking.incrementHackingIndicator(Orebfuscator.config.getAntiHitHackMaxViolation());
if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
if (playerBlockTracking.getHackingIndicator() > Orebfuscator.config.getAntiHitHackMaxViolation())
return false;
return true;
@ -57,7 +57,7 @@ public class BlockHitManager {
public static boolean canFakeHit(Player player) {
PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
if (playerBlockTracking.getHackingIndicator() > Orebfuscator.config.getAntiHitHackMaxViolation())
return false;
return true;
@ -67,7 +67,7 @@ public class BlockHitManager {
PlayerBlockTracking playerBlockTracking = getPlayerBlockTracking(player);
playerBlockTracking.incrementHackingIndicator();
if (playerBlockTracking.getHackingIndicator() > OrebfuscatorConfig.AntiHitHackMaxViolation)
if (playerBlockTracking.getHackingIndicator() > Orebfuscator.config.getAntiHitHackMaxViolation())
return false;
return true;

View File

@ -27,7 +27,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.obfuscation.BlockUpdate;
@ -41,7 +41,7 @@ public class OrebfuscatorBlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) {
if (!OrebfuscatorConfig.UpdateOnDamage) {
if (!Orebfuscator.config.isUpdateOnDamage()) {
return;
}

View File

@ -32,7 +32,6 @@ import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.obfuscation.BlockUpdate;
import com.lishid.orebfuscator.obfuscation.ProximityHider;
@ -42,15 +41,15 @@ public class OrebfuscatorPlayerListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (OrebfuscatorConfig.LoginNotification) {
if (OrebfuscatorConfig.playerBypassOp(player)) {
if (Orebfuscator.config.isLoginNotification()) {
if (Orebfuscator.config.playerBypassOp(player)) {
Orebfuscator.message(player, "Orebfuscator bypassed because you are OP.");
} else if (OrebfuscatorConfig.playerBypassPerms(player)) {
} else if (Orebfuscator.config.playerBypassPerms(player)) {
Orebfuscator.message(player, "Orebfuscator bypassed because you have permission.");
}
}
if (OrebfuscatorConfig.UseProximityHider) {
if (Orebfuscator.config.isProximityHiderEnabled()) {
ProximityHider.addPlayerToCheck(event.getPlayer(), null);
}
}
@ -58,7 +57,7 @@ public class OrebfuscatorPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) {
BlockHitManager.clearHistory(event.getPlayer());
if (OrebfuscatorConfig.UseProximityHider) {
if (Orebfuscator.config.isProximityHiderEnabled()) {
ProximityHider.clearPlayer(event.getPlayer());
}
}
@ -85,7 +84,7 @@ public class OrebfuscatorPlayerListener implements Listener {
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
BlockHitManager.clearHistory(event.getPlayer());
if (OrebfuscatorConfig.UseProximityHider) {
if (Orebfuscator.config.isProximityHiderEnabled()) {
ProximityHider.clearBlocksForOldWorld(event.getPlayer());
ProximityHider.addPlayerToCheck(event.getPlayer(), null);
}
@ -93,7 +92,7 @@ public class OrebfuscatorPlayerListener implements Listener {
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent event) {
if (OrebfuscatorConfig.UseProximityHider) {
if (Orebfuscator.config.isProximityHiderEnabled()) {
if(event.getCause() != TeleportCause.END_PORTAL
&& event.getCause() != TeleportCause.NETHER_PORTAL
)
@ -105,7 +104,7 @@ public class OrebfuscatorPlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
if (OrebfuscatorConfig.UseProximityHider) {
if (Orebfuscator.config.isProximityHiderEnabled()) {
ProximityHider.addPlayerToCheck(event.getPlayer(), event.getFrom());
}
}

View File

@ -28,14 +28,15 @@ import org.bukkit.block.Block;
import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.config.WorldConfig;
import com.lishid.orebfuscator.nms.IBlockInfo;
import com.lishid.orebfuscator.types.ChunkCoord;
public class BlockUpdate {
public static boolean needsUpdate(Block block) {
return !OrebfuscatorConfig.isBlockTransparent(DeprecatedMethods.getTypeId(block));
return !Orebfuscator.config.isBlockTransparent(DeprecatedMethods.getTypeId(block));
}
public static void update(Block block) {
@ -52,15 +53,16 @@ public class BlockUpdate {
}
World world = blocks.get(0).getWorld();
WorldConfig worldConfig = Orebfuscator.config.getWorld(world);
HashSet<IBlockInfo> updateBlocks = new HashSet<IBlockInfo>();
HashSet<ChunkCoord> invalidChunks = new HashSet<ChunkCoord>();
int updateRadius = OrebfuscatorConfig.UpdateRadius;
int updateRadius = Orebfuscator.config.getUpdateRadius();
for (Block block : blocks) {
if (needsUpdate(block)) {
IBlockInfo blockInfo = Orebfuscator.nms.getBlockInfo(world, block.getX(), block.getY(), block.getZ());
getAjacentBlocks(updateBlocks, world, blockInfo, updateRadius);
getAjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
if((blockInfo.getX() & 0xf) == 0) {
invalidChunks.add(new ChunkCoord((blockInfo.getX() >> 4) - 1, blockInfo.getZ() >> 4));
@ -86,13 +88,14 @@ public class BlockUpdate {
}
World world = locations.get(0).getWorld();
WorldConfig worldConfig = Orebfuscator.config.getWorld(world);
HashSet<IBlockInfo> updateBlocks = new HashSet<IBlockInfo>();
HashSet<ChunkCoord> invalidChunks = new HashSet<ChunkCoord>();
for (Location location : locations) {
IBlockInfo blockInfo = Orebfuscator.nms.getBlockInfo(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
getAjacentBlocks(updateBlocks, world, blockInfo, updateRadius);
getAjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
if((blockInfo.getX() & 0xf) == 0) {
invalidChunks.add(new ChunkCoord((blockInfo.getX() >> 4) - 1, blockInfo.getZ() >> 4));
@ -119,9 +122,9 @@ public class BlockUpdate {
}
private static void invalidateCachedChunks(World world, Set<ChunkCoord> invalidChunks) {
if(invalidChunks.isEmpty() || !OrebfuscatorConfig.UseCache) return;
if(invalidChunks.isEmpty() || !Orebfuscator.config.isUseCache()) return;
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), world.getName());
File cacheFolder = new File(ObfuscatedDataCache.getCacheFolder(), world.getName());
for(ChunkCoord chunk : invalidChunks) {
ObfuscatedCachedChunk cache = new ObfuscatedCachedChunk(cacheFolder, chunk.x, chunk.z);
@ -131,25 +134,30 @@ public class BlockUpdate {
}
}
private static void getAjacentBlocks(HashSet<IBlockInfo> allBlocks, World world, IBlockInfo blockInfo, int countdown) {
private static void getAjacentBlocks(
HashSet<IBlockInfo> allBlocks,
World world,
WorldConfig worldConfig,
IBlockInfo blockInfo,
int countdown
)
{
if (blockInfo == null) return;
int blockId = blockInfo.getTypeId();
if ((OrebfuscatorConfig.isObfuscated(blockId, world.getEnvironment())
|| OrebfuscatorConfig.isDarknessObfuscated(blockId)))
{
if ((worldConfig.isObfuscated(blockId) || worldConfig.isDarknessObfuscated(blockId))) {
allBlocks.add(blockInfo);
}
if (countdown > 0) {
countdown--;
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() + 1, blockInfo.getY(), blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() - 1, blockInfo.getY(), blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() + 1, blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() - 1, blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() + 1), countdown);
getAjacentBlocks(allBlocks, world, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() - 1), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() + 1, blockInfo.getY(), blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() - 1, blockInfo.getY(), blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() + 1, blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() - 1, blockInfo.getZ()), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() + 1), countdown);
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() - 1), countdown);
}
}
}

View File

@ -19,31 +19,37 @@ package com.lishid.orebfuscator.obfuscation;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.chunkmap.ChunkData;
import com.lishid.orebfuscator.chunkmap.ChunkMapManager;
import com.lishid.orebfuscator.config.ProximityHiderConfig;
import com.lishid.orebfuscator.config.WorldConfig;
import com.lishid.orebfuscator.types.BlockCoord;
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 {
if(chunkData.primaryBitMask == 0) return null;
if (!OrebfuscatorConfig.Enabled // Plugin enabled
|| OrebfuscatorConfig.isWorldDisabled(player.getWorld().getName()) // World not enabled
|| !OrebfuscatorConfig.obfuscateForPlayer(player)) // Should the player have obfuscation?
{
if (!Orebfuscator.config.isEnabled() || !Orebfuscator.config.obfuscateForPlayer(player)) {
return null;
}
WorldConfig worldConfig = Orebfuscator.config.getWorld(player.getWorld());
if(!worldConfig.isEnabled()) {
return null;
}
byte[] output;
ObfuscatedCachedChunk cache = tryUseCache(chunkData, player);
@ -88,8 +94,9 @@ public class Calculations {
}
private static byte[] obfuscate(ChunkData chunkData, Player player, ArrayList<BlockCoord> proximityBlocks) throws IOException {
Environment environment = player.getWorld().getEnvironment();
int initialRadius = OrebfuscatorConfig.InitialRadius;
WorldConfig worldConfig = Orebfuscator.config.getWorld(player.getWorld());
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
int initialRadius = Orebfuscator.config.getInitialRadius();
// Track of pseudo-randomly assigned randomBlock
int randomIncrement = 0;
@ -99,11 +106,11 @@ public class Calculations {
boolean obfuscate = false;
boolean specialObfuscate = false;
int engineMode = OrebfuscatorConfig.EngineMode;
int maxChance = OrebfuscatorConfig.AirGeneratorMaxChance;
int engineMode = Orebfuscator.config.getEngineMode();
int maxChance = worldConfig.getAirGeneratorMaxChance();
int incrementMax = maxChance;
int randomBlocksLength = OrebfuscatorConfig.getRandomBlocks(false, environment).length;
int randomBlocksLength = worldConfig.getRandomBlocks().length;
boolean randomAlternate = false;
int startX = chunkData.chunkX << 4;
@ -115,11 +122,11 @@ public class Calculations {
manager.init();
for(int i = 0; i < manager.getSectionCount(); i++) {
OrebfuscatorConfig.shuffleRandomBlocks();
worldConfig.shuffleRandomBlocks();
for(int offsetY = 0; offsetY < 16; offsetY++) {
for(int offsetZ = 0; offsetZ < 16; offsetZ++) {
incrementMax = (maxChance + OrebfuscatorConfig.random(maxChance)) / 2;
incrementMax = (maxChance + random(maxChance)) / 2;
for(int offsetX = 0; offsetX < 16; offsetX++) {
int blockData = manager.readNextBlock();
@ -136,10 +143,10 @@ public class Calculations {
specialObfuscate = false;
// Check if the block should be obfuscated for the default engine modes
if (OrebfuscatorConfig.isObfuscated(blockState.id, environment)) {
if (worldConfig.isObfuscated(blockState.id)) {
if (initialRadius == 0) {
// Do not interfere with PH
if (OrebfuscatorConfig.UseProximityHider && OrebfuscatorConfig.isProximityObfuscated(y, blockState.id)) {
if (proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockState.id)) {
if (!areAjacentBlocksTransparent(manager, player.getWorld(), false, x, y, z, 1)) {
obfuscate = true;
}
@ -156,45 +163,43 @@ public class Calculations {
}
// Check if the block should be obfuscated because of proximity check
if (!obfuscate && OrebfuscatorConfig.UseProximityHider && OrebfuscatorConfig.isProximityObfuscated(y, blockState.id)) {
if (OrebfuscatorConfig.isProximityHiderOn(y, blockState.id)) {
BlockCoord block = new BlockCoord(x, y, z);
if (block != null) {
proximityBlocks.add(block);
}
obfuscate = true;
if (OrebfuscatorConfig.UseSpecialBlockForProximityHider) {
specialObfuscate = true;
}
}
if (!obfuscate && proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockState.id)) {
BlockCoord block = new BlockCoord(x, y, z);
if (block != null) {
proximityBlocks.add(block);
}
obfuscate = true;
if (proximityHider.isUseSpecialBlock()) {
specialObfuscate = true;
}
}
// Check if the block is obfuscated
if (obfuscate) {
if (specialObfuscate) {
// Proximity hider
blockState.id = OrebfuscatorConfig.ProximityHiderID;
blockState.id = proximityHider.getSpecialBlockID();
} else {
randomIncrement2 = OrebfuscatorConfig.random(incrementMax);
if (engineMode == 1) {
// Engine mode 1, replace with stone
blockState.id = (environment == Environment.NETHER ? 87 : 1);
blockState.id = worldConfig.getMode1BlockId();
} else if (engineMode == 2) {
// Ending mode 2, replace with random block
if (randomBlocksLength > 1) {
randomIncrement = CalculationsUtil.increment(randomIncrement, randomBlocksLength);
}
blockState.id = OrebfuscatorConfig.getRandomBlock(randomIncrement, randomAlternate, environment);
blockState.id = worldConfig.getRandomBlock(randomIncrement, randomAlternate);
randomAlternate = !randomAlternate;
}
// Anti texturepack and freecam
if (OrebfuscatorConfig.AntiTexturePackAndFreecam) {
// Add random air blocks
if (randomIncrement2 == 0) {
randomCave = 1 + OrebfuscatorConfig.random(3);
if (worldConfig.isAntiTexturePackAndFreecam()) {
// Add random air blocks
randomIncrement2 = random(incrementMax);
if (randomIncrement2 == 0) {
randomCave = 1 + random(3);
}
if (randomCave > 0) {
@ -208,7 +213,7 @@ public class Calculations {
}
// Check if the block should be obfuscated because of the darkness
if (!obfuscate && OrebfuscatorConfig.DarknessHideBlocks && OrebfuscatorConfig.isDarknessObfuscated(blockState.id)) {
if (!obfuscate && worldConfig.isDarknessHideBlocks() && worldConfig.isDarknessObfuscated(blockState.id)) {
if (!areAjacentBlocksBright(player.getWorld(), x, y, z, 1)) {
// Hide block, setting it to air
blockState.id = 0;
@ -224,7 +229,7 @@ public class Calculations {
if(offsetY == 0 && offsetZ == 0 && offsetX == 0) {
manager.finalizeOutput();
manager.initOutputPalette();
addBlocksToPalette(manager, environment);
addBlocksToPalette(manager, worldConfig);
manager.initOutputSection();
}
@ -245,30 +250,26 @@ public class Calculations {
return output;
}
private static void addBlocksToPalette(ChunkMapManager manager, Environment environment) {
private static void addBlocksToPalette(ChunkMapManager manager, WorldConfig worldConfig) {
if(!manager.inputHasNonAirBlock()) {
return;
}
int[] list = environment == Environment.NETHER
? OrebfuscatorConfig.NetherPaletteBlocks
: OrebfuscatorConfig.NormalPaletteBlocks;
for(int id : list) {
for(int id : worldConfig.getPaletteBlocks()) {
int blockData = ChunkMapManager.getBlockDataFromId(id);
manager.addToOutputPalette(blockData);
}
}
private static ObfuscatedCachedChunk tryUseCache(ChunkData chunkData, Player player) {
if (!OrebfuscatorConfig.UseCache) return null;
if (!Orebfuscator.config.isUseCache()) return null;
chunkData.useCache = true;
// Hash the chunk
long hash = CalculationsUtil.Hash(chunkData.data, chunkData.data.length);
// Get cache folder
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), player.getWorld().getName());
File cacheFolder = new File(ObfuscatedDataCache.getCacheFolder(), player.getWorld().getName());
// Create cache objects
ObfuscatedCachedChunk cache = new ObfuscatedCachedChunk(cacheFolder, chunkData.chunkX, chunkData.chunkZ);
@ -339,7 +340,7 @@ public class Calculations {
id = ChunkMapManager.getBlockIdFromData(blockData);
}
if (OrebfuscatorConfig.isBlockTransparent(id)) {
if (Orebfuscator.config.isBlockTransparent(id)) {
return true;
}
}
@ -386,61 +387,8 @@ public class Calculations {
return false;
}
//16 bit char for block data, including 12 bits for block id
/*
private static final int BLOCKID_MAX = 4096;
private static char[] cacheMap = new char[BLOCKID_MAX];
static {
buildCacheMap();
private static int random(int max) {
return random.nextInt(max);
}
public static void buildCacheMap() {
for (int i = 0; i < 4096; i++) {
cacheMap[i] = (char) i;
if (OrebfuscatorConfig.isBlockTransparent((short) i) && !isBlockSpecialObfuscated(64, (char) i)) {
cacheMap[i] = 0;
}
}
}
private static void PrepareBufferForCaching(byte[] data, int bytes) {
for (int i = 0; i < bytes / 2; i++) {
int blockId = chunkGetBlockId(data, i);
blockId = cacheMap[blockId % BLOCKID_MAX];
chunkSetBlockId(data, i, blockId);
}
}
private static boolean isBlockSpecialObfuscated(int y, char id) {
if (OrebfuscatorConfig.DarknessHideBlocks && OrebfuscatorConfig.isDarknessObfuscated(id)) {
return true;
}
if (OrebfuscatorConfig.UseProximityHider && OrebfuscatorConfig.isProximityObfuscated(y, id)) {
return true;
}
return false;
}
private static void RepaintChunkToBuffer(byte[] data, ChunkInfo info) {
byte[] original = info.original;
int bytes = info.bytes;
for (int i = 0; i < bytes / 2; i++) {
int newId = chunkGetBlockId(data, i);
int originalId = chunkGetBlockId(original, i);
if (newId == 0 && originalId != 0) {
if (OrebfuscatorConfig.isBlockTransparent((short) originalId)) {
if (!isBlockSpecialObfuscated(0, (char) originalId)) {
chunkSetBlockId(data, i, originalId);
}
}
}
}
}
*/
}

View File

@ -16,8 +16,9 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
import com.lishid.orebfuscator.config.ProximityHiderConfig;
import com.lishid.orebfuscator.nms.IChunkManager;
import com.lishid.orebfuscator.types.ChunkCoord;
@ -55,13 +56,13 @@ public class ChunkReloader extends Thread implements Runnable {
while (!this.isInterrupted() && !kill.get()) {
try {
// Wait until necessary
long timeWait = lastExecute + OrebfuscatorConfig.ChunkReloaderRate - System.currentTimeMillis();
long timeWait = lastExecute + Orebfuscator.config.getChunkReloaderRate() - System.currentTimeMillis();
lastExecute = System.currentTimeMillis();
if (timeWait > 0) {
Thread.sleep(timeWait);
}
if (!OrebfuscatorConfig.UseChunkReloader) {
if (!Orebfuscator.config.isUseChunkReloader()) {
return;
}
@ -137,11 +138,11 @@ public class ChunkReloader extends Thread implements Runnable {
}
private static void scheduleReloadChunks(final World world, HashSet<ChunkCoord> chunksForReloadForWorld) {
File cacheFolder = new File(OrebfuscatorConfig.getCacheFolder(), world.getName());
File cacheFolder = new File(ObfuscatedDataCache.getCacheFolder(), world.getName());
final IChunkManager chunkManager = Orebfuscator.nms.getChunkManager(world);
for(final ChunkCoord chunk : chunksForReloadForWorld) {
if(OrebfuscatorConfig.UseCache) {
if(Orebfuscator.config.isUseCache()) {
ObfuscatedCachedChunk cache = new ObfuscatedCachedChunk(cacheFolder, chunk.x, chunk.z);
if(cache.getHash() != 0) continue;
}
@ -179,7 +180,11 @@ public class ChunkReloader extends Thread implements Runnable {
}
if(affectedPlayers.size() > 0) {
ProximityHider.addPlayersToReload(affectedPlayers);
ProximityHiderConfig proximityHider = Orebfuscator.config.getWorld(world).getProximityHiderConfig();
if(proximityHider.isEnabled()) {
ProximityHider.addPlayersToReload(affectedPlayers);
}
}
}
@ -192,9 +197,10 @@ public class ChunkReloader extends Thread implements Runnable {
}
public static void addLoadedChunk(World world, int chunkX, int chunkZ) {
if (!OrebfuscatorConfig.Enabled // Plugin enabled
|| OrebfuscatorConfig.isWorldDisabled(world.getName()) // World not enabled
|| !OrebfuscatorConfig.UseChunkReloader)
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.config.getWorld(world).isEnabled() // World not enabled
)
{
return;
}
@ -213,9 +219,10 @@ public class ChunkReloader extends Thread implements Runnable {
}
public static void addUnloadedChunk(World world, int chunkX, int chunkZ) {
if (!OrebfuscatorConfig.Enabled // Plugin enabled
|| OrebfuscatorConfig.isWorldDisabled(world.getName()) // World not enabled
|| !OrebfuscatorConfig.UseChunkReloader)
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.config.getWorld(world).isEnabled() // World not enabled
)
{
return;
}

View File

@ -29,7 +29,8 @@ import org.bukkit.entity.Player;
import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.Orebfuscator;
import com.lishid.orebfuscator.OrebfuscatorConfig;
import com.lishid.orebfuscator.config.ProximityHiderConfig;
import com.lishid.orebfuscator.config.WorldConfig;
import com.lishid.orebfuscator.types.BlockCoord;
import com.lishid.orebfuscator.types.BlockState;
@ -65,23 +66,17 @@ public class ProximityHider extends Thread implements Runnable {
while (!this.isInterrupted() && !kill.get()) {
try {
// Wait until necessary
long timeWait = lastExecute + OrebfuscatorConfig.ProximityHiderRate - System.currentTimeMillis();
long timeWait = lastExecute + Orebfuscator.config.getProximityHiderRate() - System.currentTimeMillis();
lastExecute = System.currentTimeMillis();
if (timeWait > 0) {
Thread.sleep(timeWait);
}
if (!OrebfuscatorConfig.UseProximityHider) {
if (!Orebfuscator.config.isProximityHiderEnabled()) {
running = false;
return;
}
int checkRadius = OrebfuscatorConfig.ProximityHiderDistance >> 4;
if((OrebfuscatorConfig.ProximityHiderDistance & 0xf) != 0) {
checkRadius++;
}
HashMap<Player, Location> checkPlayers = new HashMap<Player, Location>();
synchronized (playersToCheck) {
@ -89,9 +84,6 @@ public class ProximityHider extends Thread implements Runnable {
playersToCheck.clear();
}
int distance = OrebfuscatorConfig.ProximityHiderDistance;
int distanceSquared = distance * distance;
for (Player p : checkPlayers.keySet()) {
if (p == null) {
@ -137,13 +129,27 @@ public class ProximityHider extends Thread implements Runnable {
}
}
if (OrebfuscatorConfig.skipProximityHiderCheck(y)) continue;
if(localPlayerInfo.getWorld() == null || p.getWorld() == null || !p.getWorld().equals(localPlayerInfo.getWorld())) {
localPlayerInfo.clearChunks();
continue;
}
WorldConfig worldConfig = Orebfuscator.config.getWorld(p.getWorld());
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
if(proximityHider.skipProximityHiderCheck(y)) {
continue;
}
int checkRadius = proximityHider.getDistance() >> 4;
if((proximityHider.getDistance() & 0xf) != 0) {
checkRadius++;
}
int distance = proximityHider.getDistance();
int distanceSquared = distance * distance;
ArrayList<BlockCoord> removedBlocks = new ArrayList<BlockCoord>();
Location playerLocation = p.getLocation();
int minChunkX = (playerLocation.getBlockX() >> 4) - checkRadius;
@ -167,7 +173,7 @@ public class ProximityHider extends Thread implements Runnable {
Location blockLocation = new Location(localPlayerInfo.getWorld(), b.x, b.y, b.z);
if (OrebfuscatorConfig.proximityHiderDeobfuscate() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
if (proximityHider.isUseYLocationProximity() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
removedBlocks.add(b);
BlockState blockState = Orebfuscator.nms.getBlockState(localPlayerInfo.getWorld(), b.x, b.y, b.z);
@ -206,7 +212,7 @@ public class ProximityHider extends Thread implements Runnable {
if (thread.isInterrupted() || !thread.isAlive())
running = false;
if (!running && OrebfuscatorConfig.UseProximityHider) {
if (!running && Orebfuscator.config.isProximityHiderEnabled()) {
// Load ProximityHider
ProximityHider.Load();
}
@ -214,7 +220,9 @@ public class ProximityHider extends Thread implements Runnable {
}
public static void addProximityBlocks(Player player, int chunkX, int chunkZ, ArrayList<BlockCoord> blocks) {
if (!OrebfuscatorConfig.UseProximityHider) return;
ProximityHiderConfig proximityHider = Orebfuscator.config.getWorld(player.getWorld()).getProximityHiderConfig();
if (!proximityHider.isEnabled()) return;
restart();
@ -277,7 +285,7 @@ public class ProximityHider extends Thread implements Runnable {
}
public static void addPlayersToReload(HashSet<Player> players) {
if (!OrebfuscatorConfig.UseProximityHider) return;
if (!Orebfuscator.config.isProximityHiderEnabled()) return;
synchronized (playersToReload) {
playersToReload.addAll(players);