use of com.ruinscraft.panilla.craftbukkit.v1_18_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("c");
itemStacksField.setAccessible(true);
List<ItemStack> itemStacks = (List<ItemStack>) itemStacksField.get(packet);
for (ItemStack itemStack : itemStacks) {
if (itemStack == null || !itemStack.s()) {
continue;
}
NbtTagCompound tag = new NbtTagCompound(itemStack.t());
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_18_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("d");
typeField.setAccessible(true);
UUID entityId = (UUID) typeField.get(packet);
Entity entity = null;
for (WorldServer worldServer : MinecraftServer.getServer().F()) {
entity = worldServer.O.d().a(entityId);
if (entity != null)
break;
}
if (entity != null) {
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.h() == null) {
return;
}
if (!item.h().r()) {
return;
}
INbtTagCompound tag = new NbtTagCompound(item.h().t());
String itemName = item.h().c().a();
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.W().getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class PacketInspector method checkPacketPlayOutSetSlot.
@Override
public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException {
if (_packet instanceof PacketPlayOutSetSlot) {
PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet;
try {
Field windowIdField = PacketPlayOutSetSlot.class.getDeclaredField("c");
windowIdField.setAccessible(true);
int windowId = (int) windowIdField.get(packet);
// check if window is not player inventory and we are ignoring non-player inventories
if (windowId != 0 && panilla.getPConfig().ignoreNonPlayerInventories) {
return;
}
Field slotField = PacketPlayOutSetSlot.class.getDeclaredField("e");
Field itemStackField = PacketPlayOutSetSlot.class.getDeclaredField("f");
slotField.setAccessible(true);
itemStackField.setAccessible(true);
int slot = (int) slotField.get(packet);
ItemStack itemStack = (ItemStack) itemStackField.get(packet);
if (itemStack == null || !itemStack.s()) {
return;
}
NbtTagCompound tag = new NbtTagCompound(itemStack.t());
String itemClass = itemStack.getClass().getSimpleName();
String packetClass = packet.getClass().getSimpleName();
NbtChecks.checkPacketPlayOut(slot, tag, itemClass, packetClass, panilla);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
use of com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class InventoryCleaner method clean.
@Override
public void clean(IPanillaPlayer player) {
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
Container container = craftPlayer.getHandle().activeContainer;
for (int slot = 0; slot < container.c.size(); slot++) {
ItemStack itemStack = container.getSlot(slot).getItem();
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NBTTagCompound nmsTag = itemStack.getTag();
INbtTagCompound tag = new NbtTagCompound(nmsTag);
String itemName = itemStack.getItem().getName();
if (nmsTag == null || itemName == null) {
continue;
}
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.failsThreshold(failedNbt)) {
container.getSlot(slot).getItem().setTag(null);
} else if (FailedNbt.fails(failedNbt)) {
nmsTag.remove(failedNbt.key);
container.getSlot(slot).getItem().setTag(nmsTag);
}
}
}
use of com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound in project Panilla by ds58.
the class InventoryCleaner method clean.
@Override
public void clean(IPanillaPlayer player) {
CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
Container container = craftPlayer.getHandle().bV;
for (int slot = 0; slot < container.i.size(); slot++) {
ItemStack itemStack = container.getSlot(slot).getItem();
if (itemStack == null || !itemStack.hasTag()) {
continue;
}
NBTTagCompound nmsTag = itemStack.getTag();
INbtTagCompound tag = new NbtTagCompound(nmsTag);
String itemName = itemStack.getItem().getName();
if (nmsTag == null || itemName == null) {
continue;
}
FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
if (FailedNbt.failsThreshold(failedNbt)) {
container.getSlot(slot).getItem().setTag(null);
} else if (FailedNbt.fails(failedNbt)) {
nmsTag.remove(failedNbt.key);
container.getSlot(slot).getItem().setTag(nmsTag);
}
}
}
Aggregations