Hide item in hand to other players

Discussion in 'Plugin Development' started by njb_said, Sep 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    njb_said

    I need to know how I can hide the item a player has in their inventory to other players.
    For example:
    I am holding a sword, I don't want the other players to see it.
     
  2. njb_said Packets will do the job. There are multiple ways of doing this. Most easy one is by using protocolLib and listen for the Packet20NamedEntitySpawn and then set field 'h' to 0.
     
  3. Offline

    njb_said

    Kind of dont want to use any dependancies, is there another way
    And thanks for the quick reply
     
  4. Offline

    TheE

    Theoretically you could use NMS code and do what CaptainBern suggested manually. But I do not see any reason why you want to implement an extremely complicated behaviour by yourself (and keep it updated whenever Minecraft is updated), when you can just use ProtocolLib that was written for exactly this job.

    If you are worried about dependency management, just use Maven.
     
  5. njb_said Oh god you don't know what you're saying. Please for the sake of simplicity use protocolLib, you could write your own system to check for outgoing packets the same way TagApi uses but I'm not recomanding it.
     
  6. Offline

    njb_said

    I have never used protocollib to "use" as a developer. Would I listen on on that packet as an event (no) or would I do it in the onEnable() or my init class.
    Using the protocolmanager and add a listener?
    Thanks : )
     
  7. Offline

    CdoingBaddie

    njb_said
    Erm, you can use this?
    Code:
    for(Player players : Bukkit.getOnlinePlayers()){
                        players.hidePlayer(player);
                    }
    It'll make them invis. and it wont show their item in hand.
     
  8. Offline

    amhokies


    You know, technically, he's right.
     
  9. njb_said Try something like this:
    Code:java
    1. @Override
    2. public void startup() {
    3. ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this.plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGH, 20, 5) {// I hope this works, else try Packets.Server.NAMED_ENTTY_SPAWN and Packets.Server.ENTTY_EQUIPMENT
    4. @Override
    5. public void onPacketSending(PacketEvent event) {
    6. if (event.getPacketID() != 20 || event.getPacketID() != 5) { //check if it's the spawn packet or the equipment packet
    7. return;
    8. }
    9. final PacketContainer packetContainer = event.getPacket();
    10. try {
    11. //here check if its the Packet20NamedEntitySpawn, if so then read index 8 (thats the item inhand) and set it to 0 or null.
    12.  
    13. //if its the Packet5EntityEquipment then read index c, this should return an NMS Itemstack, just create a new bukkit itemstack, use some reflection to convert it to an nms-itemstack and set index c to your fresh created itemstack.
    14. } catch (final FieldAccessException e) {
    15. e.printStackTrace();
    16. }
    17. }
    18. });
     
  10. Offline

    njb_said

Thread Status:
Not open for further replies.

Share This Page