Search in sources :

Example 36 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[1];
    List<Pair<EnumItemSlot, ItemStack>> vals = Lists.newArrayList();
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        vals.add(new Pair<EnumItemSlot, ItemStack>(slot, getEquipment(slot)));
    }
    packets[0] = new PacketPlayOutEntityEquipment(getId(), vals);
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_16_R3.EnumItemSlot) Packet(net.minecraft.server.v1_16_R3.Packet) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment) Location(org.bukkit.Location) Pair(com.mojang.datafixers.util.Pair)

Example 37 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_15_R1.EnumItemSlot) Packet(net.minecraft.server.v1_15_R1.Packet) ItemStack(net.minecraft.server.v1_15_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 38 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_14_R1.EnumItemSlot) Packet(net.minecraft.server.v1_14_R1.Packet) ItemStack(net.minecraft.server.v1_14_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 39 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project FunnyGuilds by FunnyGuilds.

the class V1_13R2PlayerList method send.

@Override
public void send(Player player, String[] playerListCells, String header, String footer, int ping) {
    final List<Packet<?>> packets = Lists.newArrayList();
    final List<Object> addPlayerList = Lists.newArrayList();
    final List<Object> updatePlayerList = Lists.newArrayList();
    try {
        PacketPlayOutPlayerInfo addPlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER);
        PacketPlayOutPlayerInfo updatePlayerPacket = new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.UPDATE_DISPLAY_NAME);
        for (int i = 0; i < this.cellCount; i++) {
            if (this.profileCache[i] == null) {
                this.profileCache[i] = new GameProfile(UUID.fromString(String.format(PlayerListConstants.UUID_PATTERN, StringUtils.leftPad(String.valueOf(i), 2, '0'))), " ");
            }
            String text = playerListCells[i];
            GameProfile gameProfile = this.profileCache[i];
            IChatBaseComponent component = CraftChatMessage.fromStringOrNull(text, false);
            Object playerInfoData = PLAYER_INFO_DATA_HELPER.createPlayerInfoData(addPlayerPacket, gameProfile, ping, component);
            if (this.firstPacket) {
                addPlayerList.add(playerInfoData);
            }
            updatePlayerList.add(playerInfoData);
        }
        if (this.firstPacket) {
            this.firstPacket = false;
        }
        PLAYER_INFO_DATA_ACCESSOR.set(addPlayerPacket, addPlayerList);
        packets.add(addPlayerPacket);
        PLAYER_INFO_DATA_ACCESSOR.set(updatePlayerPacket, updatePlayerList);
        packets.add(updatePlayerPacket);
        boolean headerNotEmpty = !header.isEmpty();
        boolean footerNotEmpty = !footer.isEmpty();
        if (headerNotEmpty || footerNotEmpty) {
            IChatBaseComponent headerComponent = EMPTY_COMPONENT;
            IChatBaseComponent footerComponent = EMPTY_COMPONENT;
            if (headerNotEmpty) {
                headerComponent = CraftChatMessage.fromStringOrNull(header, true);
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromStringOrNull(footer, true);
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter();
            headerFooterPacket.header = headerComponent;
            headerFooterPacket.footer = footerComponent;
            packets.add(headerFooterPacket);
        }
        for (Packet<?> packet : packets) {
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Failed to send PlayerList for player '%s'", player.getName()), ex);
    }
}
Also used : Packet(net.minecraft.server.v1_13_R2.Packet) IChatBaseComponent(net.minecraft.server.v1_13_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_13_R2.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_13_R2.PacketPlayOutPlayerInfo)

Example 40 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project FunnyGuilds by FunnyGuilds.

the class V1_15R1EntityAccessor 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!");
    }
    Entity entity = world.createEntity(location, entityType.getEntityClass());
    Packet<?> spawnEntityPacket;
    if (entity instanceof EntityLiving) {
        spawnEntityPacket = new PacketPlayOutSpawnEntityLiving((EntityLiving) entity);
    } else {
        spawnEntityPacket = new PacketPlayOutSpawnEntity(entity, ObjectType.getIdFor(entityType));
    }
    return new FakeEntity(entity.getId(), spawnEntityPacket);
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) PacketPlayOutSpawnEntity(net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity) Entity(net.minecraft.server.v1_15_R1.Entity) PacketPlayOutSpawnEntityLiving(net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntityLiving) EntityLiving(net.minecraft.server.v1_15_R1.EntityLiving) PacketPlayOutSpawnEntityLiving(net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntityLiving) PacketPlayOutSpawnEntity(net.minecraft.server.v1_15_R1.PacketPlayOutSpawnEntity) CraftWorld(org.bukkit.craftbukkit.v1_15_R1.CraftWorld)

Aggregations

CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)12 Player (org.bukkit.entity.Player)11 GameProfile (com.mojang.authlib.GameProfile)10 Location (org.bukkit.Location)10 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)6 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)5 Packet (com.yahoo.fs4.Packet)4 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)4 BasicPacket (com.yahoo.fs4.BasicPacket)3 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)3 QueryPacket (com.yahoo.fs4.QueryPacket)3 Packet (ejip123.Packet)3 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)3 PacketPlayOutEntityLook (net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)3 World (org.bukkit.World)3 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)3 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)2