Search in sources :

Example 46 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_15_R1 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, new Vec3D(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 : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) PacketPlayOutEntityLook(net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 47 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project TheAPI by TheDevTec.

the class v1_15_R1 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.c();
    if (slot == -999)
        return false;
    int id = packet.b();
    int mouseClick = packet.d();
    net.minecraft.server.v1_15_R1.InventoryClickType nmsType = packet.g();
    InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.f());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType().isAir()) && item.getType().isAir())
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).shiftClick((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_15_R1.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_15_R1.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)

Example 48 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project TheAPI by TheDevTec.

the class v1_15_R1 method packetPlayerListHeaderFooter.

@Override
public Object packetPlayerListHeaderFooter(String header, String footer) {
    PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
    packet.header = (IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(header, true));
    packet.footer = (IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(footer, true));
    return packet;
}
Also used : PacketPlayOutPlayerListHeaderFooter(net.minecraft.server.v1_15_R1.PacketPlayOutPlayerListHeaderFooter)

Example 49 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project TheAPI by TheDevTec.

the class v1_15_R1 method processServerListPing.

@Override
public boolean processServerListPing(String player, Object channel, Object packet) {
    PacketStatusOutServerInfo status = (PacketStatusOutServerInfo) packet;
    ServerPing ping;
    try {
        ping = (ServerPing) field.get(status);
    } catch (Exception e) {
        return false;
    }
    List<PlayerProfile> players = new ArrayList<>();
    for (Player p : Bukkit.getOnlinePlayers()) players.add(new PlayerProfile(p.getName(), p.getUniqueId()));
    ServerListPingEvent event = new ServerListPingEvent(Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(), players, Bukkit.getMotd(), ping.d(), ((InetSocketAddress) ((Channel) channel).remoteAddress()).getAddress(), ping.getServerData().a(), ping.getServerData().getProtocolVersion());
    HandlerList.callEvent(event);
    if (event.isCancelled())
        return true;
    ServerPingPlayerSample playerSample = new ServerPingPlayerSample(event.getMaxPlayers(), event.getOnlinePlayers());
    if (event.getPlayersText() != null) {
        GameProfile[] profiles = new GameProfile[event.getPlayersText().size()];
        int i = -1;
        for (PlayerProfile s : event.getPlayersText()) profiles[++i] = new GameProfile(s.getUUID(), s.getName());
        playerSample.a(profiles);
    } else
        playerSample.a(new GameProfile[0]);
    ping.setPlayerSample(playerSample);
    if (event.getMotd() != null)
        ping.setMOTD((IChatBaseComponent) toIChatBaseComponent(ComponentAPI.toComponent(event.getMotd(), true)));
    else
        ping.setMOTD((IChatBaseComponent) BukkitLoader.getNmsProvider().chatBase("{\"text\":\"\"}"));
    if (event.getVersion() != null)
        ping.setServerInfo(new ServerData(event.getVersion(), event.getProtocol()));
    if (event.getFalvicon() != null)
        ping.setFavicon(event.getFalvicon());
    return false;
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) PlayerProfile(me.devtec.theapi.bukkit.events.ServerListPingEvent.PlayerProfile) Channel(io.netty.channel.Channel) ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_15_R1.IChatBaseComponent) ServerPing(net.minecraft.server.v1_15_R1.ServerPing) ServerPingPlayerSample(net.minecraft.server.v1_15_R1.ServerPing.ServerPingPlayerSample) GameProfile(com.mojang.authlib.GameProfile) ServerData(net.minecraft.server.v1_15_R1.ServerPing.ServerData) PacketStatusOutServerInfo(net.minecraft.server.v1_15_R1.PacketStatusOutServerInfo) ServerListPingEvent(me.devtec.theapi.bukkit.events.ServerListPingEvent)

Example 50 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_15_R1 method broadcastPacket.

private void broadcastPacket(Player origin, Packet<?> packet) {
    Location location = origin.getLocation();
    for (Player player : Bukkit.getOnlinePlayers()) {
        if (player == origin) {
            continue;
        }
        Location ploc = player.getLocation();
        if (ploc.getWorld() != location.getWorld()) {
            continue;
        }
        if (ploc.distanceSquared(location) > 128) {
            continue;
        }
        EntityPlayer NMSPlayer = ((CraftPlayer) player).getHandle();
        NMSPlayer.playerConnection.sendPacket(packet);
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) Location(org.bukkit.Location)

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