Hide Lore from Client

Discussion in 'Plugin Development' started by Jalau, Nov 26, 2013.

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

    Jalau

    I need to hide a line in the lore from the client I'm storing my custom durability & and a unique id from an item! They look like so: Durability int and Auction int.... How can i hide these from the client...? I didn't used any colorcodes so they are in vanilla style color, so i don't know if this means that they have colorcodes or the client just shows them in purple and italic ^^ So yeah, please help me! I don't want to always create an new itemstack, i just want to ALWAYS hide these lores from the client :)
     
  2. Offline

    desht

    You'll probably need to use ProtocolLib for this, and intercept packet 103 & 104 from the server to the client. I wrote a utility class to make this easier, based on lots of good example code from Comphenix: https://github.com/desht/dhutils/blob/master/Lib/src/main/java/me/desht/dhutils/MetaFaker.java (pardon the slightly dodgy indention in that class)

    and here's an example of how I use it: https://github.com/desht/ScrollingM...scrollingmenusign/ScrollingMenuSign.java#L335

    Basically I create an instance of my MetaFaker class, and pass it my plugin, plus an instance of my MetadataFilter with the filter() method implemented. It takes a player and some item metadata and returns the faked metadata which you want the client to see (or null if the real metadata should be passed to the client unchanged).

    The filter I've set up there strips the last line of lore from items which my plugin considers to be an "active item" - where some internal data is stored in the lore.
     
    Jalau and Garris0n like this.
  3. Offline

    Jalau

    Awesome! Will try it thanks ^^

    Edit: So i don't need to cast this at events or anything?
     
  4. Offline

    Comphenix

    Nice, but do you handle creative mode properly? The client-side item stack may be transmitted as-is to the server, and accepted as the new server-side item stack. This occurs whenever the item stack is moved or manipulated.

    The quick and dirty solution is to always disable the effect for creative players, and to update the inventory before toggling between creative and survival mode. But it can be solved - you just have to store the original item stack with a custom NBT tag, and revert it before it is received.
     
  5. Offline

    desht

    Yeah, good point. I'll need to get that fixed.
     
  6. Offline

    Craftiii4

    desht

    Do you mind if I use this? :)
     
Thread Status:
Not open for further replies.

Share This Page