ProximityHider blocks now are considered as obfuscate blocks by default, also implemented 'Issue #62: Per World Configuration'

master
Aleksey-Terzi 2016-10-16 20:38:37 +03:00
parent 6082d4e743
commit 41b2324017
17 changed files with 1273 additions and 807 deletions

View File

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

View File

@ -28,7 +28,7 @@ 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.ConfigManager;
import com.lishid.orebfuscator.config.OrebfuscatorConfig;
import com.lishid.orebfuscator.hithack.BlockHitManager;
import com.lishid.orebfuscator.hook.ProtocolLibHook;
@ -37,6 +37,7 @@ import com.lishid.orebfuscator.listeners.OrebfuscatorChunkListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorEntityListener;
import com.lishid.orebfuscator.listeners.OrebfuscatorPlayerListener;
import com.lishid.orebfuscator.nms.INmsManager;
import com.lishid.orebfuscator.utils.Globals;
/**
* Orebfuscator Anti X-RAY
@ -48,7 +49,7 @@ 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 ConfigManager configManager;
public static INmsManager nms;
@ -81,7 +82,7 @@ public class Orebfuscator extends JavaPlugin {
pm.registerEvents(new OrebfuscatorEntityListener(), this);
pm.registerEvents(new OrebfuscatorBlockListener(), this);
pm.registerEvents(new OrebfuscatorChunkListener(), this);
(new ProtocolLibHook()).register(this);
// Run CacheCleaner
@ -91,7 +92,7 @@ public class Orebfuscator extends JavaPlugin {
public void loadOrebfuscatorConfig() {
if(config == null) {
config = new OrebfuscatorConfig();
configManager = new ConfigManager12(this, logger, config);
configManager = new ConfigManager(this, logger, config);
}
configManager.load();
@ -151,14 +152,14 @@ public class Orebfuscator extends JavaPlugin {
* Log an information
*/
public static void log(String text) {
logger.info("[OFC] " + text);
logger.info(Globals.LogPrefix + text);
}
/**
* Log an error
*/
public static void log(Throwable e) {
logger.severe("[OFC] " + e.toString());
logger.severe(Globals.LogPrefix + e.toString());
e.printStackTrace();
}
@ -166,6 +167,6 @@ public class Orebfuscator extends JavaPlugin {
* Send a message to a player
*/
public static void message(CommandSender target, String message) {
target.sendMessage(ChatColor.AQUA + "[OFC] " + message);
target.sendMessage(ChatColor.AQUA + Globals.LogPrefix + message);
}
}

View File

