use of com.ruinscraft.panilla.api.nbt.INbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSpawnEntity.
@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
try {
Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("b");
typeField.setAccessible(true);
UUID entityId = (UUID) typeField.get(packet);
org.bukkit.entity.Entity bukkitEntity = org.bukkit.Bukkit.getEntity(entityId);
CraftEntity craftEntity = (CraftEntity) bukkitEntity;
if (craftEntity == null) {
return;
}
Entity entity = craftEntity.getHandle();
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
String itemName = item.getItemStack().getItem().getName();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, bukkitEntity.getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.api.nbt.INbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSpawnEntity.
@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
try {
Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("b");
typeField.setAccessible(true);
UUID entityId = (UUID) typeField.get(packet);
org.bukkit.entity.Entity bukkitEntity = org.bukkit.Bukkit.getEntity(entityId);
CraftEntity craftEntity = (CraftEntity) bukkitEntity;
if (craftEntity == null) {
return;
}
Entity entity = craftEntity.getHandle();
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
String itemName = item.getItemStack().getItem().getName();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, bukkitEntity.getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.api.nbt.INbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSpawnEntity.
@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws LegacyEntityNbtNotPermittedException {
if (_packet instanceof PacketPlayOutSpawnEntity) {
PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
try {
Field idField = PacketPlayOutSpawnEntity.class.getDeclaredField("a");
idField.setAccessible(true);
int entityId = (int) idField.get(packet);
Entity entity = getEntityById(entityId);
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
String itemName = item.getItemStack().getItem().getName();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new LegacyEntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId);
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.api.nbt.INbtTagCompound in project Panilla by ds58.
the class NbtCheck_pages method getCharCountForItem.
private static int getCharCountForItem(INbtTagCompound item) {
int charCount = 0;
if (item.hasKey("tag")) {
INbtTagCompound tag = item.getCompound("tag");
if (tag.hasKey("pages")) {
INbtTagList pages = tag.getList("pages", NbtDataType.STRING);
for (int i = 0; i < pages.size(); i++) {
final String page = pages.getString(i);
final String pageNoSpaces = page.replace(" ", "");
charCount += pageNoSpaces.length();
}
}
}
return charCount;
}
use of com.ruinscraft.panilla.api.nbt.INbtTagCompound in project Panilla by ds58.
the class NbtCheck_BlockEntityTag method check.
@Override
public NbtCheckResult check(INbtTagCompound tag, String itemName, IPanilla panilla) {
INbtTagCompound blockEntityTag = tag.getCompound(getName());
int sizeBytes = blockEntityTag.getStringSizeBytes();
int maxSizeBytes = panilla.getProtocolConstants().NOT_PROTOCOL_maxBlockEntityTagLengthBytes();
// ensure BlockEntityTag isn't huge
if (sizeBytes > maxSizeBytes) {
return NbtCheckResult.CRITICAL;
}
if (blockEntityTag.hasKey("LootTable")) {
String lootTable = blockEntityTag.getString("LootTable");
lootTable = lootTable.trim();
if (lootTable.isEmpty()) {
return NbtCheckResult.CRITICAL;
}
if (lootTable.contains(":")) {
String[] keySplit = lootTable.split(":");
if (keySplit.length < 2) {
return NbtCheckResult.CRITICAL;
}
String namespace = keySplit[0];
String key = keySplit[1];
if (namespace.isEmpty() || key.isEmpty()) {
return NbtCheckResult.CRITICAL;
}
}
}
if (panilla.getPConfig().strictness == PStrictness.STRICT) {
// locked chests
if (blockEntityTag.hasKey("Lock")) {
return NbtCheckResult.FAIL;
}
// signs with text
if (blockEntityTag.hasKey("Text1") || blockEntityTag.hasKey("Text2") || blockEntityTag.hasKey("Text3") || blockEntityTag.hasKey("Text4")) {
return NbtCheckResult.FAIL;
}
}
// tiles with items/containers (chests, hoppers, shulkerboxes, etc)
if (blockEntityTag.hasKey("Items")) {
// only ItemShulkerBoxes should have "Items" NBT tag in survival
itemName = itemName.toLowerCase();
if (panilla.getPConfig().noBlockEntityTag) {
return NbtCheckResult.FAIL;
}
if (panilla.getPConfig().strictness == PStrictness.STRICT) {
if (!(itemName.contains("shulker") || itemName.contains("itemstack") || itemName.contains("itemblock"))) {
return NbtCheckResult.FAIL;
}
}
// Campfires should not have BlockEntityTag
if (itemName.contains("campfire")) {
return NbtCheckResult.FAIL;
}
INbtTagList items = blockEntityTag.getList("Items", NbtDataType.COMPOUND);
FailedNbt failedNbt = checkItems(items, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
return failedNbt.result;
}
}
// check the item within a JukeBox
if (blockEntityTag.hasKey("RecordItem")) {
INbtTagCompound item = blockEntityTag.getCompound("RecordItem");
FailedNbt failedNbt = checkItem(item, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
return failedNbt.result;
}
}
return NbtCheckResult.PASS;
}
Aggregations