Search in sources :

Example 1 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project DragonsOnline by UniverseCraft.

the class PlayerNPC116R3 method spawnFor.

public void spawnFor(Player player) {
    if (isDestroyed)
        return;
    // resync
    location = getEntity().getLocation();
    location.setYaw(originalYaw);
    handle.setCustomNameVisible(false);
    sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, handle), player);
    sync(() -> sendPacket(new PacketPlayOutNamedEntitySpawn(handle), player), 1);
    PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
    setField(tp, "a", getEntityId());
    setField(tp, "b", location.getX());
    setField(tp, "c", location.getY());
    setField(tp, "d", location.getZ());
    setField(tp, "e", getPacketRotation(location.getYaw()));
    setField(tp, "f", getPacketRotation(location.getPitch()));
    setField(tp, "g", handle.isOnGround());
    sync(() -> sendPacket(new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true), player), 2);
    sync(() -> setTablistName(getTablistName()), 2);
    sync(() -> sendPacket(tp, player), 3);
    sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player), 6);
    sync(() -> removeFromTablistFor(player), 20 + (int) Math.ceil(2 * bridge.getPing(player) * 20 / 1000));
    lastSeenLocation.put(player, location.clone());
    // https://www.spigotmc.org/threads/remove-nameplate-of-an-nms-player-entity.436099/ (Phaze)
    ScoreboardTeam team = new ScoreboardTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), player.getName());
    team.setNameTagVisibility(ScoreboardTeamBase.EnumNameTagVisibility.NEVER);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 1), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, 0), player);
    sendPacket(new PacketPlayOutScoreboardTeam(team, List.of(handle.getName()), 3), player);
}
Also used : PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) PacketPlayOutNamedEntitySpawn(net.minecraft.server.v1_16_R3.PacketPlayOutNamedEntitySpawn) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_16_R3.PacketPlayOutEntityHeadRotation) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo) PacketPlayOutEntityTeleport(net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport) PacketPlayOutScoreboardTeam(net.minecraft.server.v1_16_R3.PacketPlayOutScoreboardTeam) ScoreboardTeam(net.minecraft.server.v1_16_R3.ScoreboardTeam)

Example 2 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_13_R2 method show.

