use of com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound 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.craftbukkit.v1_16_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutWindowItems.
@Override
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException {
if (_packet instanceof PacketPlayOutWindowItems) {
PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet;
try {
Field windowIdField = PacketPlayOutWindowItems.class.getDeclaredField("a");
windowIdField.setAccessible(true);
int windowId = (int) windowIdField.get(packet);
// check if window is not player inventory
if (windowId != 0) {
return;
}
Field itemStacksField = PacketPlayOutWindowItems.class.getDeclaredField("b");
itemStacksField.setAccessible(true);
ItemStack[] itemStacks = (ItemStack[]) itemStacksField.get(packet);
for (ItemStack itemStack : itemStacks) {
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
String itemClass = itemStack.getClass().getSimpleName();
String packetClass = packet.getClass().getSimpleName();
// TODO: set slot?
NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound 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.craftbukkit.v1_16_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayInSetCreativeSlot.
@Override
public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException {
if (_packet instanceof PacketPlayInSetCreativeSlot) {
PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet;
int slot = packet.a();
ItemStack itemStack = packet.getItemStack();
if (itemStack == null || !itemStack.hasTag())
return;
NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
String itemClass = itemStack.getItem().getClass().getSimpleName();
String packetClass = packet.getClass().getSimpleName();
NbtChecks.checkPacketPlayIn(slot, tag, itemClass, packetClass, panilla);
}
}
use of com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutWindowItems.
@Override
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException {
if (_packet instanceof PacketPlayOutWindowItems) {
PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet;
try {
Field windowIdField = PacketPlayOutWindowItems.class.getDeclaredField("a");
windowIdField.setAccessible(true);
int windowId = (int) windowIdField.get(packet);
// check if window is not player inventory
if (windowId != 0) {
return;
}
Field itemStacksField = PacketPlayOutWindowItems.class.getDeclaredField("b");
itemStacksField.setAccessible(true);
List<ItemStack> itemStacks = (List<ItemStack>) itemStacksField.get(packet);
for (ItemStack itemStack : itemStacks) {
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
String itemClass = itemStack.getClass().getSimpleName();
String packetClass = packet.getClass().getSimpleName();
// TODO: set slot?
NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
Aggregations