Search in sources :

Example 21 with Packet

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

the class V1_16R3EntityAccessor 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);
    }
    return new FakeEntity(entity.getId(), spawnEntityPacket);
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) Entity(net.minecraft.server.v1_16_R3.Entity) PacketPlayOutSpawnEntity(net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntity) FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) PacketPlayOutSpawnEntityLiving(net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntityLiving) EntityLiving(net.minecraft.server.v1_16_R3.EntityLiving) PacketPlayOutSpawnEntityLiving(net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntityLiving) PacketPlayOutSpawnEntity(net.minecraft.server.v1_16_R3.PacketPlayOutSpawnEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 22 with Packet

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

the class V1_16R3PlayerList 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_16_R3.Packet) IChatBaseComponent(net.minecraft.server.v1_16_R3.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)

Example 23 with Packet

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

the class V1_12R1PlayerList 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.fromString(text, false)[0];
            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.fromString(header, true)[0];
            }
            if (footerNotEmpty) {
                footerComponent = CraftChatMessage.fromString(footer, true)[0];
            }
            PacketPlayOutPlayerListHeaderFooter headerFooterPacket = new PacketPlayOutPlayerListHeaderFooter();
            HEADER_ACCESSOR.set(headerFooterPacket, headerComponent);
            FOOTER_ACCESSOR.set(headerFooterPacket, 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_12_R1.Packet) IChatBaseComponent(net.minecraft.server.v1_12_R1.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_12_R1.PacketPlayOutPlayerListHeaderFooter) GameProfile(com.mojang.authlib.GameProfile) PacketPlayOutPlayerInfo(net.minecraft.server.v1_12_R1.PacketPlayOutPlayerInfo)

Example 24 with Packet

use of net.minecraft.server.v1_16_R3.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_11_R1.EnumItemSlot) Packet(net.minecraft.server.v1_11_R1.Packet) ItemStack(net.minecraft.server.v1_11_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_11_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 25 with Packet

use of net.minecraft.server.v1_16_R3.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_13_R2.EnumItemSlot) Packet(net.minecraft.server.v1_13_R2.Packet) ItemStack(net.minecraft.server.v1_13_R2.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)10 Location (org.bukkit.Location)9 Player (org.bukkit.entity.Player)9 ArrayList (java.util.ArrayList)8 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)8 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)5 Packet (com.yahoo.fs4.Packet)4 List (java.util.List)4 EntityPlayer (net.minecraft.server.v1_16_R3.EntityPlayer)4 PacketPlayOutPlayerInfo (net.minecraft.server.v1_16_R3.PacketPlayOutPlayerInfo)4 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)4 BasicPacket (com.yahoo.fs4.BasicPacket)3 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)3 QueryPacket (com.yahoo.fs4.QueryPacket)3 Packet (ejip123.Packet)3 PacketPlayOutEntityLook (net.minecraft.server.v1_16_R3.PacketPlayOutEntity.PacketPlayOutEntityLook)3 CraftBlockData (org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData)3 SectionTypeArray (thpmc.engine.util.SectionTypeArray)3 Pair (com.mojang.datafixers.util.Pair)2 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2