Changing item's properties

Discussion in 'Spigot Plugin Development' started by ThomasCZE, May 25, 2018.

  1. Hello,

    I want to change lore of item using packets. How do I do that?
     
  2. Why are you trying to use packets?
    Code (Text):
    ItemStack is = new ItemStack(Material.STICK);
    ItemMeta im = is.getItemMeta();
    im.setLore(Arrays.asList("Stick of truth!"));
    is.setItemMeta(im);
     
  3. I recommend you to use ProtocolLib
    the related packets are:
    1. PacketType.Play.Server.SET_SLOT
    2. PacketType.Play.Server.WINDOW_ITEMS
     
    • Like Like x 1
  4. @Cilantro33 I want to change lore only for one user.

    @Soldier__ And what if I dont want to user ProtocolLib?
     
  5. So there's a thing I don't really understand:
    Lores are the lines that you see under an item. Right? Just a player can have that item so I don't know why you should do this!

    Anyways if you hate ProtocolLib there's nms(Net minecraft server)
     
  6. @Alex0589 Yeah, one player can have that item, but that player can trade it with another player. And I want to show one of the players different lores
     
  7. Then change the item then
     
    • Agree Agree x 1
  8. NathanWolf

    Supporter

    This is a much better solution.

    If you try to change an item's properties with packets, you're going to have a bad time. All a player has to do is drag it to a different inventory slot and suddenly it's a new ItemStack instance and will revert to its real properties.

    I speak from painful experience, it's almost impossible to catch all of the ways Spigot will make a copy of an item (and send that copy to the client).
     
  9. But I need to show different lores in item in inventory when more than 1 player is looking into same inventory.
     
  10. NathanWolf

    Supporter

    I guess you want ProtocolLib, then- you'd have to intercept packets (I think), figure out when it's your custom item and modify them. Sounds tricky, good luck!
     
  11. What should this lore show ? Any player stats or something? Because if it is, you don't need packets for that.
     
  12. Players will have a role. You can imagine Archer and Warrior. If both players open the same chest and there will be a bow, archer won't see anything, but warrior will see "§cWarriors can't use this item!"
     
  13. I am really sure that this doesn't need any packets. You have to listen when someone takes this bow from the chest and set the lore based on his role.
     
  14. NathanWolf

    Supporter

    If OP wants two players looking in the same chest to see different lore on the same item, then it will definitely require packets.

    It feels like a lot of complexity for such a minor detail that TBH no one will notice. Much easier to just prevent the Warrior from taking the item, maybe print a "You can't use that" message to the action bar. Shrug. Sounds like a fun challenge, though! :)
     
    • Like Like x 1