Issue #8: Variable proximity distances
parent
41b2324017
commit
db12295747
|
@ -4,7 +4,7 @@
|
|||
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator</artifactId>
|
||||
<version>4.1.12-SNAPSHOT</version>
|
||||
<version>4.1.13-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Orebfuscator4</name>
|
||||
|
|
|
@ -76,9 +76,9 @@ public class Convert12To13 {
|
|||
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.Y", 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.ObfuscateAboveY", oldConfig.get("Booleans.UseYLocationProximity"));
|
||||
this.config.set("Worlds.Default.ProximityHider.ProximityHiderBlocks", oldConfig.get("Lists.ProximityHiderBlocks"));
|
||||
|
||||
//Normal and TheEnd Worlds
|
||||
|
|
|
@ -17,6 +17,16 @@ import com.lishid.orebfuscator.DeprecatedMethods;
|
|||
import com.lishid.orebfuscator.utils.Globals;
|
||||
|
||||
public class MaterialReader {
|
||||
private static class MaterialResult {
|
||||
public Integer id;
|
||||
public String name;
|
||||
|
||||
public MaterialResult(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private JavaPlugin plugin;
|
||||
private Logger logger;
|
||||
|
||||
|
@ -28,6 +38,10 @@ public class MaterialReader {
|
|||
private FileConfiguration getConfig() {
|
||||
return this.plugin.getConfig();
|
||||
}
|
||||
|
||||
public Integer getMaterialId(String materialName) {
|
||||
return getMaterial(materialName, null).id;
|
||||
}
|
||||
|
||||
public Integer getMaterialIdByPath(String path, Integer defaultMaterialId, boolean withSave) {
|
||||
boolean hasKey = getConfig().get(path) != null;
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.config;
|
||||
|
||||
public class MaterialResult {
|
||||
public Integer id;
|
||||
public String name;
|
||||
|
||||
public MaterialResult(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -5,34 +5,45 @@
|
|||
|
||||
package com.lishid.orebfuscator.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProximityHiderConfig {
|
||||
public static class BlockSetting implements Cloneable {
|
||||
public int blockId;
|
||||
public int y;
|
||||
public boolean obfuscateAboveY;
|
||||
|
||||
public BlockSetting clone() throws CloneNotSupportedException {
|
||||
BlockSetting clone = new BlockSetting();
|
||||
clone.blockId = this.blockId;
|
||||
clone.y = this.y;
|
||||
clone.obfuscateAboveY = this.obfuscateAboveY;
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
|
||||
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 Integer y;
|
||||
private Boolean useSpecialBlock;
|
||||
private Boolean useYLocationProximity;
|
||||
private boolean[] proximityHiderBlocks;
|
||||
private Boolean obfuscateAboveY;
|
||||
private Integer[] proximityHiderBlockIds;
|
||||
private BlockSetting[] proximityHiderBlockSettings;
|
||||
private int[] proximityHiderBlockMatrix;
|
||||
|
||||
public void setDefaults() {
|
||||
this.enabled = true;
|
||||
this.distance = 8;
|
||||
this.distanceSquared = this.distance * this.distance;
|
||||
this.specialBlockID = 1;
|
||||
this.endY = 255;
|
||||
this.y = 255;
|
||||
this.useSpecialBlock = true;
|
||||
this.useYLocationProximity = false;
|
||||
this.proximityHiderBlocks = new boolean[256];
|
||||
|
||||
for(Integer id : defaultProximityHiderBlockIds) {
|
||||
this.proximityHiderBlocks[id] = true;
|
||||
}
|
||||
this.obfuscateAboveY = false;
|
||||
this.proximityHiderBlockIds = defaultProximityHiderBlockIds;
|
||||
}
|
||||
|
||||
public void init(ProximityHiderConfig baseCfg) {
|
||||
|
@ -49,21 +60,27 @@ public class ProximityHiderConfig {
|
|||
this.specialBlockID = baseCfg.specialBlockID;
|
||||
}
|
||||
|
||||
if(this.endY == null) {
|
||||
this.endY = baseCfg.endY;
|
||||
if(this.y == null) {
|
||||
this.y = baseCfg.y;
|
||||
}
|
||||
|
||||
if(this.useSpecialBlock == null) {
|
||||
this.useSpecialBlock = baseCfg.useSpecialBlock;
|
||||
}
|
||||
|
||||
if(this.useYLocationProximity == null) {
|
||||
this.useYLocationProximity = baseCfg.useYLocationProximity;
|
||||
if(this.obfuscateAboveY == null) {
|
||||
this.obfuscateAboveY = baseCfg.obfuscateAboveY;
|
||||
}
|
||||
|
||||
if(this.proximityHiderBlocks == null && baseCfg.proximityHiderBlocks != null) {
|
||||
this.proximityHiderBlocks = baseCfg.proximityHiderBlocks.clone();
|
||||
if(this.proximityHiderBlockIds == null && baseCfg.proximityHiderBlockIds != null) {
|
||||
this.proximityHiderBlockIds = baseCfg.proximityHiderBlockIds.clone();
|
||||
}
|
||||
|
||||
if(this.proximityHiderBlockSettings == null && baseCfg.proximityHiderBlockSettings != null) {
|
||||
this.proximityHiderBlockSettings = baseCfg.proximityHiderBlockSettings.clone();
|
||||
}
|
||||
|
||||
setProximityHiderBlockMatrix();
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
|
@ -95,12 +112,12 @@ public class ProximityHiderConfig {
|
|||
this.specialBlockID = value;
|
||||
}
|
||||
|
||||
public Integer getEndY() {
|
||||
return this.endY;
|
||||
public Integer getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setEndY(Integer value) {
|
||||
this.endY = value;
|
||||
public void setY(Integer value) {
|
||||
this.y = value;
|
||||
}
|
||||
|
||||
public Boolean isUseSpecialBlock() {
|
||||
|
@ -111,52 +128,66 @@ public class ProximityHiderConfig {
|
|||
this.useSpecialBlock = value;
|
||||
}
|
||||
|
||||
public Boolean isUseYLocationProximity() {
|
||||
return this.useYLocationProximity;
|
||||
public Boolean isObfuscateAboveY() {
|
||||
return this.obfuscateAboveY;
|
||||
}
|
||||
|
||||
public void setUseYLocationProximity(Boolean value) {
|
||||
this.useYLocationProximity = value;
|
||||
public void setObfuscateAboveY(Boolean value) {
|
||||
this.obfuscateAboveY = value;
|
||||
}
|
||||
|
||||
public boolean[] getProximityHiderBlocks() {
|
||||
return this.proximityHiderBlocks;
|
||||
}
|
||||
|
||||
public void setProximityHiderBlocks(boolean[] values) {
|
||||
this.proximityHiderBlocks = values;
|
||||
public void setProximityHiderBlockIds(Integer[] value) {
|
||||
this.proximityHiderBlockIds = value;
|
||||
}
|
||||
|
||||
public Integer[] getProximityHiderBlockIds() {
|
||||
if(this.proximityHiderBlocks == null) {
|
||||
return null;
|
||||
}
|
||||
return this.proximityHiderBlockIds;
|
||||
}
|
||||
|
||||
public BlockSetting[] getProximityHiderBlockSettings() {
|
||||
return this.proximityHiderBlockSettings;
|
||||
}
|
||||
|
||||
public void setProximityHiderBlockSettings(BlockSetting[] value) {
|
||||
this.proximityHiderBlockSettings = value;
|
||||
}
|
||||
|
||||
public int[] getProximityHiderBlockMatrix() {
|
||||
return this.proximityHiderBlockMatrix;
|
||||
}
|
||||
|
||||
private void setProximityHiderBlockMatrix() {
|
||||
this.proximityHiderBlockMatrix = new int[256];
|
||||
|
||||
List<Integer> result = new ArrayList<Integer>();
|
||||
|
||||
for(Integer i = 0; i < this.proximityHiderBlocks.length; i++) {
|
||||
if(this.proximityHiderBlocks[i]) {
|
||||
result.add(i);
|
||||
if(this.proximityHiderBlockIds != null) {
|
||||
for(int blockId : this.proximityHiderBlockIds) {
|
||||
this.proximityHiderBlockMatrix[blockId] = this.obfuscateAboveY ? -this.y: this.y;
|
||||
}
|
||||
}
|
||||
|
||||
return result.toArray(new Integer[0]);
|
||||
if(this.proximityHiderBlockSettings != null) {
|
||||
for(BlockSetting block : this.proximityHiderBlockSettings) {
|
||||
this.proximityHiderBlockMatrix[block.blockId] = block.obfuscateAboveY ? -block.y: block.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Help methods
|
||||
|
||||
public Boolean isProximityObfuscated(Integer y, Integer id) {
|
||||
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(Integer y) {
|
||||
return this.useYLocationProximity && y < this.endY;
|
||||
|
||||
int proximityY = this.proximityHiderBlockMatrix[id];
|
||||
|
||||
if(proximityY == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(proximityY > 0) {
|
||||
return y <= proximityY;
|
||||
}
|
||||
|
||||
return y >= (proximityY & 0x7FFFFFFF);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ public class WorldConfig {
|
|||
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;
|
||||
|
@ -77,10 +76,6 @@ public class WorldConfig {
|
|||
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;
|
||||
}
|
||||
|
@ -95,10 +90,10 @@ public class WorldConfig {
|
|||
}
|
||||
|
||||
this.proximityHiderConfig.init(baseWorld.proximityHiderConfig);
|
||||
setObfuscateAndProximityBlocks();
|
||||
}
|
||||
|
||||
setPaletteBlocks();
|
||||
setObfuscateAndProximityBlocks();
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
@ -164,13 +159,15 @@ public class WorldConfig {
|
|||
}
|
||||
|
||||
private void setObfuscateAndProximityBlocks() {
|
||||
this.obfuscateAndProximityBlocks = new boolean[256];
|
||||
|
||||
boolean isProximityHiderEnabled = this.proximityHiderConfig != null && this.proximityHiderConfig.isEnabled();
|
||||
boolean[] proximityHiderBlocks = isProximityHiderEnabled ? this.proximityHiderConfig.getProximityHiderBlocks(): null;
|
||||
int[] proximityHiderBlocks = isProximityHiderEnabled ? this.proximityHiderConfig.getProximityHiderBlockMatrix(): null;
|
||||
|
||||
for(int i = 0; i < this.obfuscateAndProximityBlocks.length; i++) {
|
||||
this.obfuscateAndProximityBlocks[i] =
|
||||
this.obfuscateBlocks[i]
|
||||
|| isProximityHiderEnabled && proximityHiderBlocks[i]
|
||||
|| isProximityHiderEnabled && proximityHiderBlocks[i] != 0
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,18 +205,55 @@ public class WorldReader {
|
|||
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);
|
||||
Integer y = getInt(sectionPath + ".Y", cfg.getY(), 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);
|
||||
Boolean useYLocationProximity = getBoolean(sectionPath + ".ObfuscateAboveY", cfg.isObfuscateAboveY(), withSave);
|
||||
Integer[] proximityHiderBlockIds = this.materialReader.getMaterialIdsByPath(sectionPath + ".ProximityHiderBlocks", cfg.getProximityHiderBlockIds(), withSave);
|
||||
ProximityHiderConfig.BlockSetting[] proximityHiderBlockSettings = readProximityHiderBlockSettings(sectionPath + ".ProximityHiderBlockSettings", cfg.getProximityHiderBlockSettings());
|
||||
|
||||
cfg.setEnabled(enabled);
|
||||
cfg.setDistance(distance);
|
||||
cfg.setSpecialBlockID(specialBlockID);
|
||||
cfg.setEndY(endY);
|
||||
cfg.setY(y);
|
||||
cfg.setUseSpecialBlock(useSpecialBlock);
|
||||
cfg.setUseYLocationProximity(useYLocationProximity);
|
||||
cfg.setProximityHiderBlocks(proximityHiderBlocks);
|
||||
cfg.setObfuscateAboveY(useYLocationProximity);
|
||||
cfg.setProximityHiderBlockIds(proximityHiderBlockIds);
|
||||
cfg.setProximityHiderBlockSettings(proximityHiderBlockSettings);
|
||||
}
|
||||
|
||||
private ProximityHiderConfig.BlockSetting[] readProximityHiderBlockSettings(
|
||||
String configKey,
|
||||
ProximityHiderConfig.BlockSetting[] defaultBlocks
|
||||
)
|
||||
{
|
||||
ConfigurationSection section = getConfig().getConfigurationSection(configKey);
|
||||
|
||||
if(section == null) {
|
||||
return defaultBlocks;
|
||||
}
|
||||
|
||||
Set<String> keys = section.getKeys(false);
|
||||
|
||||
List<ProximityHiderConfig.BlockSetting> list = new ArrayList<ProximityHiderConfig.BlockSetting>();
|
||||
|
||||
for(String key : keys) {
|
||||
Integer blockId = this.materialReader.getMaterialId(key);
|
||||
|
||||
if(blockId == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String blockPath = configKey + "." + key;
|
||||
|
||||
ProximityHiderConfig.BlockSetting block = new ProximityHiderConfig.BlockSetting();
|
||||
block.blockId = blockId;
|
||||
block.y = getConfig().getInt(blockPath + ".Y", 255);
|
||||
block.obfuscateAboveY = getConfig().getBoolean(blockPath + ".ObfuscateAboveY", false);
|
||||
|
||||
list.add(block);
|
||||
}
|
||||
|
||||
return list.toArray(new ProximityHiderConfig.BlockSetting[0]);
|
||||
}
|
||||
|
||||
private boolean[] readBlockMatrix(boolean[] original, Integer[] defaultBlockIds, String configKey, boolean withSave) {
|
||||
|
|
|
@ -113,8 +113,6 @@ public class ProximityHider extends Thread implements Runnable {
|
|||
proximityHiderTrackerLocal.put(p, localPlayerInfo = new ProximityHiderPlayer(p.getWorld()));
|
||||
}
|
||||
|
||||
int y = (int) Math.floor(p.getLocation().getY());
|
||||
|
||||
synchronized (proximityHiderTracker) {
|
||||
ProximityHiderPlayer playerInfo = proximityHiderTracker.get(p);
|
||||
|
||||
|
@ -137,10 +135,6 @@ public class ProximityHider extends Thread implements Runnable {
|
|||
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(p.getWorld());
|
||||
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
|
||||
|
||||
if(proximityHider.skipProximityHiderCheck(y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int checkRadius = proximityHider.getDistance() >> 4;
|
||||
|
||||
if((proximityHider.getDistance() & 0xf) != 0) {
|
||||
|
@ -172,7 +166,7 @@ public class ProximityHider extends Thread implements Runnable {
|
|||
|
||||
Location blockLocation = new Location(localPlayerInfo.getWorld(), b.x, b.y, b.z);
|
||||
|
||||
if (proximityHider.isUseYLocationProximity() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
|
||||
if (proximityHider.isObfuscateAboveY() || playerLocation.distanceSquared(blockLocation) < distanceSquared) {
|
||||
removedBlocks.add(b);
|
||||
|
||||
BlockState blockState = Orebfuscator.nms.getBlockState(localPlayerInfo.getWorld(), b.x, b.y, b.z);
|
||||
|
|
Loading…
Reference in New Issue