Search in sources :

Example 21 with WorldServer

use of net.minecraft.server.level.WorldServer in project Nokaut by smaks6.

the class NpcNew method spawnNPC.

// ChatColor.RED +
private EntityPlayer spawnNPC() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
    Location location = knockedPlayer.getLocation();
    MinecraftServer nmsServer = (MinecraftServer) Reflection.getNMSServer();
    WorldServer nmsWorld = (WorldServer) Reflection.getNMSWorld();
    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), knockedPlayer.getName());
    if (is1_18()) {
        if (Main.getVersion().equals("v1_18_R1")) {
            Method method = EntityPlayer.class.getMethod("fp");
            GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
            gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
        } else {
            gameProfile.getProperties().putAll(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)).fq().getProperties());
        }
    } else {
        Method method = EntityPlayer.class.getMethod("getProfile");
        GameProfile knockedPlayerGameProfile = (GameProfile) method.invoke(((EntityPlayer) Reflection.getEntityPlayer(knockedPlayer)));
        gameProfile.getProperties().putAll(knockedPlayerGameProfile.getProperties());
    }
    EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile);
    setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), npc);
    // npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), 40f);
    DataWatcher watcher = null;
    if (is1_18()) {
        entityplayerId = npc.ae();
    } else {
        Method getId = EntityPlayer.class.getMethod("getId");
        entityplayerId = (int) getId.invoke(npc);
    }
    // a - ADD_Player
    // e - REMOVE-PLAYER
    sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc));
    sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
    // d - swimming
    if (is1_18()) {
        watcher = npc.ai();
        byte o = (Byte) watcher.a(DataWatcherRegistry.a.a(17));
        watcher.b(DataWatcherRegistry.a.a(17), o);
        watcher.b(DataWatcherRegistry.s.a(6), EntityPose.d);
        sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, true));
    } else {
        Method getDataWatcher = EntityPlayer.class.getMethod("getDataWatcher");
        watcher = (DataWatcher) getDataWatcher.invoke(npc);
        setPose(npc);
        sendPacket(new PacketPlayOutEntityMetadata(entityplayerId, watcher, false));
    }
    return npc;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.server.level.EntityPlayer) WorldServer(net.minecraft.server.level.WorldServer) Method(java.lang.reflect.Method) Location(org.bukkit.Location) MinecraftServer(net.minecraft.server.MinecraftServer) DataWatcher(net.minecraft.network.syncher.DataWatcher)

Example 22 with WorldServer

use of net.minecraft.server.level.WorldServer 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 23 with WorldServer

use of net.minecraft.server.level.WorldServer in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    Entity entity = null;
    for (WorldServer worldServer : MinecraftServer.getServer().getWorlds()) {
        entity = worldServer.G.d().a(entityId);
        if (entity != null)
            break;
    }
    if (entity instanceof EntityItem) {
        EntityItem item = (EntityItem) entity;
        if (item.getItemStack() == null)
            return;
        if (!item.getItemStack().hasTag())
            return;
        item.getItemStack().setTag(null);
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) WorldServer(net.minecraft.server.level.WorldServer) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 24 with WorldServer

use of net.minecraft.server.level.WorldServer in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    Entity entity = null;
    for (WorldServer worldServer : MinecraftServer.getServer().F()) {
        entity = worldServer.P.d().a(entityId);
        if (entity != null)
            break;
    }
    if (entity instanceof EntityItem) {
        EntityItem item = (EntityItem) entity;
        if (item.h() == null)
            return;
        if (!item.h().r())
            return;
        item.h().c((NBTTagCompound) null);
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) WorldServer(net.minecraft.server.level.WorldServer) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 25 with WorldServer

use of net.minecraft.server.level.WorldServer 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

WorldServer (net.minecraft.server.level.WorldServer)27 EntityItem (net.minecraft.world.entity.item.EntityItem)9 BlockPosition (net.minecraft.core.BlockPosition)8 EntityPlayer (net.minecraft.server.level.EntityPlayer)7 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)6 Field (java.lang.reflect.Field)5 PacketPlayOutSpawnEntity (net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity)5 Entity (net.minecraft.world.entity.Entity)5 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)5 Method (java.lang.reflect.Method)4 World (org.bukkit.World)4 LivingEntity (org.bukkit.entity.LivingEntity)4 PacketType (com.comphenix.protocol.PacketType)3 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 InteractionVisualizer (com.loohp.interactionvisualizer.InteractionVisualizer)3 BlockPosition (com.loohp.interactionvisualizer.objectholders.BlockPosition)3 BoundingBox (com.loohp.interactionvisualizer.objectholders.BoundingBox)3 ChunkPosition (com.loohp.interactionvisualizer.objectholders.ChunkPosition)3 NMSTileEntitySet (com.loohp.interactionvisualizer.objectholders.NMSTileEntitySet)3 TileEntity (com.loohp.interactionvisualizer.objectholders.TileEntity)3