Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by ThomasCZE, May 25, 2018.
I want to change lore of item using packets. How do I do that?
Why are you trying to use packets?
ItemStack is = new ItemStack(Material.STICK);
ItemMeta im = is.getItemMeta();
im.setLore(Arrays.asList("Stick of truth!"));
I recommend you to use ProtocolLib
the related packets are:
@Cilantro33 I want to change lore only for one user.
@Soldier__ And what if I dont want to user ProtocolLib?
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)
@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
Then change the item then
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).
But I need to show different lores in item in inventory when more than 1 player is looking into same inventory.
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!
What should this lore show ? Any player stats or something? Because if it is, you don't need packets for that.
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!"
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.
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!