use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.
the class PacketInspector method stripNbtFromItemEntity.
@Override
public void stripNbtFromItemEntity(UUID entityId) {
org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
if (bukkitEntity instanceof CraftEntity) {
CraftEntity craftEntity = (CraftEntity) bukkitEntity;
Entity entity = craftEntity.getHandle();
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
item.getItemStack().setTag(null);
}
}
}
use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.
the class PacketInspector method stripNbtFromItemEntity.
@Override
public void stripNbtFromItemEntity(UUID entityId) {
org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
if (bukkitEntity instanceof CraftEntity) {
CraftEntity craftEntity = (CraftEntity) bukkitEntity;
Entity entity = craftEntity.getHandle();
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
if (item.getItemStack() == null) {
return;
}
if (!item.getItemStack().hasTag()) {
return;
}
item.getItemStack().setTag(null);
}
}
}
use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity 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 org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity 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 org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project MyPet by xXKeyleXx.
the class PlatformHelper method applyTagToEntity.
@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
net.minecraft.server.v1_12_R1.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
// Just a temporary fix until I come up with a better solution
if (bukkitEntity instanceof Villager) {
EntityVillager villager = (EntityVillager) entity;
villager.setProfession(vanillaNBT.getInt("Profession"));
villager.riches = vanillaNBT.getInt("Riches");
ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("Career"));
ReflectionUtil.setFieldValue("bL", villager, vanillaNBT.getInt("CareerLevel"));
ReflectionUtil.setFieldValue("bH", villager, vanillaNBT.getBoolean("Willing"));
if (vanillaNBT.hasKeyOfType("Offers", 10)) {
NBTTagCompound nbttaglist = vanillaNBT.getCompound("Offers");
ReflectionUtil.setFieldValue("trades", villager, new MerchantRecipeList(nbttaglist));
}
NBTTagList invTag = vanillaNBT.getList("Inventory", 10);
for (int i = 0; i < invTag.size(); ++i) {
ItemStack itemstack = new ItemStack(invTag.get(i));
villager.inventory.a(itemstack);
}
villager.m(true);
if (villager.isBaby()) {
villager.goalSelector.a(8, new PathfinderGoalPlay(villager, 0.32D));
} else if (villager.getProfession() == 0) {
villager.goalSelector.a(6, new PathfinderGoalVillagerFarm(villager, 0.6D));
}
}
// can not be used in 1.10
// entity.f(vanillaNBT);
}
Aggregations