use of com.ruinscraft.panilla.craftbukkit.v1_8_R3.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("a");
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("b");
Field itemStackField = PacketPlayOutSetSlot.class.getDeclaredField("c");
slotField.setAccessible(true);
itemStackField.setAccessible(true);
int slot = (int) slotField.get(packet);
ItemStack itemStack = (ItemStack) itemStackField.get(packet);
if (itemStack == null || !itemStack.hasTag())
return;
NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
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_8_R3.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.b();
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_8_R3.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;
int containerSlotsSize = 0;
if (is_1_12_2) {
containerSlotsSize = container.slots.size();
} else {
try {
Field slotsField = Container.class.getField("c");
List<Slot> slots = (List<Slot>) slotsField.get(container);
containerSlotsSize = slots.size();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
for (int slot = 0; slot < containerSlotsSize; 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_8_R3.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("a");
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("b");
Field itemStackField = PacketPlayOutSetSlot.class.getDeclaredField("c");
slotField.setAccessible(true);
itemStackField.setAccessible(true);
int slot = (int) slotField.get(packet);
ItemStack itemStack = (ItemStack) itemStackField.get(packet);
if (itemStack == null || !itemStack.hasTag())
return;
NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
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_8_R3.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.b();
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);
}
}
Aggregations