Solved Hidden Lore/Attributes

Discussion in 'Plugin Development' started by DrJava, Jan 12, 2014.

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

    DrJava

    Hi there.
    Does anybody know how to hide a string within lore/attributes? The reason is because I'm working on a custom item plugin. On damage events, heal events etc. I need to check if the item is a custom item. Within my custom item class, I have a hashmap that stores the custom items; their id
    Code:
    BigInteger.valueOf(rand.nextInt(Integer.MAX_VALUE)).toByteArray();
    and their Meta
    Code:
    getItemMeta()
    Within the item, I then set the last line of it's lore to be the generated id. Is there any way to hide this id, and retrieve it at later times?
     
  2. Offline

    newboyhun

    DrJava
    Use ChatColor.COLOR_CHAR before every character, you want to hide.
     
    xize likes this.
  3. Offline

    DrJava

    newboyhun For now, I just set the id string colour to black; it's only about 20% visible.
    I don't see what your method does though; wouldn't it just make the string white?
     
  4. Offline

    newboyhun

    DrJava
    No it will make it invisible because no color is specified.
    I wrote this method for one of my plugin (custom items) to hide custom item id.
    Code:
       
        public static String convertToInvisibleString(String s) {
            String hidden = "";
            for (char c : s.toCharArray()) hidden += ChatColor.COLOR_CHAR+""+c;
            return hidden;
        }
    
     
  5. Offline

    DrJava

    Ahh, I thought it would just return the paragraph symbol. Would I just use
    Code:
    ChatColor.stripColor(input);
    to retrieve the string?
     
  6. Offline

    Drkmaster83

    You could do that, or call String.replaceAll("§", "");
     
  7. Offline

    DrJava

    Doesn't work :confused:.
    Edit: Nevermind, it does. Thanks!
     
  8. Offline

    newboyhun

    DrJava
    Well, i'm not sure because i didn't try it.
    But try it.
    If it doesn't work, write your own replace.
     
  9. Offline

    Drkmaster83

    xD, glad to help! ChatColor is just a big ol' fat StringBuilder appending "§" to the beginning of color codes! Either that, or "\u00A7". "\u00A7" is the unicode value for the Section Symbol (§). Fun facts! Yay!
     
    DrJava likes this.
  10. Offline

    metalhedd

    This works alright, but it still displays a blank line (or more) where the lore should be. If this is an issue, The same can be accomplished with protocollib without showing ANYTHING to the user. It's quite complicated, But I do it in my plugin PortableHorses, which you can feel free to borrow from: https://github.com/andrepl/PortableHorses/
     
  11. Offline

    DrJava

    Thanks, but I hate libraries and apis. I'd rather just code it myself.
     
  12. Offline

    Avygeil

    Hey, I know this is solved but as I've done the same experiments a week before, I thought I'd share it.

    Basically, it uses the CanDestroy NBT list (http://minecraft.gamepedia.com/Player.dat_format#Other). As you might know, custom or inappropriate NBT tags are removed when the world is loaded. However, it seems that this particular tag persists for any item. I don't know if the tag itself even works (it doesn't destroy grass with a pickaxe if I add the grass ID in adventure mode), but it's a nice way to store information without hiding them with ProtocolLib or resources-heavy strings.

    You are then free to implement that in your custom item class, for example hard-coded IDs for effects. In my plugin, I use a bit-flag system for IDs which is then cached in a map. :)
     
    DrJava likes this.
Thread Status:
Not open for further replies.

Share This Page