1.17.x Packet is not sending.

Discussion in 'Spigot Plugin Development' started by PixelsDE, Jul 26, 2021.

Thread Status:
Not open for further replies.
  1. Well I want the player to see the view of the target with:

    Code (Java):
    PacketPlayOutCamera camera = new PacketPlayOutCamera(((CraftPlayer) target).getHandle());
    ((CraftPlayer) player).getHandle().b.sendPacket(camera);
    But nothing happens. dunno why
     
    #1 PixelsDE, Jul 26, 2021
    Last edited: Jul 26, 2021
  2. Is the given entity loaded by the player? If not that packet is ignored.
     
  3. meaning the player hast to "stand" close to the target that the target is rendered to the player and only than this packet fires?
     
  4. Yes
     
  5. even than its not working. teleported both players to each other and nothing (paper 1.17.1)


    Code (Java):
      @EventHandler
        public void onClick(final PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Game game = Game.getPlayerGames().get(player);
            if (game == null)
                return;
            if (game.getPlaying().contains(player)) {

                if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && player.getInventory().getItemInMainHand().hasItemMeta() && player.getInventory().getItemInMainHand().getItemMeta().equals(theEye().getItemMeta())) {
                    event.setCancelled(true);
                    int PlayerNr = new Random().nextInt(game.getPlaying().size());
                    Player target = (Player) game.getPlaying().toArray()[PlayerNr];

                    if (game.getPlaying().contains(target)) {
                        if (!target.equals(player)) {
                            theHunterMain.getPlugin().getVariables().removeItem(player, 1, theEye().getItemMeta());
                            player.updateInventory();

                            SpectatorView.setCamera(player, player);
                            player.sendMessage(ChatColor.translateAlternateColorCodes('&', Settings.cfg.getString("Prefix"))
                                    + ChatColor.translateAlternateColorCodes('&',
                                    Messages.cfg.getString("theEye_Use").replace("%player%", target.getName())));
                            Bukkit.getScheduler().runTaskLater(theHunterMain.getPlugin(), () -> {
                                try {
                                    SpectatorView.removeCamera(player);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }, 20 * Settings.cfg.getInt("Eye_View"));
                        }
                    }
                }
            }
        }
    Code (Java):
     public static void setCamera(Player player, Player target) {
            try {
                PacketPlayOutCamera camera = new PacketPlayOutCamera(((CraftPlayer) target).getHandle());
                ((CraftPlayer) player).getHandle().b.sendPacket(camera);
                //sendPacket(player, target);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        public static void removeCamera(Player player) {
            setCamera(player, player);
        }
    It sais that Im in the view of.. but well no view
     
  6. Done so. cant find any clue to that problem.
     
  7. Maybe setCamera(player, player) to setCamera(player, target)
     
  8. hey you... I hate and love you the same time...
    but still I get a method not found from:


    Code (Java):

    public static void setCamera(Player player, Player target) {
        try {
            sendPacket(player, new PacketPlayOutCamera((net.minecraft.world.entity.Entity) getNMSPlayer(target)));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void removeCamera(Player player) {
        setCamera(player, player);
    }

    private static void sendPacket(Player player, Object packet) {
        try {
            Object nmsPlayer = getNMSPlayer(player);
            Object connection = nmsPlayer.getClass().getField("b").get(nmsPlayer);
            connection.getClass().getMethod("sendPacket", Packet.class).invoke(connection, packet);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static Object getNMSPlayer(Player player) {
        try {
            return player.getClass().getMethod("getHandle").invoke(player);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
     
    in paper 1.17.1
    updated
     
    • Funny Funny x 1
Thread Status:
Not open for further replies.