Merge branch 'master' into lishid-master
commit
a842b26b79
|
@ -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,22 @@
|
|||
|
||||
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();
|
||||
|
||||
Material[] getExtraTransparentBlocks();
|
||||
|
||||
void setMaxLoadedCacheFiles(int value);
|
||||
|
||||
INBT createNBT();
|
||||
|
||||
|
@ -25,12 +33,26 @@ 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);
|
||||
|
||||
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.2-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;
|
||||
|
|
|
@ -7,17 +7,26 @@ package com.lishid.orebfuscator.chunkmap;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.lishid.orebfuscator.types.BlockState;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
|
||||
public class ChunkMapManager implements AutoCloseable {
|
||||
private static final Object _lock = new Object();
|
||||
private static final Stack<ChunkMapBuffer> _bufferStack = new Stack<>();
|
||||
|
||||
private static ChunkMapBuffer popBuffer() {
|
||||
synchronized(_lock) {
|
||||
return _bufferStack.isEmpty() ? new ChunkMapBuffer() : _bufferStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private static void pushBuffer(ChunkMapBuffer buffer) {
|
||||
synchronized(_lock) {
|
||||
_bufferStack.push(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public class ChunkMapManager {
|
||||
private static final ThreadLocal<ChunkMapBuffer> _buffer = new ThreadLocal<ChunkMapBuffer>() {
|
||||
@Override
|
||||
protected ChunkMapBuffer initialValue() {
|
||||
return new ChunkMapBuffer();
|
||||
}
|
||||
};
|
||||
|
||||
private ChunkMapBuffer buffer;
|
||||
private ChunkData chunkData;
|
||||
private ChunkReader reader;
|
||||
|
@ -42,68 +51,55 @@ public class ChunkMapManager {
|
|||
return this.chunkData;
|
||||
}
|
||||
|
||||
public ChunkMapManager(ChunkData chunkData) {
|
||||
this.buffer = _buffer.get();
|
||||
this.chunkData = chunkData;
|
||||
}
|
||||
|
||||
public void init() throws IOException {
|
||||
this.reader = new ChunkReader(this.chunkData.data);
|
||||
this.sectionCount = 0;
|
||||
this.sectionIndex = -1;
|
||||
this.minX = this.chunkData.chunkX << 4;
|
||||
this.maxX = this.minX + 15;
|
||||
this.minZ = this.chunkData.chunkZ << 4;
|
||||
this.maxZ = this.minZ + 15;
|
||||
|
||||
this.buffer.lightArrayLength = 2048;
|
||||
private ChunkMapManager() {
|
||||
|
||||
}
|
||||
|
||||
public static ChunkMapManager create(ChunkData chunkData) throws IOException {
|
||||
ChunkMapManager manager = new ChunkMapManager();
|
||||
manager.chunkData = chunkData;
|
||||
manager.buffer = popBuffer();
|
||||
manager.reader = new ChunkReader(chunkData.data);
|
||||
manager.sectionCount = 0;
|
||||
manager.sectionIndex = -1;
|
||||
manager.minX = chunkData.chunkX << 4;
|
||||
manager.maxX = manager.minX + 15;
|
||||
manager.minZ = chunkData.chunkZ << 4;
|
||||
manager.maxZ = manager.minZ + 15;
|
||||
|
||||
manager.buffer.lightArrayLength = 2048;
|
||||
|
||||
if(this.chunkData.isOverworld) {
|
||||
this.buffer.lightArrayLength <<= 1;
|
||||
if(chunkData.isOverworld) {
|
||||
manager.buffer.lightArrayLength <<= 1;
|
||||
}
|
||||
|
||||
manager.buffer.writer.init();
|
||||
|
||||
this.buffer.writer.init();
|
||||
|
||||
int mask = this.chunkData.primaryBitMask;
|
||||
int mask = chunkData.primaryBitMask;
|
||||
|
||||
while(mask != 0) {
|
||||
if((mask & 0x1) != 0) {
|
||||
this.sectionCount++;
|
||||
manager.sectionCount++;
|
||||
}
|
||||
|
||||
mask >>>= 1;
|
||||
}
|
||||
|
||||
this.buffer.clearLayers();
|
||||
|
||||
moveToNextLayer();
|
||||
manager.buffer.clearLayers();
|
||||
|
||||
manager.moveToNextLayer();
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
|
||||
public void close() throws Exception {
|
||||
pushBuffer(this.buffer);
|
||||
}
|
||||
|
||||
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 +184,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 +223,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 +350,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;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class ChunkReader {
|
|||
|
||||
private void readLong() throws IOException {
|
||||
if(this.byteIndex + 7 >= this.data.length) {
|
||||
throw new IOException("No data to read.");
|
||||
throw new IOException("No data to read. byteIndex = " + this.byteIndex);
|
||||
}
|
||||
|
||||
this.buffer = ((this.data[this.byteIndex] & 0xffL) << 56)
|
||||
|
@ -83,7 +83,7 @@ public class ChunkReader {
|
|||
value |= (b & 0x7F) << (size++ * 7);
|
||||
|
||||
if(size > 5) {
|
||||
throw new IOException("Invalid VarInt.");
|
||||
throw new IOException("Invalid VarInt. byteIndex = " + this.byteIndex + ", value = " + value + ", size = " + size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class ChunkReader {
|
|||
|
||||
public int readByte() throws IOException {
|
||||
if(this.byteIndex >= this.data.length) {
|
||||
throw new IOException("No data to read.");
|
||||
throw new IOException("No data to read. byteIndex = " + this.byteIndex);
|
||||
}
|
||||
|
||||
return this.data[this.byteIndex++] & 0xff;
|
||||
|
|
|
@ -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,206 @@ 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> transparentBlockNames = new ArrayList<>();
|
||||
List<String> nonTransparentBlockNames = 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) {
|
||||
transparentBlockNames.add(material.name());
|
||||
} else {
|
||||
nonTransparentBlockNames.add(material.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(transparentBlockNames);
|
||||
Collections.sort(nonTransparentBlockNames);
|
||||
|
||||
StringBuilder blocks = new StringBuilder();
|
||||
blocks.append("Transparent blocks:");
|
||||
|
||||
for (String blockName : transparentBlockNames) {
|
||||
blocks.append("\n - " + blockName);
|
||||
}
|
||||
|
||||
blocks.append("\nNon-Transparent blocks:");
|
||||
|
||||
for (String blockName : nonTransparentBlockNames) {
|
||||
blocks.append("\n - " + blockName);
|
||||
}
|
||||
|
||||
Orebfuscator.message(sender, blocks.toString());
|
||||
}
|
||||
}
|
|
@ -5,14 +5,15 @@
|
|||
|
||||
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.Orebfuscator;
|
||||
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 +22,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 +104,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 +120,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 +262,41 @@ 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[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[id] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Material[] extraTransparentBlocks = NmsInstance.current.getExtraTransparentBlocks();
|
||||
|
||||
for(Material material : extraTransparentBlocks) {
|
||||
Set<Integer> ids = NmsInstance.current.getMaterialIds(material);
|
||||
|
||||
for (int id : ids) {
|
||||
transparentBlocks[id] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Set<Integer> lavaIds = NmsInstance.current.getMaterialIds(Material.LAVA);
|
||||
|
||||
for (int id : lavaIds) {
|
||||
transparentBlocks[id] = (byte)(engineMode == 1 ? 0 : 1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package com.lishid.orebfuscator.config;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.lishid.orebfuscator.Orebfuscator;
|
||||
|
@ -31,7 +30,7 @@ public class OrebfuscatorConfig {
|
|||
private boolean noObfuscationForPermission;
|
||||
private boolean loginNotification;
|
||||
|
||||
private boolean[] transparentBlocks;
|
||||
private byte[] transparentBlocks;
|
||||
|
||||
private WorldConfig defaultWorld;
|
||||
private WorldConfig normalWorld;
|
||||
|
@ -158,12 +157,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 +254,7 @@ public class OrebfuscatorConfig {
|
|||
// Helper methods
|
||||
|
||||
public boolean isBlockTransparent(int id) {
|
||||
if (id < 0)
|
||||
id += 256;
|
||||
|
||||
if (id >= 256) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.transparentBlocks[id];
|
||||
return this.transparentBlocks[id] == 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ package com.lishid.orebfuscator.hook;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -33,11 +34,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;
|
||||
|
@ -48,6 +51,8 @@ public class ProtocolLibHook {
|
|||
this.manager.addPacketListener(new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
ChunkData chunkData = null;
|
||||
|
||||
try {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
|
@ -66,22 +71,34 @@ 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);
|
||||
|
||||
ChunkData chunkData = new ChunkData();
|
||||
List nmsTags = list.read(0);
|
||||
|
||||
chunkData = new ChunkData();
|
||||
chunkData.chunkX = ints.read(0);
|
||||
chunkData.chunkZ = ints.read(1);
|
||||
chunkData.groundUpContinuous = bools.read(0);
|
||||
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 != null && result.output != null) {
|
||||
byteArray.write(0, result.output);
|
||||
|
||||
if(nmsTags != null) {
|
||||
removeBlockEntities(nmsTags, chunkData.blockEntities, result.removedEntities);
|
||||
list.write(0, nmsTags);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if(chunkData != null) {
|
||||
Orebfuscator.logger.log(Level.SEVERE, "ChunkX = " + chunkData.chunkX + ", chunkZ = " + chunkData.chunkZ);
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -101,24 +118,43 @@ 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) {
|
||||
if(_isSaved) return;
|
||||
|
@ -127,7 +163,7 @@ public class ProtocolLibHook {
|
|||
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream("D:\\Temp\\chunk.dat");
|
||||
fos = new FileOutputStream("D:\\Temp\\chunk_X" + chunkData.chunkX + "_Z" + chunkData.chunkZ + ".dat");
|
||||
fos.write(chunkData.chunkX & 0xff);
|
||||
fos.write((chunkData.chunkX >> 8) & 0xff);
|
||||
fos.write(chunkData.chunkZ & 0xff);
|
||||
|
|
|
@ -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,14 +21,16 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import com.lishid.orebfuscator.NmsInstance;
|
||||
|
||||
import com.lishid.orebfuscator.utils.Globals;
|
||||
import org.bukkit.World;
|
||||
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 +39,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 Exception {
|
||||
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 +86,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 Exception
|
||||
{
|
||||
ProximityHiderConfig proximityHider = worldConfig.getProximityHiderConfig();
|
||||
int initialRadius = Orebfuscator.config.getInitialRadius();
|
||||
|
||||
|
@ -100,7 +149,6 @@ public class Calculations {
|
|||
|
||||
int engineMode = Orebfuscator.config.getEngineMode();
|
||||
int maxChance = worldConfig.getAirGeneratorMaxChance();
|
||||
int incrementMax = maxChance;
|
||||
|
||||
int randomBlocksLength = worldConfig.getRandomBlocks().length;
|
||||
boolean randomAlternate = false;
|
||||
|
@ -108,152 +156,144 @@ public class Calculations {
|
|||
int startX = chunkData.chunkX << 4;
|
||||
int startZ = chunkData.chunkZ << 4;
|
||||
|
||||
BlockState blockState = new BlockState();
|
||||
byte[] output;
|
||||
|
||||
ChunkMapManager manager = new ChunkMapManager(chunkData);
|
||||
manager.init();
|
||||
|
||||
for(int i = 0; i < manager.getSectionCount(); i++) {
|
||||
worldConfig.shuffleRandomBlocks();
|
||||
try (ChunkMapManager manager = ChunkMapManager.create(chunkData)) {
|
||||
for (int i = 0; i < manager.getSectionCount(); i++) {
|
||||
worldConfig.shuffleRandomBlocks();
|
||||
|
||||
for(int offsetY = 0; offsetY < 16; offsetY++) {
|
||||
for(int offsetZ = 0; offsetZ < 16; offsetZ++) {
|
||||
incrementMax = (maxChance + random(maxChance)) / 2;
|
||||
|
||||
for(int offsetX = 0; offsetX < 16; offsetX++) {
|
||||
int blockData = manager.readNextBlock();
|
||||
|
||||
ChunkMapManager.blockDataToState(blockData, blockState);
|
||||
for (int offsetY = 0; offsetY < 16; offsetY++) {
|
||||
for (int offsetZ = 0; offsetZ < 16; offsetZ++) {
|
||||
int incrementMax = (maxChance + random(maxChance)) / 2;
|
||||
|
||||
if (blockState.id < 256) {
|
||||
for (int offsetX = 0; offsetX < 16; offsetX++) {
|
||||
int blockData = manager.readNextBlock();
|
||||
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);
|
||||
|
||||
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();
|
||||
// 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 (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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
manager.finalizeOutput();
|
||||
|
||||
output = manager.createOutput();
|
||||
}
|
||||
|
||||
ProximityHider.addProximityBlocks(player, chunkData.chunkX, chunkData.chunkZ, proximityBlocks);
|
||||
|
||||
|
||||
//Orebfuscator.log("Create new chunk data for x = " + chunkData.chunkX + ", z = " + chunkData.chunkZ);/*debug*/
|
||||
|
||||
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 +314,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 +341,7 @@ public class Calculations {
|
|||
}
|
||||
|
||||
for(int id : worldConfig.getPaletteBlocks()) {
|
||||
int blockData = ChunkMapManager.getBlockDataFromId(id);
|
||||
manager.addToOutputPalette(blockData);
|
||||
manager.addToOutputPalette(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,23 +364,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 +395,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 +412,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:
|
||||
|
|
|
@ -1,219 +0,0 @@
|
|||
0:true //minecraft:air
|
||||
1:false //minecraft:stone
|
||||
2:false //minecraft:grass
|
||||
3:false //minecraft:dirt
|
||||
4:false //minecraft:cobblestone
|
||||
5:false //minecraft:planks
|
||||
6:true //minecraft:sapling
|
||||
7:false //minecraft:bedrock
|
||||
8:true //minecraft:flowing_water
|
||||
9:true //minecraft:water
|
||||
10:true //minecraft:flowing_lava
|
||||
11:true //minecraft:lava
|
||||
12:false //minecraft:sand
|
||||
13:false //minecraft:gravel
|
||||
14:false //minecraft:gold_ore
|
||||
15:false //minecraft:iron_ore
|
||||
16:false //minecraft:coal_ore
|
||||
17:false //minecraft:log
|
||||
18:true //minecraft:leaves
|
||||
19:false //minecraft:sponge
|
||||
20:true //minecraft:glass
|
||||
21:false //minecraft:lapis_ore
|
||||
22:false //minecraft:lapis_block
|
||||
23:false //minecraft:dispenser
|
||||
24:false //minecraft:sandstone
|
||||
25:false //minecraft:noteblock
|
||||
26:true //minecraft:bed
|
||||
27:true //minecraft:golden_rail
|
||||
28:true //minecraft:detector_rail
|
||||
29:false //minecraft:sticky_piston
|
||||
30:true //minecraft:web
|
||||
31:true //minecraft:tallgrass
|
||||
32:true //minecraft:deadbush
|
||||
33:false //minecraft:piston
|
||||
34:true //minecraft:piston_head
|
||||
35:false //minecraft:wool
|
||||
36:true //minecraft:piston_extension
|
||||
37:true //minecraft:yellow_flower
|
||||
38:true //minecraft:red_flower
|
||||
39:true //minecraft:brown_mushroom
|
||||
40:true //minecraft:red_mushroom
|
||||
41:false //minecraft:gold_block
|
||||
42:false //minecraft:iron_block
|
||||
43:false //minecraft:double_stone_slab
|
||||
44:true //minecraft:stone_slab
|
||||
45:false //minecraft:brick_block
|
||||
46:false //minecraft:tnt
|
||||
47:false //minecraft:bookshelf
|
||||
48:false //minecraft:mossy_cobblestone
|
||||
49:false //minecraft:obsidian
|
||||
50:true //minecraft:torch
|
||||
51:true //minecraft:fire
|
||||
52:true //minecraft:mob_spawner
|
||||
53:true //minecraft:oak_stairs
|
||||
54:true //minecraft:chest
|
||||
55:true //minecraft:redstone_wire
|
||||
56:false //minecraft:diamond_ore
|
||||
57:false //minecraft:diamond_block
|
||||
58:false //minecraft:crafting_table
|
||||
59:true //minecraft:wheat
|
||||
60:false //minecraft:farmland
|
||||
61:false //minecraft:furnace
|
||||
62:false //minecraft:lit_furnace
|
||||
63:true //minecraft:standing_sign
|
||||
64:true //minecraft:wooden_door
|
||||
65:true //minecraft:ladder
|
||||
66:true //minecraft:rail
|
||||
67:true //minecraft:stone_stairs
|
||||
68:true //minecraft:wall_sign
|
||||
69:true //minecraft:lever
|
||||
70:true //minecraft:stone_pressure_plate
|
||||
71:true //minecraft:iron_door
|
||||
72:true //minecraft:wooden_pressure_plate
|
||||
73:false //minecraft:redstone_ore
|
||||
74:false //minecraft:lit_redstone_ore
|
||||
75:true //minecraft:unlit_redstone_torch
|
||||
76:true //minecraft:redstone_torch
|
||||
77:true //minecraft:stone_button
|
||||
78:true //minecraft:snow_layer
|
||||
79:true //minecraft:ice
|
||||
80:false //minecraft:snow
|
||||
81:true //minecraft:cactus
|
||||
82:false //minecraft:clay
|
||||
83:true //minecraft:reeds
|
||||
84:false //minecraft:jukebox
|
||||
85:true //minecraft:fence
|
||||
86:false //minecraft:pumpkin
|
||||
87:false //minecraft:netherrack
|
||||
88:false //minecraft:soul_sand
|
||||
89:false //minecraft:glowstone
|
||||
90:true //minecraft:portal
|
||||
91:false //minecraft:lit_pumpkin
|
||||
92:true //minecraft:cake
|
||||
93:true //minecraft:unpowered_repeater
|
||||
94:true //minecraft:powered_repeater
|
||||
95:true //minecraft:stained_glass
|
||||
96:true //minecraft:trapdoor
|
||||
97:false //minecraft:monster_egg
|
||||
98:false //minecraft:stonebrick
|
||||
99:false //minecraft:brown_mushroom_block
|
||||
100:false //minecraft:red_mushroom_block
|
||||
101:true //minecraft:iron_bars
|
||||
102:true //minecraft:glass_pane
|
||||
103:false //minecraft:melon_block
|
||||
104:true //minecraft:pumpkin_stem
|
||||
105:true //minecraft:melon_stem
|
||||
106:true //minecraft:vine
|
||||
107:true //minecraft:fence_gate
|
||||
108:true //minecraft:brick_stairs
|
||||
109:true //minecraft:stone_brick_stairs
|
||||
110:false //minecraft:mycelium
|
||||
111:true //minecraft:waterlily
|
||||
112:false //minecraft:nether_brick
|
||||
113:true //minecraft:nether_brick_fence
|
||||
114:true //minecraft:nether_brick_stairs
|
||||
115:true //minecraft:nether_wart
|
||||
116:false //minecraft:enchanting_table
|
||||
117:true //minecraft:brewing_stand
|
||||
118:true //minecraft:cauldron
|
||||
119:true //minecraft:end_portal
|
||||
120:true //minecraft:end_portal_frame
|
||||
121:false //minecraft:end_stone
|
||||
122:true //minecraft:dragon_egg
|
||||
123:false //minecraft:redstone_lamp
|
||||
124:false //minecraft:lit_redstone_lamp
|
||||
125:false //minecraft:double_wooden_slab
|
||||
126:true //minecraft:wooden_slab
|
||||
127:true //minecraft:cocoa
|
||||
128:true //minecraft:sandstone_stairs
|
||||
129:false //minecraft:emerald_ore
|
||||
130:true //minecraft:ender_chest
|
||||
131:true //minecraft:tripwire_hook
|
||||
132:true //minecraft:tripwire
|
||||
133:false //minecraft:emerald_block
|
||||
134:true //minecraft:spruce_stairs
|
||||
135:true //minecraft:birch_stairs
|
||||
136:true //minecraft:jungle_stairs
|
||||
137:false //minecraft:command_block
|
||||
138:true //minecraft:beacon
|
||||
139:true //minecraft:cobblestone_wall
|
||||
140:true //minecraft:flower_pot
|
||||
141:true //minecraft:carrots
|
||||
142:true //minecraft:potatoes
|
||||
143:true //minecraft:wooden_button
|
||||
144:true //minecraft:skull
|
||||
145:true //minecraft:anvil
|
||||
146:true //minecraft:trapped_chest
|
||||
147:true //minecraft:light_weighted_pressure_plate
|
||||
148:true //minecraft:heavy_weighted_pressure_plate
|
||||
149:true //minecraft:unpowered_comparator
|
||||
150:true //minecraft:powered_comparator
|
||||
151:true //minecraft:daylight_detector
|
||||
152:false //minecraft:redstone_block
|
||||
153:false //minecraft:quartz_ore
|
||||
154:true //minecraft:hopper
|
||||
155:false //minecraft:quartz_block
|
||||
156:true //minecraft:quartz_stairs
|
||||
157:true //minecraft:activator_rail
|
||||
158:false //minecraft:dropper
|
||||
159:false //minecraft:stained_hardened_clay
|
||||
160:true //minecraft:stained_glass_pane
|
||||
161:true //minecraft:leaves2
|
||||
162:false //minecraft:log2
|
||||
163:true //minecraft:acacia_stairs
|
||||
164:true //minecraft:dark_oak_stairs
|
||||
165:true //minecraft:slime
|
||||
166:true //minecraft:barrier
|
||||
167:true //minecraft:iron_trapdoor
|
||||
168:false //minecraft:prismarine
|
||||
169:false //minecraft:sea_lantern
|
||||
170:false //minecraft:hay_block
|
||||
171:true //minecraft:carpet
|
||||
172:false //minecraft:hardened_clay
|
||||
173:false //minecraft:coal_block
|
||||
174:true //minecraft:packed_ice
|
||||
175:true //minecraft:double_plant
|
||||
176:true //minecraft:standing_banner
|
||||
177:true //minecraft:wall_banner
|
||||
178:true //minecraft:daylight_detector_inverted
|
||||
179:false //minecraft:red_sandstone
|
||||
180:true //minecraft:red_sandstone_stairs
|
||||
181:false //minecraft:double_stone_slab2
|
||||
182:true //minecraft:stone_slab2
|
||||
183:true //minecraft:spruce_fence_gate
|
||||
184:true //minecraft:birch_fence_gate
|
||||
185:true //minecraft:jungle_fence_gate
|
||||
186:true //minecraft:dark_oak_fence_gate
|
||||
187:true //minecraft:acacia_fence_gate
|
||||
188:true //minecraft:spruce_fence
|
||||
189:true //minecraft:birch_fence
|
||||
190:true //minecraft:jungle_fence
|
||||
191:true //minecraft:dark_oak_fence
|
||||
192:true //minecraft:acacia_fence
|
||||
193:true //minecraft:spruce_door
|
||||
194:true //minecraft:birch_door
|
||||
195:true //minecraft:jungle_door
|
||||
196:true //minecraft:acacia_door
|
||||
197:true //minecraft:dark_oak_door
|
||||
198:true //minecraft:end_rod
|
||||
199:true //minecraft:chorus_plant
|
||||
200:true //minecraft:chorus_flower
|
||||
201:false //minecraft:purpur_block
|
||||
202:false //minecraft:purpur_pillar
|
||||
203:true //minecraft:purpur_stairs
|
||||
204:false //minecraft:purpur_double_slab
|
||||
205:true //minecraft:purpur_slab
|
||||
206:false //minecraft:end_bricks
|
||||
207:true //minecraft:beetroots
|
||||
208:true //minecraft:grass_path
|
||||
209:true //minecraft:end_gateway
|
||||
210:false //minecraft:repeating_command_block
|
||||
211:false //minecraft:chain_command_block
|
||||
212:true //minecraft:frosted_ice
|
||||
213:false //minecraft:magma_block
|
||||
214:false //minecraft:nether_wart_block
|
||||
215:false //minecraft:red_nether_brick
|
||||
216:false //minecraft:bone_block
|
||||
217:true //minecraft:structure_void
|
||||
255:false //minecraft:structure_block
|
|
@ -1 +0,0 @@
|
|||
11:false //minecraft:lava
|
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,10 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
Block block = this.blockData.getBlock();
|
||||
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_10_R1;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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 +18,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 +31,213 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private Material[] extraTransparentBlocks;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.WORKBENCH,
|
||||
Material.FURNACE,
|
||||
Material.BURNING_FURNACE,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.MOB_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.ENDER_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.ENDER_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.ENDER_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.ENDER_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICK,
|
||||
Material.QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.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.WOOD,
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BED_BLOCK,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_WOOD_STAIRS,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.CACTUS,
|
||||
Material.CAKE_BLOCK,
|
||||
Material.CAULDRON,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLE_WALL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DAYLIGHT_DETECTOR_INVERTED,
|
||||
Material.DRAGON_EGG,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.FENCE,
|
||||
Material.FENCE_GATE,
|
||||
Material.GLASS,
|
||||
Material.HOPPER,
|
||||
Material.ICE,
|
||||
Material.IRON_DOOR_BLOCK,
|
||||
Material.IRON_FENCE,
|
||||
Material.IRON_PLATE,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_WOOD_STAIRS,
|
||||
Material.LAVA,
|
||||
Material.LEAVES,
|
||||
Material.LEAVES_2,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.NETHER_FENCE,
|
||||
Material.PACKED_ICE,
|
||||
Material.PISTON_BASE,
|
||||
Material.PISTON_EXTENSION,
|
||||
Material.PISTON_MOVING_PIECE,
|
||||
Material.PISTON_STICKY_BASE,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SIGN_POST,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SMOOTH_STAIRS,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_WOOD_STAIRS,
|
||||
Material.STAINED_GLASS,
|
||||
Material.STAINED_GLASS_PANE,
|
||||
Material.STANDING_BANNER,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.STEP,
|
||||
Material.STONE_PLATE,
|
||||
Material.STONE_SLAB2,
|
||||
Material.THIN_GLASS,
|
||||
Material.TRAP_DOOR,
|
||||
Material.WALL_BANNER,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WEB,
|
||||
Material.WOODEN_DOOR,
|
||||
Material.WOOD_PLATE,
|
||||
Material.WOOD_STAIRS,
|
||||
Material.WOOD_STEP
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,28 +291,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 +302,76 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
int typeId = combinedBlockId >> 4;
|
||||
|
||||
return typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId();
|
||||
}
|
||||
|
||||
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 Set<Integer> getMaterialIds(Material material) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
int blockId = material.getId() << 4;
|
||||
Block block = Block.getById(material.getId());
|
||||
ImmutableList<IBlockData> blockDataList = block.t().a();
|
||||
|
||||
for(IBlockData blockData : blockDataList) {
|
||||
ids.add(blockId | block.toLegacyData(blockData));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -131,4 +385,27 @@ public class NmsManager implements INmsManager {
|
|||
|
||||
return chunk != null ? chunk.getBlockData(new BlockPosition(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,9 +34,10 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
Block block = this.blockData.getBlock();
|
||||
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_11_R1;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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 +18,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 +31,213 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private Material[] extraTransparentBlocks;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.WORKBENCH,
|
||||
Material.FURNACE,
|
||||
Material.BURNING_FURNACE,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.MOB_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.ENDER_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.ENDER_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.ENDER_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.ENDER_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICK,
|
||||
Material.QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.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.WOOD,
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BED_BLOCK,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_WOOD_STAIRS,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.CACTUS,
|
||||
Material.CAKE_BLOCK,
|
||||
Material.CAULDRON,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLE_WALL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DAYLIGHT_DETECTOR_INVERTED,
|
||||
Material.DRAGON_EGG,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.FENCE,
|
||||
Material.FENCE_GATE,
|
||||
Material.GLASS,
|
||||
Material.HOPPER,
|
||||
Material.ICE,
|
||||
Material.IRON_DOOR_BLOCK,
|
||||
Material.IRON_FENCE,
|
||||
Material.IRON_PLATE,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_WOOD_STAIRS,
|
||||
Material.LAVA,
|
||||
Material.LEAVES,
|
||||
Material.LEAVES_2,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.NETHER_FENCE,
|
||||
Material.PACKED_ICE,
|
||||
Material.PISTON_BASE,
|
||||
Material.PISTON_EXTENSION,
|
||||
Material.PISTON_MOVING_PIECE,
|
||||
Material.PISTON_STICKY_BASE,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SIGN_POST,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SMOOTH_STAIRS,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_WOOD_STAIRS,
|
||||
Material.STAINED_GLASS,
|
||||
Material.STAINED_GLASS_PANE,
|
||||
Material.STANDING_BANNER,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.STEP,
|
||||
Material.STONE_PLATE,
|
||||
Material.STONE_SLAB2,
|
||||
Material.THIN_GLASS,
|
||||
Material.TRAP_DOOR,
|
||||
Material.WALL_BANNER,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WEB,
|
||||
Material.WOODEN_DOOR,
|
||||
Material.WOOD_PLATE,
|
||||
Material.WOOD_STAIRS,
|
||||
Material.WOOD_STEP
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,28 +291,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 +302,75 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
int typeId = combinedBlockId >> 4;
|
||||
|
||||
return typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId();
|
||||
}
|
||||
|
||||
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 Set<Integer> getMaterialIds(Material material) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
int blockId = material.getId() << 4;
|
||||
Block block = Block.getById(material.getId());
|
||||
ImmutableList<IBlockData> blockDataList = block.s().a();
|
||||
|
||||
for(IBlockData blockData : blockDataList) {
|
||||
ids.add(blockId | block.toLegacyData(blockData));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -131,4 +385,27 @@ public class NmsManager implements INmsManager {
|
|||
|
||||
return chunk != null ? chunk.getBlockData(new BlockPosition(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,9 +34,10 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
Block block = this.blockData.getBlock();
|
||||
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
|
||||
}
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
|
|
|
@ -6,16 +6,12 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_12_R1;
|
||||
|
||||
import net.minecraft.server.v1_12_R1.Block;
|
||||
import net.minecraft.server.v1_12_R1.BlockPosition;
|
||||
import net.minecraft.server.v1_12_R1.Chunk;
|
||||
import net.minecraft.server.v1_12_R1.ChunkProviderServer;
|
||||
import net.minecraft.server.v1_12_R1.IBlockData;
|
||||
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
|
||||
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 com.google.common.collect.ImmutableList;
|
||||
import com.lishid.orebfuscator.types.ConfigDefaults;
|
||||
import net.minecraft.server.v1_12_R1.*;
|
||||
|
||||
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 +23,213 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private Material[] extraTransparentBlocks;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.WORKBENCH,
|
||||
Material.FURNACE,
|
||||
Material.BURNING_FURNACE,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.MOB_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.ENDER_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.ENDER_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.ENDER_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.ENDER_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICK,
|
||||
Material.QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.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.WOOD,
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BED_BLOCK,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_WOOD_STAIRS,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.CACTUS,
|
||||
Material.CAKE_BLOCK,
|
||||
Material.CAULDRON,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLE_WALL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DAYLIGHT_DETECTOR_INVERTED,
|
||||
Material.DRAGON_EGG,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.FENCE,
|
||||
Material.FENCE_GATE,
|
||||
Material.GLASS,
|
||||
Material.HOPPER,
|
||||
Material.ICE,
|
||||
Material.IRON_DOOR_BLOCK,
|
||||
Material.IRON_FENCE,
|
||||
Material.IRON_PLATE,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_WOOD_STAIRS,
|
||||
Material.LAVA,
|
||||
Material.LEAVES,
|
||||
Material.LEAVES_2,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.NETHER_FENCE,
|
||||
Material.PACKED_ICE,
|
||||
Material.PISTON_BASE,
|
||||
Material.PISTON_EXTENSION,
|
||||
Material.PISTON_MOVING_PIECE,
|
||||
Material.PISTON_STICKY_BASE,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SIGN_POST,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SMOOTH_STAIRS,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_WOOD_STAIRS,
|
||||
Material.STAINED_GLASS,
|
||||
Material.STAINED_GLASS_PANE,
|
||||
Material.STANDING_BANNER,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.STEP,
|
||||
Material.STONE_PLATE,
|
||||
Material.STONE_SLAB2,
|
||||
Material.THIN_GLASS,
|
||||
Material.TRAP_DOOR,
|
||||
Material.WALL_BANNER,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WEB,
|
||||
Material.WOODEN_DOOR,
|
||||
Material.WOOD_PLATE,
|
||||
Material.WOOD_STAIRS,
|
||||
Material.WOOD_STEP
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -84,27 +283,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 +294,75 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
int typeId = combinedBlockId >> 4;
|
||||
|
||||
return typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId();
|
||||
}
|
||||
|
||||
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 Set<Integer> getMaterialIds(Material material) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
int blockId = material.getId() << 4;
|
||||
Block block = Block.getById(material.getId());
|
||||
ImmutableList<IBlockData> blockDataList = block.s().a();
|
||||
|
||||
for(IBlockData blockData : blockDataList) {
|
||||
ids.add(blockId | block.toLegacyData(blockData));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -130,4 +377,27 @@ public class NmsManager implements INmsManager {
|
|||
|
||||
return chunk != null ? chunk.getBlockData(new BlockPosition(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_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,564 @@
|
|||
/**
|
||||
* @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 Material[] extraTransparentBlocks;
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_LEAVES,
|
||||
Material.ACACIA_PRESSURE_PLATE,
|
||||
Material.ACACIA_SLAB,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ACACIA_TRAPDOOR,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_LEAVES,
|
||||
Material.BIRCH_PRESSURE_PLATE,
|
||||
Material.BIRCH_SLAB,
|
||||
Material.BIRCH_STAIRS,
|
||||
Material.BIRCH_TRAPDOOR,
|
||||
Material.BLACK_BANNER,
|
||||
Material.BLACK_BED,
|
||||
Material.BLACK_STAINED_GLASS,
|
||||
Material.BLACK_STAINED_GLASS_PANE,
|
||||
Material.BLACK_WALL_BANNER,
|
||||
Material.BLUE_BANNER,
|
||||
Material.BLUE_BED,
|
||||
Material.BLUE_ICE,
|
||||
Material.BLUE_STAINED_GLASS,
|
||||
Material.BLUE_STAINED_GLASS_PANE,
|
||||
Material.BLUE_WALL_BANNER,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_SLAB,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.BRAIN_CORAL,
|
||||
Material.BRAIN_CORAL_FAN,
|
||||
Material.BRAIN_CORAL_WALL_FAN,
|
||||
Material.BROWN_BANNER,
|
||||
Material.BROWN_BED,
|
||||
Material.BROWN_STAINED_GLASS,
|
||||
Material.BROWN_STAINED_GLASS_PANE,
|
||||
Material.BROWN_WALL_BANNER,
|
||||
Material.BUBBLE_COLUMN,
|
||||
Material.BUBBLE_CORAL,
|
||||
Material.BUBBLE_CORAL_FAN,
|
||||
Material.BUBBLE_CORAL_WALL_FAN,
|
||||
Material.CACTUS,
|
||||
Material.CAKE,
|
||||
Material.CAULDRON,
|
||||
Material.CHIPPED_ANVIL,
|
||||
Material.COBBLESTONE_SLAB,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLESTONE_WALL,
|
||||
Material.COBWEB,
|
||||
Material.CONDUIT,
|
||||
Material.CYAN_BANNER,
|
||||
Material.CYAN_BED,
|
||||
Material.CYAN_STAINED_GLASS,
|
||||
Material.CYAN_STAINED_GLASS_PANE,
|
||||
Material.CYAN_WALL_BANNER,
|
||||
Material.DAMAGED_ANVIL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_LEAVES,
|
||||
Material.DARK_OAK_PRESSURE_PLATE,
|
||||
Material.DARK_OAK_SLAB,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DARK_OAK_TRAPDOOR,
|
||||
Material.DARK_PRISMARINE_SLAB,
|
||||
Material.DARK_PRISMARINE_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DEAD_BRAIN_CORAL_FAN,
|
||||
Material.DEAD_BRAIN_CORAL_WALL_FAN,
|
||||
Material.DEAD_BUBBLE_CORAL_FAN,
|
||||
Material.DEAD_BUBBLE_CORAL_WALL_FAN,
|
||||
Material.DEAD_FIRE_CORAL_FAN,
|
||||
Material.DEAD_FIRE_CORAL_WALL_FAN,
|
||||
Material.DEAD_HORN_CORAL_FAN,
|
||||
Material.DEAD_HORN_CORAL_WALL_FAN,
|
||||
Material.DEAD_TUBE_CORAL_FAN,
|
||||
Material.DEAD_TUBE_CORAL_WALL_FAN,
|
||||
Material.DRAGON_EGG,
|
||||
Material.FARMLAND,
|
||||
Material.FIRE_CORAL,
|
||||
Material.FIRE_CORAL_FAN,
|
||||
Material.FIRE_CORAL_WALL_FAN,
|
||||
Material.FROSTED_ICE,
|
||||
Material.GLASS,
|
||||
Material.GLASS_PANE,
|
||||
Material.GRAY_BANNER,
|
||||
Material.GRAY_BED,
|
||||
Material.GRAY_STAINED_GLASS,
|
||||
Material.GRAY_STAINED_GLASS_PANE,
|
||||
Material.GRAY_WALL_BANNER,
|
||||
Material.GREEN_BANNER,
|
||||
Material.GREEN_BED,
|
||||
Material.GREEN_STAINED_GLASS,
|
||||
Material.GREEN_STAINED_GLASS_PANE,
|
||||
Material.GREEN_WALL_BANNER,
|
||||
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
||||
Material.HOPPER,
|
||||
Material.HORN_CORAL,
|
||||
Material.HORN_CORAL_FAN,
|
||||
Material.HORN_CORAL_WALL_FAN,
|
||||
Material.ICE,
|
||||
Material.IRON_BARS,
|
||||
Material.IRON_DOOR,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_LEAVES,
|
||||
Material.JUNGLE_PRESSURE_PLATE,
|
||||
Material.JUNGLE_SLAB,
|
||||
Material.JUNGLE_STAIRS,
|
||||
Material.JUNGLE_TRAPDOOR,
|
||||
Material.KELP,
|
||||
Material.KELP_PLANT,
|
||||
Material.LIGHT_BLUE_BANNER,
|
||||
Material.LIGHT_BLUE_BED,
|
||||
Material.LIGHT_BLUE_STAINED_GLASS,
|
||||
Material.LIGHT_BLUE_STAINED_GLASS_PANE,
|
||||
Material.LIGHT_BLUE_WALL_BANNER,
|
||||
Material.LIGHT_GRAY_BANNER,
|
||||
Material.LIGHT_GRAY_BED,
|
||||
Material.LIGHT_GRAY_STAINED_GLASS,
|
||||
Material.LIGHT_GRAY_STAINED_GLASS_PANE,
|
||||
Material.LIGHT_GRAY_WALL_BANNER,
|
||||
Material.LIGHT_WEIGHTED_PRESSURE_PLATE,
|
||||
Material.LIME_BANNER,
|
||||
Material.LIME_BED,
|
||||
Material.LIME_STAINED_GLASS,
|
||||
Material.LIME_STAINED_GLASS_PANE,
|
||||
Material.LIME_WALL_BANNER,
|
||||
Material.MAGENTA_BANNER,
|
||||
Material.MAGENTA_BED,
|
||||
Material.MAGENTA_STAINED_GLASS,
|
||||
Material.MAGENTA_STAINED_GLASS_PANE,
|
||||
Material.MAGENTA_WALL_BANNER,
|
||||
Material.MOSSY_COBBLESTONE_WALL,
|
||||
Material.MOVING_PISTON,
|
||||
Material.NETHER_BRICK_FENCE,
|
||||
Material.NETHER_BRICK_SLAB,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.OAK_DOOR,
|
||||
Material.OAK_FENCE,
|
||||
Material.OAK_FENCE_GATE,
|
||||
Material.OAK_LEAVES,
|
||||
Material.OAK_PRESSURE_PLATE,
|
||||
Material.OAK_SLAB,
|
||||
Material.OAK_STAIRS,
|
||||
Material.OAK_TRAPDOOR,
|
||||
Material.ORANGE_BANNER,
|
||||
Material.ORANGE_BED,
|
||||
Material.ORANGE_STAINED_GLASS,
|
||||
Material.ORANGE_STAINED_GLASS_PANE,
|
||||
Material.ORANGE_WALL_BANNER,
|
||||
Material.PACKED_ICE,
|
||||
Material.PETRIFIED_OAK_SLAB,
|
||||
Material.PINK_BANNER,
|
||||
Material.PINK_BED,
|
||||
Material.PINK_STAINED_GLASS,
|
||||
Material.PINK_STAINED_GLASS_PANE,
|
||||
Material.PINK_WALL_BANNER,
|
||||
Material.PISTON,
|
||||
Material.PISTON_HEAD,
|
||||
Material.PRISMARINE_BRICK_SLAB,
|
||||
Material.PRISMARINE_BRICK_STAIRS,
|
||||
Material.PRISMARINE_SLAB,
|
||||
Material.PRISMARINE_STAIRS,
|
||||
Material.PURPLE_BANNER,
|
||||
Material.PURPLE_BED,
|
||||
Material.PURPLE_STAINED_GLASS,
|
||||
Material.PURPLE_STAINED_GLASS_PANE,
|
||||
Material.PURPLE_WALL_BANNER,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_SLAB,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_BANNER,
|
||||
Material.RED_BED,
|
||||
Material.RED_SANDSTONE_SLAB,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.RED_STAINED_GLASS,
|
||||
Material.RED_STAINED_GLASS_PANE,
|
||||
Material.RED_WALL_BANNER,
|
||||
Material.SANDSTONE_SLAB,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SEAGRASS,
|
||||
Material.SEA_PICKLE,
|
||||
Material.SIGN,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SPAWNER,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_LEAVES,
|
||||
Material.SPRUCE_PRESSURE_PLATE,
|
||||
Material.SPRUCE_SLAB,
|
||||
Material.SPRUCE_STAIRS,
|
||||
Material.SPRUCE_TRAPDOOR,
|
||||
Material.STICKY_PISTON,
|
||||
Material.STONE_BRICK_SLAB,
|
||||
Material.STONE_BRICK_STAIRS,
|
||||
Material.STONE_PRESSURE_PLATE,
|
||||
Material.STONE_SLAB,
|
||||
Material.TALL_SEAGRASS,
|
||||
Material.TUBE_CORAL,
|
||||
Material.TUBE_CORAL_FAN,
|
||||
Material.TUBE_CORAL_WALL_FAN,
|
||||
Material.TURTLE_EGG,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WHITE_BANNER,
|
||||
Material.WHITE_BED,
|
||||
Material.WHITE_STAINED_GLASS,
|
||||
Material.WHITE_STAINED_GLASS_PANE,
|
||||
Material.WHITE_WALL_BANNER,
|
||||
Material.YELLOW_BANNER,
|
||||
Material.YELLOW_BED,
|
||||
Material.YELLOW_STAINED_GLASS,
|
||||
Material.YELLOW_STAINED_GLASS_PANE,
|
||||
Material.YELLOW_WALL_BANNER
|
||||
};
|
||||
}
|
||||
|
||||
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 Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
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 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,561 @@
|
|||
/**
|
||||
* @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 Material[] extraTransparentBlocks;
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_LEAVES,
|
||||
Material.ACACIA_PRESSURE_PLATE,
|
||||
Material.ACACIA_SLAB,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ACACIA_TRAPDOOR,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_LEAVES,
|
||||
Material.BIRCH_PRESSURE_PLATE,
|
||||
Material.BIRCH_SLAB,
|
||||
Material.BIRCH_STAIRS,
|
||||
Material.BIRCH_TRAPDOOR,
|
||||
Material.BLACK_BANNER,
|
||||
Material.BLACK_BED,
|
||||
Material.BLACK_STAINED_GLASS,
|
||||
Material.BLACK_STAINED_GLASS_PANE,
|
||||
Material.BLACK_WALL_BANNER,
|
||||
Material.BLUE_BANNER,
|
||||
Material.BLUE_BED,
|
||||
Material.BLUE_ICE,
|
||||
Material.BLUE_STAINED_GLASS,
|
||||
Material.BLUE_STAINED_GLASS_PANE,
|
||||
Material.BLUE_WALL_BANNER,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_SLAB,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.BRAIN_CORAL,
|
||||
Material.BRAIN_CORAL_FAN,
|
||||
Material.BRAIN_CORAL_WALL_FAN,
|
||||
Material.BROWN_BANNER,
|
||||
Material.BROWN_BED,
|
||||
Material.BROWN_STAINED_GLASS,
|
||||
Material.BROWN_STAINED_GLASS_PANE,
|
||||
Material.BROWN_WALL_BANNER,
|
||||
Material.BUBBLE_COLUMN,
|
||||
Material.BUBBLE_CORAL,
|
||||
Material.BUBBLE_CORAL_FAN,
|
||||
Material.BUBBLE_CORAL_WALL_FAN,
|
||||
Material.CACTUS,
|
||||
Material.CAKE,
|
||||
Material.CAULDRON,
|
||||
Material.CHIPPED_ANVIL,
|
||||
Material.COBBLESTONE_SLAB,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLESTONE_WALL,
|
||||
Material.COBWEB,
|
||||
Material.CONDUIT,
|
||||
Material.CYAN_BANNER,
|
||||
Material.CYAN_BED,
|
||||
Material.CYAN_STAINED_GLASS,
|
||||
Material.CYAN_STAINED_GLASS_PANE,
|
||||
Material.CYAN_WALL_BANNER,
|
||||
Material.DAMAGED_ANVIL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_LEAVES,
|
||||
Material.DARK_OAK_PRESSURE_PLATE,
|
||||
Material.DARK_OAK_SLAB,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DARK_OAK_TRAPDOOR,
|
||||
Material.DARK_PRISMARINE_SLAB,
|
||||
Material.DARK_PRISMARINE_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DEAD_BRAIN_CORAL,
|
||||
Material.DEAD_BRAIN_CORAL_FAN,
|
||||
Material.DEAD_BRAIN_CORAL_WALL_FAN,
|
||||
Material.DEAD_BUBBLE_CORAL,
|
||||
Material.DEAD_BUBBLE_CORAL_FAN,
|
||||
Material.DEAD_BUBBLE_CORAL_WALL_FAN,
|
||||
Material.DEAD_FIRE_CORAL,
|
||||
Material.DEAD_FIRE_CORAL_FAN,
|
||||
Material.DEAD_FIRE_CORAL_WALL_FAN,
|
||||
Material.DEAD_HORN_CORAL,
|
||||
Material.DEAD_HORN_CORAL_FAN,
|
||||
Material.DEAD_HORN_CORAL_WALL_FAN,
|
||||
Material.DEAD_TUBE_CORAL,
|
||||
Material.DEAD_TUBE_CORAL_FAN,
|
||||
Material.DEAD_TUBE_CORAL_WALL_FAN,
|
||||
Material.DRAGON_EGG,
|
||||
Material.FARMLAND,
|
||||
Material.FIRE_CORAL,
|
||||
Material.FIRE_CORAL_FAN,
|
||||
Material.FIRE_CORAL_WALL_FAN,
|
||||
Material.FROSTED_ICE,
|
||||
Material.GLASS,
|
||||
Material.GLASS_PANE,
|
||||
Material.GRAY_BANNER,
|
||||
Material.GRAY_BED,
|
||||
Material.GRAY_STAINED_GLASS,
|
||||
Material.GRAY_STAINED_GLASS_PANE,
|
||||
Material.GRAY_WALL_BANNER,
|
||||
Material.GREEN_BANNER,
|
||||
Material.GREEN_BED,
|
||||
Material.GREEN_STAINED_GLASS,
|
||||
Material.GREEN_STAINED_GLASS_PANE,
|
||||
Material.GREEN_WALL_BANNER,
|
||||
Material.HEAVY_WEIGHTED_PRESSURE_PLATE,
|
||||
Material.HOPPER,
|
||||
Material.HORN_CORAL,
|
||||
Material.HORN_CORAL_FAN,
|
||||
Material.HORN_CORAL_WALL_FAN,
|
||||
Material.ICE,
|
||||
Material.IRON_BARS,
|
||||
Material.IRON_DOOR,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_LEAVES,
|
||||
Material.JUNGLE_PRESSURE_PLATE,
|
||||
Material.JUNGLE_SLAB,
|
||||
Material.JUNGLE_STAIRS,
|
||||
Material.JUNGLE_TRAPDOOR,
|
||||
Material.KELP,
|
||||
Material.KELP_PLANT,
|
||||
Material.LIGHT_BLUE_BANNER,
|
||||
Material.LIGHT_BLUE_BED,
|
||||
Material.LIGHT_BLUE_STAINED_GLASS,
|
||||
Material.LIGHT_BLUE_STAINED_GLASS_PANE,
|
||||
Material.LIGHT_BLUE_WALL_BANNER,
|
||||
Material.LIGHT_GRAY_BANNER,
|
||||
Material.LIGHT_GRAY_BED,
|
||||
Material.LIGHT_GRAY_STAINED_GLASS,
|
||||
Material.LIGHT_GRAY_STAINED_GLASS_PANE,
|
||||
Material.LIGHT_GRAY_WALL_BANNER,
|
||||
Material.LIGHT_WEIGHTED_PRESSURE_PLATE,
|
||||
Material.LIME_BANNER,
|
||||
Material.LIME_BED,
|
||||
Material.LIME_STAINED_GLASS,
|
||||
Material.LIME_STAINED_GLASS_PANE,
|
||||
Material.LIME_WALL_BANNER,
|
||||
Material.MAGENTA_BANNER,
|
||||
Material.MAGENTA_BED,
|
||||
Material.MAGENTA_STAINED_GLASS,
|
||||
Material.MAGENTA_STAINED_GLASS_PANE,
|
||||
Material.MAGENTA_WALL_BANNER,
|
||||
Material.MOSSY_COBBLESTONE_WALL,
|
||||
Material.MOVING_PISTON,
|
||||
Material.NETHER_BRICK_FENCE,
|
||||
Material.NETHER_BRICK_SLAB,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.OAK_DOOR,
|
||||
Material.OAK_FENCE,
|
||||
Material.OAK_FENCE_GATE,
|
||||
Material.OAK_LEAVES,
|
||||
Material.OAK_PRESSURE_PLATE,
|
||||
Material.OAK_SLAB,
|
||||
Material.OAK_STAIRS,
|
||||
Material.OAK_TRAPDOOR,
|
||||
Material.ORANGE_BANNER,
|
||||
Material.ORANGE_BED,
|
||||
Material.ORANGE_STAINED_GLASS,
|
||||
Material.ORANGE_STAINED_GLASS_PANE,
|
||||
Material.ORANGE_WALL_BANNER,
|
||||
Material.PACKED_ICE,
|
||||
Material.PETRIFIED_OAK_SLAB,
|
||||
Material.PINK_BANNER,
|
||||
Material.PINK_BED,
|
||||
Material.PINK_STAINED_GLASS,
|
||||
Material.PINK_STAINED_GLASS_PANE,
|
||||
Material.PINK_WALL_BANNER,
|
||||
Material.PISTON,
|
||||
Material.PISTON_HEAD,
|
||||
Material.PRISMARINE_BRICK_SLAB,
|
||||
Material.PRISMARINE_BRICK_STAIRS,
|
||||
Material.PRISMARINE_SLAB,
|
||||
Material.PRISMARINE_STAIRS,
|
||||
Material.PURPLE_BANNER,
|
||||
Material.PURPLE_BED,
|
||||
Material.PURPLE_STAINED_GLASS,
|
||||
Material.PURPLE_STAINED_GLASS_PANE,
|
||||
Material.PURPLE_WALL_BANNER,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_SLAB,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_BANNER,
|
||||
Material.RED_BED,
|
||||
Material.RED_SANDSTONE_SLAB,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.RED_STAINED_GLASS,
|
||||
Material.RED_STAINED_GLASS_PANE,
|
||||
Material.RED_WALL_BANNER,
|
||||
Material.SANDSTONE_SLAB,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SEAGRASS,
|
||||
Material.SEA_PICKLE,
|
||||
Material.SIGN,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SPAWNER,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_LEAVES,
|
||||
Material.SPRUCE_PRESSURE_PLATE,
|
||||
Material.SPRUCE_SLAB,
|
||||
Material.SPRUCE_STAIRS,
|
||||
Material.SPRUCE_TRAPDOOR,
|
||||
Material.STICKY_PISTON,
|
||||
Material.STONE_BRICK_SLAB,
|
||||
Material.STONE_BRICK_STAIRS,
|
||||
Material.STONE_PRESSURE_PLATE,
|
||||
Material.STONE_SLAB,
|
||||
Material.TALL_SEAGRASS,
|
||||
Material.TUBE_CORAL,
|
||||
Material.TUBE_CORAL_FAN,
|
||||
Material.TUBE_CORAL_WALL_FAN,
|
||||
Material.TURTLE_EGG,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WHITE_BANNER,
|
||||
Material.WHITE_BED,
|
||||
Material.WHITE_STAINED_GLASS,
|
||||
Material.WHITE_STAINED_GLASS_PANE,
|
||||
Material.WHITE_WALL_BANNER,
|
||||
Material.YELLOW_BANNER,
|
||||
Material.YELLOW_BED,
|
||||
Material.YELLOW_STAINED_GLASS,
|
||||
Material.YELLOW_STAINED_GLASS_PANE,
|
||||
Material.YELLOW_WALL_BANNER
|
||||
};
|
||||
}
|
||||
|
||||
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 Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
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 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,16 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
Block block = this.blockData.getBlock();
|
||||
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
|
||||
}
|
||||
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof BlockInfo)) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_9_R1;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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 +18,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 +31,214 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private Material[] extraTransparentBlocks;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.WORKBENCH,
|
||||
Material.FURNACE,
|
||||
Material.BURNING_FURNACE,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.MOB_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.ENDER_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.ENDER_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.ENDER_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.ENDER_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICK,
|
||||
Material.QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.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.WOOD,
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BED_BLOCK,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_WOOD_STAIRS,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.CACTUS,
|
||||
Material.CAKE_BLOCK,
|
||||
Material.CAULDRON,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLE_WALL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DAYLIGHT_DETECTOR_INVERTED,
|
||||
Material.DRAGON_EGG,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.FENCE,
|
||||
Material.FENCE_GATE,
|
||||
Material.GLASS,
|
||||
Material.HOPPER,
|
||||
Material.ICE,
|
||||
Material.IRON_DOOR_BLOCK,
|
||||
Material.IRON_FENCE,
|
||||
Material.IRON_PLATE,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_WOOD_STAIRS,
|
||||
Material.LAVA,
|
||||
Material.LEAVES,
|
||||
Material.LEAVES_2,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.NETHER_FENCE,
|
||||
Material.PACKED_ICE,
|
||||
Material.PISTON_BASE,
|
||||
Material.PISTON_EXTENSION,
|
||||
Material.PISTON_MOVING_PIECE,
|
||||
Material.PISTON_STICKY_BASE,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SIGN_POST,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SMOOTH_STAIRS,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_WOOD_STAIRS,
|
||||
Material.STAINED_GLASS,
|
||||
Material.STAINED_GLASS_PANE,
|
||||
Material.STANDING_BANNER,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.STEP,
|
||||
Material.STONE_PLATE,
|
||||
Material.STONE_SLAB2,
|
||||
Material.THIN_GLASS,
|
||||
Material.TRAP_DOOR,
|
||||
Material.WALL_BANNER,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WEB,
|
||||
Material.WOODEN_DOOR,
|
||||
Material.WOOD_PLATE,
|
||||
Material.WOOD_STAIRS,
|
||||
Material.WOOD_STEP
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
}
|
||||
|
@ -78,30 +285,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 +296,75 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
int typeId = combinedBlockId >> 4;
|
||||
|
||||
return typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId();
|
||||
}
|
||||
|
||||
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 Set<Integer> getMaterialIds(Material material) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
int blockId = material.getId() << 4;
|
||||
Block block = Block.getById(material.getId());
|
||||
ImmutableList<IBlockData> blockDataList = block.t().a();
|
||||
|
||||
for(IBlockData blockData : blockDataList) {
|
||||
ids.add(blockId | block.toLegacyData(blockData));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -122,4 +378,27 @@ public class NmsManager implements INmsManager {
|
|||
|
||||
return chunk != null ? chunk.getBlockData(new BlockPosition(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,11 +34,12 @@ public class BlockInfo implements IBlockInfo {
|
|||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return Block.getId(this.blockData.getBlock());
|
||||
|
||||
public int getCombinedId() {
|
||||
Block block = this.blockData.getBlock();
|
||||
return (Block.getId(block) << 4) | block.toLegacyData(this.blockData);
|
||||
}
|
||||
|
||||
|
||||
public IBlockData getBlockData() {
|
||||
return this.blockData;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
package com.lishid.orebfuscator.nms.v1_9_R2;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
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 +18,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 +31,213 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class NmsManager implements INmsManager {
|
||||
private ConfigDefaults configDefaults;
|
||||
private Material[] extraTransparentBlocks;
|
||||
private int maxLoadedCacheFiles;
|
||||
|
||||
public NmsManager() {
|
||||
this.configDefaults = new ConfigDefaults();
|
||||
|
||||
// Default World
|
||||
|
||||
this.configDefaults.defaultProximityHiderBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.DISPENSER,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.CHEST,
|
||||
Material.HOPPER,
|
||||
Material.WORKBENCH,
|
||||
Material.FURNACE,
|
||||
Material.BURNING_FURNACE,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.EMERALD_ORE,
|
||||
Material.ENDER_CHEST,
|
||||
Material.ANVIL,
|
||||
Material.TRAPPED_CHEST,
|
||||
Material.DIAMOND_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.defaultDarknessBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.MOB_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.ENDER_STONE,
|
||||
Material.PURPUR_BLOCK,
|
||||
Material.END_BRICKS
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.ENDER_STONE
|
||||
});
|
||||
|
||||
this.configDefaults.endWorldMode1BlockId = getMaterialIds(Material.ENDER_STONE).iterator().next();
|
||||
this.configDefaults.endWorldRequiredObfuscateBlockIds = convertMaterialsToIds(new Material[] { Material.ENDER_STONE });
|
||||
|
||||
// Nether World
|
||||
|
||||
this.configDefaults.netherWorldRandomBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.GRAVEL,
|
||||
Material.NETHERRACK,
|
||||
Material.SOUL_SAND,
|
||||
Material.NETHER_BRICK,
|
||||
Material.QUARTZ_ORE
|
||||
});
|
||||
|
||||
this.configDefaults.netherWorldObfuscateBlockIds = convertMaterialsToIds(new Material[] {
|
||||
Material.NETHERRACK,
|
||||
Material.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.WOOD,
|
||||
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
|
||||
});
|
||||
|
||||
// Extra transparent blocks
|
||||
|
||||
this.extraTransparentBlocks = new Material[] {
|
||||
Material.ACACIA_DOOR,
|
||||
Material.ACACIA_FENCE,
|
||||
Material.ACACIA_FENCE_GATE,
|
||||
Material.ACACIA_STAIRS,
|
||||
Material.ANVIL,
|
||||
Material.BEACON,
|
||||
Material.BED_BLOCK,
|
||||
Material.BIRCH_DOOR,
|
||||
Material.BIRCH_FENCE,
|
||||
Material.BIRCH_FENCE_GATE,
|
||||
Material.BIRCH_WOOD_STAIRS,
|
||||
Material.BREWING_STAND,
|
||||
Material.BRICK_STAIRS,
|
||||
Material.CACTUS,
|
||||
Material.CAKE_BLOCK,
|
||||
Material.CAULDRON,
|
||||
Material.COBBLESTONE_STAIRS,
|
||||
Material.COBBLE_WALL,
|
||||
Material.DARK_OAK_DOOR,
|
||||
Material.DARK_OAK_FENCE,
|
||||
Material.DARK_OAK_FENCE_GATE,
|
||||
Material.DARK_OAK_STAIRS,
|
||||
Material.DAYLIGHT_DETECTOR,
|
||||
Material.DAYLIGHT_DETECTOR_INVERTED,
|
||||
Material.DRAGON_EGG,
|
||||
Material.ENCHANTMENT_TABLE,
|
||||
Material.FENCE,
|
||||
Material.FENCE_GATE,
|
||||
Material.GLASS,
|
||||
Material.HOPPER,
|
||||
Material.ICE,
|
||||
Material.IRON_DOOR_BLOCK,
|
||||
Material.IRON_FENCE,
|
||||
Material.IRON_PLATE,
|
||||
Material.IRON_TRAPDOOR,
|
||||
Material.JUNGLE_DOOR,
|
||||
Material.JUNGLE_FENCE,
|
||||
Material.JUNGLE_FENCE_GATE,
|
||||
Material.JUNGLE_WOOD_STAIRS,
|
||||
Material.LAVA,
|
||||
Material.LEAVES,
|
||||
Material.LEAVES_2,
|
||||
Material.MOB_SPAWNER,
|
||||
Material.NETHER_BRICK_STAIRS,
|
||||
Material.NETHER_FENCE,
|
||||
Material.PACKED_ICE,
|
||||
Material.PISTON_BASE,
|
||||
Material.PISTON_EXTENSION,
|
||||
Material.PISTON_MOVING_PIECE,
|
||||
Material.PISTON_STICKY_BASE,
|
||||
Material.PURPUR_SLAB,
|
||||
Material.PURPUR_STAIRS,
|
||||
Material.QUARTZ_STAIRS,
|
||||
Material.RED_SANDSTONE_STAIRS,
|
||||
Material.SANDSTONE_STAIRS,
|
||||
Material.SIGN_POST,
|
||||
Material.SLIME_BLOCK,
|
||||
Material.SMOOTH_STAIRS,
|
||||
Material.SPRUCE_DOOR,
|
||||
Material.SPRUCE_FENCE,
|
||||
Material.SPRUCE_FENCE_GATE,
|
||||
Material.SPRUCE_WOOD_STAIRS,
|
||||
Material.STAINED_GLASS,
|
||||
Material.STAINED_GLASS_PANE,
|
||||
Material.STANDING_BANNER,
|
||||
Material.STATIONARY_LAVA,
|
||||
Material.STATIONARY_WATER,
|
||||
Material.STEP,
|
||||
Material.STONE_PLATE,
|
||||
Material.STONE_SLAB2,
|
||||
Material.THIN_GLASS,
|
||||
Material.TRAP_DOOR,
|
||||
Material.WALL_BANNER,
|
||||
Material.WALL_SIGN,
|
||||
Material.WATER,
|
||||
Material.WEB,
|
||||
Material.WOODEN_DOOR,
|
||||
Material.WOOD_PLATE,
|
||||
Material.WOOD_STAIRS,
|
||||
Material.WOOD_STEP
|
||||
};
|
||||
}
|
||||
|
||||
public ConfigDefaults getConfigDefaults() {
|
||||
return this.configDefaults;
|
||||
}
|
||||
|
||||
public Material[] getExtraTransparentBlocks() {
|
||||
return this.extraTransparentBlocks;
|
||||
}
|
||||
|
||||
public void setMaxLoadedCacheFiles(int value) {
|
||||
this.maxLoadedCacheFiles = value;
|
||||
|
@ -79,26 +286,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 +296,75 @@ 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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean isSign(int combinedBlockId) {
|
||||
int typeId = combinedBlockId >> 4;
|
||||
|
||||
return typeId == Material.WALL_SIGN.getId()
|
||||
|| typeId == Material.SIGN_POST.getId();
|
||||
}
|
||||
|
||||
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 Set<Integer> getMaterialIds(Material material) {
|
||||
Set<Integer> ids = new HashSet<>();
|
||||
int blockId = material.getId() << 4;
|
||||
Block block = Block.getById(material.getId());
|
||||
ImmutableList<IBlockData> blockDataList = block.t().a();
|
||||
|
||||
for(IBlockData blockData : blockDataList) {
|
||||
ids.add(blockId | block.toLegacyData(blockData));
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -122,4 +378,27 @@ public class NmsManager implements INmsManager {
|
|||
|
||||
return chunk != null ? chunk.getBlockData(new BlockPosition(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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue