Merge pull request #152 from DevotedMC/master

Selective treatment of signs
master
Daniel Boston 2017-05-05 11:02:32 -04:00 committed by GitHub
commit 3afa09602f
16 changed files with 214 additions and 4 deletions

View File

@ -31,4 +31,6 @@ public interface INmsManager {
BlockState getBlockState(World world, int x, int y, int z);
int getBlockId(World world, int x, int y, int z);
String getTextFromChatComponent(String json);
}

BIN
Oreb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

46
Oreb.svg Normal file
View File

@ -0,0 +1,46 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="none" x="0px" y="0px" width="550px" height="400px" viewBox="0 0 550 400">
<defs>
<g id="Layer0_0_FILL">
<path fill="#000000" stroke="none" d="
M 133 96.5
L 101.6 170.05 133 243.55 164.4 170 133 96.5
M 241.5 325.55
L 272.9 252 241.5 178.5 210.1 252.05 241.5 325.55
M 380.9 170
L 349.5 96.5 318.1 170.05 349.5 243.55 380.9 170 Z"/>
</g>
<path id="Layer0_0_1_STROKES" stroke="#000000" stroke-width="10" stroke-linejoin="round" stroke-linecap="round" fill="none" d="
M 409.5 96.5
L 440.9 170 409.5 243.55
M 389.5 96.5
L 420.9 170 389.5 243.55
M 318.1 170.05
L 349.5 96.5 380.9 170 349.5 243.55 318.1 170.05 Z
M 369.5 96.5
L 400.9 170 369.5 243.55
M 193 96.5
L 224.4 170 193 243.55
M 173 96.5
L 204.4 170 173 243.55
M 101.6 170.05
L 133 96.5 164.4 170 133 243.55 101.6 170.05 Z
M 210.1 252.05
L 241.5 178.5 272.9 252 241.5 325.55 210.1 252.05 Z
M 261.5 178.5
L 292.9 252 261.5 325.55
M 281.5 178.5
L 312.9 252 281.5 325.55
M 153 96.5
L 184.4 170 153 243.55
M 301.5 178.5
L 332.9 252 301.5 325.55"/>
</defs>
<g transform="matrix( 1, 0, 0, 1, 0,0) ">
<use xlink:href="#Layer0_0_FILL"/>
<use xlink:href="#Layer0_0_1_STROKES"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

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

View File