@ -18,7 +18,6 @@ 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;
@ -86,34 +85,6 @@ public class OrebfuscatorCommandExecutor {
return true;
}
else if (args[0].equalsIgnoreCase("airgen") && args.length > 1) {
int airgen = Orebfuscator.config.getDefaultWorld().getAirGeneratorMaxChance();
try {
airgen = new Integer(args[1]);
}
catch (NumberFormatException e) {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
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 = Orebfuscator.config.getDefaultWorld().getProximityHiderConfig().getDistance();
try {
ProximityHiderDistance = new Integer(args[1]);
}
catch (NumberFormatException e) {
Orebfuscator.message(sender, args[1] + " is not a number!");
return true;
}
Orebfuscator.configManager.setProximityHiderDistance(ProximityHiderDistance);
Orebfuscator.message(sender, "ProximityHider Distance set to: " + ProximityHiderDistance);
return true;
}
else if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("disable")) {
boolean data = args[0].equalsIgnoreCase("enable");
@ -128,11 +99,7 @@ public class OrebfuscatorCommandExecutor {
}
else if (args.length > 1) {
if (args[1].equalsIgnoreCase("darknesshide")) {
Orebfuscator.configManager.setDarknessHideBlocks(data);
Orebfuscator.message(sender, "Darkness obfuscation " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("op")) {
if (args[1].equalsIgnoreCase("op")) {
Orebfuscator.configManager.setNoObfuscationForOps(data);
Orebfuscator.message(sender, "Ops No-Obfuscation " + (data ? "enabled" : "disabled") + ".");
}
@ -144,32 +111,13 @@ public class OrebfuscatorCommandExecutor {
Orebfuscator.configManager.setUseCache(data);
Orebfuscator.message(sender, "Cache " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("axr")) {
Orebfuscator.configManager.setAntiTexturePackAndFreecam(data);
Orebfuscator.message(sender, "AntiTexturePackAndFreecam " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("notification")) {
Orebfuscator.configManager.setLoginNotification(data);
Orebfuscator.message(sender, "Login Notification " + (data ? "enabled" : "disabled") + ".");
}
else if (args[1].equalsIgnoreCase("world") && args.length > 2) {
Orebfuscator.configManager.setWorldEnabled(args[2], data);
Orebfuscator.message(sender, "World \"" + args[2] + "\" obfuscation " + (data ? "enabled" : "disabled") + ".");
}
}
}
else if (args[0].equalsIgnoreCase("use") && args.length > 1) {
if (args[1].equalsIgnoreCase("blacklist")) {
Orebfuscator.configManager.setUseWorldsAsBlacklist(true);
Orebfuscator.message(sender, "Use worlds as blacklist.");
}
else if (args[1].equalsIgnoreCase("whitelist")) {
Orebfuscator.configManager.setUseWorldsAsBlacklist(false);
Orebfuscator.message(sender, "Use worlds as whitelist.");
}
}
else if (args[0].equalsIgnoreCase("reload")) {
Orebfuscator.instance.reloadOrebfuscatorConfig();
Orebfuscator.message(sender, "Reload complete.");
@ -192,12 +140,12 @@ public class OrebfuscatorCommandExecutor {
String worlds = "";
for(World world : Orebfuscator.config.getWorlds().keySet()) {
for(String name : Orebfuscator.config.getWorlds().keySet()) {
if(worlds.length() > 0) {
worlds += ", ";
name += ", ";
}
worlds += world.getName();
worlds += name;
}
Orebfuscator.message(sender, "Worlds: " + (worlds.equals("") ? "None" : worlds));

View File

@ -0,0 +1,335 @@
/**
* @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.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.orebfuscator.utils.Globals;
public class ConfigManager {
private static final int CONFIG_VERSION = 13;
private boolean[] transparentBlocks;
private boolean[] transparentBlocksMode1;
private boolean[] transparentBlocksMode2;
private JavaPlugin plugin;
private Logger logger;
private OrebfuscatorConfig orebfuscatorConfig;
private MaterialReader materialReader;
public ConfigManager(JavaPlugin plugin, Logger logger, OrebfuscatorConfig orebfuscatorConfig) {
this.plugin = plugin;
this.logger = logger;
this.orebfuscatorConfig = orebfuscatorConfig;
this.materialReader = new MaterialReader(this.plugin, this.logger);
}
public WorldConfig getWorld(World world) {
if(world == null) {
return null;
}
WorldConfig baseCfg;
switch(world.getEnvironment()) {
case THE_END:
baseCfg = this.orebfuscatorConfig.getEndWorld();
break;
case NETHER:
baseCfg = this.orebfuscatorConfig.getNetherWorld();
break;
default:
baseCfg = this.orebfuscatorConfig.getNormalWorld();
}
WorldConfig cfg = this.orebfuscatorConfig.getWorlds().get(world.getName().toLowerCase());
if(cfg == null) {
return baseCfg;
}
if(!cfg.isInitialized()) {
cfg.init(baseCfg);
this.logger.log(Level.INFO, Globals.LogPrefix + "Config for world '" + world.getName() + "' is initialized.");
}
return cfg;
}
public void load() {
// Version check
int version = getInt("ConfigVersion", CONFIG_VERSION);
if (version < CONFIG_VERSION) {
if(version <= 12) {
new Convert12To13(this.plugin).convert();
logger.info(Globals.LogPrefix + "Warning, InitialRadius is 0. This will cause all exposed blocks to be obfuscated.");
} else {
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(Globals.LogPrefix + "EngineMode must be 1 or 2.");
}
int initialRadius = getInt("Integers.InitialRadius", 1, 0, 2);
if (initialRadius == 0) {
logger.info(Globals.LogPrefix + "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);
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);
new WorldReader(this.plugin, this.logger, this.orebfuscatorConfig, this.materialReader).load();
this.orebfuscatorConfig.setProximityHiderEnabled();
logger.info(Globals.LogPrefix + "Proximity Hider is " + (this.orebfuscatorConfig.isProximityHiderEnabled() ? "Enabled": "Disabled"));
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 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 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);
}
private FileConfiguration getConfig() {
return this.plugin.getConfig();
}
private void save() {
this.plugin.saveConfig();
}
private String getString(String path, String defaultData, boolean withSave) {
if (getConfig().get(path) == null) {
if(!withSave) {
return defaultData;
}
getConfig().set(path, defaultData);
}
return getConfig().getString(path, defaultData);
}
private String getString(String path, String defaultData) {
return getString(path, defaultData, true);
}
private int getInt(String path, int defaultData) {
return getInt(path, defaultData, true);
}
private int getInt(String path, int defaultData, boolean withSave) {
if (getConfig().get(path) == null) {
if(!withSave) {
return defaultData;
}
getConfig().set(path, defaultData);
}
return getConfig().getInt(path, defaultData);
}
private int getInt(String path, int defaultData, int min, int max, boolean withSave) {
if (getConfig().get(path) == null && withSave) {
getConfig().set(path, defaultData);
}
int value = getConfig().get(path) != null ? getConfig().getInt(path, defaultData): defaultData;
if(value < min) {
value = min;
}
else if(value > max) {
value = max;
}
return value;
}
private int getInt(String path, int defaultData, int min, int max) {
return getInt(path, defaultData, min, max, true);
}
private boolean getBoolean(String path, boolean defaultData, boolean withSave) {
if (getConfig().get(path) == null) {
if(!withSave) {
return defaultData;
}
getConfig().set(path, defaultData);
}
return getConfig().getBoolean(path, defaultData);
}
private boolean getBoolean(String path, boolean defaultData) {
return getBoolean(path, defaultData, true);
}
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);
Integer[] customTransparentBlocks = this.materialReader.getMaterialIdsByPath("Lists.TransparentBlocks", new Integer[0], true);
if(customTransparentBlocks != null) {
for(int blockId : customTransparentBlocks) {
if(blockId >= 0 && blockId <= 255) {
this.transparentBlocks[blockId] = true;
}
}
}
Integer[] customNonTransparentBlocks = this.materialReader.getMaterialIdsByPath("Lists.NonTransparentBlocks", new Integer[0], true);
if(customNonTransparentBlocks != null) {
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 = ConfigManager.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 = ConfigManager.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 = ConfigManager.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

@ -1,631 +0,0 @@
/**
* @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,107 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.util.List;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class Convert12To13 {
private static final int CONFIG_VERSION = 13;
private JavaPlugin plugin;
private FileConfiguration config;
public Convert12To13(JavaPlugin plugin) {
this.plugin = plugin;
}
public void convert() {
this.config = new YamlConfiguration();
setGlobalValues();
setWorldValues();
String contents = this.config.saveToString();
try {
this.plugin.getConfig().loadFromString(contents);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
private void setGlobalValues() {
FileConfiguration oldConfig = this.plugin.getConfig();
this.config.set("ConfigVersion", CONFIG_VERSION);
this.config.set("Booleans.UseCache", oldConfig.get("Booleans.UseCache"));
this.config.set("Booleans.Enabled", oldConfig.get("Booleans.Enabled"));
this.config.set("Booleans.UpdateOnDamage", oldConfig.get("Booleans.UpdateOnDamage"));
this.config.set("Booleans.NoObfuscationForMetadata", oldConfig.get("Booleans.NoObfuscationForMetadata"));
this.config.set("Booleans.NoObfuscationForOps", oldConfig.get("Booleans.NoObfuscationForOps"));
this.config.set("Booleans.NoObfuscationForPermission", oldConfig.get("Booleans.NoObfuscationForPermission"));
this.config.set("Booleans.LoginNotification", oldConfig.get("Booleans.LoginNotification"));
this.config.set("Integers.MaxLoadedCacheFiles", oldConfig.get("Integers.MaxLoadedCacheFiles"));
this.config.set("Integers.DeleteCacheFilesAfterDays", oldConfig.get("Integers.DeleteCacheFilesAfterDays"));
this.config.set("Integers.EngineMode", oldConfig.get("Integers.EngineMode"));
this.config.set("Integers.InitialRadius", oldConfig.get("Integers.InitialRadius"));
this.config.set("Integers.UpdateRadius", oldConfig.get("Integers.UpdateRadius"));
this.config.set("Strings.CacheLocation", oldConfig.get("Strings.CacheLocation"));
this.config.set("Strings.NoObfuscationForMetadataTagName", oldConfig.get("Strings.NoObfuscationForMetadataTagName"));
this.config.set("Lists.TransparentBlocks", oldConfig.get("Lists.TransparentBlocks"));
this.config.set("Lists.NonTransparentBlocks", oldConfig.get("Lists.NonTransparentBlocks"));
}
private void setWorldValues() {
FileConfiguration oldConfig = this.plugin.getConfig();
boolean worldEnabled = oldConfig.get("Booleans.UseWorldsAsBlacklist") == null
|| oldConfig.getBoolean("Booleans.UseWorldsAsBlacklist");
// Default World
this.config.set("Worlds.Default.Types", new String[] { "DEFAULT" });
this.config.set("Worlds.Default.Enabled", worldEnabled);
this.config.set("Worlds.Default.AntiTexturePackAndFreecam", oldConfig.get("Booleans.AntiTexturePackAndFreecam"));
this.config.set("Worlds.Default.AirGeneratorMaxChance", oldConfig.get("Integers.AirGeneratorMaxChance"));
this.config.set("Worlds.Default.DarknessHideBlocks", oldConfig.get("Booleans.DarknessHideBlocks"));
this.config.set("Worlds.Default.DarknessBlocks", oldConfig.get("Lists.DarknessBlocks"));
this.config.set("Worlds.Default.Mode1Block", 1);
this.config.set("Worlds.Default.ProximityHider.Enabled", oldConfig.get("Booleans.UseProximityHider"));
this.config.set("Worlds.Default.ProximityHider.Distance", oldConfig.get("Integers.ProximityHiderDistance"));
this.config.set("Worlds.Default.ProximityHider.SpecialBlock", oldConfig.get("Integers.ProximityHiderID"));
this.config.set("Worlds.Default.ProximityHider.EndY", oldConfig.get("Integers.ProximityHiderEnd"));
this.config.set("Worlds.Default.ProximityHider.UseSpecialBlock", oldConfig.get("Booleans.UseSpecialBlockForProximityHider"));
this.config.set("Worlds.Default.ProximityHider.UseEndY", oldConfig.get("Booleans.UseYLocationProximity"));
this.config.set("Worlds.Default.ProximityHider.ProximityHiderBlocks", oldConfig.get("Lists.ProximityHiderBlocks"));
//Normal and TheEnd Worlds
this.config.set("Worlds.Normal.Types", new String[] { "NORMAL", "THE_END" });
this.config.set("Worlds.Normal.Mode1Block", 1);
this.config.set("Worlds.Normal.RandomBlocks", oldConfig.get("Lists.RandomBlocks"));
this.config.set("Worlds.Normal.ObfuscateBlocks", oldConfig.get("Lists.ObfuscateBlocks"));
//Nether World
this.config.set("Worlds.Nether.Types", new String[] { "NETHER" });
this.config.set("Worlds.Nether.Mode1Block", 87);
this.config.set("Worlds.Nether.RandomBlocks", oldConfig.get("Lists.NetherRandomBlocks"));
this.config.set("Worlds.Nether.ObfuscateBlocks", oldConfig.get("Lists.NetherObfuscateBlocks"));
List<String> worldNames = oldConfig.getStringList("Lists.Worlds");
if(worldNames == null) {
worldNames = oldConfig.getStringList("Lists.DisabledWorlds");
}
if(worldNames != null && worldNames.size() > 0) {
this.config.set("Worlds.CustomWorld.Names", worldNames);
this.config.set("Worlds.CustomWorld.Enabled", !worldEnabled);
}
}
}

View File

@ -0,0 +1,136 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.orebfuscator.DeprecatedMethods;
import com.lishid.orebfuscator.utils.Globals;
public class MaterialReader {
private JavaPlugin plugin;
private Logger logger;
public MaterialReader(JavaPlugin plugin, Logger logger) {
this.plugin = plugin;
this.logger = logger;
}
private FileConfiguration getConfig() {
return this.plugin.getConfig();
}
public Integer getMaterialIdByPath(String path, Integer defaultMaterialId, boolean withSave) {
boolean hasKey = getConfig().get(path) != null;
if(!hasKey && defaultMaterialId == null) {
return null;
}
String materialName = hasKey ? getConfig().getString(path): Integer.toString(defaultMaterialId);
MaterialResult material = getMaterial(materialName, defaultMaterialId);
if(withSave || hasKey) {
getConfig().set(path, material.name);
}
return material.id;
}
public Integer[] getMaterialIdsByPath(String path, Integer[] defaultMaterials, boolean withSave) {
List<String> list;
if(getConfig().get(path) != null) {
list = getConfig().getStringList(path);
withSave = true;
} else {
if(defaultMaterials != null) {
list = new ArrayList<String>();
for(int materialId : defaultMaterials) {
list.add(DeprecatedMethods.getMaterial(materialId).name());
}
} else {
return null;
}
}
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);
}
}
if(withSave) {
getConfig().set(path, list);
}
return result.toArray(new Integer[0]);
}
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(Globals.LogPrefix + "Material with ID = " + materialId + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info(Globals.LogPrefix + "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(Globals.LogPrefix + "Material " + materialName + " is not found. Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info(Globals.LogPrefix + "Material " + materialName + " is not found. Skipped.");
materialId = null;
}
}
}
} catch (Exception e) {
if(defaultMaterialId != null) {
this.logger.info(Globals.LogPrefix + "Invalid material ID or name: " + materialName + ". Will be used default material: " + defaultMaterialName);
materialId = defaultMaterialId;
materialName = defaultMaterialName;
} else {
this.logger.info(Globals.LogPrefix + "Invalid material ID or name: " + materialName + ". Skipped.");
materialId = null;
}
}
return materialId != null ? new MaterialResult(materialId, materialName): null;
}
}

View File

@ -6,7 +6,7 @@
package com.lishid.orebfuscator.config;
public class MaterialResult {
public int id;
public Integer id;
public String name;
public MaterialResult(int id, String name) {

View File

@ -7,8 +7,6 @@ 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;
@ -38,7 +36,7 @@ public class OrebfuscatorConfig {
private WorldConfig normalWorld;
private WorldConfig endWorld;
private WorldConfig netherWorld;
private Map<World, WorldConfig> worlds;
private Map<String, WorldConfig> worlds;
private boolean proximityHiderEnabled;
@ -49,28 +47,6 @@ public class OrebfuscatorConfig {
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;
}
@ -223,11 +199,11 @@ public class OrebfuscatorConfig {
this.netherWorld = value;
}
public Map<World, WorldConfig> getWorlds() {
public Map<String, WorldConfig> getWorlds() {
return this.worlds;
}
public void setWorlds(Map<World, WorldConfig> value) {
public void setWorlds(Map<String, WorldConfig> value) {
this.worlds = value;
}
@ -243,7 +219,7 @@ public class OrebfuscatorConfig {
if(!this.proximityHiderEnabled) {
for(WorldConfig world : this.worlds.values()) {
if(world.getProximityHiderConfig().isEnabled()) {
if(world.getProximityHiderConfig().isEnabled() != null && world.getProximityHiderConfig().isEnabled()) {
this.proximityHiderEnabled = true;
break;
}

View File

@ -5,60 +5,117 @@
package com.lishid.orebfuscator.config;
import java.util.ArrayList;
import java.util.List;
public class ProximityHiderConfig {
private boolean enabled;
private int distance;
private int specialBlockID;
private int endY;
private boolean useSpecialBlock;
private boolean useYLocationProximity;
private static final Integer[] defaultProximityHiderBlockIds = new Integer[]{ 23, 52, 54, 56, 58, 61, 62, 116, 129, 130, 145, 146 };
private Boolean enabled;
private Integer distance;
private int distanceSquared;
private Integer specialBlockID;
private Integer endY;
private Boolean useSpecialBlock;
private Boolean useYLocationProximity;
private boolean[] proximityHiderBlocks;
public boolean isEnabled() {
public void setDefaults() {
this.enabled = true;
this.distance = 8;
this.distanceSquared = this.distance * this.distance;
this.specialBlockID = 1;
this.endY = 255;
this.useSpecialBlock = true;
this.useYLocationProximity = false;
this.proximityHiderBlocks = new boolean[256];
for(Integer id : defaultProximityHiderBlockIds) {
this.proximityHiderBlocks[id] = true;
}
}
public void init(ProximityHiderConfig baseCfg) {
if(this.enabled == null) {
this.enabled = baseCfg.enabled;
}
if(this.distance == null) {
this.distance = baseCfg.distance;
this.distanceSquared = baseCfg.distanceSquared;
}
if(this.specialBlockID == null) {
this.specialBlockID = baseCfg.specialBlockID;
}
if(this.endY == null) {
this.endY = baseCfg.endY;
}
if(this.useSpecialBlock == null) {
this.useSpecialBlock = baseCfg.useSpecialBlock;
}
if(this.useYLocationProximity == null) {
this.useYLocationProximity = baseCfg.useYLocationProximity;
}
if(this.proximityHiderBlocks == null && baseCfg.proximityHiderBlocks != null) {
this.proximityHiderBlocks = baseCfg.proximityHiderBlocks.clone();
}
}
public Boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean value) {
public void setEnabled(Boolean value) {
this.enabled = value;
}
public int getDistance() {
public Integer getDistance() {
return this.distance;
}
public void setDistance(int value) {
public void setDistance(Integer value) {
this.distance = value;
this.distanceSquared = this.distance != null ? this.distance * this.distance: 0;
}
public int getSpecialBlockID() {
public int getDistanceSquared() {
return this.distanceSquared;
}
public Integer getSpecialBlockID() {
return this.specialBlockID;
}
public void setSpecialBlockID(int value) {
public void setSpecialBlockID(Integer value) {
this.specialBlockID = value;
}
public int getEndY() {
public Integer getEndY() {
return this.endY;
}
public void setEndY(int value) {
public void setEndY(Integer value) {
this.endY = value;
}
public boolean isUseSpecialBlock() {
public Boolean isUseSpecialBlock() {
return this.useSpecialBlock;
}
public void setUseSpecialBlock(boolean value) {
public void setUseSpecialBlock(Boolean value) {
this.useSpecialBlock = value;
}
public boolean isUseYLocationProximity() {
public Boolean isUseYLocationProximity() {
return this.useYLocationProximity;
}
public void setUseYLocationProximity(boolean value) {
public void setUseYLocationProximity(Boolean value) {
this.useYLocationProximity = value;
}
@ -70,22 +127,25 @@ public class ProximityHiderConfig {
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;
public Integer[] getProximityHiderBlockIds() {
if(this.proximityHiderBlocks == null) {
return null;
}
List<Integer> result = new ArrayList<Integer>();
for(Integer i = 0; i < this.proximityHiderBlocks.length; i++) {
if(this.proximityHiderBlocks[i]) {
result.add(i);
}
}
return result.toArray(new Integer[0]);
}
// Help methods
public boolean isProximityObfuscated(int y, int id) {
public Boolean isProximityObfuscated(Integer y, Integer id) {
if (id < 0)
id += 256;
@ -96,7 +156,7 @@ public class ProximityHiderConfig {
);
}
public boolean skipProximityHiderCheck(int y) {
public Boolean skipProximityHiderCheck(Integer y) {
return this.useYLocationProximity && y < this.endY;
}
}

View File

@ -5,51 +5,137 @@
package com.lishid.orebfuscator.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class WorldConfig {
private boolean enabled;
private boolean darknessHideBlocks;
private boolean antiTexturePackAndFreecam;
private int airGeneratorMaxChance;
private Boolean enabled;
private Boolean darknessHideBlocks;
private Boolean antiTexturePackAndFreecam;
private Integer airGeneratorMaxChance;
private boolean[] obfuscateBlocks;
private boolean[] obfuscateAndProximityBlocks;
private boolean[] darknessBlocks;
private Integer[] randomBlocks;
private Integer[] randomBlocks2;
private int mode1BlockId;
private Integer mode1BlockId;
private int[] paletteBlocks;
private ProximityHiderConfig proximityHiderConfig;
private boolean initialized;
public boolean isEnabled() {
public WorldConfig() {
this.proximityHiderConfig = new ProximityHiderConfig();
}
public void setDefaults() {
this.enabled = true;
this.darknessHideBlocks = false;
this.antiTexturePackAndFreecam = true;
this.airGeneratorMaxChance = 43;
this.obfuscateBlocks = new boolean[256];
this.obfuscateAndProximityBlocks = new boolean[256];
this.darknessBlocks = new boolean[256];
this.darknessBlocks[52] = true;
this.darknessBlocks[54] = true;
this.randomBlocks = new Integer[0];
this.randomBlocks2 = this.randomBlocks;
this.mode1BlockId = 1;
this.paletteBlocks = null;
this.proximityHiderConfig.setDefaults();
}
public void init(WorldConfig baseWorld) {
if(this.initialized) {
return;
}
if(baseWorld != null) {
if(this.enabled == null) {
this.enabled = baseWorld.enabled;
}
if(this.darknessHideBlocks == null) {
this.darknessHideBlocks = baseWorld.darknessHideBlocks;
}
if(this.antiTexturePackAndFreecam == null) {
this.antiTexturePackAndFreecam = baseWorld.antiTexturePackAndFreecam;
}
if(this.airGeneratorMaxChance == null) {
this.airGeneratorMaxChance = baseWorld.airGeneratorMaxChance;
}
if(this.obfuscateBlocks == null) {
this.obfuscateBlocks = baseWorld.obfuscateBlocks != null ? baseWorld.obfuscateBlocks.clone(): null;
}
if(this.obfuscateAndProximityBlocks == null) {
this.obfuscateAndProximityBlocks = baseWorld.obfuscateAndProximityBlocks != null ? baseWorld.obfuscateAndProximityBlocks.clone(): null;
}
if(this.darknessBlocks == null) {
this.darknessBlocks = baseWorld.darknessBlocks != null ? baseWorld.darknessBlocks.clone(): null;
}
if(this.randomBlocks == null) {
this.randomBlocks = baseWorld.randomBlocks != null ? baseWorld.randomBlocks.clone(): null;
this.randomBlocks2 = baseWorld.randomBlocks2 != null ? baseWorld.randomBlocks2.clone(): null;
}
if(this.mode1BlockId == null) {
this.mode1BlockId = baseWorld.mode1BlockId;
}
this.proximityHiderConfig.init(baseWorld.proximityHiderConfig);
}
setPaletteBlocks();
setObfuscateAndProximityBlocks();
this.initialized = true;
}
public boolean isInitialized() {
return this.initialized;
}
public Boolean isEnabled() {
return this.enabled;
}
public void setEnabled(boolean value) {
public void setEnabled(Boolean value) {
this.enabled = value;
}
public boolean isDarknessHideBlocks() {
public Boolean isDarknessHideBlocks() {
return this.darknessHideBlocks;
}
public void setDarknessHideBlocks(boolean value) {
public void setDarknessHideBlocks(Boolean value) {
this.darknessHideBlocks = value;
}
public boolean isAntiTexturePackAndFreecam() {
public Boolean isAntiTexturePackAndFreecam() {
return this.antiTexturePackAndFreecam;
}
public void setAntiTexturePackAndFreecam(boolean value) {
public void setAntiTexturePackAndFreecam(Boolean value) {
this.antiTexturePackAndFreecam = value;
}
public int getAirGeneratorMaxChance() {
public Integer getAirGeneratorMaxChance() {
return this.airGeneratorMaxChance;
}
public void setAirGeneratorMaxChance(int value) {
public void setAirGeneratorMaxChance(Integer value) {
this.airGeneratorMaxChance = value;
}
@ -61,6 +147,34 @@ public class WorldConfig {
this.obfuscateBlocks = values;
}
public Integer[] getObfuscateBlockIds() {
if(this.obfuscateBlocks == null) {
return null;
}
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i < this.obfuscateBlocks.length; i++) {
if(this.obfuscateBlocks[i]) {
result.add(i);
}
}
return result.toArray(new Integer[0]);
}
private void setObfuscateAndProximityBlocks() {
boolean isProximityHiderEnabled = this.proximityHiderConfig != null && this.proximityHiderConfig.isEnabled();
boolean[] proximityHiderBlocks = isProximityHiderEnabled ? this.proximityHiderConfig.getProximityHiderBlocks(): null;
for(int i = 0; i < this.obfuscateAndProximityBlocks.length; i++) {
this.obfuscateAndProximityBlocks[i] =
this.obfuscateBlocks[i]
|| isProximityHiderEnabled && proximityHiderBlocks[i]
;
}
}
public boolean[] getDarknessBlocks() {
return this.darknessBlocks;
}
@ -69,6 +183,22 @@ public class WorldConfig {
this.darknessBlocks = values;
}
public Integer[] getDarknessBlockIds() {
if(this.darknessBlocks == null) {
return null;
}
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i < this.darknessBlocks.length; i++) {
if(this.darknessBlocks[i]) {
result.add(i);
}
}
return result.toArray(new Integer[0]);
}
public Integer[] getRandomBlocks() {
return this.randomBlocks;
}
@ -89,20 +219,46 @@ public class WorldConfig {
}
}
public int getMode1BlockId() {
public Integer getMode1BlockId() {
return this.mode1BlockId;
}
public void setMode1BlockId(int value) {
public void setMode1BlockId(Integer value) {
this.mode1BlockId = value;
}
public int[] getPaletteBlocks() {
return this.paletteBlocks;
}
public void setPaletteBlocks(int[] values) {
this.paletteBlocks = values;
private void setPaletteBlocks() {
if(this.randomBlocks == null) {
return;
}
HashSet<Integer> map = new HashSet<Integer>();
map.add(0);
map.add(this.mode1BlockId);
if(this.proximityHiderConfig.isUseSpecialBlock()) {
map.add(this.proximityHiderConfig.getSpecialBlockID());
}
for(Integer id : this.randomBlocks) {
if(id != null) {
map.add(id);
}
}
int[] paletteBlocks = new int[map.size()];
int index = 0;
for(Integer id : map) {
paletteBlocks[index++] = id;
}
this.paletteBlocks = paletteBlocks;
}
public ProximityHiderConfig getProximityHiderConfig() {
@ -113,29 +269,13 @@ public class WorldConfig {
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];
return this.obfuscateAndProximityBlocks[id];
}
public boolean isDarknessObfuscated(int id) {

View File

@ -0,0 +1,393 @@
/**
* @author Aleksey Terzi
*
*/
package com.lishid.orebfuscator.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import com.lishid.orebfuscator.utils.Globals;
public class WorldReader {
private static enum WorldType { Default, Normal, TheEnd, Nether }
private boolean[] transparentBlocks;
private WorldConfig defaultWorld;
private WorldConfig normalWorld;
private WorldConfig endWorld;
private WorldConfig netherWorld;
private Map<String, WorldConfig> worlds;
private JavaPlugin plugin;
private Logger logger;
private OrebfuscatorConfig orebfuscatorConfig;
private MaterialReader materialReader;
public WorldReader(
JavaPlugin plugin,
Logger logger,
OrebfuscatorConfig orebfuscatorConfig,
MaterialReader materialReader
)
{
this.plugin = plugin;
this.logger = logger;
this.orebfuscatorConfig = orebfuscatorConfig;
this.materialReader = materialReader;
}
public void load() {
this.transparentBlocks = this.orebfuscatorConfig.getTransparentBlocks();
ConfigurationSection section = getConfig().getConfigurationSection("Worlds");
Set<String> keys = section != null ? section.getKeys(false): new HashSet<String>();
this.defaultWorld = readWorldByType(keys, WorldType.Default, null);
this.normalWorld = readWorldByType(keys, WorldType.Normal, this.defaultWorld);
this.endWorld = readWorldByType(keys, WorldType.TheEnd, this.defaultWorld);
this.netherWorld = readWorldByType(keys, WorldType.Nether, this.defaultWorld);
this.worlds = new WeakHashMap<String, WorldConfig>();
for(String key : keys) {
readWorldsByName("Worlds." + key);
}
this.orebfuscatorConfig.setDefaultWorld(this.defaultWorld);
this.orebfuscatorConfig.setNormalWorld(this.normalWorld);
this.orebfuscatorConfig.setEndWorld(this.endWorld);
this.orebfuscatorConfig.setNetherWorld(this.netherWorld);
this.orebfuscatorConfig.setWorlds(this.worlds);
}
private FileConfiguration getConfig() {
return this.plugin.getConfig();
}
public static String createPath(String path, String key, FileConfiguration config) {
int counter = 1;
String newPath = path + "." + key;
while(config.get(newPath) != null) {
newPath = path + "." + key + (counter++);
}
return newPath;
}
private WorldConfig readWorldByType(Set<String> keys, WorldType worldType, WorldConfig baseWorld) {
WorldConfig world = null;
for(String key : keys) {
String worldPath = "Worlds." + key;
List<String> types = getStringList(worldPath + ".Types", null, false);
if(types != null && types.size() > 0 && parseWorldTypes(types).contains(worldType)) {
if(worldType == WorldType.Default) {
world = new WorldConfig();
world.setDefaults();
}
world = readWorld(worldPath, world, worldType == WorldType.Default);
break;
}
}
if(world == null) {
switch(worldType) {
case Default:
world = createDefaultWorld(createPath("Worlds", "Default", getConfig()));
break;
case Normal:
world = createNormalWorld(createPath("Worlds", "Normal", getConfig()));
break;
case TheEnd:
world = createEndWorld(createPath("Worlds", "TheEnd", getConfig()));
break;
case Nether:
world = createNetherWorld(createPath("Worlds", "Nether", getConfig()));
break;
}
}
world.init(baseWorld);
return world;
}
private void readWorldsByName(String worldPath) {
List<String> names = getStringList(worldPath + ".Names", null, false);
if(names == null || names.size() == 0) {
return;
}
for(String name : names) {
String key = name.toLowerCase();
if(!this.worlds.containsKey(key)) {
this.worlds.put(key, readWorld(worldPath, null, false));
}
}
}
private List<WorldType> parseWorldTypes(List<String> types) {
List<WorldType> parsedTypes = new ArrayList<WorldType>();
for(String type : types) {
WorldType worldType;
if(type.equalsIgnoreCase("DEFAULT")) {
worldType = WorldType.Default;
} else if(type.equalsIgnoreCase("NORMAL")) {
worldType = WorldType.Normal;
} else if(type.equalsIgnoreCase("THE_END")) {
worldType = WorldType.TheEnd;
} else if(type.equalsIgnoreCase("NETHER")) {
worldType = WorldType.Nether;
} else {
this.logger.log(Level.WARNING, Globals.LogPrefix + "World type '" + type + "' is not supported.");
continue;
}
parsedTypes.add(worldType);
}
return parsedTypes;
}
private WorldConfig readWorld(String worldPath, WorldConfig cfg, boolean withSave) {
if(cfg == null) {
cfg = new WorldConfig();
}
Boolean enabled = getBoolean(worldPath + ".Enabled", cfg.isEnabled(), withSave);
Boolean antiTexturePackAndFreecam = getBoolean(worldPath + ".AntiTexturePackAndFreecam", cfg.isAntiTexturePackAndFreecam(), withSave);
Integer airGeneratorMaxChance = getInt(worldPath + ".AirGeneratorMaxChance", cfg.getAirGeneratorMaxChance(), 40, 100, withSave);
Boolean darknessHideBlocks = getBoolean(worldPath + ".DarknessHideBlocks", cfg.isDarknessHideBlocks(), withSave);
boolean[] darknessBlocks = readBlockMatrix(cfg.getDarknessBlocks(), cfg.getDarknessBlockIds(), worldPath + ".DarknessBlocks", withSave);
Integer mode1Block = this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", cfg.getMode1BlockId(), withSave);
Integer[] randomBlocks = this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", cfg.getRandomBlocks(), withSave);
boolean[] obfuscateBlocks = readBlockMatrix(cfg.getObfuscateBlocks(), cfg.getObfuscateBlockIds(), worldPath + ".ObfuscateBlocks", withSave);
readProximityHider(worldPath, cfg, withSave);
cfg.setEnabled(enabled);
cfg.setAntiTexturePackAndFreecam(antiTexturePackAndFreecam);
cfg.setAirGeneratorMaxChance(airGeneratorMaxChance);
cfg.setDarknessHideBlocks(darknessHideBlocks);
cfg.setDarknessBlocks(darknessBlocks);
cfg.setMode1BlockId(mode1Block);
cfg.setRandomBlocks(randomBlocks);
cfg.setObfuscateBlocks(obfuscateBlocks);
return cfg;
}
private void readProximityHider(String worldPath, WorldConfig worldConfig, boolean withSave) {
ProximityHiderConfig cfg = worldConfig.getProximityHiderConfig();
String sectionPath = worldPath + ".ProximityHider";
Boolean enabled = getBoolean(sectionPath + ".Enabled", cfg.isEnabled(), withSave);
Integer distance = getInt(sectionPath + ".Distance", cfg.getDistance(), 2, 64, withSave);
Integer specialBlockID = this.materialReader.getMaterialIdByPath(sectionPath + ".SpecialBlock", cfg.getSpecialBlockID(), withSave);
Integer endY = getInt(sectionPath + ".EndY", cfg.getEndY(), 0, 255, withSave);
Boolean useSpecialBlock = getBoolean(sectionPath + ".UseSpecialBlock", cfg.isUseSpecialBlock(), withSave);
Boolean useYLocationProximity = getBoolean(sectionPath + ".UseEndY", cfg.isUseYLocationProximity(), withSave);
boolean[] proximityHiderBlocks = readBlockMatrix(cfg.getProximityHiderBlocks(), cfg.getProximityHiderBlockIds(), sectionPath + ".ProximityHiderBlocks", withSave);
cfg.setEnabled(enabled);
cfg.setDistance(distance);
cfg.setSpecialBlockID(specialBlockID);
cfg.setEndY(endY);
cfg.setUseSpecialBlock(useSpecialBlock);
cfg.setUseYLocationProximity(useYLocationProximity);
cfg.setProximityHiderBlocks(proximityHiderBlocks);
}
private boolean[] readBlockMatrix(boolean[] original, Integer[] defaultBlockIds, String configKey, boolean withSave) {
boolean[] blocks = original;
Integer[] blockIds = this.materialReader.getMaterialIdsByPath(configKey, defaultBlockIds, withSave);
if(blockIds != null) {
if(blocks == null) {
blocks = new boolean[256];
}
setBlockValues(blocks, blockIds);
}
return blocks;
}
private WorldConfig createDefaultWorld(String worldPath) {
getConfig().set(worldPath + ".Types", new String[] { "DEFAULT" });
WorldConfig world = new WorldConfig();
world.setDefaults();
return readWorld(worldPath, world, true);
}
private WorldConfig createNormalWorld(String worldPath) {
Integer[] randomBlocks = new Integer[]{ 1, 4, 5, 14, 15, 16, 21, 46, 48, 49, 56, 73, 82, 129 };
Integer[] obfuscateBlockIds = new Integer[] { 14, 15, 16, 21, 54, 56, 73, 74, 129, 130 };
getConfig().set(worldPath + ".Types", new String[] { "NORMAL" });
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 1, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
boolean[] obfuscateBlocks = new boolean[256];
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
obfuscateBlocks[1] = true;
WorldConfig cfg = new WorldConfig();
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setRandomBlocks(randomBlocks);
cfg.setMode1BlockId(1);
return cfg;
}
private WorldConfig createEndWorld(String worldPath) {
Integer[] randomBlocks = new Integer[]{ 7, 49, 121, 201, 206 };
Integer[] obfuscateBlockIds = new Integer[] { 121 };
getConfig().set(worldPath + ".Types", new String[] { "THE_END" });
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 121, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
boolean[] obfuscateBlocks = new boolean[256];
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
obfuscateBlocks[121] = true;
WorldConfig cfg = new WorldConfig();
cfg.setRandomBlocks(randomBlocks);
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setMode1BlockId(121);
return cfg;
}
private WorldConfig createNetherWorld(String worldPath) {
Integer[] randomBlocks = new Integer[]{ 13, 87, 88, 112, 153 };
Integer[] obfuscateBlockIds = new Integer[]{ 87, 153 };
getConfig().set(worldPath + ".Types", new String[] { "NETHER" });
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 87, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
boolean[] obfuscateBlocks = new boolean[256];
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
obfuscateBlocks[87] = true;
WorldConfig cfg = new WorldConfig();
cfg.setRandomBlocks(randomBlocks);
cfg.setObfuscateBlocks(obfuscateBlocks);
cfg.setMode1BlockId(87);
return cfg;
}
private static void setBlockValues(boolean[] boolArray, Integer[] blocks) {
List<Integer> blockList = Arrays.asList(blocks);
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blockList.contains(i);
}
}
private void setBlockValues(boolean[] boolArray, Integer[] blocks, boolean transparent) {
List<Integer> blockList = Arrays.asList(blocks);
for (int i = 0; i < boolArray.length; i++) {
boolArray[i] = blockList.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 Integer getInt(String path, Integer defaultData, int min, int max, boolean withSave) {
if (getConfig().get(path) == null && withSave) {
getConfig().set(path, defaultData);
}
Integer value = getConfig().get(path) != null ? (Integer)getConfig().getInt(path): defaultData;
if(value != null) {
if(value < min) {
value = min;
}
else if(value > max) {
value = max;
}
}
return value;
}
private Boolean getBoolean(String path, Boolean defaultData, boolean withSave) {
if (getConfig().get(path) == null) {
if(!withSave) {
return defaultData;
}
getConfig().set(path, defaultData);
}
return getConfig().get(path) != null ? (Boolean)getConfig().getBoolean(path): defaultData;
}
private List<String> getStringList(String path, List<String> defaultData, boolean withSave) {
if (getConfig().get(path) == null) {
if(!withSave) {
return defaultData;
}
getConfig().set(path, defaultData);
}
return getConfig().getStringList(path);
}
private boolean isBlockTransparent(int id) {
if (id < 0)
id += 256;
if (id >= 256) {
return false;
}
return this.transparentBlocks[id];
}
}

View File

@ -53,7 +53,7 @@ public class BlockUpdate {
}
World world = blocks.get(0).getWorld();
WorldConfig worldConfig = Orebfuscator.config.getWorld(world);
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(world);
HashSet<IBlockInfo> updateBlocks = new HashSet<IBlockInfo>();
HashSet<ChunkCoord> invalidChunks = new HashSet<ChunkCoord>();
int updateRadius = Orebfuscator.config.getUpdateRadius();
@ -88,7 +88,7 @@ public class BlockUpdate {
}
World world = locations.get(0).getWorld();
WorldConfig worldConfig = Orebfuscator.config.getWorld(world);
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(world);
HashSet<IBlockInfo> updateBlocks = new HashSet<IBlockInfo>();
HashSet<ChunkCoord> invalidChunks = new HashSet<ChunkCoord>();

View File

@ -44,7 +44,7 @@ public class Calculations {
return null;
}
WorldConfig worldConfig = Orebfuscator.config.getWorld(player.getWorld());
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
if(!worldConfig.isEnabled()) {
return null;
@ -94,7 +94,7 @@ public class Calculations {
}
private static byte[] obfuscate(ChunkData chunkData, Player player, ArrayList<BlockCoord> proximityBlocks) throws IOException {
WorldConfig worldConfig = Orebfuscator.config.getWorld(player.getWorld());
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
int initialRadius = Orebfuscator.config.getInitialRadius();
@ -102,9 +102,6 @@ public class Calculations {
int randomIncrement = 0;
int randomIncrement2 = 0;
int randomCave = 0;
// Track of whether a block should be obfuscated or not
boolean obfuscate = false;
boolean specialObfuscate = false;
int engineMode = Orebfuscator.config.getEngineMode();
int maxChance = worldConfig.getAirGeneratorMaxChance();
@ -139,8 +136,8 @@ public class Calculations {
int z = startZ | offsetZ;
// Initialize data
obfuscate = false;
specialObfuscate = false;
boolean obfuscate = false;
boolean specialObfuscate = false;
// Check if the block should be obfuscated for the default engine modes
if (worldConfig.isObfuscated(blockState.id)) {

View File

@ -180,7 +180,7 @@ public class ChunkReloader extends Thread implements Runnable {
}
if(affectedPlayers.size() > 0) {
ProximityHiderConfig proximityHider = Orebfuscator.config.getWorld(world).getProximityHiderConfig();
ProximityHiderConfig proximityHider = Orebfuscator.configManager.getWorld(world).getProximityHiderConfig();
if(proximityHider.isEnabled()) {
ProximityHider.addPlayersToReload(affectedPlayers);
@ -199,7 +199,7 @@ public class ChunkReloader extends Thread implements Runnable {
public static void addLoadedChunk(World world, int chunkX, int chunkZ) {
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.config.getWorld(world).isEnabled() // World not enabled
|| !Orebfuscator.configManager.getWorld(world).isEnabled() // World not enabled
)
{
return;
@ -221,7 +221,7 @@ public class ChunkReloader extends Thread implements Runnable {
public static void addUnloadedChunk(World world, int chunkX, int chunkZ) {
if (!Orebfuscator.config.isEnabled() // Plugin enabled
|| !Orebfuscator.config.isUseChunkReloader()
|| !Orebfuscator.config.getWorld(world).isEnabled() // World not enabled
|| !Orebfuscator.configManager.getWorld(world).isEnabled() // World not enabled
)
{
return;

View File

@ -76,7 +76,7 @@ public class ProximityHider extends Thread implements Runnable {
running = false;
return;
}
HashMap<Player, Location> checkPlayers = new HashMap<Player, Location>();
synchronized (playersToCheck) {
@ -134,7 +134,7 @@ public class ProximityHider extends Thread implements Runnable {
continue;
}
WorldConfig worldConfig = Orebfuscator.config.getWorld(p.getWorld());
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(p.getWorld());
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
if(proximityHider.skipProximityHiderCheck(y)) {
@ -147,8 +147,7 @@ public class ProximityHider extends Thread implements Runnable {
checkRadius++;
}
int distance = proximityHider.getDistance();
int distanceSquared = distance * distance;
int distanceSquared = proximityHider.getDistanceSquared();
ArrayList<BlockCoord> removedBlocks = new ArrayList<BlockCoord>();
Location playerLocation = p.getLocation();
@ -220,7 +219,7 @@ public class ProximityHider extends Thread implements Runnable {
}
public static void addProximityBlocks(Player player, int chunkX, int chunkZ, ArrayList<BlockCoord> blocks) {
ProximityHiderConfig proximityHider = Orebfuscator.config.getWorld(player.getWorld()).getProximityHiderConfig();
ProximityHiderConfig proximityHider = Orebfuscator.configManager.getWorld(player.getWorld()).getProximityHiderConfig();
if (!proximityHider.isEnabled()) return;

View File

@ -0,0 +1,5 @@
package com.lishid.orebfuscator.utils;
public class Globals {
public static final String LogPrefix = "[OFC] ";
}