use of com.ruinscraft.panilla.api.exception.LegacyEntityNbtNotPermittedException 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();
}
}
}
Aggregations