Search in sources :

Example 1 with PacketPlayOutSpawnEntity

use of net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity in project FunnyGuilds by FunnyGuilds.

the class V1_17EntityAccessor method createFakeEntity.

@Override
public FakeEntity createFakeEntity(EntityType entityType, Location location) {
    Preconditions.checkNotNull(entityType, "entity type can't be null!");
    Preconditions.checkNotNull(location, "location can't be null!");
    Preconditions.checkArgument(entityType.isSpawnable(), "entity type is not spawnable!");
    CraftWorld world = ((CraftWorld) location.getWorld());
    if (world == null) {
        throw new IllegalStateException("location's world is null!");
    }
    net.minecraft.world.entity.Entity entity = world.createEntity(location, entityType.getEntityClass());
    Packet<?> spawnEntityPacket;
    if (entity instanceof EntityLiving) {
        spawnEntityPacket = new PacketPlayOutSpawnEntityLiving((EntityLiving) entity);
    } else {
        spawnEntityPacket = new PacketPlayOutSpawnEntity(entity);
    }
    return new FakeEntity(entity.getId(), spawnEntityPacket);
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) PacketPlayOutSpawnEntityLiving(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving) PacketPlayOutSpawnEntityLiving(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving) EntityLiving(net.minecraft.world.entity.EntityLiving) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 2 with PacketPlayOutSpawnEntity

use of net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity in project FunnyGuilds by FunnyGuilds.

the class V1_18EntityAccessor method createFakeEntity.

@Override
public FakeEntity createFakeEntity(EntityType entityType, Location location) {
    Preconditions.checkNotNull(entityType, "entity type can't be null!");
    Preconditions.checkNotNull(location, "location can't be null!");
    Preconditions.checkArgument(entityType.isSpawnable(), "entity type is not spawnable!");
    CraftWorld world = ((CraftWorld) location.getWorld());
    if (world == null) {
        throw new IllegalStateException("location's world is null!");
    }
    net.minecraft.world.entity.Entity entity = world.createEntity(location, entityType.getEntityClass());
    Packet<?> spawnEntityPacket;
    if (entity instanceof EntityLiving) {
        spawnEntityPacket = new PacketPlayOutSpawnEntityLiving((EntityLiving) entity);
    } else {
        spawnEntityPacket = new PacketPlayOutSpawnEntity(entity);
    }
    // ae() zwraca aT czyli chyba getId
    return new FakeEntity(entity.ae(), spawnEntityPacket);
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) PacketPlayOutSpawnEntityLiving(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving) PacketPlayOutSpawnEntityLiving(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving) EntityLiving(net.minecraft.world.entity.EntityLiving) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 3 with PacketPlayOutSpawnEntity

use of net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity 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();
        }
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) WorldServer(net.minecraft.server.level.WorldServer) Field(java.lang.reflect.Field) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 4 with PacketPlayOutSpawnEntity

use of net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity 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();
        }
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound) WorldServer(net.minecraft.server.level.WorldServer) Field(java.lang.reflect.Field) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 5 with PacketPlayOutSpawnEntity

use of net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity 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.P.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();
        }
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) WorldServer(net.minecraft.server.level.WorldServer) Field(java.lang.reflect.Field) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt) EntityItem(net.minecraft.world.entity.item.EntityItem)

Aggregations

PacketPlayOutSpawnEntity (net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity)5 EntityNbtNotPermittedException (com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException)3 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)3 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)3 Field (java.lang.reflect.Field)3 UUID (java.util.UUID)3 WorldServer (net.minecraft.server.level.WorldServer)3 Entity (net.minecraft.world.entity.Entity)3 EntityItem (net.minecraft.world.entity.item.EntityItem)3 FakeEntity (net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity)2 PacketPlayOutSpawnEntityLiving (net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving)2 EntityLiving (net.minecraft.world.entity.EntityLiving)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1