Upgraded to MC 1.13
parent
284b844bbb
commit
9fa505a079
|
@ -31,7 +31,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
|
|
@ -9,5 +9,5 @@ public interface IBlockInfo {
|
|||
int getX();
|
||||
int getY();
|
||||
int getZ();
|
||||
int getTypeId();
|
||||
int getCombinedId();
|
||||
}
|
||||
|
|
|
@ -5,14 +5,20 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface INmsManager {
|
||||
void setMaxLoadedCacheFiles(int value);
|
||||
ConfigDefaults getConfigDefaults();
|
||||
|
||||
void setMaxLoadedCacheFiles(int value);
|
||||
|
||||
INBT createNBT();
|
||||
|
||||
|
@ -25,12 +31,28 @@ public interface INmsManager {
|
|||
int getBlockLightLevel(World world, int x, int y, int z);
|
||||
|
||||
IBlockInfo getBlockInfo(World world, int x, int y, int z);
|
||||
|
||||
BlockState getBlockState(World world, int x, int y, int z);
|
||||
|
||||
int getBlockId(World world, int x, int y, int z);
|
||||
|
||||
int loadChunkAndGetBlockId(World world, int x, int y, int z);
|
||||
|
||||
String getTextFromChatComponent(String json);
|
||||
}
|
||||
|
||||
boolean isHoe(Material item);
|
||||
|
||||
boolean isSign(int combinedBlockId);
|
||||
|
||||
boolean isAir(int combinedBlockId);
|
||||
|
||||
boolean isTileEntity(int combinedBlockId);
|
||||
|
||||
int getCaveAirBlockId();
|
||||
|
||||
int getBitsPerBlock();
|
||||
|
||||
boolean canApplyPhysics(Material blockMaterial);
|
||||
|
||||
Set<Integer> getMaterialIds(Material material);
|
||||
|
||||
int getTypeId(int combinedBlockId);
|
||||
|
||||
boolean sendBlockChange(Player player, Location blockLocation);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.types;
|
||||
|
||||
public class BlockState {
|
||||
public int id;
|
||||
public int meta;
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.types;
|
||||
|
||||
public class ConfigDefaults {
|
||||
public int[] defaultProximityHiderBlockIds;
|
||||
public int[] defaultDarknessBlockIds;
|
||||
public int defaultMode1BlockId;
|
||||
public int defaultProximityHiderSpecialBlockId;
|
||||
|
||||
public int[] endWorldRandomBlockIds;
|
||||
public int[] endWorldObfuscateBlockIds;
|
||||
public int endWorldMode1BlockId;
|
||||
public int[] endWorldRequiredObfuscateBlockIds;
|
||||
|
||||
public int[] netherWorldRandomBlockIds;
|
||||
public int[] netherWorldObfuscateBlockIds;
|
||||
public int netherWorldMode1BlockId;
|
||||
public int[] netherWorldRequiredObfuscateBlockIds;
|
||||
|
||||
public int[] normalWorldRandomBlockIds;
|
||||
public int[] normalWorldObfuscateBlockIds;
|
||||
public int normalWorldMode1BlockId;
|
||||
public int[] normalWorldRequiredObfuscateBlockIds;
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator</artifactId>
|
||||
<version>4.3.4-SNAPSHOT</version>
|
||||
<version>4.4.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Orebfuscator4</name>
|
||||
|
@ -20,7 +20,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
@ -89,7 +89,23 @@
|
|||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-v1_13_R1</artifactId>
|
||||
<version>v1_13_R1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-v1_13_R2</artifactId>
|
||||
<version>v1_13_R2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<directory>../target</directory>
|
||||
|
|
|
@ -5,43 +5,11 @@
|
|||
|
||||
package com.lishid.orebfuscator;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DeprecatedMethods {
|
||||
public static Material getMaterial(int materialId) {
|
||||
return Material.getMaterial(materialId);
|
||||
public static boolean isTransparent(Material material) {
|
||||
return material.isTransparent();
|
||||
}
|
||||
|
||||
public static int getMaterialId(Material material) {
|
||||
return material.getId();
|
||||
}
|
||||
|
||||
public static boolean applyPhysics(Block block) {
|
||||
// See net.minecraft.server.v1_4_5.BlockSand.canFall(World world, int i, int j, int k)
|
||||
|
||||
int blockID = block.getRelative(0, -1, 0).getTypeId();
|
||||
|
||||
int air = Material.AIR.getId();
|
||||
int fire = Material.FIRE.getId();
|
||||
int water = Material.WATER.getId();
|
||||
int water2 = Material.STATIONARY_WATER.getId();
|
||||
int lava = Material.LAVA.getId();
|
||||
int lava2 = Material.STATIONARY_LAVA.getId();
|
||||
|
||||
return (blockID == air || blockID == fire || blockID == water || blockID == water2 || blockID == lava || blockID == lava2);
|
||||
}
|
||||
|
||||
public static int getTypeId(Block block) {
|
||||
return block.getTypeId();
|
||||
}
|
||||
|
||||
public static void sendBlockChange(Player player, Location blockLocation, BlockState blockState) {
|
||||
player.sendBlockChange(blockLocation, blockState.id, (byte)blockState.meta);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator;
|
||||
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
|
||||
public class NmsInstance {
|
||||
public static INmsManager current;
|
||||
}
|
|
@ -19,6 +19,8 @@ package com.lishid.orebfuscator;
|
|||
import java.io.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.lishid.orebfuscator.chunkmap.ChunkMapBuffer;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -50,8 +52,6 @@ public class Orebfuscator extends JavaPlugin {
|
|||
public static OrebfuscatorConfig config;
|
||||
public static ConfigManager configManager;
|
||||
|
||||
public static INmsManager nms;
|
||||
|
||||
private boolean isProtocolLibFound;
|
||||
public boolean getIsProtocolLibFound() {
|
||||
return this.isProtocolLibFound;
|
||||
|
@ -64,7 +64,11 @@ public class Orebfuscator extends JavaPlugin {
|
|||
PluginManager pm = getServer().getPluginManager();
|
||||
|
||||
instance = this;
|
||||
nms = createNmsManager();
|
||||
|
||||
NmsInstance.current = createNmsManager();
|
||||
|
||||
MaterialHelper.init();
|
||||
ChunkMapBuffer.init(NmsInstance.current.getBitsPerBlock());
|
||||
|
||||
// Load configurations
|
||||
loadOrebfuscatorConfig();
|
||||
|
@ -86,7 +90,7 @@ public class Orebfuscator extends JavaPlugin {
|
|||
(new ProtocolLibHook()).register(this);
|
||||
|
||||
// Run CacheCleaner
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, new CacheCleaner(), 0, config.getCacheCleanRate());
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new CacheCleaner(), 0, config.getCacheCleanRate());
|
||||
}
|
||||
|
||||
public void loadOrebfuscatorConfig() {
|
||||
|
@ -99,7 +103,7 @@ public class Orebfuscator extends JavaPlugin {
|
|||
|
||||
ObfuscatedDataCache.resetCacheFolder();
|
||||
|
||||
nms.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());
|
||||
NmsInstance.current.setMaxLoadedCacheFiles(config.getMaxLoadedCacheFiles());
|
||||
|
||||
//Make sure cache is cleared if config was changed since last start
|
||||
try {
|
||||
|
@ -115,7 +119,6 @@ public class Orebfuscator extends JavaPlugin {
|
|||
if(outputFile.exists()) return;
|
||||
|
||||
InputStream configStream = Orebfuscator.class.getResourceAsStream("/resources/config.example_enabledworlds.yml");
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(configStream));
|
||||
PrintWriter writer = new PrintWriter(outputFile)
|
||||
|
@ -140,7 +143,13 @@ public class Orebfuscator extends JavaPlugin {
|
|||
|
||||
String serverVersion = org.bukkit.Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
if(serverVersion.equals("v1_12_R1")) {
|
||||
if(serverVersion.equals("v1_13_R2")) {
|
||||
return new com.lishid.orebfuscator.nms.v1_13_R2.NmsManager();
|
||||
}
|
||||
else if(serverVersion.equals("v1_13_R1")) {
|
||||
return new com.lishid.orebfuscator.nms.v1_13_R1.NmsManager();
|
||||
}
|
||||
else if(serverVersion.equals("v1_12_R1")) {
|
||||
return new com.lishid.orebfuscator.nms.v1_12_R1.NmsManager();
|
||||
}
|
||||
else if(serverVersion.equals("v1_11_R1")) {
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.io.DataInputStream;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.nms.INBT;
|
||||
|
||||
public class ObfuscatedCachedChunk {
|
||||
|
@ -29,12 +29,13 @@ public class ObfuscatedCachedChunk {
|
|||
int z;
|
||||
public byte[] data;
|
||||
public int[] proximityList;
|
||||
public int[] removedEntityList;
|
||||
public long hash = 0L;
|
||||
private boolean loaded = false;
|
||||
|
||||
private static final ThreadLocal<INBT> nbtAccessor = new ThreadLocal<INBT>() {
|
||||
protected INBT initialValue() {
|
||||
return Orebfuscator.nms.createNBT();
|
||||
return NmsInstance.current.createNBT();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -46,12 +47,13 @@ public class ObfuscatedCachedChunk {
|
|||
}
|
||||
|
||||
public void invalidate() {
|
||||
write(0L, new byte[0], new int[0]);
|
||||
write(0L, new byte[0], new int[0], new int[0]);
|
||||
}
|
||||
|
||||
public void free() {
|
||||
data = null;
|
||||
proximityList = null;
|
||||
removedEntityList = null;
|
||||
}
|
||||
|
||||
public long getHash() {
|
||||
|
@ -84,6 +86,7 @@ public class ObfuscatedCachedChunk {
|
|||
// Get Data
|
||||
data = nbt.getByteArray("Data");
|
||||
proximityList = nbt.getIntArray("ProximityList");
|
||||
removedEntityList = nbt.getIntArray("RemovedEntityList");
|
||||
loaded = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -93,7 +96,7 @@ public class ObfuscatedCachedChunk {
|
|||
}
|
||||
}
|
||||
|
||||
public void write(long hash, byte[] data, int[] proximityList) {
|
||||
public void write(long hash, byte[] data, int[] proximityList, int[] removedEntityList) {
|
||||
try {
|
||||
INBT nbt = nbtAccessor.get();
|
||||
nbt.reset();
|
||||
|
@ -108,6 +111,7 @@ public class ObfuscatedCachedChunk {
|
|||
// Set data
|
||||
nbt.setByteArray("Data", data);
|
||||
nbt.setIntArray("ProximityList", proximityList);
|
||||
nbt.setIntArray("RemovedEntityList", removedEntityList);
|
||||
|
||||
DataOutputStream stream = ObfuscatedDataCache.getOutputStream(path, x, z);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
|||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
|
@ -36,7 +37,7 @@ public class ObfuscatedDataCache {
|
|||
|
||||
private static IChunkCache getInternalCache() {
|
||||
if (internalCache == null) {
|
||||
internalCache = Orebfuscator.nms.createChunkCache();
|
||||
internalCache = NmsInstance.current.createChunkCache();
|
||||
}
|
||||
return internalCache;
|
||||
}
|
||||
|
|
|
@ -6,26 +6,36 @@
|
|||
package com.lishid.orebfuscator.chunkmap;
|
||||
|
||||
public class ChunkMapBuffer {
|
||||
private static int _bitsPerBlock;
|
||||
public static int getBitsPerBlock() { return _bitsPerBlock; }
|
||||
|
||||
private static final int BITS_PER_BLOCK_SIZE = 1;
|
||||
private static final int PALETTE_LENGTH_SIZE = 5;
|
||||
private static final int DATA_ARRAY_LENGTH_SIZE = 5;
|
||||
private static final int BLOCKS_PER_CHUNK_SECTION = 16 * 16 * 16;
|
||||
private static final int DATA_ARRAY_SIZE = BLOCKS_PER_CHUNK_SECTION * 13 / 8;
|
||||
private static final int BLOCK_LIGHT_SIZE = BLOCKS_PER_CHUNK_SECTION / 2;
|
||||
private static final int SKY_LIGHT_SIZE = BLOCKS_PER_CHUNK_SECTION / 2;
|
||||
private static final int COLUMNS_PER_CHUNK = 16;
|
||||
|
||||
private static final int MAX_BYTES_PER_CHUNK =
|
||||
COLUMNS_PER_CHUNK *
|
||||
(
|
||||
BITS_PER_BLOCK_SIZE
|
||||
+ PALETTE_LENGTH_SIZE
|
||||
+ DATA_ARRAY_LENGTH_SIZE
|
||||
+ DATA_ARRAY_SIZE
|
||||
+ BLOCK_LIGHT_SIZE
|
||||
+ SKY_LIGHT_SIZE
|
||||
);
|
||||
|
||||
|
||||
private static int MAX_BYTES_PER_CHUNK;
|
||||
|
||||
public static void init(int bitsPerBlock) {
|
||||
_bitsPerBlock = bitsPerBlock;
|
||||
|
||||
int dataArraySize = BLOCKS_PER_CHUNK_SECTION * _bitsPerBlock / 8;
|
||||
|
||||
MAX_BYTES_PER_CHUNK =
|
||||
COLUMNS_PER_CHUNK *
|
||||
(
|
||||
BITS_PER_BLOCK_SIZE
|
||||
+ PALETTE_LENGTH_SIZE
|
||||
+ DATA_ARRAY_LENGTH_SIZE
|
||||
+ dataArraySize
|
||||
+ BLOCK_LIGHT_SIZE
|
||||
+ SKY_LIGHT_SIZE
|
||||
);
|
||||
}
|
||||
|
||||
public int[] palette;
|
||||
public byte[] output;
|
||||
public int[] outputPalette;
|
||||
|
|
|
@ -8,7 +8,8 @@ package com.lishid.orebfuscator.chunkmap;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
|
||||
public class ChunkMapManager {
|
||||
private static final ThreadLocal<ChunkMapBuffer> _buffer = new ThreadLocal<ChunkMapBuffer>() {
|
||||
|
@ -80,30 +81,9 @@ public class ChunkMapManager {
|
|||
}
|
||||
|
||||
public boolean inputHasNonAirBlock() {
|
||||
return this.buffer.paletteLength > 1 || this.buffer.palette[0] != 0;
|
||||
return this.buffer.paletteLength > 1 || NmsInstance.current.isAir(this.buffer.palette[0]);
|
||||
}
|
||||
|
||||
public static void blockDataToState(int blockData, BlockState blockState) {
|
||||
blockState.id = blockData >>> 4;
|
||||
blockState.meta = blockData & 0xf;
|
||||
}
|
||||
|
||||
public static int getBlockIdFromData(int blockData) {
|
||||
return blockData >>> 4;
|
||||
}
|
||||
|
||||
public static int getBlockMetaFromData(int blockData) {
|
||||
return blockData & 0xf;
|
||||
}
|
||||
|
||||
public static int blockStateToData(BlockState blockState) {
|
||||
return (blockState.id << 4) | blockState.meta;
|
||||
}
|
||||
|
||||
public static int getBlockDataFromId(int id) {
|
||||
return id << 4;
|
||||
}
|
||||
|
||||
public boolean initOutputPalette() {
|
||||
if(this.buffer.paletteLength == 0 || this.buffer.paletteLength == 255) {
|
||||
this.buffer.outputPaletteLength = 0;
|
||||
|
@ -188,9 +168,7 @@ public class ChunkMapManager {
|
|||
long paletteIndex = this.buffer.outputPaletteMap[blockData] & 0xffL;
|
||||
|
||||
if(paletteIndex == 255) {
|
||||
BlockState blockState = new BlockState();
|
||||
blockDataToState(blockData, blockState);
|
||||
throw new IllegalArgumentException("Block " + blockState.id + ":" + blockState.meta + " is absent in output palette.");
|
||||
throw new IllegalArgumentException("Block " + blockData + " is absent in output palette.");
|
||||
}
|
||||
|
||||
this.buffer.writer.writeBlockBits(paletteIndex);
|
||||
|
@ -229,7 +207,7 @@ public class ChunkMapManager {
|
|||
|
||||
private void calcOutputBitsPerBlock() {
|
||||
if(this.buffer.outputPaletteLength == 0) {
|
||||
this.buffer.outputBitsPerBlock = 13;
|
||||
this.buffer.outputBitsPerBlock = ChunkMapBuffer.getBitsPerBlock();
|
||||
} else {
|
||||
byte mask = (byte)this.buffer.outputPaletteLength;
|
||||
int index = 0;
|
||||
|
@ -356,7 +334,7 @@ public class ChunkMapManager {
|
|||
if(this.buffer.paletteLength > 0) {
|
||||
blockData = blockData >= 0 && blockData < this.buffer.paletteLength
|
||||
? this.buffer.palette[blockData]
|
||||
: 0;
|
||||
: NmsInstance.current.getCaveAirBlockId();
|
||||
}
|
||||
|
||||
layer.map[i] = blockData;
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
package com.lishid.orebfuscator.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.config.WorldConfig;
|
||||
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
|
@ -28,7 +31,6 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
|
||||
|
||||
|
@ -173,45 +175,196 @@ public class OrebfuscatorCommandExecutor {
|
|||
}
|
||||
|
||||
else if (args[0].equalsIgnoreCase("obfuscateblocks")) {
|
||||
if(args.length == 1) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "World is required parameter.");
|
||||
} else {
|
||||
String worldName = args[1];
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
|
||||
if(world == null) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "Specified world is not found.");
|
||||
} else {
|
||||
if(args.length > 2) {
|
||||
Material material = Material.getMaterial(args[2]);
|
||||
|
||||
if(material == null) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "Specified material is not found.");
|
||||
} else {
|
||||
int materialId = DeprecatedMethods.getMaterialId(material);
|
||||
|
||||
if(Orebfuscator.configManager.getWorld(world).isObfuscated(materialId))
|
||||
Orebfuscator.message(sender, material.name() + ": " + ChatColor.GREEN + "obfuscate");
|
||||
else
|
||||
Orebfuscator.message(sender, material.name() + ": " + ChatColor.RED + "not obfuscate");
|
||||
}
|
||||
} else {
|
||||
boolean[] blocks = Orebfuscator.configManager.getWorld(world).getObfuscateAndProximityBlocks();
|
||||
|
||||
Orebfuscator.message(sender, ChatColor.GREEN + "Obfuscate blocks:");
|
||||
|
||||
for(int i = 0; i < blocks.length; i++) {
|
||||
if(blocks[i]) {
|
||||
Orebfuscator.message(sender, " - " + DeprecatedMethods.getMaterial(i).name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commandObfuscateBlocks(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
else if (args[0].equalsIgnoreCase("ph")) {
|
||||
commandProximityHider(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (args[0].equalsIgnoreCase("lm")) {
|
||||
commandListMaterials(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (args[0].equalsIgnoreCase("tp")) {
|
||||
commandTransparentBlocks(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void commandObfuscateBlocks(CommandSender sender, String[] args) {
|
||||
if(args.length == 1) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "World is required parameter.");
|
||||
return;
|
||||
}
|
||||
|
||||
String worldName = args[1];
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
|
||||
if(world == null) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "Specified world is not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
if(args.length > 2) {
|
||||
Material material = Material.getMaterial(args[2]);
|
||||
|
||||
if(material == null) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "Specified material is not found.");
|
||||
} else {
|
||||
int materialId = NmsInstance.current.getMaterialIds(material).iterator().next();
|
||||
|
||||
if((Orebfuscator.configManager.getWorld(world).getObfuscatedBits(materialId) & Globals.MASK_OBFUSCATE) != 0)
|
||||
Orebfuscator.message(sender, material.name() + ": " + ChatColor.GREEN + "obfuscate");
|
||||
else
|
||||
Orebfuscator.message(sender, material.name() + ": " + ChatColor.RED + "not obfuscate");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Material[] materials = Material.values();
|
||||
ArrayList<String> blockNames = new ArrayList<>();
|
||||
|
||||
for(Material material : materials) {
|
||||
if(material.isBlock()) {
|
||||
int blockId = NmsInstance.current.getMaterialIds(material).iterator().next();
|
||||
int bits = Orebfuscator.configManager.getWorld(world).getObfuscatedBits(blockId);
|
||||
|
||||
if(bits != 0) {
|
||||
blockNames.add(material.name() + " " + ChatColor.WHITE + bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(blockNames);
|
||||
|
||||
StringBuilder blocks = new StringBuilder();
|
||||
blocks.append("Obfuscate blocks:");
|
||||
|
||||
if(blockNames.size() > 0) {
|
||||
for (String blockName : blockNames) {
|
||||
blocks.append(ChatColor.GREEN + "\n - " + blockName);
|
||||
}
|
||||
} else {
|
||||
blocks.append(" None");
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, blocks.toString());
|
||||
}
|
||||
|
||||
private static void commandProximityHider(CommandSender sender, String[] args) {
|
||||
if(args.length == 1) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "World is required parameter.");
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig worldConfig = null;
|
||||
String worldName = args[1];
|
||||
|
||||
if(worldName.startsWith(":")) {
|
||||
if(worldName.equalsIgnoreCase(":default")) {
|
||||
worldConfig = Orebfuscator.config.getDefaultWorld();
|
||||
} else if(worldName.equalsIgnoreCase(":normal")) {
|
||||
worldConfig = Orebfuscator.config.getNormalWorld();
|
||||
} else if(worldName.equalsIgnoreCase(":nether")) {
|
||||
worldConfig = Orebfuscator.config.getNetherWorld();
|
||||
} else if(worldName.equalsIgnoreCase(":end")) {
|
||||
worldConfig = Orebfuscator.config.getEndWorld();
|
||||
}
|
||||
} else {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
worldConfig = Orebfuscator.configManager.getWorld(world);
|
||||
}
|
||||
|
||||
if (worldConfig == null) {
|
||||
Orebfuscator.message(sender, ChatColor.RED + "Specified world is not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, "ProximityHider: " + (worldConfig.getProximityHiderConfig().isEnabled() ? "Enabled" : "Disabled"));
|
||||
|
||||
StringBuilder blocks = new StringBuilder();
|
||||
blocks.append("Obfuscate blocks:");
|
||||
|
||||
Set<Integer> blockIds = worldConfig.getProximityHiderConfig().getProximityHiderBlocks();
|
||||
|
||||
if(blockIds.size() > 0) {
|
||||
ArrayList<String> blockNames = new ArrayList<>();
|
||||
|
||||
for (int id : blockIds) {
|
||||
blockNames.add(MaterialHelper.getById(id).name());
|
||||
}
|
||||
|
||||
Collections.sort(blockNames);
|
||||
|
||||
for (String blockName : blockNames) {
|
||||
blocks.append("\n - " + blockName);
|
||||
}
|
||||
} else {
|
||||
blocks.append(" None");
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, blocks.toString());
|
||||
}
|
||||
|
||||
private static void commandListMaterials(CommandSender sender, String[] args) {
|
||||
Material[] materials = Material.values();
|
||||
|
||||
List<String> blockNames = new ArrayList<>();
|
||||
|
||||
for (Material material : materials) {
|
||||
if(material.isBlock()) {
|
||||
List<Integer> ids = new ArrayList<>(NmsInstance.current.getMaterialIds(material));
|
||||
Collections.sort(ids);
|
||||
|
||||
for(int id : ids) {
|
||||
blockNames.add(material.name() + " = " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(blockNames);
|
||||
|
||||
StringBuilder blocks = new StringBuilder();
|
||||
|
||||
for (String blockName : blockNames) {
|
||||
blocks.append("\n - " + blockName);
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, blocks.toString());
|
||||
}
|
||||
|
||||
private static void commandTransparentBlocks(CommandSender sender, String[] args) {
|
||||
Material[] materials = Material.values();
|
||||
|
||||
List<String> blockNames = new ArrayList<>();
|
||||
|
||||
for (Material material : materials) {
|
||||
if(material.isBlock()) {
|
||||
int blockId = NmsInstance.current.getMaterialIds(material).iterator().next();
|
||||
boolean isTransparent = Orebfuscator.config.isBlockTransparent(blockId);
|
||||
|
||||
if(isTransparent) {
|
||||
blockNames.add(material.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(blockNames);
|
||||
|
||||
StringBuilder blocks = new StringBuilder();
|
||||
blocks.append("Transparent blocks:");
|
||||
|
||||
for (String blockName : blockNames) {
|
||||
blocks.append("\n - " + blockName);
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, blocks.toString());
|
||||
}
|
||||
}
|
|
@ -5,14 +5,14 @@
|
|||
|
||||
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.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -21,11 +21,7 @@ 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;
|
||||
|
@ -107,8 +103,7 @@ public class ConfigManager {
|
|||
boolean noObfuscationForOps = getBoolean("Booleans.NoObfuscationForOps", false);
|
||||
boolean noObfuscationForPermission = getBoolean("Booleans.NoObfuscationForPermission", false);
|
||||
boolean loginNotification = getBoolean("Booleans.LoginNotification", true);
|
||||
|
||||
generateTransparentBlocks(engineMode);
|
||||
byte[] transparentBlocks = generateTransparentBlocks(engineMode);
|
||||
|
||||
this.orebfuscatorConfig.setUseCache(useCache);
|
||||
this.orebfuscatorConfig.setMaxLoadedCacheFiles(maxLoadedCacheFiles);
|
||||
|
@ -124,7 +119,7 @@ public class ConfigManager {
|
|||
this.orebfuscatorConfig.setNoObfuscationForOps(noObfuscationForOps);
|
||||
this.orebfuscatorConfig.setNoObfuscationForPermission(noObfuscationForPermission);
|
||||
this.orebfuscatorConfig.setLoginNotification(loginNotification);
|
||||
this.orebfuscatorConfig.setTransparentBlocks(this.transparentBlocks);
|
||||
this.orebfuscatorConfig.setTransparentBlocks(transparentBlocks);
|
||||
|
||||
new WorldReader(this.plugin, this.logger, this.orebfuscatorConfig, this.materialReader).load();
|
||||
|
||||
|
@ -266,71 +261,25 @@ public class ConfigManager {
|
|||
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);
|
||||
private byte[] generateTransparentBlocks(int engineMode) {
|
||||
byte[] transparentBlocks = new byte[NmsInstance.current.getTypeId(MaterialHelper.getMaxId() + 1)];
|
||||
|
||||
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);
|
||||
Material[] allMaterials = Material.values();
|
||||
|
||||
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;
|
||||
for(Material material : allMaterials) {
|
||||
if(material.isBlock()) {
|
||||
boolean isTransparent = DeprecatedMethods.isTransparent(material);
|
||||
|
||||
if(!isTransparent) {
|
||||
Set<Integer> ids = NmsInstance.current.getMaterialIds(material);
|
||||
|
||||
for (int id : ids) {
|
||||
transparentBlocks[NmsInstance.current.getTypeId(id)] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return transparentBlocks;
|
||||
}
|
||||
}
|
|
@ -5,24 +5,25 @@
|
|||
|
||||
package com.lishid.orebfuscator.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
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 static class MaterialResult {
|
||||
public Integer id;
|
||||
public Set<Integer> ids;
|
||||
public String name;
|
||||
|
||||
public MaterialResult(int id, String name) {
|
||||
this.id = id;
|
||||
public MaterialResult(Set<Integer> ids, String name) {
|
||||
this.ids = ids;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +40,8 @@ public class MaterialReader {
|
|||
return this.plugin.getConfig();
|
||||
}
|
||||
|
||||
public Integer getMaterialId(String materialName) {
|
||||
return getMaterial(materialName, null).id;
|
||||
public Set<Integer> getMaterialIds(String materialName) {
|
||||
return getMaterial(materialName, null).ids;
|
||||
}
|
||||
|
||||
public Integer getMaterialIdByPath(String path, Integer defaultMaterialId, boolean withSave) {
|
||||
|
@ -57,9 +58,9 @@ public class MaterialReader {
|
|||
getConfig().set(path, material.name);
|
||||
}
|
||||
|
||||
return material.id;
|
||||
return material.ids.iterator().next();
|
||||
}
|
||||
|
||||
|
||||
public Integer[] getMaterialIdsByPath(String path, Integer[] defaultMaterials, boolean withSave) {
|
||||
List<String> list;
|
||||
|
||||
|
@ -71,80 +72,92 @@ public class MaterialReader {
|
|||
list = new ArrayList<String>();
|
||||
|
||||
for(int materialId : defaultMaterials) {
|
||||
list.add(DeprecatedMethods.getMaterial(materialId).name());
|
||||
list.add(MaterialHelper.getById(materialId).name());
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> result = new ArrayList<Integer>();
|
||||
List<Integer> result = new ArrayList<>();
|
||||
HashSet<String> uniqueNames = new HashSet<>();
|
||||
|
||||
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);
|
||||
uniqueNames.add(material.name);
|
||||
result.addAll(material.ids);
|
||||
}
|
||||
}
|
||||
|
||||
if(withSave) {
|
||||
list.clear();
|
||||
list.addAll(uniqueNames);
|
||||
Collections.sort(list);
|
||||
|
||||
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;
|
||||
private MaterialResult getMaterial(String inputMaterialName, Integer defaultMaterialId) {
|
||||
Set<Integer> materialIds = null;
|
||||
String defaultMaterialName = defaultMaterialId != null ? MaterialHelper.getById(defaultMaterialId).name(): null;
|
||||
String materialName = inputMaterialName;
|
||||
|
||||
try {
|
||||
if(Character.isDigit(materialName.charAt(0))) {
|
||||
materialId = Integer.parseInt(materialName);
|
||||
int id = Integer.parseInt(materialName);
|
||||
|
||||
Material obj = DeprecatedMethods.getMaterial(materialId);
|
||||
Material obj = MaterialHelper.getById(id);
|
||||
|
||||
if(obj != null) {
|
||||
materialName = obj.name();
|
||||
} else {
|
||||
|
||||
materialIds = new HashSet<>();
|
||||
materialIds.add(id);
|
||||
} 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;
|
||||
this.logger.info(Globals.LogPrefix + "Material with ID = " + id + " is not found. Will be used default material: " + defaultMaterialName);
|
||||
materialName = defaultMaterialName;
|
||||
|
||||
materialIds = new HashSet<>();
|
||||
materialIds.add(defaultMaterialId);
|
||||
} else {
|
||||
this.logger.info(Globals.LogPrefix + "Material with ID = " + id + " is not found. Skipped.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Material obj = Material.getMaterial(materialName.toUpperCase());
|
||||
|
||||
if(obj != null) {
|
||||
materialId = DeprecatedMethods.getMaterialId(obj);
|
||||
materialIds = NmsInstance.current.getMaterialIds(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;
|
||||
|
||||
materialIds = new HashSet<>();
|
||||
materialIds.add(defaultMaterialId);
|
||||
} 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;
|
||||
|
||||
materialIds = new HashSet<>();
|
||||
materialIds.add(defaultMaterialId);
|
||||
} else {
|
||||
this.logger.info(Globals.LogPrefix + "Invalid material ID or name: " + materialName + ". Skipped.");
|
||||
materialId = null;
|
||||
}
|
||||
}
|
||||
|
||||
return materialId != null ? new MaterialResult(materialId, materialName): null;
|
||||
|
||||
return materialIds != null ? new MaterialResult(materialIds, materialName): null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
package com.lishid.orebfuscator.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -31,7 +33,7 @@ public class OrebfuscatorConfig {
|
|||
private boolean noObfuscationForPermission;
|
||||
private boolean loginNotification;
|
||||
|
||||
private boolean[] transparentBlocks;
|
||||
private byte[] transparentBlocks;
|
||||
|
||||
private WorldConfig defaultWorld;
|
||||
private WorldConfig normalWorld;
|
||||
|
@ -158,12 +160,8 @@ public class OrebfuscatorConfig {
|
|||
this.loginNotification = value;
|
||||
}
|
||||
|
||||
public boolean[] getTransparentBlocks() {
|
||||
return this.transparentBlocks;
|
||||
}
|
||||
|
||||
public void setTransparentBlocks(boolean[] value) {
|
||||
this.transparentBlocks = value;
|
||||
public void setTransparentBlocks(byte[] transparentBlocks) {
|
||||
this.transparentBlocks = transparentBlocks;
|
||||
}
|
||||
|
||||
public WorldConfig getDefaultWorld() {
|
||||
|
@ -259,14 +257,8 @@ public class OrebfuscatorConfig {
|
|||
// Helper methods
|
||||
|
||||
public boolean isBlockTransparent(int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
if (id >= 256) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.transparentBlocks[id];
|
||||
int blockTypeId = NmsInstance.current.getTypeId(id);
|
||||
return this.transparentBlocks[blockTypeId] == 0;
|
||||
}
|
||||
|
||||
public boolean obfuscateForPlayer(Player player) {
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
package com.lishid.orebfuscator.config;
|
||||
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ProximityHiderConfig {
|
||||
public static class BlockSetting implements Cloneable {
|
||||
public int blockId;
|
||||
|
@ -22,8 +27,6 @@ public class ProximityHiderConfig {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -32,20 +35,24 @@ public class ProximityHiderConfig {
|
|||
private Boolean useSpecialBlock;
|
||||
private Boolean obfuscateAboveY;
|
||||
private Boolean useFastGazeCheck;
|
||||
private Integer[] proximityHiderBlockIds;
|
||||
private HashSet<Integer> proximityHiderBlocks;
|
||||
private BlockSetting[] proximityHiderBlockSettings;
|
||||
private int[] proximityHiderBlockMatrix;
|
||||
|
||||
private short[] proximityHiderBlocksAndY;
|
||||
|
||||
public void setDefaults() {
|
||||
this.enabled = true;
|
||||
this.distance = 8;
|
||||
this.distanceSquared = this.distance * this.distance;
|
||||
this.specialBlockID = 1;
|
||||
this.specialBlockID = NmsInstance.current.getConfigDefaults().defaultProximityHiderSpecialBlockId;
|
||||
this.y = 255;
|
||||
this.useSpecialBlock = true;
|
||||
this.obfuscateAboveY = false;
|
||||
this.useFastGazeCheck = true;
|
||||
this.proximityHiderBlockIds = defaultProximityHiderBlockIds;
|
||||
|
||||
this.proximityHiderBlocks = new HashSet<>();
|
||||
for(int blockId : NmsInstance.current.getConfigDefaults().defaultProximityHiderBlockIds) {
|
||||
this.proximityHiderBlocks.add(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
public void init(ProximityHiderConfig baseCfg) {
|
||||
|
@ -74,8 +81,9 @@ public class ProximityHiderConfig {
|
|||
this.obfuscateAboveY = baseCfg.obfuscateAboveY;
|
||||
}
|
||||
|
||||
if(this.proximityHiderBlockIds == null && baseCfg.proximityHiderBlockIds != null) {
|
||||
this.proximityHiderBlockIds = baseCfg.proximityHiderBlockIds.clone();
|
||||
if(this.proximityHiderBlocks == null && baseCfg.proximityHiderBlocks != null) {
|
||||
this.proximityHiderBlocks = new HashSet<>();
|
||||
this.proximityHiderBlocks.addAll(baseCfg.proximityHiderBlocks);
|
||||
}
|
||||
|
||||
if(this.proximityHiderBlockSettings == null && baseCfg.proximityHiderBlockSettings != null) {
|
||||
|
@ -142,12 +150,18 @@ public class ProximityHiderConfig {
|
|||
this.obfuscateAboveY = value;
|
||||
}
|
||||
|
||||
public void setProximityHiderBlockIds(Integer[] value) {
|
||||
this.proximityHiderBlockIds = value;
|
||||
public void setProximityHiderBlocks(Integer[] blockIds) {
|
||||
if(blockIds != null) {
|
||||
this.proximityHiderBlocks = new HashSet<>();
|
||||
|
||||
for (Integer id : blockIds) {
|
||||
this.proximityHiderBlocks.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Integer[] getProximityHiderBlockIds() {
|
||||
return this.proximityHiderBlockIds;
|
||||
public HashSet<Integer> getProximityHiderBlocks() {
|
||||
return this.proximityHiderBlocks;
|
||||
}
|
||||
|
||||
public BlockSetting[] getProximityHiderBlockSettings() {
|
||||
|
@ -158,22 +172,20 @@ public class ProximityHiderConfig {
|
|||
this.proximityHiderBlockSettings = value;
|
||||
}
|
||||
|
||||
public int[] getProximityHiderBlockMatrix() {
|
||||
return this.proximityHiderBlockMatrix;
|
||||
}
|
||||
|
||||
private void setProximityHiderBlockMatrix() {
|
||||
this.proximityHiderBlockMatrix = new int[256];
|
||||
|
||||
if(this.proximityHiderBlockIds != null) {
|
||||
for(int blockId : this.proximityHiderBlockIds) {
|
||||
this.proximityHiderBlockMatrix[blockId] = this.obfuscateAboveY ? -this.y: this.y;
|
||||
}
|
||||
this.proximityHiderBlocksAndY = new short[MaterialHelper.getMaxId() + 1];
|
||||
|
||||
if(this.proximityHiderBlocks == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for(int blockId : this.proximityHiderBlocks) {
|
||||
this.proximityHiderBlocksAndY[blockId] = (short)(this.obfuscateAboveY ? -this.y: this.y);
|
||||
}
|
||||
|
||||
if(this.proximityHiderBlockSettings != null) {
|
||||
for(BlockSetting block : this.proximityHiderBlockSettings) {
|
||||
this.proximityHiderBlockMatrix[block.blockId] = block.obfuscateAboveY ? -block.y: block.y;
|
||||
this.proximityHiderBlocksAndY[block.blockId] = (short)(block.obfuscateAboveY ? -block.y: block.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,21 +199,14 @@ public class ProximityHiderConfig {
|
|||
}
|
||||
|
||||
// Help methods
|
||||
|
||||
|
||||
public boolean isProximityObfuscated(int y, int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
int proximityY = this.proximityHiderBlockMatrix[id];
|
||||
|
||||
if(proximityY == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int proximityY = this.proximityHiderBlocksAndY[id];
|
||||
|
||||
if(proximityY > 0) {
|
||||
return y <= proximityY;
|
||||
return y <= proximityY;
|
||||
}
|
||||
|
||||
return y >= (proximityY & 0x7FFFFFFF);
|
||||
|
||||
return y >= (proximityY & 0xFFF);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
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;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class WorldConfig {
|
||||
private String name;
|
||||
|
@ -18,9 +18,9 @@ public class WorldConfig {
|
|||
private Boolean antiTexturePackAndFreecam;
|
||||
private Boolean bypassObfuscationForSignsWithText;
|
||||
private Integer airGeneratorMaxChance;
|
||||
private boolean[] obfuscateBlocks;
|
||||
private boolean[] obfuscateAndProximityBlocks;
|
||||
private boolean[] darknessBlocks;
|
||||
private HashSet<Integer> obfuscateBlocks;
|
||||
private HashSet<Integer> darknessBlocks;
|
||||
private byte[] obfuscateAndProximityBlocks;
|
||||
private Integer[] randomBlocks;
|
||||
private Integer[] randomBlocks2;
|
||||
private Integer mode1BlockId;
|
||||
|
@ -38,16 +38,17 @@ public class WorldConfig {
|
|||
this.antiTexturePackAndFreecam = true;
|
||||
this.bypassObfuscationForSignsWithText = false;
|
||||
this.airGeneratorMaxChance = 43;
|
||||
this.obfuscateBlocks = new boolean[256];
|
||||
|
||||
this.darknessBlocks = new boolean[256];
|
||||
this.darknessBlocks[52] = true;
|
||||
this.darknessBlocks[54] = true;
|
||||
|
||||
this.obfuscateBlocks = new HashSet<>();
|
||||
|
||||
this.darknessBlocks = new HashSet<>();
|
||||
for(int blockId : NmsInstance.current.getConfigDefaults().defaultDarknessBlockIds) {
|
||||
this.darknessBlocks.add(blockId);
|
||||
}
|
||||
|
||||
this.randomBlocks = new Integer[0];
|
||||
this.randomBlocks2 = this.randomBlocks;
|
||||
|
||||
this.mode1BlockId = 1;
|
||||
this.mode1BlockId = NmsInstance.current.getConfigDefaults().defaultMode1BlockId;
|
||||
this.paletteBlocks = null;
|
||||
|
||||
this.proximityHiderConfig.setDefaults();
|
||||
|
@ -80,11 +81,11 @@ public class WorldConfig {
|
|||
}
|
||||
|
||||
if(this.obfuscateBlocks == null) {
|
||||
this.obfuscateBlocks = baseWorld.obfuscateBlocks != null ? baseWorld.obfuscateBlocks.clone(): null;
|
||||
this.obfuscateBlocks = baseWorld.obfuscateBlocks != null ? (HashSet<Integer>)baseWorld.obfuscateBlocks.clone(): null;
|
||||
}
|
||||
|
||||
if(this.darknessBlocks == null) {
|
||||
this.darknessBlocks = baseWorld.darknessBlocks != null ? baseWorld.darknessBlocks.clone(): null;
|
||||
this.darknessBlocks = baseWorld.darknessBlocks != null ? (HashSet<Integer>)baseWorld.darknessBlocks.clone(): null;
|
||||
}
|
||||
|
||||
if(this.randomBlocks == null) {
|
||||
|
@ -157,72 +158,68 @@ public class WorldConfig {
|
|||
this.airGeneratorMaxChance = value;
|
||||
}
|
||||
|
||||
public boolean[] getObfuscateBlocks() {
|
||||
public HashSet<Integer> getObfuscateBlocks() {
|
||||
return this.obfuscateBlocks;
|
||||
}
|
||||
|
||||
public void setObfuscateBlocks(boolean[] values) {
|
||||
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]);
|
||||
}
|
||||
|
||||
|
||||
public void setObfuscateBlocks(HashSet<Integer> value) {
|
||||
this.obfuscateBlocks = value;
|
||||
}
|
||||
|
||||
public void setObfuscateBlocks(Integer[] value) {
|
||||
this.obfuscateBlocks = new HashSet<>();
|
||||
|
||||
for(int id : value) {
|
||||
this.obfuscateBlocks.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void setObfuscateAndProximityBlocks() {
|
||||
this.obfuscateAndProximityBlocks = new boolean[256];
|
||||
|
||||
boolean isProximityHiderEnabled = this.proximityHiderConfig != null && this.proximityHiderConfig.isEnabled();
|
||||
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] != 0
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean[] getObfuscateAndProximityBlocks() {
|
||||
this.obfuscateAndProximityBlocks = new byte[MaterialHelper.getMaxId() + 1];
|
||||
|
||||
setObfuscateMask(this.obfuscateBlocks, false, false);
|
||||
|
||||
if(this.darknessBlocks != null && this.darknessHideBlocks) {
|
||||
setObfuscateMask(this.darknessBlocks, true, false);
|
||||
}
|
||||
|
||||
if(this.proximityHiderConfig != null && this.proximityHiderConfig.isEnabled()) {
|
||||
setObfuscateMask(this.proximityHiderConfig.getProximityHiderBlocks(), false, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setObfuscateMask(Set<Integer> blockIds, boolean isDarknessBlock, boolean isProximityHider) {
|
||||
for(int blockId : blockIds) {
|
||||
int bits = this.obfuscateAndProximityBlocks[blockId] | Globals.MASK_OBFUSCATE;
|
||||
|
||||
if(isDarknessBlock) {
|
||||
bits |= Globals.MASK_DARKNESSBLOCK;
|
||||
}
|
||||
|
||||
if(isProximityHider) {
|
||||
bits |= Globals.MASK_PROXIMITYHIDER;
|
||||
}
|
||||
|
||||
if(NmsInstance.current.isTileEntity(blockId)) {
|
||||
bits |= Globals.MASK_TILEENTITY;
|
||||
}
|
||||
|
||||
this.obfuscateAndProximityBlocks[blockId] = (byte)bits;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getObfuscateAndProximityBlocks() {
|
||||
return this.obfuscateAndProximityBlocks;
|
||||
}
|
||||
|
||||
public boolean[] getDarknessBlocks() {
|
||||
public HashSet<Integer> getDarknessBlocks() {
|
||||
return this.darknessBlocks;
|
||||
}
|
||||
|
||||
public void setDarknessBlocks(boolean[] values) {
|
||||
public void setDarknessBlocks(HashSet<Integer> values) {
|
||||
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;
|
||||
}
|
||||
|
@ -257,8 +254,8 @@ public class WorldConfig {
|
|||
}
|
||||
|
||||
HashSet<Integer> map = new HashSet<Integer>();
|
||||
|
||||
map.add(0);
|
||||
|
||||
map.add(NmsInstance.current.getCaveAirBlockId());
|
||||
map.add(this.mode1BlockId);
|
||||
|
||||
if(this.proximityHiderConfig.isUseSpecialBlock()) {
|
||||
|
@ -287,21 +284,11 @@ public class WorldConfig {
|
|||
|
||||
// Helper methods
|
||||
|
||||
public boolean isObfuscated(int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
public int getObfuscatedBits(int id) {
|
||||
return this.obfuscateAndProximityBlocks[id];
|
||||
}
|
||||
|
||||
public boolean isDarknessObfuscated(int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
return this.darknessBlocks[id];
|
||||
}
|
||||
|
||||
public int getRandomBlock(int index, boolean alternate) {
|
||||
return (int)(alternate ? this.randomBlocks2[index] : this.randomBlocks[index]);
|
||||
return alternate ? this.randomBlocks2[index] : this.randomBlocks[index];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,19 +9,16 @@ import java.util.*;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
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 WorldReader {
|
||||
private static enum WorldType { Default, Normal, TheEnd, Nether }
|
||||
private enum WorldType { Default, Normal, TheEnd, Nether }
|
||||
|
||||
private boolean[] transparentBlocks;
|
||||
|
||||
private WorldConfig defaultWorld;
|
||||
private WorldConfig normalWorld;
|
||||
private WorldConfig endWorld;
|
||||
|
@ -47,8 +44,6 @@ public class WorldReader {
|
|||
}
|
||||
|
||||
public void load() {
|
||||
this.transparentBlocks = this.orebfuscatorConfig.getTransparentBlocks();
|
||||
|
||||
ConfigurationSection section = getConfig().getConfigurationSection("Worlds");
|
||||
Set<String> keys = section != null ? section.getKeys(false): new HashSet<String>();
|
||||
|
||||
|
@ -179,31 +174,40 @@ public class WorldReader {
|
|||
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 bypassObfuscationForSignsWithText = getBoolean(worldPath + ".BypassObfuscationForSignsWithText", cfg.isBypassObfuscationForSignsWithText(), withSave);
|
||||
boolean[] darknessBlocks = readBlockMatrix(cfg.getDarknessBlocks(), cfg.getDarknessBlockIds(), worldPath + ".DarknessBlocks", withSave);
|
||||
HashSet<Integer> darknessBlocks = readBlockMatrix(cfg.getDarknessBlocks(), 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);
|
||||
HashSet<Integer> obfuscateBlocks = readBlockMatrix(cfg.getObfuscateBlocks(), worldPath + ".ObfuscateBlocks", withSave);
|
||||
|
||||
int[] requiredObfuscateBlockIds;
|
||||
|
||||
switch(worldType) {
|
||||
case Normal:
|
||||
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.STONE)] = true;
|
||||
requiredObfuscateBlockIds = NmsInstance.current.getConfigDefaults().normalWorldRequiredObfuscateBlockIds;
|
||||
break;
|
||||
case TheEnd:
|
||||
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.ENDER_STONE)] = true;
|
||||
requiredObfuscateBlockIds = NmsInstance.current.getConfigDefaults().endWorldRequiredObfuscateBlockIds;
|
||||
break;
|
||||
case Nether:
|
||||
obfuscateBlocks[DeprecatedMethods.getMaterialId(Material.NETHERRACK)] = true;
|
||||
requiredObfuscateBlockIds = NmsInstance.current.getConfigDefaults().netherWorldRequiredObfuscateBlockIds;
|
||||
break;
|
||||
default:
|
||||
requiredObfuscateBlockIds = null;
|
||||
break;
|
||||
}
|
||||
|
||||
if(requiredObfuscateBlockIds != null) {
|
||||
for (int blockId : requiredObfuscateBlockIds) {
|
||||
obfuscateBlocks.add(blockId);
|
||||
}
|
||||
}
|
||||
|
||||
readProximityHider(worldPath, cfg, withSave);
|
||||
|
||||
cfg.setEnabled(enabled);
|
||||
|
@ -215,12 +219,13 @@ public class WorldReader {
|
|||
cfg.setMode1BlockId(mode1Block);
|
||||
cfg.setRandomBlocks(randomBlocks);
|
||||
cfg.setObfuscateBlocks(obfuscateBlocks);
|
||||
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private void readProximityHider(String worldPath, WorldConfig worldConfig, boolean withSave) {
|
||||
ProximityHiderConfig cfg = worldConfig.getProximityHiderConfig();
|
||||
Integer[] defaultProximityHiderBlockIds = cfg.getProximityHiderBlocks() != null ? cfg.getProximityHiderBlocks().toArray(new Integer[0]) : null;
|
||||
|
||||
String sectionPath = worldPath + ".ProximityHider";
|
||||
Boolean enabled = getBoolean(sectionPath + ".Enabled", cfg.isEnabled(), withSave);
|
||||
|
@ -229,7 +234,7 @@ public class WorldReader {
|
|||
Integer y = getInt(sectionPath + ".Y", cfg.getY(), 0, 255, withSave);
|
||||
Boolean useSpecialBlock = getBoolean(sectionPath + ".UseSpecialBlock", cfg.isUseSpecialBlock(), withSave);
|
||||
Boolean useYLocationProximity = getBoolean(sectionPath + ".ObfuscateAboveY", cfg.isObfuscateAboveY(), withSave);
|
||||
Integer[] proximityHiderBlockIds = this.materialReader.getMaterialIdsByPath(sectionPath + ".ProximityHiderBlocks", cfg.getProximityHiderBlockIds(), withSave);
|
||||
Integer[] proximityHiderBlockIds = this.materialReader.getMaterialIdsByPath(sectionPath + ".ProximityHiderBlocks", defaultProximityHiderBlockIds, withSave);
|
||||
ProximityHiderConfig.BlockSetting[] proximityHiderBlockSettings = readProximityHiderBlockSettings(sectionPath + ".ProximityHiderBlockSettings", cfg.getProximityHiderBlockSettings());
|
||||
Boolean useFastGazeCheck = getBoolean(sectionPath + ".UseFastGazeCheck", cfg.isUseFastGazeCheck(), withSave);
|
||||
|
||||
|
@ -239,7 +244,7 @@ public class WorldReader {
|
|||
cfg.setY(y);
|
||||
cfg.setUseSpecialBlock(useSpecialBlock);
|
||||
cfg.setObfuscateAboveY(useYLocationProximity);
|
||||
cfg.setProximityHiderBlockIds(proximityHiderBlockIds);
|
||||
cfg.setProximityHiderBlocks(proximityHiderBlockIds);
|
||||
cfg.setProximityHiderBlockSettings(proximityHiderBlockSettings);
|
||||
cfg.setUseFastGazeCheck(useFastGazeCheck);
|
||||
}
|
||||
|
@ -260,36 +265,57 @@ public class WorldReader {
|
|||
List<ProximityHiderConfig.BlockSetting> list = new ArrayList<ProximityHiderConfig.BlockSetting>();
|
||||
|
||||
for(String key : keys) {
|
||||
Integer blockId = this.materialReader.getMaterialId(key);
|
||||
Set<Integer> blockIds = this.materialReader.getMaterialIds(key);
|
||||
|
||||
if(blockId == null) {
|
||||
if(blockIds == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String blockPath = configKey + "." + key;
|
||||
int blockY = getConfig().getInt(blockPath + ".Y", 255);
|
||||
boolean blockObfuscateAboveY = getConfig().getBoolean(blockPath + ".ObfuscateAboveY", false);
|
||||
|
||||
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);
|
||||
for(int blockId : blockIds) {
|
||||
ProximityHiderConfig.BlockSetting block = new ProximityHiderConfig.BlockSetting();
|
||||
block.blockId = blockId;
|
||||
block.y = blockY;
|
||||
block.obfuscateAboveY = blockObfuscateAboveY;
|
||||
|
||||
list.add(block);
|
||||
}
|
||||
}
|
||||
|
||||
return list.toArray(new ProximityHiderConfig.BlockSetting[0]);
|
||||
}
|
||||
|
||||
private boolean[] readBlockMatrix(boolean[] original, Integer[] defaultBlockIds, String configKey, boolean withSave) {
|
||||
boolean[] blocks = original;
|
||||
private HashSet<Integer> readBlockMatrix(HashSet<Integer> original, String configKey, boolean withSave) {
|
||||
Integer[] defaultBlockIds;
|
||||
|
||||
if(original != null && original.size() != 0) {
|
||||
defaultBlockIds = new Integer[original.size()];
|
||||
|
||||
int index = 0;
|
||||
|
||||
for(Integer id : original) {
|
||||
defaultBlockIds[index++] = id;
|
||||
}
|
||||
} else {
|
||||
defaultBlockIds = null;
|
||||
}
|
||||
|
||||
Integer[] blockIds = this.materialReader.getMaterialIdsByPath(configKey, defaultBlockIds, withSave);
|
||||
|
||||
|
||||
HashSet<Integer> blocks;
|
||||
|
||||
if(blockIds != null) {
|
||||
if(blocks == null) {
|
||||
blocks = new boolean[256];
|
||||
}
|
||||
|
||||
setBlockValues(blocks, blockIds);
|
||||
}
|
||||
blocks = new HashSet<>();
|
||||
|
||||
for(int id : blockIds) {
|
||||
blocks.add(id);
|
||||
}
|
||||
} else {
|
||||
blocks = original;
|
||||
}
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
@ -304,92 +330,64 @@ public class WorldReader {
|
|||
}
|
||||
|
||||
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 };
|
||||
Integer[] randomBlocks = cloneIntArray(NmsInstance.current.getConfigDefaults().normalWorldRandomBlockIds);
|
||||
Integer[] obfuscateBlockIds = mergeIntArrays(NmsInstance.current.getConfigDefaults().normalWorldObfuscateBlockIds, NmsInstance.current.getConfigDefaults().normalWorldRequiredObfuscateBlockIds);
|
||||
|
||||
getConfig().set(worldPath + ".Types", new String[] { "NORMAL" });
|
||||
|
||||
int mode1BlockId = NmsInstance.current.getConfigDefaults().normalWorldMode1BlockId;
|
||||
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 1, true);
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", mode1BlockId, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
|
||||
|
||||
boolean[] obfuscateBlocks = new boolean[256];
|
||||
|
||||
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
|
||||
|
||||
WorldConfig cfg = new WorldConfig();
|
||||
cfg.setObfuscateBlocks(obfuscateBlocks);
|
||||
cfg.setObfuscateBlocks(obfuscateBlockIds);
|
||||
cfg.setRandomBlocks(randomBlocks);
|
||||
cfg.setMode1BlockId(1);
|
||||
cfg.setMode1BlockId(mode1BlockId);
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private WorldConfig createEndWorld(String worldPath) {
|
||||
Integer[] randomBlocks = new Integer[]{ 7, 49, 121, 201, 206 };
|
||||
Integer[] obfuscateBlockIds = new Integer[] { 121 };
|
||||
Integer[] randomBlocks = cloneIntArray(NmsInstance.current.getConfigDefaults().endWorldRandomBlockIds);
|
||||
Integer[] obfuscateBlockIds = mergeIntArrays(NmsInstance.current.getConfigDefaults().endWorldObfuscateBlockIds, NmsInstance.current.getConfigDefaults().endWorldRequiredObfuscateBlockIds);
|
||||
|
||||
getConfig().set(worldPath + ".Types", new String[] { "THE_END" });
|
||||
|
||||
int mode1BlockId = NmsInstance.current.getConfigDefaults().endWorldMode1BlockId;
|
||||
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 121, true);
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", mode1BlockId, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
|
||||
|
||||
boolean[] obfuscateBlocks = new boolean[256];
|
||||
|
||||
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
|
||||
|
||||
WorldConfig cfg = new WorldConfig();
|
||||
cfg.setRandomBlocks(randomBlocks);
|
||||
cfg.setObfuscateBlocks(obfuscateBlocks);
|
||||
cfg.setMode1BlockId(121);
|
||||
cfg.setObfuscateBlocks(obfuscateBlockIds);
|
||||
cfg.setMode1BlockId(mode1BlockId);
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private WorldConfig createNetherWorld(String worldPath) {
|
||||
Integer[] randomBlocks = new Integer[]{ 13, 87, 88, 112, 153 };
|
||||
Integer[] obfuscateBlockIds = new Integer[]{ 87, 153 };
|
||||
Integer[] randomBlocks = cloneIntArray(NmsInstance.current.getConfigDefaults().netherWorldRandomBlockIds);
|
||||
Integer[] obfuscateBlockIds = mergeIntArrays(NmsInstance.current.getConfigDefaults().netherWorldObfuscateBlockIds, NmsInstance.current.getConfigDefaults().netherWorldRequiredObfuscateBlockIds);
|
||||
|
||||
getConfig().set(worldPath + ".Types", new String[] { "NETHER" });
|
||||
|
||||
int mode1BlockId = NmsInstance.current.getConfigDefaults().netherWorldMode1BlockId;
|
||||
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", 87, true);
|
||||
this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", mode1BlockId, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", randomBlocks, true);
|
||||
this.materialReader.getMaterialIdsByPath(worldPath + ".ObfuscateBlocks", obfuscateBlockIds, true);
|
||||
|
||||
boolean[] obfuscateBlocks = new boolean[256];
|
||||
|
||||
setBlockValues(obfuscateBlocks, obfuscateBlockIds, false);
|
||||
|
||||
WorldConfig cfg = new WorldConfig();
|
||||
cfg.setRandomBlocks(randomBlocks);
|
||||
cfg.setObfuscateBlocks(obfuscateBlocks);
|
||||
cfg.setMode1BlockId(87);
|
||||
cfg.setObfuscateBlocks(obfuscateBlockIds);
|
||||
cfg.setMode1BlockId(mode1BlockId);
|
||||
|
||||
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) {
|
||||
|
@ -433,15 +431,28 @@ public class WorldReader {
|
|||
|
||||
return getConfig().getStringList(path);
|
||||
}
|
||||
|
||||
private boolean isBlockTransparent(int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
if (id >= 256) {
|
||||
return false;
|
||||
}
|
||||
private static Integer[] cloneIntArray(int[] array) {
|
||||
Integer[] result = new Integer[array.length];
|
||||
|
||||
return this.transparentBlocks[id];
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < array.length; i++) {
|
||||
result[i] = array[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Integer[] mergeIntArrays(int[] array1, int[] array2) {
|
||||
Integer[] result = new Integer[array1.length + array2.length];
|
||||
|
||||
for(int i = 0; i < array1.length; i++) {
|
||||
result[i] = array1[i];
|
||||
}
|
||||
|
||||
for(int i = 0; i < array2.length; i++) {
|
||||
result[array1.length + i] = array2[i];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -33,11 +33,13 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
|||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.chunkmap.ChunkData;
|
||||
import com.lishid.orebfuscator.config.WorldConfig;
|
||||
import com.lishid.orebfuscator.hithack.BlockHitManager;
|
||||
import com.lishid.orebfuscator.obfuscation.Calculations;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
|
||||
public class ProtocolLibHook {
|
||||
private ProtocolManager manager;
|
||||
|
@ -66,6 +68,9 @@ public class ProtocolLibHook {
|
|||
StructureModifier<Integer> ints = packet.getIntegers();
|
||||
StructureModifier<byte[]> byteArray = packet.getByteArrays();
|
||||
StructureModifier<Boolean> bools = packet.getBooleans();
|
||||
StructureModifier<List> list = packet.getSpecificModifier(List.class);
|
||||
|
||||
List nmsTags = list.read(0);
|
||||
|
||||
ChunkData chunkData = new ChunkData();
|
||||
chunkData.chunkX = ints.read(0);
|
||||
|
@ -74,12 +79,17 @@ public class ProtocolLibHook {
|
|||
chunkData.primaryBitMask = ints.read(2);
|
||||
chunkData.data = byteArray.read(0);
|
||||
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
|
||||
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
|
||||
chunkData.blockEntities = getBlockEntities(nmsTags);
|
||||
|
||||
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, player, worldConfig);
|
||||
Calculations.Result result = Calculations.obfuscateOrUseCache(chunkData, player, worldConfig);
|
||||
|
||||
if(newData != null) {
|
||||
byteArray.write(0, newData);
|
||||
if(result.output != null) {
|
||||
byteArray.write(0, result.output);
|
||||
|
||||
if(nmsTags != null) {
|
||||
removeBlockEntities(nmsTags, chunkData.blockEntities, result.removedEntities);
|
||||
list.write(0, nmsTags);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -101,23 +111,42 @@ public class ProtocolLibHook {
|
|||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static List<NbtCompound> getBlockEntities(PacketContainer packet, Player player) {
|
||||
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
|
||||
private static List<NbtCompound> getBlockEntities(List nmsTags) {
|
||||
List<NbtCompound> entities = new ArrayList<>();
|
||||
|
||||
if(nmsTags != null) {
|
||||
for (Object nmsTag : nmsTags) {
|
||||
entities.add(NbtFactory.fromNMSCompound(nmsTag));
|
||||
}
|
||||
}
|
||||
|
||||
if(!worldConfig.isBypassObfuscationForSignsWithText()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List list = packet.getSpecificModifier(List.class).read(0);
|
||||
List<NbtCompound> result = new ArrayList<NbtCompound>();
|
||||
|
||||
for(Object tag : list) {
|
||||
result.add(NbtFactory.fromNMSCompound(tag));
|
||||
}
|
||||
|
||||
return result;
|
||||
return entities;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static void removeBlockEntities(List nmsTags, List<NbtCompound> tags, List<BlockCoord> removedEntities) {
|
||||
for(int i = nmsTags.size() - 1; i >= 0; i--) {
|
||||
if(removedEntities.size() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
NbtCompound tag = tags.get(i);
|
||||
int x = tag.getInteger("x");
|
||||
int y = tag.getInteger("y");
|
||||
int z = tag.getInteger("z");
|
||||
|
||||
for(int k = 0; k < removedEntities.size(); k++) {
|
||||
BlockCoord blockCoord = removedEntities.get(k);
|
||||
|
||||
if(blockCoord.x == x && blockCoord.y == y && blockCoord.z == z) {
|
||||
nmsTags.remove(i);
|
||||
removedEntities.remove(k);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private static boolean _isSaved;
|
||||
private void saveTestData(ChunkData chunkData) {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.listeners;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
@ -26,7 +27,6 @@ import org.bukkit.event.block.BlockPhysicsEvent;
|
|||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.hithack.BlockHitManager;
|
||||
import com.lishid.orebfuscator.obfuscation.BlockUpdate;
|
||||
|
@ -62,7 +62,9 @@ public class OrebfuscatorBlockListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!DeprecatedMethods.applyPhysics(event.getBlock())) {
|
||||
Material blockMaterial = event.getBlock().getRelative(0, -1, 0).getType();
|
||||
|
||||
if(!NmsInstance.current.canApplyPhysics(blockMaterial)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.listeners;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
|
@ -71,10 +72,8 @@ public class OrebfuscatorPlayerListener implements Listener {
|
|||
if (event.getItem() != null &&
|
||||
event.getItem().getType() != null &&
|
||||
(event.getMaterial() == Material.DIRT || event.getMaterial() == Material.GRASS) &&
|
||||
((event.getItem().getType() == Material.WOOD_HOE) ||
|
||||
(event.getItem().getType() == Material.IRON_HOE) ||
|
||||
(event.getItem().getType() == Material.GOLD_HOE) ||
|
||||
(event.getItem().getType() == Material.DIAMOND_HOE)))
|
||||
NmsInstance.current.isHoe(event.getItem().getType())
|
||||
)
|
||||
{
|
||||
BlockUpdate.update(event.getClickedBlock());
|
||||
}
|
||||
|
|
|
@ -22,11 +22,12 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
|
||||
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
|
||||
|
@ -36,7 +37,8 @@ import com.lishid.orebfuscator.types.ChunkCoord;
|
|||
|
||||
public class BlockUpdate {
|
||||
public static boolean needsUpdate(Block block) {
|
||||
return !Orebfuscator.config.isBlockTransparent(DeprecatedMethods.getTypeId(block));
|
||||
int materialId = NmsInstance.current.getMaterialIds(block.getType()).iterator().next();
|
||||
return !Orebfuscator.config.isBlockTransparent(materialId);
|
||||
}
|
||||
|
||||
public static void update(Block block) {
|
||||
|
@ -60,9 +62,9 @@ public class BlockUpdate {
|
|||
|
||||
for (Block block : blocks) {
|
||||
if (needsUpdate(block)) {
|
||||
IBlockInfo blockInfo = Orebfuscator.nms.getBlockInfo(world, block.getX(), block.getY(), block.getZ());
|
||||
IBlockInfo blockInfo = NmsInstance.current.getBlockInfo(world, block.getX(), block.getY(), block.getZ());
|
||||
|
||||
getAjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
|
||||
getAdjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
|
||||
|
||||
if((blockInfo.getX() & 0xf) == 0) {
|
||||
invalidChunks.add(new ChunkCoord((blockInfo.getX() >> 4) - 1, blockInfo.getZ() >> 4));
|
||||
|
@ -93,9 +95,9 @@ public class BlockUpdate {
|
|||
HashSet<ChunkCoord> invalidChunks = new HashSet<ChunkCoord>();
|
||||
|
||||
for (Location location : locations) {
|
||||
IBlockInfo blockInfo = Orebfuscator.nms.getBlockInfo(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
IBlockInfo blockInfo = NmsInstance.current.getBlockInfo(world, location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
getAjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
|
||||
getAdjacentBlocks(updateBlocks, world, worldConfig, blockInfo, updateRadius);
|
||||
|
||||
if((blockInfo.getX() & 0xf) == 0) {
|
||||
invalidChunks.add(new ChunkCoord((blockInfo.getX() >> 4) - 1, blockInfo.getZ() >> 4));
|
||||
|
@ -117,7 +119,7 @@ public class BlockUpdate {
|
|||
//Orebfuscator.log("Notify block change for " + blocks.size() + " blocks");/*debug*/
|
||||
|
||||
for (IBlockInfo blockInfo : blocks) {
|
||||
Orebfuscator.nms.notifyBlockChange(world, blockInfo);
|
||||
NmsInstance.current.notifyBlockChange(world, blockInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +136,7 @@ public class BlockUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
private static void getAjacentBlocks(
|
||||
private static void getAdjacentBlocks(
|
||||
HashSet<IBlockInfo> allBlocks,
|
||||
World world,
|
||||
WorldConfig worldConfig,
|
||||
|
@ -144,20 +146,20 @@ public class BlockUpdate {
|
|||
{
|
||||
if (blockInfo == null) return;
|
||||
|
||||
int blockId = blockInfo.getTypeId();
|
||||
int blockId = blockInfo.getCombinedId();
|
||||
|
||||
if ((worldConfig.isObfuscated(blockId) || worldConfig.isDarknessObfuscated(blockId))) {
|
||||
if ((worldConfig.getObfuscatedBits(blockId) & Globals.MASK_OBFUSCATE) != 0) {
|
||||
allBlocks.add(blockInfo);
|
||||
}
|
||||
|
||||
if (countdown > 0) {
|
||||
countdown--;
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() + 1, blockInfo.getY(), blockInfo.getZ()), countdown);
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX() - 1, blockInfo.getY(), blockInfo.getZ()), countdown);
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() + 1, blockInfo.getZ()), countdown);
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() - 1, blockInfo.getZ()), countdown);
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() + 1), countdown);
|
||||
getAjacentBlocks(allBlocks, world, worldConfig, Orebfuscator.nms.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() - 1), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX() + 1, blockInfo.getY(), blockInfo.getZ()), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX() - 1, blockInfo.getY(), blockInfo.getZ()), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() + 1, blockInfo.getZ()), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX(), blockInfo.getY() - 1, blockInfo.getZ()), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() + 1), countdown);
|
||||
getAdjacentBlocks(allBlocks, world, worldConfig, NmsInstance.current.getBlockInfo(world, blockInfo.getX(), blockInfo.getY(), blockInfo.getZ() - 1), countdown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import com.lishid.orebfuscator.utils.MaterialHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -28,7 +32,7 @@ import org.bukkit.entity.Player;
|
|||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtType;
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.cache.ObfuscatedCachedChunk;
|
||||
import com.lishid.orebfuscator.cache.ObfuscatedDataCache;
|
||||
|
@ -37,44 +41,43 @@ import com.lishid.orebfuscator.chunkmap.ChunkMapManager;
|
|||
import com.lishid.orebfuscator.config.ProximityHiderConfig;
|
||||
import com.lishid.orebfuscator.config.WorldConfig;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
public class Calculations {
|
||||
public static class Result {
|
||||
public byte[] output;
|
||||
public ArrayList<BlockCoord> removedEntities;
|
||||
}
|
||||
|
||||
private static Random random = new Random();
|
||||
|
||||
public static byte[] obfuscateOrUseCache(ChunkData chunkData, Player player, WorldConfig worldConfig) throws IOException {
|
||||
public static Result obfuscateOrUseCache(ChunkData chunkData, Player player, WorldConfig worldConfig) throws IOException {
|
||||
if(chunkData.primaryBitMask == 0) return null;
|
||||
|
||||
byte[] output;
|
||||
ArrayList<BlockCoord> removedEntities;
|
||||
|
||||
ObfuscatedCachedChunk cache = tryUseCache(chunkData, player);
|
||||
|
||||
if(cache != null && cache.data != null) {
|
||||
//Orebfuscator.log("Read from cache");/*debug*/
|
||||
output = cache.data;
|
||||
removedEntities = getCoordFromArray(cache.removedEntityList);
|
||||
} else {
|
||||
// Blocks kept track for ProximityHider
|
||||
ArrayList<BlockCoord> proximityBlocks = new ArrayList<BlockCoord>();
|
||||
ArrayList<BlockCoord> proximityBlocks = new ArrayList<>();
|
||||
|
||||
removedEntities = new ArrayList<>();
|
||||
|
||||
output = obfuscate(chunkData, player, proximityBlocks);
|
||||
output = obfuscate(worldConfig, chunkData, player, proximityBlocks, removedEntities);
|
||||
|
||||
if (cache != null) {
|
||||
// If cache is still allowed
|
||||
if(chunkData.useCache) {
|
||||
// Save cache
|
||||
int[] proximityList = new int[proximityBlocks.size() * 3];
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < proximityBlocks.size(); i++) {
|
||||
BlockCoord b = proximityBlocks.get(i);
|
||||
if (b != null) {
|
||||
proximityList[index++] = b.x;
|
||||
proximityList[index++] = b.y;
|
||||
proximityList[index++] = b.z;
|
||||
}
|
||||
}
|
||||
|
||||
cache.write(cache.hash, output, proximityList);
|
||||
int[] proximityList = getArrayFromCoord(proximityBlocks);
|
||||
int[] removedEntityList = getArrayFromCoord(removedEntities);
|
||||
|
||||
cache.write(cache.hash, output, proximityList, removedEntityList);
|
||||
|
||||
//Orebfuscator.log("Write to cache");/*debug*/
|
||||
}
|
||||
|
@ -85,11 +88,59 @@ public class Calculations {
|
|||
|
||||
//Orebfuscator.log("Send chunk x = " + chunkData.chunkX + ", z = " + chunkData.chunkZ + " to player " + player.getName());/*debug*/
|
||||
|
||||
return output;
|
||||
Result result = new Result();
|
||||
result.output = output;
|
||||
result.removedEntities = removedEntities;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int[] getArrayFromCoord(ArrayList<BlockCoord> coords) {
|
||||
int[] list = new int[coords.size() * 3];
|
||||
int index = 0;
|
||||
|
||||
for (int i = 0; i < coords.size(); i++) {
|
||||
BlockCoord b = coords.get(i);
|
||||
if (b != null) {
|
||||
list[index++] = b.x;
|
||||
list[index++] = b.y;
|
||||
list[index++] = b.z;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static ArrayList<BlockCoord> getCoordFromArray(int[] array) {
|
||||
ArrayList<BlockCoord> list = new ArrayList<>();
|
||||
|
||||
// Decrypt chest list
|
||||
if (array != null) {
|
||||
int index = 0;
|
||||
|
||||
while (index < array.length) {
|
||||
int x = array[index++];
|
||||
int y = array[index++];
|
||||
int z = array[index++];
|
||||
BlockCoord b = new BlockCoord(x, y, z);
|
||||
|
||||
if(b != null) {
|
||||
list.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static byte[] obfuscate(ChunkData chunkData, Player player, ArrayList<BlockCoord> proximityBlocks) throws IOException {
|
||||
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
|
||||
private static byte[] obfuscate(
|
||||
WorldConfig worldConfig,
|
||||
ChunkData chunkData,
|
||||
Player player,
|
||||
ArrayList<BlockCoord> proximityBlocks,
|
||||
ArrayList<BlockCoord> removedEntities
|
||||
) throws IOException
|
||||
{
|
||||
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
|
||||
int initialRadius = Orebfuscator.config.getInitialRadius();
|
||||
|
||||
|
@ -108,11 +159,9 @@ public class Calculations {
|
|||
int startX = chunkData.chunkX << 4;
|
||||
int startZ = chunkData.chunkZ << 4;
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
|
||||
ChunkMapManager manager = new ChunkMapManager(chunkData);
|
||||
manager.init();
|
||||
|
||||
|
||||
for(int i = 0; i < manager.getSectionCount(); i++) {
|
||||
worldConfig.shuffleRandomBlocks();
|
||||
|
||||
|
@ -122,115 +171,114 @@ public class Calculations {
|
|||
|
||||
for(int offsetX = 0; offsetX < 16; offsetX++) {
|
||||
int blockData = manager.readNextBlock();
|
||||
|
||||
ChunkMapManager.blockDataToState(blockData, blockState);
|
||||
int x = startX | offsetX;
|
||||
int y = manager.getY();
|
||||
int z = startZ | offsetZ;
|
||||
|
||||
if (blockState.id < 256) {
|
||||
int x = startX | offsetX;
|
||||
int y = manager.getY();
|
||||
int z = startZ | offsetZ;
|
||||
|
||||
// Initialize data
|
||||
boolean obfuscate = false;
|
||||
boolean specialObfuscate = false;
|
||||
|
||||
// Check if the block should be obfuscated for the default engine modes
|
||||
if (worldConfig.isObfuscated(blockState.id)) {
|
||||
if (initialRadius == 0) {
|
||||
// Do not interfere with PH
|
||||
if (proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockState.id)) {
|
||||
if (!areAjacentBlocksTransparent(manager, player.getWorld(), false, x, y, z, 1)) {
|
||||
obfuscate = true;
|
||||
}
|
||||
} else {
|
||||
// Obfuscate all blocks
|
||||
obfuscate = true;
|
||||
}
|
||||
} else {
|
||||
// Check if any nearby blocks are transparent
|
||||
if (!areAjacentBlocksTransparent(manager, player.getWorld(), false, x, y, z, initialRadius)) {
|
||||
obfuscate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the block should be obfuscated because of proximity check
|
||||
if (!obfuscate && proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockState.id)) {
|
||||
BlockCoord block = new BlockCoord(x, y, z);
|
||||
if (block != null) {
|
||||
proximityBlocks.add(block);
|
||||
}
|
||||
|
||||
obfuscate = true;
|
||||
if (proximityHider.isUseSpecialBlock()) {
|
||||
specialObfuscate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the block is obfuscated
|
||||
if (obfuscate && canObfuscate(chunkData, x, y, z, blockState)) {
|
||||
if (specialObfuscate) {
|
||||
// Proximity hider
|
||||
blockState.id = proximityHider.getSpecialBlockID();
|
||||
} else {
|
||||
if (engineMode == 1) {
|
||||
// Engine mode 1, replace with stone
|
||||
blockState.id = worldConfig.getMode1BlockId();
|
||||
} else if (engineMode == 2) {
|
||||
// Ending mode 2, replace with random block
|
||||
if (randomBlocksLength > 1) {
|
||||
randomIncrement = CalculationsUtil.increment(randomIncrement, randomBlocksLength);
|
||||
}
|
||||
|
||||
blockState.id = worldConfig.getRandomBlock(randomIncrement, randomAlternate);
|
||||
randomAlternate = !randomAlternate;
|
||||
}
|
||||
// Anti texturepack and freecam
|
||||
if (worldConfig.isAntiTexturePackAndFreecam()) {
|
||||
// Add random air blocks
|
||||
randomIncrement2 = random(incrementMax);
|
||||
// Initialize data
|
||||
int obfuscateBits = worldConfig.getObfuscatedBits(blockData);
|
||||
boolean obfuscateFlag = (obfuscateBits & Globals.MASK_OBFUSCATE) != 0;
|
||||
boolean proximityHiderFlag = (obfuscateBits & Globals.MASK_PROXIMITYHIDER) != 0;
|
||||
boolean darknessBlockFlag = (obfuscateBits & Globals.MASK_DARKNESSBLOCK) != 0;
|
||||
boolean tileEntityFlag = (obfuscateBits & Globals.MASK_TILEENTITY) != 0;
|
||||
|
||||
boolean obfuscate = false;
|
||||
boolean specialObfuscate = false;
|
||||
|
||||
// Check if the block should be obfuscated for the default engine modes
|
||||
if (obfuscateFlag) {
|
||||
if (initialRadius == 0) {
|
||||
// Do not interfere with PH
|
||||
if (proximityHiderFlag && proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockData)) {
|
||||
if (!areAjacentBlocksTransparent(manager, player.getWorld(), false, x, y, z, 1)) {
|
||||
obfuscate = true;
|
||||
}
|
||||
} else {
|
||||
// Obfuscate all blocks
|
||||
obfuscate = true;
|
||||
}
|
||||
} else {
|
||||
// Check if any nearby blocks are transparent
|
||||
if (!areAjacentBlocksTransparent(manager, player.getWorld(), false, x, y, z, initialRadius)) {
|
||||
obfuscate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the block should be obfuscated because of proximity check
|
||||
if (!obfuscate && proximityHiderFlag && proximityHider.isEnabled() && proximityHider.isProximityObfuscated(y, blockData)) {
|
||||
BlockCoord block = new BlockCoord(x, y, z);
|
||||
if (block != null) {
|
||||
proximityBlocks.add(block);
|
||||
}
|
||||
|
||||
obfuscate = true;
|
||||
if (proximityHider.isUseSpecialBlock()) {
|
||||
specialObfuscate = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the block is obfuscated
|
||||
if (obfuscate && (!worldConfig.isBypassObfuscationForSignsWithText() || canObfuscate(chunkData, x, y, z, blockData))) {
|
||||
if (specialObfuscate) {
|
||||
// Proximity hider
|
||||
blockData = proximityHider.getSpecialBlockID();
|
||||
} else {
|
||||
if (engineMode == 1) {
|
||||
// Engine mode 1, replace with stone
|
||||
blockData = worldConfig.getMode1BlockId();
|
||||
} else if (engineMode == 2) {
|
||||
// Ending mode 2, replace with random block
|
||||
if (randomBlocksLength > 1) {
|
||||
randomIncrement = CalculationsUtil.increment(randomIncrement, randomBlocksLength);
|
||||
}
|
||||
|
||||
blockData = worldConfig.getRandomBlock(randomIncrement, randomAlternate);
|
||||
randomAlternate = !randomAlternate;
|
||||
}
|
||||
// Anti texturepack and freecam
|
||||
if (worldConfig.isAntiTexturePackAndFreecam()) {
|
||||
// Add random air blocks
|
||||
randomIncrement2 = random(incrementMax);
|
||||
|
||||
if (randomIncrement2 == 0) {
|
||||
randomCave = 1 + random(3);
|
||||
}
|
||||
|
||||
if (randomCave > 0) {
|
||||
blockData = NmsInstance.current.getCaveAirBlockId();
|
||||
randomCave--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the block should be obfuscated because of the darkness
|
||||
if (!obfuscate && darknessBlockFlag && worldConfig.isDarknessHideBlocks()) {
|
||||
if (!areAjacentBlocksBright(player.getWorld(), x, y, z, 1)) {
|
||||
// Hide block, setting it to air
|
||||
blockData = NmsInstance.current.getCaveAirBlockId();
|
||||
obfuscate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obfuscate && tileEntityFlag) {
|
||||
removedEntities.add(new BlockCoord(x, y, z));
|
||||
}
|
||||
|
||||
if (randomIncrement2 == 0) {
|
||||
randomCave = 1 + random(3);
|
||||
}
|
||||
|
||||
if (randomCave > 0) {
|
||||
blockState.id = 0;
|
||||
randomCave--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blockState.meta = 0;
|
||||
}
|
||||
|
||||
// Check if the block should be obfuscated because of the darkness
|
||||
if (!obfuscate && worldConfig.isDarknessHideBlocks() && worldConfig.isDarknessObfuscated(blockState.id)) {
|
||||
if (!areAjacentBlocksBright(player.getWorld(), x, y, z, 1)) {
|
||||
// Hide block, setting it to air
|
||||
blockState.id = 0;
|
||||
blockState.meta = 0;
|
||||
}
|
||||
}
|
||||
|
||||
blockData = ChunkMapManager.blockStateToData(blockState);
|
||||
} else {
|
||||
blockData = 0;
|
||||
}
|
||||
|
||||
if(offsetY == 0 && offsetZ == 0 && offsetX == 0) {
|
||||
manager.finalizeOutput();
|
||||
manager.initOutputPalette();
|
||||
addBlocksToPalette(manager, worldConfig);
|
||||
manager.initOutputSection();
|
||||
}
|
||||
|
||||
manager.writeOutputBlock(blockData);
|
||||
|
||||
manager.writeOutputBlock(blockData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
manager.finalizeOutput();
|
||||
|
||||
byte[] output = manager.createOutput();
|
||||
|
@ -242,18 +290,12 @@ public class Calculations {
|
|||
return output;
|
||||
}
|
||||
|
||||
private static boolean canObfuscate(ChunkData chunkData, int x, int y, int z, BlockState blockState) {
|
||||
if(chunkData.blockEntities == null
|
||||
|| (
|
||||
blockState.id != DeprecatedMethods.getMaterialId(Material.WALL_SIGN)
|
||||
&& blockState.id != DeprecatedMethods.getMaterialId(Material.SIGN_POST)
|
||||
)
|
||||
)
|
||||
{
|
||||
private static boolean canObfuscate(ChunkData chunkData, int x, int y, int z, int blockData) {
|
||||
if(!NmsInstance.current.isSign(blockData)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
NbtCompound tag = getNbtTag(chunkData, x, y, z);
|
||||
|
||||
NbtCompound tag = getBlockEntity(chunkData, x, y, z);
|
||||
|
||||
return tag == null ||
|
||||
isSignTextEmpty(tag, "Text1")
|
||||
|
@ -274,23 +316,22 @@ public class Calculations {
|
|||
if(json == null || json.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String text = Orebfuscator.nms.getTextFromChatComponent(json);
|
||||
|
||||
String text = NmsInstance.current.getTextFromChatComponent(json);
|
||||
|
||||
return text == null || text.isEmpty();
|
||||
}
|
||||
|
||||
private static NbtCompound getNbtTag(ChunkData chunkData, int x, int y, int z) {
|
||||
private static NbtCompound getBlockEntity(ChunkData chunkData, int x, int y, int z) {
|
||||
for(NbtCompound tag : chunkData.blockEntities) {
|
||||
if(tag != null) {
|
||||
if(x == tag.getInteger("x")
|
||||
&& y == tag.getInteger("y")
|
||||
&& z == tag.getInteger("z")
|
||||
)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
if(tag != null
|
||||
&& x == tag.getInteger("x")
|
||||
&& y == tag.getInteger("y")
|
||||
&& z == tag.getInteger("z")
|
||||
)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -302,8 +343,7 @@ public class Calculations {
|
|||
}
|
||||
|
||||
for(int id : worldConfig.getPaletteBlocks()) {
|
||||
int blockData = ChunkMapManager.getBlockDataFromId(id);
|
||||
manager.addToOutputPalette(blockData);
|
||||
manager.addToOutputPalette(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,23 +366,7 @@ public class Calculations {
|
|||
|
||||
if (storedHash == hash && cache.data != null) {
|
||||
int[] proximityList = cache.proximityList;
|
||||
ArrayList<BlockCoord> proximityBlocks = new ArrayList<BlockCoord>();
|
||||
|
||||
// Decrypt chest list
|
||||
if (proximityList != null) {
|
||||
int index = 0;
|
||||
|
||||
while (index < proximityList.length) {
|
||||
int x = proximityList[index++];
|
||||
int y = proximityList[index++];
|
||||
int z = proximityList[index++];
|
||||
BlockCoord b = new BlockCoord(x, y, z);
|
||||
|
||||
if(b != null) {
|
||||
proximityBlocks.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
ArrayList<BlockCoord> proximityBlocks = getCoordFromArray(proximityList);
|
||||
|
||||
// ProximityHider add blocks
|
||||
ProximityHider.addProximityBlocks(player, chunkData.chunkX, chunkData.chunkZ, proximityBlocks);
|
||||
|
@ -373,20 +397,16 @@ public class Calculations {
|
|||
if(checkCurrentBlock) {
|
||||
ChunkData chunkData = manager.getChunkData();
|
||||
int blockData = manager.get(x, y, z);
|
||||
int id;
|
||||
|
||||
|
||||
if (blockData < 0) {
|
||||
id = Orebfuscator.nms.loadChunkAndGetBlockId(world, x, y, z);
|
||||
blockData = NmsInstance.current.loadChunkAndGetBlockId(world, x, y, z);
|
||||
|
||||
if (id < 0) {
|
||||
id = 1;// Stone
|
||||
if (blockData < 0) {
|
||||
chunkData.useCache = false;
|
||||
}
|
||||
} else {
|
||||
id = ChunkMapManager.getBlockIdFromData(blockData);
|
||||
}
|
||||
|
||||
if (Orebfuscator.config.isBlockTransparent(id)) {
|
||||
if (blockData >= 0 && Orebfuscator.config.isBlockTransparent(blockData)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -394,42 +414,30 @@ public class Calculations {
|
|||
if (countdown == 0)
|
||||
return false;
|
||||
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y + 1, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y - 1, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x + 1, y, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x - 1, y, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y, z + 1, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y, z - 1, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y + 1, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y - 1, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x + 1, y, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x - 1, y, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y, z + 1, countdown - 1)) return true;
|
||||
if (areAjacentBlocksTransparent(manager, world, true, x, y, z - 1, countdown - 1)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean areAjacentBlocksBright(World world, int x, int y, int z, int countdown) {
|
||||
if(Orebfuscator.nms.getBlockLightLevel(world, x, y, z) > 0) {
|
||||
if(NmsInstance.current.getBlockLightLevel(world, x, y, z) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (countdown == 0)
|
||||
return false;
|
||||
|
||||
if (areAjacentBlocksBright(world, x, y + 1, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x, y - 1, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x + 1, y, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x - 1, y, z, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x, y, z + 1, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x, y, z - 1, countdown - 1))
|
||||
return true;
|
||||
if (areAjacentBlocksBright(world, x, y + 1, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksBright(world, x, y - 1, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksBright(world, x + 1, y, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksBright(world, x - 1, y, z, countdown - 1)) return true;
|
||||
if (areAjacentBlocksBright(world, x, y, z + 1, countdown - 1)) return true;
|
||||
if (areAjacentBlocksBright(world, x, y, z - 1, countdown - 1)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -16,22 +16,19 @@
|
|||
|
||||
package com.lishid.orebfuscator.obfuscation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import com.lishid.orebfuscator.nms.IBlockInfo;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.DeprecatedMethods;
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
import com.lishid.orebfuscator.config.ProximityHiderConfig;
|
||||
import com.lishid.orebfuscator.config.WorldConfig;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
public class ProximityHider extends Thread implements Runnable {
|
||||
private static final Map<Player, ProximityHiderPlayer> proximityHiderTracker = new HashMap<Player, ProximityHiderPlayer>();
|
||||
|
@ -174,15 +171,12 @@ public class ProximityHider extends Thread implements Runnable {
|
|||
// 4.3.1 -- GAZE CHECK END
|
||||
removedBlocks.add(b);
|
||||
|
||||
BlockState blockState = Orebfuscator.nms.getBlockState(localPlayerInfo.getWorld(), b.x, b.y, b.z);
|
||||
|
||||
if (blockState != null) {
|
||||
DeprecatedMethods.sendBlockChange(p, blockLocation, blockState);
|
||||
if (NmsInstance.current.sendBlockChange(p, blockLocation)) {
|
||||
final BlockCoord block = b;
|
||||
final Player player = p;
|
||||
Orebfuscator.instance.runTask(new Runnable() {
|
||||
public void run() {
|
||||
Orebfuscator.nms.updateBlockTileEntity(block, player);
|
||||
NmsInstance.current.updateBlockTileEntity(block, player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -265,8 +259,8 @@ public class ProximityHider extends Thread implements Runnable {
|
|||
ly = Math.floor(ey);
|
||||
lz = Math.floor(ez);
|
||||
if (lx == bx && ly == by && lz == bz) return true; // we've reached our starting block, don't test it.
|
||||
int between = Orebfuscator.nms.getBlockId(world, (int) lx, (int) ly, (int) lz);
|
||||
if (between > 0 && !Orebfuscator.config.isBlockTransparent(between)) { // -1 is null, 0 is air, above that? check with config.
|
||||
IBlockInfo between = NmsInstance.current.getBlockInfo(world, (int) lx, (int) ly, (int) lz);
|
||||
if (between != null && !Orebfuscator.config.isBlockTransparent(between.getCombinedId())) {
|
||||
return false; // fail on first hit, this ray is "blocked"
|
||||
}
|
||||
s--; // we stop
|
||||
|
|
|
@ -2,4 +2,9 @@ package com.lishid.orebfuscator.utils;
|
|||
|
||||
public class Globals {
|
||||
public static final String LogPrefix = "[OFC] ";
|
||||
|
||||
public static final int MASK_OBFUSCATE = 1;
|
||||
public static final int MASK_TILEENTITY = 2;
|
||||
public static final int MASK_PROXIMITYHIDER = 4;
|
||||
public static final int MASK_DARKNESSBLOCK = 8;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.utils;
|
||||
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class MaterialHelper {
|
||||
private static HashMap<Integer, Material> _blocks;
|
||||
|
||||
public static void init() {
|
||||
_blocks = new HashMap<>();
|
||||
|
||||
Material[] allMaterials = Material.values();
|
||||
|
||||
for(Material material : allMaterials) {
|
||||
if(material.isBlock()) {
|
||||
Set<Integer> ids = NmsInstance.current.getMaterialIds(material);
|
||||
|
||||
for(int id : ids) {
|
||||
_blocks.put(id, material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Material getById(int combinedBlockId) {
|
||||
return _blocks.get(combinedBlockId);
|
||||
}
|
||||
|
||||
public static int getMaxId() {
|
||||
int maxId = -1;
|
||||
|
||||
for(int id : _blocks.keySet()) {
|
||||
if(id > maxId) {
|
||||
maxId = id;
|
||||
}
|
||||
}
|
||||
|
||||
return maxId;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ author: lishid
|
|||
authors: [Aleksey-Terzi, ProgrammerDan]
|
||||
softdepend: [ProtocolLib]
|
||||
load: startup
|
||||
api-version: 1.13
|
||||
description: 'The most powerful and efficient Anti Xray plugin compatible with any CraftBukkit fork!'
|
||||
commands:
|
||||
ofc:
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -36,6 +36,8 @@
|
|||
<module>v1_10_R1</module>
|
||||
<module>v1_11_R1</module>
|
||||
<module>v1_12_R1</module>
|
||||
<module>v1_13_R1</module>
|
||||
<module>v1_13_R2</module>
|
||||
<module>Plugin</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_10_R1;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_10_R1.Block;
|
||||
import net.minecraft.server.v1_10_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_10_R1.Chunk;
|
||||
|
@ -16,6 +17,8 @@ import net.minecraft.server.v1_10_R1.Packet;
|
|||
import net.minecraft.server.v1_10_R1.TileEntity;
|
||||
import net.minecraft.server.v1_10_R1.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
|
||||
|
@ -27,10 +30,122 @@ import com.lishid.orebfuscator.nms.IChunkCache;
|
|||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = new int[] {
|
||||
getMaterialId(Material.DISPENSER),
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.HOPPER),
|
||||
getMaterialId(Material.WORKBENCH),
|
||||
getMaterialId(Material.FURNACE),
|
||||
getMaterialId(Material.BURNING_FURNACE),
|
||||
getMaterialId(Material.ENCHANTMENT_TABLE),
|
||||
getMaterialId(Material.EMERALD_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.ANVIL),
|
||||
getMaterialId(Material.TRAPPED_CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = new int[] {
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialId(Material.STONE);
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialId(Material.STONE);
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.BEDROCK),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.ENDER_STONE),
|
||||
getMaterialId(Material.PURPUR_BLOCK),
|
||||
getMaterialId(Material.END_BRICKS)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.ENDER_STONE)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialId(Material.ENDER_STONE);
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = new int[] { getMaterialId(Material.ENDER_STONE) };
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.GRAVEL),
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.SOUL_SAND),
|
||||
getMaterialId(Material.NETHER_BRICK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialId(Material.NETHERRACK);
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK)
|
||||
};
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE),
|
||||
getMaterialId(Material.COBBLESTONE),
|
||||
getMaterialId(Material.WOOD),
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.TNT),
|
||||
getMaterialId(Material.MOSSY_COBBLESTONE),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialId(Material.STONE);
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE)
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,28 +199,6 @@ public class NmsManager implements INmsManager {
|
|||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
if(blockData == null) return null;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
blockState.id = Block.getId(block);
|
||||
blockState.meta = block.toLegacyData(blockData);
|
||||
|
||||
return blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
|
@ -117,7 +210,72 @@ public class NmsManager implements INmsManager {
|
|||
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
|
||||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOOD_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLD_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return combinedBlockId == getMaterialId(Material.WALL_SIGN)
|
||||
|| combinedBlockId == getMaterialId(Material.SIGN_POST);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return combinedBlockId == 0;
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.STATIONARY_WATER
|
||||
|| blockMaterial == Material.LAVA
|
||||
|| blockMaterial == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getMaterialId(Material material) {
|
||||
return material.getId() << 4;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId & ~(0x0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
int blockId = Block.getId(block);
|
||||
byte meta = (byte)block.toLegacyData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, blockId, meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
|
|
|
@ -34,9 +34,9 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_11_R1;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_11_R1.Block;
|
||||
import net.minecraft.server.v1_11_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_11_R1.Chunk;
|
||||
|
@ -16,6 +17,8 @@ import net.minecraft.server.v1_11_R1.Packet;
|
|||
import net.minecraft.server.v1_11_R1.TileEntity;
|
||||
import net.minecraft.server.v1_11_R1.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
|
||||
|
@ -27,10 +30,122 @@ import com.lishid.orebfuscator.nms.IChunkCache;
|
|||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = new int[] {
|
||||
getMaterialId(Material.DISPENSER),
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.HOPPER),
|
||||
getMaterialId(Material.WORKBENCH),
|
||||
getMaterialId(Material.FURNACE),
|
||||
getMaterialId(Material.BURNING_FURNACE),
|
||||
getMaterialId(Material.ENCHANTMENT_TABLE),
|
||||
getMaterialId(Material.EMERALD_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.ANVIL),
|
||||
getMaterialId(Material.TRAPPED_CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = new int[] {
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialId(Material.STONE);
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialId(Material.STONE);
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.BEDROCK),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.ENDER_STONE),
|
||||
getMaterialId(Material.PURPUR_BLOCK),
|
||||
getMaterialId(Material.END_BRICKS)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.ENDER_STONE)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialId(Material.ENDER_STONE);
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = new int[] { getMaterialId(Material.ENDER_STONE) };
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.GRAVEL),
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.SOUL_SAND),
|
||||
getMaterialId(Material.NETHER_BRICK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialId(Material.NETHERRACK);
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK)
|
||||
};
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE),
|
||||
getMaterialId(Material.COBBLESTONE),
|
||||
getMaterialId(Material.WOOD),
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.TNT),
|
||||
getMaterialId(Material.MOSSY_COBBLESTONE),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialId(Material.STONE);
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE)
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,28 +199,6 @@ public class NmsManager implements INmsManager {
|
|||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
if(blockData == null) return null;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
blockState.id = Block.getId(block);
|
||||
blockState.meta = block.toLegacyData(blockData);
|
||||
|
||||
return blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
|
@ -117,6 +210,71 @@ public class NmsManager implements INmsManager {
|
|||
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
|
||||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOOD_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLD_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return combinedBlockId == getMaterialId(Material.WALL_SIGN)
|
||||
|| combinedBlockId == getMaterialId(Material.SIGN_POST);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return combinedBlockId == 0;
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.STATIONARY_WATER
|
||||
|| blockMaterial == Material.LAVA
|
||||
|| blockMaterial == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getMaterialId(Material material) {
|
||||
return material.getId() << 4;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId & ~(0x0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
int blockId = Block.getId(block);
|
||||
byte meta = (byte)block.toLegacyData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, blockId, meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
|
|
|
@ -34,9 +34,9 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_12_R1;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Chunk;
|
||||
|
@ -16,6 +17,8 @@ import net.minecraft.server.v1_12_R1.Packet;
|
|||
import net.minecraft.server.v1_12_R1.TileEntity;
|
||||
import net.minecraft.server.v1_12_R1.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
|
||||
|
@ -27,10 +30,122 @@ import com.lishid.orebfuscator.nms.IChunkCache;
|
|||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = new int[] {
|
||||
getMaterialId(Material.DISPENSER),
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.HOPPER),
|
||||
getMaterialId(Material.WORKBENCH),
|
||||
getMaterialId(Material.FURNACE),
|
||||
getMaterialId(Material.BURNING_FURNACE),
|
||||
getMaterialId(Material.ENCHANTMENT_TABLE),
|
||||
getMaterialId(Material.EMERALD_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.ANVIL),
|
||||
getMaterialId(Material.TRAPPED_CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = new int[] {
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialId(Material.STONE);
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialId(Material.STONE);
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.BEDROCK),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.ENDER_STONE),
|
||||
getMaterialId(Material.PURPUR_BLOCK),
|
||||
getMaterialId(Material.END_BRICKS)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.ENDER_STONE)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialId(Material.ENDER_STONE);
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = new int[] { getMaterialId(Material.ENDER_STONE) };
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.GRAVEL),
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.SOUL_SAND),
|
||||
getMaterialId(Material.NETHER_BRICK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialId(Material.NETHERRACK);
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK)
|
||||
};
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE),
|
||||
getMaterialId(Material.COBBLESTONE),
|
||||
getMaterialId(Material.WOOD),
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.TNT),
|
||||
getMaterialId(Material.MOSSY_COBBLESTONE),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialId(Material.STONE);
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE)
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,27 +199,6 @@ public class NmsManager implements INmsManager {
|
|||
: null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
if(blockData == null) return null;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
blockState.id = Block.getId(block);
|
||||
blockState.meta = block.toLegacyData(blockData);
|
||||
|
||||
return blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
|
@ -116,6 +210,71 @@ public class NmsManager implements INmsManager {
|
|||
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
|
||||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOOD_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLD_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return combinedBlockId == getMaterialId(Material.WALL_SIGN)
|
||||
|| combinedBlockId == getMaterialId(Material.SIGN_POST);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return combinedBlockId == 0;
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.STATIONARY_WATER
|
||||
|| blockMaterial == Material.LAVA
|
||||
|| blockMaterial == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getMaterialId(Material material) {
|
||||
return material.getId() << 4;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId & ~(0x0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
int blockId = Block.getId(block);
|
||||
byte meta = (byte)block.toLegacyData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, blockId, meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-v1_13_R1</artifactId>
|
||||
<version>v1_13_R1</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Orebfuscator4 v1_13_R1</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid.parent</groupId>
|
||||
<artifactId>orebfuscator-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-api</artifactId>
|
||||
<version>API</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R1;
|
||||
|
||||
import net.minecraft.server.v1_13_R1.Block;
|
||||
import net.minecraft.server.v1_13_R1.IBlockData;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IBlockInfo;
|
||||
|
||||
public class BlockInfo implements IBlockInfo {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private IBlockData blockData;
|
||||
|
||||
public BlockInfo(int x, int y, int z, IBlockData blockData) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof BlockInfo)) {
|
||||
return false;
|
||||
}
|
||||
BlockInfo object = (BlockInfo) other;
|
||||
|
||||
return this.x == object.x && this.y == object.y && this.z == object.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.x ^ this.y ^ this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.x + " " + this.y + " " + this.z;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R1;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.server.v1_13_R1.RegionFile;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IChunkCache;
|
||||
|
||||
public class ChunkCache implements IChunkCache {
|
||||
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
|
||||
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public ChunkCache(int maxLoadedCacheFiles) {
|
||||
this.maxLoadedCacheFiles = maxLoadedCacheFiles;
|
||||
}
|
||||
|
||||
public DataInputStream getInputStream(File folder, int x, int z) {
|
||||
RegionFile regionFile = getRegionFile(folder, x, z);
|
||||
return regionFile.a(x & 0x1F, z & 0x1F);
|
||||
}
|
||||
|
||||
public DataOutputStream getOutputStream(File folder, int x, int z) {
|
||||
RegionFile regionFile = getRegionFile(folder, x, z);
|
||||
return regionFile.c(x & 0x1F, z & 0x1F);
|
||||
}
|
||||
|
||||
public void closeCacheFiles() {
|
||||
closeCacheFilesInternal();
|
||||
}
|
||||
|
||||
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
|
||||
File path = new File(folder, "region");
|
||||
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
|
||||
try {
|
||||
RegionFile regionFile = cachedRegionFiles.get(file);
|
||||
if (regionFile != null) {
|
||||
return regionFile;
|
||||
}
|
||||
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
|
||||
if (cachedRegionFiles.size() >= this.maxLoadedCacheFiles) {
|
||||
closeCacheFiles();
|
||||
}
|
||||
|
||||
regionFile = new RegionFile(file);
|
||||
cachedRegionFiles.put(file, regionFile);
|
||||
|
||||
return regionFile;
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
file.delete();
|
||||
}
|
||||
catch (Exception e2) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized void closeCacheFilesInternal() {
|
||||
for (RegionFile regionFile : cachedRegionFiles.values()) {
|
||||
try {
|
||||
if (regionFile != null)
|
||||
regionFile.c();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
cachedRegionFiles.clear();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R1;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.server.v1_13_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
|
||||
import com.lishid.orebfuscator.nms.INBT;
|
||||
|
||||
public class NBT implements INBT {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
||||
public void reset() {
|
||||
nbt = new NBTTagCompound();
|
||||
}
|
||||
|
||||
public void setInt(String tag, int value) {
|
||||
nbt.setInt(tag, value);
|
||||
}
|
||||
|
||||
public void setLong(String tag, long value) {
|
||||
nbt.setLong(tag, value);
|
||||
}
|
||||
|
||||
public void setByteArray(String tag, byte[] value) {
|
||||
nbt.setByteArray(tag, value);
|
||||
}
|
||||
|
||||
public void setIntArray(String tag, int[] value) {
|
||||
nbt.setIntArray(tag, value);
|
||||
}
|
||||
|
||||
public int getInt(String tag) {
|
||||
return nbt.getInt(tag);
|
||||
}
|
||||
|
||||
public long getLong(String tag) {
|
||||
return nbt.getLong(tag);
|
||||
}
|
||||
|
||||
public byte[] getByteArray(String tag) {
|
||||
return nbt.getByteArray(tag);
|
||||
}
|
||||
|
||||
public int[] getIntArray(String tag) {
|
||||
return nbt.getIntArray(tag);
|
||||
}
|
||||
|
||||
public void Read(DataInput stream) throws IOException {
|
||||
nbt = NBTCompressedStreamTools.a((DataInputStream) stream);
|
||||
}
|
||||
|
||||
public void Write(DataOutput stream) throws IOException {
|
||||
NBTCompressedStreamTools.a(nbt, stream);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,336 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R1;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_13_R1.Block;
|
||||
import net.minecraft.server.v1_13_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_13_R1.Chunk;
|
||||
import net.minecraft.server.v1_13_R1.ChunkProviderServer;
|
||||
import net.minecraft.server.v1_13_R1.IBlockData;
|
||||
import net.minecraft.server.v1_13_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_13_R1.Packet;
|
||||
import net.minecraft.server.v1_13_R1.TileEntity;
|
||||
import net.minecraft.server.v1_13_R1.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.util.CraftChatMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IBlockInfo;
|
||||
import com.lishid.orebfuscator.nms.IChunkCache;
|
||||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private static final int BITS_PER_BLOCK = 14;
|
||||
|
||||
private int BLOCK_ID_CAVE_AIR;
|
||||
private Set<Integer> BLOCK_ID_AIRS;
|
||||
private Set<Integer> BLOCK_ID_SIGNS;
|
||||
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
private HashMap<Material, Set<Integer>> materialIds;
|
||||
|
||||
public NmsManager() {
|
||||
initBlockIds();
|
||||
|
||||
this.BLOCK_ID_CAVE_AIR = getMaterialIds(Material.CAVE_AIR).iterator().next();
|
||||
this.BLOCK_ID_AIRS = convertMaterialsToSet(new Material[] { Material.AIR, Material.CAVE_AIR, Material.VOID_AIR });
|
||||
this.BLOCK_ID_SIGNS = convertMaterialsToSet(new Material[] { Material.SIGN, Material.WALL_SIGN });
|
||||
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.CRAFTING_TABLE,
|
||||
Material.FURNACE,
|
||||
Material.ENCHANTING_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.CHIPPED_ANVIL,
|
||||
Material.DAMAGED_ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.SPAWNER,
|
||||
Material.CHEST
|
||||
});
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.BEDROCK,
|
||||
Material.OBSIDIAN,
|
||||
Material.END_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_STONE_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.END_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.END_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.END_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICKS,
|
||||
Material.NETHER_QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.NETHER_QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialIds(Material.NETHERRACK).iterator().next();
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK
|
||||
});
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.STONE,
|
||||
Material.COBBLESTONE,
|
||||
Material.OAK_PLANKS,
|
||||
Material.GOLD_ORE,
|
||||
Material.IRON_ORE,
|
||||
Material.COAL_ORE,
|
||||
Material.LAPIS_ORE,
|
||||
Material.TNT,
|
||||
Material.MOSSY_COBBLESTONE,
|
||||
Material.OBSIDIAN,
|
||||
Material.DIAMOND_ORE,
|
||||
Material.REDSTONE_ORE,
|
||||
Material.CLAY,
|
||||
Material.EMERALD_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GOLD_ORE,
|
||||
Material.IRON_ORE,
|
||||
Material.COAL_ORE,
|
||||
Material.LAPIS_ORE,
|
||||
Material.CHEST,
|
||||
Material.DIAMOND_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.REDSTONE_ORE,
|
||||
Material.CLAY,
|
||||
Material.EMERALD_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.STONE
|
||||
});
|
||||
}
|
||||
|
||||
private void initBlockIds() {
|
||||
this.materialIds = new HashMap<>();
|
||||
|
||||
Block.REGISTRY_ID.iterator().forEachRemaining(blockData -> {
|
||||
Material material = CraftBlockData.fromData(blockData).getMaterial();
|
||||
|
||||
if(material.isBlock()) {
|
||||
int materialId = Block.REGISTRY_ID.getId(blockData);
|
||||
|
||||
Set<Integer> ids = this.materialIds.get(material);
|
||||
|
||||
if (ids == null) {
|
||||
this.materialIds.put(material, ids = new HashSet<>());
|
||||
}
|
||||
|
||||
ids.add(materialId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
}
|
||||
|
||||
public INBT createNBT() {
|
||||
return new NBT();
|
||||
}
|
||||
|
||||
public IChunkCache createChunkCache() {
|
||||
return new ChunkCache(this.maxLoadedCacheFiles);
|
||||
}
|
||||
|
||||
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
|
||||
CraftWorld world = (CraftWorld)player.getWorld();
|
||||
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
|
||||
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Packet<?> packet = tileEntity.getUpdatePacket();
|
||||
|
||||
if (packet != null) {
|
||||
CraftPlayer player2 = (CraftPlayer)player;
|
||||
player2.getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyBlockChange(World world, IBlockInfo blockInfo) {
|
||||
BlockPosition blockPosition = new BlockPosition(blockInfo.getX(), blockInfo.getY(), blockInfo.getZ());
|
||||
IBlockData blockData = ((BlockInfo)blockInfo).getBlockData();
|
||||
|
||||
((CraftWorld)world).getHandle().notify(blockPosition, blockData, blockData, 0);
|
||||
}
|
||||
|
||||
public int getBlockLightLevel(World world, int x, int y, int z) {
|
||||
return ((CraftWorld)world).getHandle().getLightLevel(new BlockPosition(x, y, z));
|
||||
}
|
||||
|
||||
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null
|
||||
? new BlockInfo(x, y, z, blockData)
|
||||
: null;
|
||||
}
|
||||
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
return blockData != null ? Block.getCombinedId(blockData): -1;
|
||||
}
|
||||
|
||||
public String getTextFromChatComponent(String json) {
|
||||
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
|
||||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOODEN_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLDEN_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return BLOCK_ID_SIGNS.contains(combinedBlockId);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return BLOCK_ID_AIRS.contains(combinedBlockId);
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return BLOCK_ID_CAVE_AIR;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return BITS_PER_BLOCK;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.CAVE_AIR
|
||||
|| blockMaterial == Material.VOID_AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.LAVA;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return this.materialIds.get(material);
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId;
|
||||
}
|
||||
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
CraftBlockData craftBlockData = CraftBlockData.fromData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, craftBlockData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
|
||||
WorldServer worldServer = ((CraftWorld)world).getHandle();
|
||||
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
|
||||
|
||||
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
|
||||
|
||||
Chunk chunk = chunkProviderServer.getOrLoadChunkAt(chunkX, chunkZ);
|
||||
|
||||
return chunk != null ? chunk.getBlockData(x, y, z) : null;
|
||||
}
|
||||
|
||||
private Set<Integer> convertMaterialsToSet(Material[] materials) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
|
||||
for(Material material : materials) {
|
||||
ids.addAll(getMaterialIds(material));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
private int[] convertMaterialsToIds(Material[] materials) {
|
||||
Set<Integer> ids = convertMaterialsToSet(materials);
|
||||
|
||||
int[] result = new int[ids.size()];
|
||||
int index = 0;
|
||||
|
||||
for(int id : ids) {
|
||||
result[index++] = id;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-v1_13_R2</artifactId>
|
||||
<version>v1_13_R2</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Orebfuscator4 v1_13_R2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.lishid.parent</groupId>
|
||||
<artifactId>orebfuscator-parent</artifactId>
|
||||
<version>parent</version>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.13.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lishid</groupId>
|
||||
<artifactId>orebfuscator-api</artifactId>
|
||||
<version>API</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R2;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.Block;
|
||||
import net.minecraft.server.v1_13_R2.IBlockData;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IBlockInfo;
|
||||
|
||||
public class BlockInfo implements IBlockInfo {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private IBlockData blockData;
|
||||
|
||||
public BlockInfo(int x, int y, int z, IBlockData blockData) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof BlockInfo)) {
|
||||
return false;
|
||||
}
|
||||
BlockInfo object = (BlockInfo) other;
|
||||
|
||||
return this.x == object.x && this.y == object.y && this.z == object.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.x ^ this.y ^ this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.x + " " + this.y + " " + this.z;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R2;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.RegionFile;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IChunkCache;
|
||||
|
||||
public class ChunkCache implements IChunkCache {
|
||||
private static final HashMap<File, RegionFile> cachedRegionFiles = new HashMap<File, RegionFile>();
|
||||
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public ChunkCache(int maxLoadedCacheFiles) {
|
||||
this.maxLoadedCacheFiles = maxLoadedCacheFiles;
|
||||
}
|
||||
|
||||
public DataInputStream getInputStream(File folder, int x, int z) {
|
||||
RegionFile regionFile = getRegionFile(folder, x, z);
|
||||
return regionFile.a(x & 0x1F, z & 0x1F);
|
||||
}
|
||||
|
||||
public DataOutputStream getOutputStream(File folder, int x, int z) {
|
||||
RegionFile regionFile = getRegionFile(folder, x, z);
|
||||
return regionFile.c(x & 0x1F, z & 0x1F);
|
||||
}
|
||||
|
||||
public void closeCacheFiles() {
|
||||
closeCacheFilesInternal();
|
||||
}
|
||||
|
||||
private synchronized RegionFile getRegionFile(File folder, int x, int z) {
|
||||
File path = new File(folder, "region");
|
||||
File file = new File(path, "r." + (x >> 5) + "." + (z >> 5) + ".mcr");
|
||||
try {
|
||||
RegionFile regionFile = cachedRegionFiles.get(file);
|
||||
if (regionFile != null) {
|
||||
return regionFile;
|
||||
}
|
||||
|
||||
if (!path.exists()) {
|
||||
path.mkdirs();
|
||||
}
|
||||
|
||||
if (cachedRegionFiles.size() >= this.maxLoadedCacheFiles) {
|
||||
closeCacheFiles();
|
||||
}
|
||||
|
||||
regionFile = new RegionFile(file);
|
||||
cachedRegionFiles.put(file, regionFile);
|
||||
|
||||
return regionFile;
|
||||
}
|
||||
catch (Exception e) {
|
||||
try {
|
||||
file.delete();
|
||||
}
|
||||
catch (Exception e2) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private synchronized void closeCacheFilesInternal() {
|
||||
for (RegionFile regionFile : cachedRegionFiles.values()) {
|
||||
try {
|
||||
if (regionFile != null)
|
||||
regionFile.c();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
cachedRegionFiles.clear();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R2;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
|
||||
import com.lishid.orebfuscator.nms.INBT;
|
||||
|
||||
public class NBT implements INBT {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
||||
public void reset() {
|
||||
nbt = new NBTTagCompound();
|
||||
}
|
||||
|
||||
public void setInt(String tag, int value) {
|
||||
nbt.setInt(tag, value);
|
||||
}
|
||||
|
||||
public void setLong(String tag, long value) {
|
||||
nbt.setLong(tag, value);
|
||||
}
|
||||
|
||||
public void setByteArray(String tag, byte[] value) {
|
||||
nbt.setByteArray(tag, value);
|
||||
}
|
||||
|
||||
public void setIntArray(String tag, int[] value) {
|
||||
nbt.setIntArray(tag, value);
|
||||
}
|
||||
|
||||
public int getInt(String tag) {
|
||||
return nbt.getInt(tag);
|
||||
}
|
||||
|
||||
public long getLong(String tag) {
|
||||
return nbt.getLong(tag);
|
||||
}
|
||||
|
||||
public byte[] getByteArray(String tag) {
|
||||
return nbt.getByteArray(tag);
|
||||
}
|
||||
|
||||
public int[] getIntArray(String tag) {
|
||||
return nbt.getIntArray(tag);
|
||||
}
|
||||
|
||||
public void Read(DataInput stream) throws IOException {
|
||||
nbt = NBTCompressedStreamTools.a((DataInputStream) stream);
|
||||
}
|
||||
|
||||
public void Write(DataOutput stream) throws IOException {
|
||||
NBTCompressedStreamTools.a(nbt, stream);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,328 @@
|
|||
/**
|
||||
* @author lishid
|
||||
* @author Aleksey Terzi
|
||||
*
|
||||
*/
|
||||
|
||||
package com.lishid.orebfuscator.nms.v1_13_R2;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_13_R2.*;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.util.CraftChatMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.nms.IBlockInfo;
|
||||
import com.lishid.orebfuscator.nms.IChunkCache;
|
||||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private static final int BITS_PER_BLOCK = 14;
|
||||
|
||||
private int BLOCK_ID_CAVE_AIR;
|
||||
private Set<Integer> BLOCK_ID_AIRS;
|
||||
private Set<Integer> BLOCK_ID_SIGNS;
|
||||
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
private HashMap<Material, Set<Integer>> materialIds;
|
||||
|
||||
public NmsManager() {
|
||||
initBlockIds();
|
||||
|
||||
this.BLOCK_ID_CAVE_AIR = getMaterialIds(Material.CAVE_AIR).iterator().next();
|
||||
this.BLOCK_ID_AIRS = convertMaterialsToSet(new Material[] { Material.AIR, Material.CAVE_AIR, Material.VOID_AIR });
|
||||
this.BLOCK_ID_SIGNS = convertMaterialsToSet(new Material[] { Material.SIGN, Material.WALL_SIGN });
|
||||
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.CRAFTING_TABLE,
|
||||
Material.FURNACE,
|
||||
Material.ENCHANTING_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.CHIPPED_ANVIL,
|
||||
Material.DAMAGED_ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.SPAWNER,
|
||||
Material.CHEST
|
||||
});
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.BEDROCK,
|
||||
Material.OBSIDIAN,
|
||||
Material.END_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_STONE_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.END_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.END_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.END_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICKS,
|
||||
Material.NETHER_QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.NETHER_QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialIds(Material.NETHERRACK).iterator().next();
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK
|
||||
});
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.STONE,
|
||||
Material.COBBLESTONE,
|
||||
Material.OAK_PLANKS,
|
||||
Material.GOLD_ORE,
|
||||
Material.IRON_ORE,
|
||||
Material.COAL_ORE,
|
||||
Material.LAPIS_ORE,
|
||||
Material.TNT,
|
||||
Material.MOSSY_COBBLESTONE,
|
||||
Material.OBSIDIAN,
|
||||
Material.DIAMOND_ORE,
|
||||
Material.REDSTONE_ORE,
|
||||
Material.CLAY,
|
||||
Material.EMERALD_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GOLD_ORE,
|
||||
Material.IRON_ORE,
|
||||
Material.COAL_ORE,
|
||||
Material.LAPIS_ORE,
|
||||
Material.CHEST,
|
||||
Material.DIAMOND_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.REDSTONE_ORE,
|
||||
Material.CLAY,
|
||||
Material.EMERALD_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialIds(Material.STONE).iterator().next();
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.STONE
|
||||
});
|
||||
}
|
||||
|
||||
private void initBlockIds() {
|
||||
this.materialIds = new HashMap<>();
|
||||
|
||||
Block.REGISTRY_ID.iterator().forEachRemaining(blockData -> {
|
||||
Material material = CraftBlockData.fromData(blockData).getMaterial();
|
||||
|
||||
if(material.isBlock()) {
|
||||
int materialId = Block.REGISTRY_ID.getId(blockData);
|
||||
|
||||
Set<Integer> ids = this.materialIds.get(material);
|
||||
|
||||
if (ids == null) {
|
||||
this.materialIds.put(material, ids = new HashSet<>());
|
||||
}
|
||||
|
||||
ids.add(materialId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
}
|
||||
|
||||
public INBT createNBT() {
|
||||
return new NBT();
|
||||
}
|
||||
|
||||
public IChunkCache createChunkCache() {
|
||||
return new ChunkCache(this.maxLoadedCacheFiles);
|
||||
}
|
||||
|
||||
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
|
||||
CraftWorld world = (CraftWorld)player.getWorld();
|
||||
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
|
||||
|
||||
if (tileEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Packet<?> packet = tileEntity.getUpdatePacket();
|
||||
|
||||
if (packet != null) {
|
||||
CraftPlayer player2 = (CraftPlayer)player;
|
||||
player2.getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyBlockChange(World world, IBlockInfo blockInfo) {
|
||||
BlockPosition blockPosition = new BlockPosition(blockInfo.getX(), blockInfo.getY(), blockInfo.getZ());
|
||||
IBlockData blockData = ((BlockInfo)blockInfo).getBlockData();
|
||||
|
||||
((CraftWorld)world).getHandle().notify(blockPosition, blockData, blockData, 0);
|
||||
}
|
||||
|
||||
public int getBlockLightLevel(World world, int x, int y, int z) {
|
||||
return ((CraftWorld)world).getHandle().getLightLevel(new BlockPosition(x, y, z));
|
||||
}
|
||||
|
||||
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null
|
||||
? new BlockInfo(x, y, z, blockData)
|
||||
: null;
|
||||
}
|
||||
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
return blockData != null ? Block.getCombinedId(blockData): -1;
|
||||
}
|
||||
|
||||
public String getTextFromChatComponent(String json) {
|
||||
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
|
||||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOODEN_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLDEN_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return BLOCK_ID_SIGNS.contains(combinedBlockId);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return BLOCK_ID_AIRS.contains(combinedBlockId);
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return BLOCK_ID_CAVE_AIR;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return BITS_PER_BLOCK;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.CAVE_AIR
|
||||
|| blockMaterial == Material.VOID_AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.LAVA;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return this.materialIds.get(material);
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId;
|
||||
}
|
||||
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
CraftBlockData craftBlockData = CraftBlockData.fromData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, craftBlockData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
|
||||
WorldServer worldServer = ((CraftWorld)world).getHandle();
|
||||
ChunkProviderServer chunkProviderServer = worldServer.getChunkProviderServer();
|
||||
|
||||
if(!loadChunk && !chunkProviderServer.isLoaded(chunkX, chunkZ)) return null;
|
||||
|
||||
Chunk chunk = chunkProviderServer.getChunkAt(chunkX, chunkZ, true, true);
|
||||
|
||||
return chunk != null ? chunk.getBlockData(x, y, z) : null;
|
||||
}
|
||||
|
||||
private Set<Integer> convertMaterialsToSet(Material[] materials) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
|
||||
for(Material material : materials) {
|
||||
ids.addAll(getMaterialIds(material));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
private int[] convertMaterialsToIds(Material[] materials) {
|
||||
Set<Integer> ids = convertMaterialsToSet(materials);
|
||||
|
||||
int[] result = new int[ids.size()];
|
||||
int index = 0;
|
||||
|
||||
for(int id : ids) {
|
||||
result[index++] = id;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -34,15 +34,15 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof BlockInfo)) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_9_R1;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_9_R1.Block;
|
||||
import net.minecraft.server.v1_9_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R1.Chunk;
|
||||
|
@ -16,6 +17,8 @@ import net.minecraft.server.v1_9_R1.Packet;
|
|||
import net.minecraft.server.v1_9_R1.TileEntity;
|
||||
import net.minecraft.server.v1_9_R1.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
|
||||
|
@ -27,11 +30,123 @@ import com.lishid.orebfuscator.nms.IChunkCache;
|
|||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = new int[] {
|
||||
getMaterialId(Material.DISPENSER),
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.HOPPER),
|
||||
getMaterialId(Material.WORKBENCH),
|
||||
getMaterialId(Material.FURNACE),
|
||||
getMaterialId(Material.BURNING_FURNACE),
|
||||
getMaterialId(Material.ENCHANTMENT_TABLE),
|
||||
getMaterialId(Material.EMERALD_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.ANVIL),
|
||||
getMaterialId(Material.TRAPPED_CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = new int[] {
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialId(Material.STONE);
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialId(Material.STONE);
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.BEDROCK),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.ENDER_STONE),
|
||||
getMaterialId(Material.PURPUR_BLOCK),
|
||||
getMaterialId(Material.END_BRICKS)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.ENDER_STONE)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialId(Material.ENDER_STONE);
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = new int[] { getMaterialId(Material.ENDER_STONE) };
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.GRAVEL),
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.SOUL_SAND),
|
||||
getMaterialId(Material.NETHER_BRICK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialId(Material.NETHERRACK);
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK)
|
||||
};
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE),
|
||||
getMaterialId(Material.COBBLESTONE),
|
||||
getMaterialId(Material.WOOD),
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.TNT),
|
||||
getMaterialId(Material.MOSSY_COBBLESTONE),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialId(Material.STONE);
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE)
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
}
|
||||
|
@ -78,30 +193,10 @@ public class NmsManager implements INmsManager {
|
|||
? new BlockInfo(x, y, z, blockData)
|
||||
: null;
|
||||
}
|
||||
|
||||
public BlockState getBlockState(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
if(blockData == null) return null;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
blockState.id = Block.getId(block);
|
||||
blockState.meta = block.toLegacyData(blockData);
|
||||
|
||||
return blockState;
|
||||
}
|
||||
|
||||
public int getBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
}
|
||||
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
return blockData != null ? Block.getCombinedId(blockData): -1;
|
||||
}
|
||||
|
||||
public String getTextFromChatComponent(String json) {
|
||||
|
@ -109,6 +204,71 @@ public class NmsManager implements INmsManager {
|
|||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOOD_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLD_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return combinedBlockId == getMaterialId(Material.WALL_SIGN)
|
||||
|| combinedBlockId == getMaterialId(Material.SIGN_POST);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return combinedBlockId == 0;
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.STATIONARY_WATER
|
||||
|| blockMaterial == Material.LAVA
|
||||
|| blockMaterial == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getMaterialId(Material material) {
|
||||
return material.getId() << 4;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId & ~(0x0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
int blockId = Block.getId(block);
|
||||
byte meta = (byte)block.toLegacyData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, blockId, meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
|
|
|
@ -34,9 +34,9 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
return Block.getCombinedId(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_9_R2;
|
||||
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_9_R2.Block;
|
||||
import net.minecraft.server.v1_9_R2.BlockPosition;
|
||||
import net.minecraft.server.v1_9_R2.Chunk;
|
||||
|
@ -16,6 +17,8 @@ import net.minecraft.server.v1_9_R2.Packet;
|
|||
import net.minecraft.server.v1_9_R2.TileEntity;
|
||||
import net.minecraft.server.v1_9_R2.WorldServer;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
|
||||
|
@ -27,10 +30,122 @@ import com.lishid.orebfuscator.nms.IChunkCache;
|
|||
import com.lishid.orebfuscator.nms.INBT;
|
||||
import com.lishid.orebfuscator.nms.INmsManager;
|
||||
import com.lishid.orebfuscator.types.BlockCoord;
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = new int[] {
|
||||
getMaterialId(Material.DISPENSER),
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.HOPPER),
|
||||
getMaterialId(Material.WORKBENCH),
|
||||
getMaterialId(Material.FURNACE),
|
||||
getMaterialId(Material.BURNING_FURNACE),
|
||||
getMaterialId(Material.ENCHANTMENT_TABLE),
|
||||
getMaterialId(Material.EMERALD_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.ANVIL),
|
||||
getMaterialId(Material.TRAPPED_CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = new int[] {
|
||||
getMaterialId(Material.MOB_SPAWNER),
|
||||
getMaterialId(Material.CHEST)
|
||||
};
|
||||
|
||||
this.configDefaults.defaultMode1BlockId = getMaterialId(Material.STONE);
|
||||
this.configDefaults.defaultProximityHiderSpecialBlockId = getMaterialId(Material.STONE);
|
||||
|
||||
// The End
|
||||
|
||||
this.configDefaults.endWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.BEDROCK),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.ENDER_STONE),
|
||||
getMaterialId(Material.PURPUR_BLOCK),
|
||||
getMaterialId(Material.END_BRICKS)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.ENDER_STONE)
|
||||
};
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialId(Material.ENDER_STONE);
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = new int[] { getMaterialId(Material.ENDER_STONE) };
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.GRAVEL),
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.SOUL_SAND),
|
||||
getMaterialId(Material.NETHER_BRICK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK),
|
||||
getMaterialId(Material.QUARTZ_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.netherWorldMode1BlockId = getMaterialId(Material.NETHERRACK);
|
||||
|
||||
this.configDefaults.netherWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.NETHERRACK)
|
||||
};
|
||||
|
||||
// Normal World
|
||||
|
||||
this.configDefaults.normalWorldRandomBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE),
|
||||
getMaterialId(Material.COBBLESTONE),
|
||||
getMaterialId(Material.WOOD),
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.TNT),
|
||||
getMaterialId(Material.MOSSY_COBBLESTONE),
|
||||
getMaterialId(Material.OBSIDIAN),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.GOLD_ORE),
|
||||
getMaterialId(Material.IRON_ORE),
|
||||
getMaterialId(Material.COAL_ORE),
|
||||
getMaterialId(Material.LAPIS_ORE),
|
||||
getMaterialId(Material.CHEST),
|
||||
getMaterialId(Material.DIAMOND_ORE),
|
||||
getMaterialId(Material.ENDER_CHEST),
|
||||
getMaterialId(Material.REDSTONE_ORE),
|
||||
getMaterialId(Material.CLAY),
|
||||
getMaterialId(Material.EMERALD_ORE)
|
||||
};
|
||||
|
||||
this.configDefaults.normalWorldMode1BlockId = getMaterialId(Material.STONE);
|
||||
|
||||
this.configDefaults.normalWorldRequiredObfuscateBlockIds = new int[] {
|
||||
getMaterialId(Material.STONE)
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -79,26 +194,6 @@ public class NmsManager implements INmsManager {
|
|||
: null;
|
||||
}
|
||||
|
||||
public BlockState getBlockState(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
if(blockData == null) return null;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
blockState.id = Block.getId(block);
|
||||
blockState.meta = block.toLegacyData(blockData);
|
||||
|
||||
return blockState;
|
||||
}
|
||||
|
||||
public int getBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, false);
|
||||
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
}
|
||||
|
||||
public int loadChunkAndGetBlockId(World world, int x, int y, int z) {
|
||||
IBlockData blockData = getBlockData(world, x, y, z, true);
|
||||
return blockData != null ? Block.getId(blockData.getBlock()): -1;
|
||||
|
@ -109,6 +204,71 @@ public class NmsManager implements INmsManager {
|
|||
return CraftChatMessage.fromComponent(component);
|
||||
}
|
||||
|
||||
public boolean isHoe(Material item) {
|
||||
return item == Material.WOOD_HOE
|
||||
|| item == Material.IRON_HOE
|
||||
|| item == Material.GOLD_HOE
|
||||
|| item == Material.DIAMOND_HOE;
|
||||
}
|
||||
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
return combinedBlockId == getMaterialId(Material.WALL_SIGN)
|
||||
|| combinedBlockId == getMaterialId(Material.SIGN_POST);
|
||||
}
|
||||
|
||||
public boolean isAir(int combinedBlockId) {
|
||||
return combinedBlockId == 0;
|
||||
}
|
||||
|
||||
public boolean isTileEntity(int combinedBlockId) {
|
||||
return Block.getByCombinedId(combinedBlockId).getBlock().isTileEntity();
|
||||
}
|
||||
|
||||
public int getCaveAirBlockId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return 13;
|
||||
}
|
||||
|
||||
public boolean canApplyPhysics(Material blockMaterial) {
|
||||
return blockMaterial == Material.AIR
|
||||
|| blockMaterial == Material.FIRE
|
||||
|| blockMaterial == Material.WATER
|
||||
|| blockMaterial == Material.STATIONARY_WATER
|
||||
|| blockMaterial == Material.LAVA
|
||||
|| blockMaterial == Material.STATIONARY_LAVA;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public int getMaterialId(Material material) {
|
||||
return material.getId() << 4;
|
||||
}
|
||||
|
||||
public Set<Integer> getMaterialIds(Material material) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getTypeId(int combinedBlockId) {
|
||||
return combinedBlockId & ~(0x0F);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean sendBlockChange(Player player, Location blockLocation) {
|
||||
IBlockData blockData = getBlockData(blockLocation.getWorld(), blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ(), false);
|
||||
|
||||
if(blockData == null) return false;
|
||||
|
||||
Block block = blockData.getBlock();
|
||||
int blockId = Block.getId(block);
|
||||
byte meta = (byte)block.toLegacyData(blockData);
|
||||
|
||||
player.sendBlockChange(blockLocation, blockId, meta);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IBlockData getBlockData(World world, int x, int y, int z, boolean loadChunk) {
|
||||
int chunkX = x >> 4;
|
||||
int chunkZ = z >> 4;
|
||||
|
|
Loading…
Reference in New Issue