how to hide an item drop from a few players?

Discussion in 'Spigot Plugin Help' started by J-B, Jul 9, 2019.

  1. J-B

    J-B

    Hello,
    I would like to know how to hide an item from several players in order to make several 1v1s in the same place.

    I tried that, but it didn't work:

    Code (Text):
        @EventHandler
        public void onDropItem(PlayerDropItemEvent e) {
            Player p = (Player) e.getPlayer();
            Item item = e.getItemDrop();
              PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(item.getEntityId());
                 for (Player p1 : Bukkit.getOnlinePlayers())
                 {
                   ArrayList<Player> players = new ArrayList<Player>();
                   players.add(p1);
                   players.remove(p);
                   for (Player pl : players){
                       if (pl != p) {
                           ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityDestroy(item.getEntityId()));
                       }
                     Bukkit.broadcastMessage(pl.toString());
                     ((CraftPlayer)pl).getHandle().playerConnection.sendPacket(packet);
                   }
                 }
           
           
        }
    I use spigot 1.8

    Thank you for your help
     
  2. Is that your requirement to handle this through packet? (I'm assuming that you don't want other players to see those dropped item and possibly pick them up?)

    if other players possibly picking those dropped items up is the main issue, you can simply limit the access to those dropped items.
     
  3. J-B

    J-B

    Yes, but I also wouldn't want them to see them, the fact that they can't pick them up is easier since it doesn't involve packet interception.

    If anyone can help me

    Thank you. Thank you.
     
  4. If you don’t anyone to pick them up, you can simply remove them. If you want to limit who can pick up, there are a few different ways to achieve that.
     
  5. J-B

    J-B

    I wish that only the opponent and the player can see and retrieve the item.
     
  6. Hmm then you would probably need to do both (manipulate packets for visibility and uuid/player based pickup restriction)
     
  7. J-B

    J-B

    Yes I agree but already I can't make the item invisible to other players
     
  8. J-B

    J-B

    can you help me hide a drop item, please?
     
  9. J-B

    J-B

    Hi,

    can you help me hide a drop item, please?
     
  10. one mistake i saw from your code
    you put declaration inside loop that makes the ArrayList only contain one object

    and you don't need this
    Code (Text):
    if (pl != p)
    because it is redundant! because you have removed the p from player, and i really don't understand with your program, it looks like not effective and useless
     
  11. i tried to understand your code and try to re-write them, your code is full of redundant line
    Code (Text):

            @EventHandler
            public void onDropItem(PlayerDropItemEvent e) {
                Player p = (Player) e.getPlayer();
                Item item = e.getItemDrop();

                PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(item.getEntityId());

                Bukkit.broadcastMessage(p.toString());
                (CraftPlayer)p.getHandle().playerConnection.sendPacket(packet);

                e.cancelEvent();
            }
     
    i dont know will this work or not, because im never use any PacketPlayOutEntityDestroy
     
  12. J-B

    J-B

    Hello,

    Thank you for your answer,

    I want a drop item on the ground to be visible and recoverable by only a few players (the 2 who are in 1vs1) but not by others who are in the same arena (neither visible nor recoverable)

    Thank you.
     
  13. J-B

    J-B

    If you have another way to hide an item on the ground from a few players, I'm a taker, it still doesn't work.

    Thank you for your help
     
  14. Strahan

    Benefactor

    If it doesn't have to be invisible, just protected against other people picking them up, Anti Loot Steal would protect items won in PVP from being picked up by anyone but the victor.
     
  15. J-B

    J-B

    Hello,

    Thank you very much, it helps me a lot!

    I always need to hide the item from those who are not allowed to pick up the item in question.


    Thank you for your answers