@ -5,6 +5,10 @@
package com.lishid.orebfuscator.chunkmap;
import java.util.List;
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
public class ChunkData {
public int chunkX;
public int chunkZ;
@ -13,4 +17,5 @@ public class ChunkData {
public byte[] data;
public boolean isOverworld;
public boolean useCache;
public List<NbtCompound> blockEntities;
}

View File

@ -54,6 +54,7 @@ public class ConfigManager {
break;
default:
baseCfg = this.orebfuscatorConfig.getNormalWorld();
break;
}
WorldConfig cfg = this.orebfuscatorConfig.getWorlds().get(world.getName().toLowerCase());

View File

@ -15,7 +15,8 @@ public class WorldConfig {
private Boolean enabled;
private Boolean darknessHideBlocks;
private Boolean antiTexturePackAndFreecam;
private Integer airGeneratorMaxChance;
private Boolean bypassObfuscationForSignsWithText;
private Integer airGeneratorMaxChance;
private boolean[] obfuscateBlocks;
private boolean[] obfuscateAndProximityBlocks;
private boolean[] darknessBlocks;
@ -34,6 +35,7 @@ public class WorldConfig {
this.enabled = true;
this.darknessHideBlocks = false;
this.antiTexturePackAndFreecam = true;
this.bypassObfuscationForSignsWithText = false;
this.airGeneratorMaxChance = 43;
this.obfuscateBlocks = new boolean[256];
@ -68,6 +70,10 @@ public class WorldConfig {
this.antiTexturePackAndFreecam = baseWorld.antiTexturePackAndFreecam;
}
if(this.bypassObfuscationForSignsWithText == null) {
this.bypassObfuscationForSignsWithText = baseWorld.bypassObfuscationForSignsWithText;
}
if(this.airGeneratorMaxChance == null) {
this.airGeneratorMaxChance = baseWorld.airGeneratorMaxChance;
}
@ -126,6 +132,14 @@ public class WorldConfig {
this.antiTexturePackAndFreecam = value;
}
public Boolean isBypassObfuscationForSignsWithText() {
return this.bypassObfuscationForSignsWithText;
}
public void setBypassObfuscationForSignsWithText(Boolean value) {
this.bypassObfuscationForSignsWithText = value;
}
public Integer getAirGeneratorMaxChance() {
return this.airGeneratorMaxChance;
}

View File

@ -181,6 +181,7 @@ public class WorldReader {
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);
Integer mode1Block = this.materialReader.getMaterialIdByPath(worldPath + ".Mode1Block", cfg.getMode1BlockId(), withSave);
Integer[] randomBlocks = this.materialReader.getMaterialIdsByPath(worldPath + ".RandomBlocks", cfg.getRandomBlocks(), withSave);
@ -204,6 +205,7 @@ public class WorldReader {
cfg.setEnabled(enabled);
cfg.setAntiTexturePackAndFreecam(antiTexturePackAndFreecam);
cfg.setBypassObfuscationForSignsWithText(bypassObfuscationForSignsWithText);
cfg.setAirGeneratorMaxChance(airGeneratorMaxChance);
cfg.setDarknessHideBlocks(darknessHideBlocks);
cfg.setDarknessBlocks(darknessBlocks);

View File

@ -16,7 +16,11 @@
package com.lishid.orebfuscator.hook;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.PacketType;
@ -27,7 +31,11 @@ import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
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;
@ -53,6 +61,7 @@ public class ProtocolLibHook {
chunkData.primaryBitMask = ints.read(2);
chunkData.data = byteArray.read(0);
chunkData.isOverworld = event.getPlayer().getWorld().getEnvironment() == World.Environment.NORMAL;
chunkData.blockEntities = getBlockEntities(packet, event.getPlayer());
try {
byte[] newData = Calculations.obfuscateOrUseCache(chunkData, event.getPlayer());
@ -79,6 +88,24 @@ public class ProtocolLibHook {
});
}
@SuppressWarnings("rawtypes")
private static List<NbtCompound> getBlockEntities(PacketContainer packet, Player player) {
WorldConfig worldConfig = Orebfuscator.configManager.getWorld(player.getWorld());
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;
}
/*
private static boolean _isSaved;
private void saveTestData(ChunkData chunkData) {

View File

@ -21,9 +21,14 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import org.bukkit.Material;
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;
@ -173,7 +178,7 @@ public class Calculations {
}
// Check if the block is obfuscated
if (obfuscate) {
if (obfuscate && canObfuscate(chunkData, x, y, z, blockState)) {
if (specialObfuscate) {
// Proximity hider
blockState.id = proximityHider.getSpecialBlockID();
@ -247,6 +252,60 @@ public class Calculations {
return output;
}
private static boolean canObfuscate(ChunkData chunkData, int x, int y, int z, BlockState blockState) {
if(chunkData.blockEntities == null
|| (
blockState.id != DeprecatedMethods.getMaterialId(Material.WALL_SIGN)
&& blockState.id != DeprecatedMethods.getMaterialId(Material.SIGN_POST)
)
)
{
return true;
}
NbtCompound tag = getNbtTag(chunkData, x, y, z);
return tag == null ||
isSignTextEmpty(tag, "Text1")
&& isSignTextEmpty(tag, "Text2")
&& isSignTextEmpty(tag, "Text3")
&& isSignTextEmpty(tag, "Text4");
}
private static boolean isSignTextEmpty(NbtCompound compound, String key) {
NbtBase<?> tag = compound.getValue(key);
if(tag == null || tag.getType() != NbtType.TAG_STRING) {
return true;
}
String json = (String)tag.getValue();
if(json == null || json.isEmpty()) {
return true;
}
String text = Orebfuscator.nms.getTextFromChatComponent(json);
return text == null || text.isEmpty();
}
private static NbtCompound getNbtTag(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;
}
}
}
return null;
}
private static void addBlocksToPalette(ChunkMapManager manager, WorldConfig worldConfig) {
if(!manager.inputHasNonAirBlock()) {
return;

View File

@ -1,8 +1,12 @@
#Orebfuscator:
![Orebfuscator - Anti X-Ray](https://raw.githubusercontent.com/DevotedMC/Orebfuscator/master/Oreb.png)
**#Orebfuscator**
The definitive Anti X-Ray plugin for CraftBukkit
###Changelog:
- Updated to support 1.11 - 1.11.2
- Updated to support 1.10 (Thanks Asgorioth)
- Updated to support 1.9.4
- Updated to support 1.9-1.9.2 (https://www.devotedmc.com)

View File

@ -23,6 +23,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>techcable-repo</id>
<url>https://repo.techcable.net/content/groups/public/</url>
</repository>
</repositories>
<modules>

View File

@ -11,6 +11,7 @@ import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.Chunk;
import net.minecraft.server.v1_10_R1.ChunkProviderServer;
import net.minecraft.server.v1_10_R1.IBlockData;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.Packet;
import net.minecraft.server.v1_10_R1.PlayerChunkMap;
import net.minecraft.server.v1_10_R1.TileEntity;
@ -19,6 +20,7 @@ import net.minecraft.server.v1_10_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.util.CraftChatMessage;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
@ -40,10 +42,12 @@ public class NmsManager implements INmsManager {
return new NBT();
}
@Override
public IChunkCache createChunkCache() {
return new ChunkCache(this.maxLoadedCacheFiles);
}
@Override
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
@ -51,6 +55,7 @@ public class NmsManager implements INmsManager {
return new ChunkManager(chunkMap);
}
@Override
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
@ -67,6 +72,7 @@ public class NmsManager implements INmsManager {
}
}
@Override
public void notifyBlockChange(World world, IBlockInfo blockInfo) {
BlockPosition blockPosition = new BlockPosition(blockInfo.getX(), blockInfo.getY(), blockInfo.getZ());
IBlockData blockData = ((BlockInfo)blockInfo).getBlockData();
@ -74,10 +80,12 @@ public class NmsManager implements INmsManager {
((CraftWorld)world).getHandle().notify(blockPosition, blockData, blockData, 0);
}
@Override
public int getBlockLightLevel(World world, int x, int y, int z) {
return ((CraftWorld)world).getHandle().getLightLevel(new BlockPosition(x, y, z));
}
@Override
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
@ -86,6 +94,7 @@ 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);
@ -100,12 +109,19 @@ public class NmsManager implements INmsManager {
return blockState;
}
@Override
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
int chunkX = x >> 4;
int chunkZ = z >> 4;

View File

@ -11,6 +11,7 @@ import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.Chunk;
import net.minecraft.server.v1_11_R1.ChunkProviderServer;
import net.minecraft.server.v1_11_R1.IBlockData;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.Packet;
import net.minecraft.server.v1_11_R1.PlayerChunkMap;
import net.minecraft.server.v1_11_R1.TileEntity;
@ -19,6 +20,7 @@ import net.minecraft.server.v1_11_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_11_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_11_R1.util.CraftChatMessage;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
@ -40,10 +42,12 @@ public class NmsManager implements INmsManager {
return new NBT();
}
@Override
public IChunkCache createChunkCache() {
return new ChunkCache(this.maxLoadedCacheFiles);
}
@Override
public IChunkManager getChunkManager(World world) {
WorldServer worldServer = ((CraftWorld)world).getHandle();
PlayerChunkMap chunkMap = worldServer.getPlayerChunkMap();
@ -51,6 +55,7 @@ public class NmsManager implements INmsManager {
return new ChunkManager(chunkMap);
}
@Override
public void updateBlockTileEntity(BlockCoord blockCoord, Player player) {
CraftWorld world = (CraftWorld)player.getWorld();
TileEntity tileEntity = world.getTileEntityAt(blockCoord.x, blockCoord.y, blockCoord.z);
@ -67,6 +72,7 @@ public class NmsManager implements INmsManager {
}
}
@Override
public void notifyBlockChange(World world, IBlockInfo blockInfo) {
BlockPosition blockPosition = new BlockPosition(blockInfo.getX(), blockInfo.getY(), blockInfo.getZ());
IBlockData blockData = ((BlockInfo)blockInfo).getBlockData();
@ -74,10 +80,12 @@ public class NmsManager implements INmsManager {
((CraftWorld)world).getHandle().notify(blockPosition, blockData, blockData, 0);
}
@Override
public int getBlockLightLevel(World world, int x, int y, int z) {
return ((CraftWorld)world).getHandle().getLightLevel(new BlockPosition(x, y, z));
}
@Override
public IBlockInfo getBlockInfo(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
@ -86,6 +94,7 @@ 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);
@ -100,12 +109,19 @@ public class NmsManager implements INmsManager {
return blockState;
}
@Override
public int getBlockId(World world, int x, int y, int z) {
IBlockData blockData = getBlockData(world, x, y, z);
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
@Override
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
int chunkX = x >> 4;
int chunkZ = z >> 4;

View File

@ -11,6 +11,7 @@ import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.Chunk;
import net.minecraft.server.v1_9_R1.ChunkProviderServer;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.IChatBaseComponent;
import net.minecraft.server.v1_9_R1.Packet;
import net.minecraft.server.v1_9_R1.PlayerChunkMap;
import net.minecraft.server.v1_9_R1.TileEntity;
@ -19,6 +20,7 @@ import net.minecraft.server.v1_9_R1.WorldServer;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_9_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R1.util.CraftChatMessage;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
@ -106,6 +108,11 @@ public class NmsManager implements INmsManager {
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
int chunkX = x >> 4;
int chunkZ = z >> 4;

View File

@ -11,6 +11,7 @@ import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.Chunk;
import net.minecraft.server.v1_9_R2.ChunkProviderServer;
import net.minecraft.server.v1_9_R2.IBlockData;
import net.minecraft.server.v1_9_R2.IChatBaseComponent;
import net.minecraft.server.v1_9_R2.Packet;
import net.minecraft.server.v1_9_R2.PlayerChunkMap;
import net.minecraft.server.v1_9_R2.TileEntity;
@ -19,6 +20,7 @@ import net.minecraft.server.v1_9_R2.WorldServer;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_9_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_9_R2.util.CraftChatMessage;
import org.bukkit.entity.Player;
import com.lishid.orebfuscator.nms.IBlockInfo;
@ -106,6 +108,11 @@ public class NmsManager implements INmsManager {
return blockData != null ? Block.getId(blockData.getBlock()): -1;
}
public String getTextFromChatComponent(String json) {
IChatBaseComponent component = IChatBaseComponent.ChatSerializer.a(json);
return CraftChatMessage.fromComponent(component);
}
private static IBlockData getBlockData(World world, int x, int y, int z) {
int chunkX = x >> 4;
int chunkZ = z >> 4;