public void show() {
    // Construct the packets out of the loop to save resources, they will
    // be the same for each Player.
    Packet<?> spawn = type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0);
    PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true);
    PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()));
    PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false);
    PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, motion.getX(), motion.getY(), motion.getZ());
    for (Player temp : DistanceUtil.getPlayersInRange(location)) {
        PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection;
        if (connections.contains(connection)) {
            continue;
        }
        connection.sendPacket(spawn);
        connection.sendPacket(meta);
        connection.sendPacket(head);
        connection.sendPacket(velocity);
        connection.sendPacket(look);
        PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket();
        if (equipment != null) {
            for (PacketPlayOutEntityEquipment packet : equipment) {
                connection.sendPacket(packet);
            }
        }
        connections.add(connection);
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) PacketPlayOutEntityLook(net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 3 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project Citizens2 by CitizensDev.

the class PlayerAnimationImpl method play.

public static void play(PlayerAnimation animation, Player bplayer, int radius) {
    // TODO: this is pretty gross
    final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
    if (DEFAULTS.containsKey(animation)) {
        playDefaultAnimation(player, radius, DEFAULTS.get(animation));
        return;
    }
    switch(animation) {
        case SIT:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
            NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
            if (registry == null) {
                registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
            }
            final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
            holder.spawn(player.getBukkitEntity().getLocation());
            ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
            trait.setGravity(false);
            trait.setHasArms(false);
            trait.setHasBaseplate(false);
            trait.setSmall(true);
            trait.setMarker(true);
            trait.setVisible(false);
            holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
            holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
            new BukkitRunnable() {

                @Override
                public void cancel() {
                    super.cancel();
                    holder.destroy();
                }

                @Override
                public void run() {
                    if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
                        cancel();
                        return;
                    }
                    if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
                        cancel();
                        return;
                    }
                    if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
                        NMS.mount(holder.getEntity(), player.getBukkitEntity());
                    }
                }
            }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
            break;
        case SLEEP:
            PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
            sendPacketNearby(packet, player, radius);
            break;
        case SNEAK:
            player.getBukkitEntity().setSneaking(true);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_ELYTRA:
            player.J();
            break;
        case START_USE_MAINHAND_ITEM:
            player.c(EnumHand.MAIN_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_USE_OFFHAND_ITEM:
            player.c(EnumHand.OFF_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_SITTING:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
            NMS.mount(player.getBukkitEntity(), null);
            break;
        case STOP_SLEEPING:
            playDefaultAnimation(player, radius, 2);
            break;
        case STOP_SNEAKING:
            player.getBukkitEntity().setSneaking(false);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_USE_ITEM:
            player.clearActiveItem();
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) PacketPlayOutEntityMetadata(net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PacketPlayOutBed(net.minecraft.server.v1_13_R2.PacketPlayOutBed) MemoryNPCDataStore(net.citizensnpcs.api.npc.MemoryNPCDataStore) EntityPlayer(net.minecraft.server.v1_13_R2.EntityPlayer) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry)

Example 4 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project Citizens2 by CitizensDev.

the class PlayerAnimationImpl method play.

public static void play(PlayerAnimation animation, Player bplayer, int radius) {
    // TODO: this is pretty gross
    final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
    if (DEFAULTS.containsKey(animation)) {
        playDefaultAnimation(player, radius, DEFAULTS.get(animation));
        return;
    }
    switch(animation) {
        case SIT:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
            NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
            if (registry == null) {
                registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
            }
            final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
            holder.spawn(player.getBukkitEntity().getLocation());
            ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
            trait.setGravity(false);
            trait.setHasArms(false);
            trait.setHasBaseplate(false);
            trait.setSmall(true);
            trait.setMarker(true);
            trait.setVisible(false);
            holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
            holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
            new BukkitRunnable() {

                @Override
                public void cancel() {
                    super.cancel();
                    holder.destroy();
                }

                @Override
                public void run() {
                    if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
                        cancel();
                        return;
                    }
                    if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
                        cancel();
                        return;
                    }
                    if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
                        NMS.mount(holder.getEntity(), player.getBukkitEntity());
                    }
                }
            }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
            break;
        case SLEEP:
            PacketPlayOutBed packet = new PacketPlayOutBed(player, new BlockPosition((int) player.locX, (int) player.locY, (int) player.locZ));
            sendPacketNearby(packet, player, radius);
            break;
        case SNEAK:
            player.getBukkitEntity().setSneaking(true);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_ELYTRA:
            player.N();
            break;
        case START_USE_MAINHAND_ITEM:
            player.c(EnumHand.MAIN_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_USE_OFFHAND_ITEM:
            player.c(EnumHand.OFF_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_SITTING:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
            NMS.mount(player.getBukkitEntity(), null);
            break;
        case STOP_SLEEPING:
            playDefaultAnimation(player, radius, 2);
            break;
        case STOP_SNEAKING:
            player.getBukkitEntity().setSneaking(false);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_USE_ITEM:
            player.clearActiveItem();
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) PacketPlayOutEntityMetadata(net.minecraft.server.v1_12_R1.PacketPlayOutEntityMetadata) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PacketPlayOutBed(net.minecraft.server.v1_12_R1.PacketPlayOutBed) MemoryNPCDataStore(net.citizensnpcs.api.npc.MemoryNPCDataStore) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry)

Example 5 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project Citizens2 by CitizensDev.

the class PlayerAnimationImpl method play.

