use of com.ruinscraft.panilla.api.exception.FailedNbt 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.exception.FailedNbt 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.slots.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.api.exception.FailedNbt 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.exception.FailedNbt in project Panilla by ds58.
the class NbtCheck_EntityTag method check.
@Override
public NbtCheckResult check(INbtTagCompound tag, String itemName, IPanilla panilla) {
INbtTagCompound entityTag = tag.getCompound(getName());
if (panilla.getPConfig().strictness == PStrictness.STRICT) {
for (String armorStandTag : ARMOR_STAND_TAGS) {
if (entityTag.hasKey(armorStandTag)) {
return NbtCheckResult.FAIL;
}
}
}
if (entityTag.hasKey("CustomName")) {
String customName = entityTag.getString("CustomName");
if (customName.length() > panilla.getProtocolConstants().NOT_PROTOCOL_maxEntityTagCustomNameLength()) {
return NbtCheckResult.CRITICAL;
}
try {
panilla.getPacketInspector().validateBaseComponentParse(customName);
} catch (Exception e) {
return NbtCheckResult.CRITICAL;
}
}
if (entityTag.hasKey("UUID")) {
String uuid = entityTag.getString("UUID");
try {
UUID.fromString(uuid);
} catch (Exception e) {
return NbtCheckResult.CRITICAL;
}
}
if (entityTag.hasKey("ExplosionPower")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Invulnerable")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Motion")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("power")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("ArmorItems")) {
INbtTagList items = entityTag.getList("ArmorItems", NbtDataType.COMPOUND);
FailedNbt failedNbt = checkItems(items, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
return failedNbt.result;
}
}
if (entityTag.hasKey("HandItems")) {
INbtTagList items = entityTag.getList("HandItems", NbtDataType.COMPOUND);
FailedNbt failedNbt = checkItems(items, itemName, panilla);
if (FailedNbt.fails(failedNbt)) {
return failedNbt.result;
}
}
boolean hasIdTag = entityTag.hasKey("id");
if (hasIdTag) {
if (panilla.getPConfig().strictness == PStrictness.STRICT) {
return NbtCheckResult.FAIL;
}
String id = entityTag.getString("id");
// prevent lightning bolt eggs
if (id.toLowerCase().contains("lightning")) {
return NbtCheckResult.FAIL;
}
// check for massive slime spawn eggs
if (entityTag.hasKey("Size")) {
if (entityTag.getInt("Size") > panilla.getProtocolConstants().maxSlimeSize()) {
return NbtCheckResult.CRITICAL;
}
}
// see nms.EntityAreaEffectCloud
if (entityTag.hasKey("Age")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Duration")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("WaitTime")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("ReapplicationDelay")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("DurationOnUse")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("RadiusOnUse")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("RadiusPerTick")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Radius")) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Particle") && panilla.getPConfig().strictness == PStrictness.STRICT) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Color") && panilla.getPConfig().strictness == PStrictness.STRICT) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Potion") && panilla.getPConfig().strictness == PStrictness.STRICT) {
return NbtCheckResult.FAIL;
}
if (entityTag.hasKey("Effects")) {
return NbtCheckResult.FAIL;
}
}
return NbtCheckResult.PASS;
}
use of com.ruinscraft.panilla.api.exception.FailedNbt 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().getWorlds()) {
entity = worldServer.G.d().a(entityId);
if (entity != null)
break;
}
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, entity.getWorld().getWorld().getName());
}
}
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
Aggregations