public static void play(PlayerAnimation animation, Player bplayer, int radius) {
    final EntityPlayer player = (EntityPlayer) NMSImpl.getHandle(bplayer);
    if (DEFAULTS.containsKey(animation)) {
        playDefaultAnimation(player, radius, DEFAULTS.get(animation));
        return;
    }
    switch(animation) {
        case SIT:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), true));
            NPCRegistry registry = CitizensAPI.getNamedNPCRegistry("PlayerAnimationImpl");
            if (registry == null) {
                registry = CitizensAPI.createNamedNPCRegistry("PlayerAnimationImpl", new MemoryNPCDataStore());
            }
            final NPC holder = registry.createNPC(EntityType.ARMOR_STAND, "");
            holder.spawn(player.getBukkitEntity().getLocation());
            ArmorStandTrait trait = holder.getOrAddTrait(ArmorStandTrait.class);
            trait.setGravity(false);
            trait.setHasArms(false);
            trait.setHasBaseplate(false);
            trait.setSmall(true);
            trait.setMarker(true);
            trait.setVisible(false);
            holder.data().set(NPC.NAMEPLATE_VISIBLE_METADATA, false);
            holder.data().set(NPC.DEFAULT_PROTECTED_METADATA, true);
            new BukkitRunnable() {

                @Override
                public void cancel() {
                    super.cancel();
                    holder.destroy();
                }

                @Override
                public void run() {
                    if (player.dead || !player.valid || !player.getBukkitEntity().hasMetadata("citizens.sitting") || !player.getBukkitEntity().getMetadata("citizens.sitting").get(0).asBoolean()) {
                        cancel();
                        return;
                    }
                    if (player instanceof NPCHolder && !((NPCHolder) player).getNPC().isSpawned()) {
                        cancel();
                        return;
                    }
                    if (!NMS.getPassengers(holder.getEntity()).contains(player.getBukkitEntity())) {
                        NMS.mount(holder.getEntity(), player.getBukkitEntity());
                    }
                }
            }.runTaskTimer(CitizensAPI.getPlugin(), 0, 1);
            break;
        case SLEEP:
            try {
                ENTITY_SETPOSE_METHOD.invoke(player, EntityPose.SLEEPING);
            } catch (Throwable e) {
                e.printStackTrace();
            }
            break;
        case SNEAK:
            player.getBukkitEntity().setSneaking(true);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_ELYTRA:
            player.startGliding();
            break;
        case START_USE_MAINHAND_ITEM:
            player.c(EnumHand.MAIN_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case START_USE_OFFHAND_ITEM:
            player.c(EnumHand.OFF_HAND);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_SITTING:
            player.getBukkitEntity().setMetadata("citizens.sitting", new FixedMetadataValue(CitizensAPI.getPlugin(), false));
            NMS.mount(player.getBukkitEntity(), null);
            break;
        case STOP_SLEEPING:
            try {
                ENTITY_SETPOSE_METHOD.invoke(player, EntityPose.STANDING);
            } catch (Throwable e) {
                e.printStackTrace();
            }
            break;
        case STOP_SNEAKING:
            player.getBukkitEntity().setSneaking(false);
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        case STOP_USE_ITEM:
            player.clearActiveItem();
            sendPacketNearby(new PacketPlayOutEntityMetadata(player.getId(), player.getDataWatcher(), true), player, radius);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : MemoryNPCDataStore(net.citizensnpcs.api.npc.MemoryNPCDataStore) NPC(net.citizensnpcs.api.npc.NPC) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ArmorStandTrait(net.citizensnpcs.trait.ArmorStandTrait) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry)

Aggregations

MemoryNPCDataStore (net.citizensnpcs.api.npc.MemoryNPCDataStore)8 NPC (net.citizensnpcs.api.npc.NPC)8 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 ArmorStandTrait (net.citizensnpcs.trait.ArmorStandTrait)8 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)8 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)8 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata)4 ArrayList (java.util.ArrayList)3 PacketPlayOutEntityLook (net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook)2 Item (net.minecraft.server.v1_16_R2.DataWatcher.Item)2 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata)2 Item (net.minecraft.server.v1_16_R3.DataWatcher.Item)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1 Field (java.lang.reflect.Field)1 SneakyThrows (lombok.SneakyThrows)1 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)1 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)1