Solved Setting Item Tooltip DisplayName

Discussion in 'Plugin Development' started by ericejs123, Nov 10, 2018.

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


    Hi, is there any way at all to get/set the display name of the item being held? NOT looking to change the actual name of the item through itemmeta. Also, is there a way to enable/disable the hiding of the name after a few seconds, after the player changes the item held?

    Attached Files:

  2. Offline


    @ericejs123 I don't know if theres an easier way but for hiding the name when the player changes held item maybe you could set the actionbar message to " " or 'null' when the player changes held item. Just an idea, hope it helps. :7
  3. Offline


    How would I get the actionbar object? I'm not familiar with that. Not looking for spoon-fed code, just want a point in the right direction :p
  4. Offline


    Sending action bar messages are more complicated than they should be. To my knowledge there is no method in the player object that allows this, however you can quite easily send it with packets.
    ericejs123 likes this.
  5. Offline


    You can just disable the item tooltip in your minecraft settings.
  6. Offline


    @MattTheBeast it indeed it... but for a project I made I crated this (can use TITLE, ACTIONBAR and SUBTITLE as actionF enum value)
    1. try {
    3. String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
    4. Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
    5. Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
    6. Class<?> chatSerializer = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer");
    7. Class<?> chatComponent = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent");
    9. Class<?> packet = Class.forName("net.minecraft.server." + version + ".PacketPlayOutTitle");
    11. String message = "{\"text\":\"your name\"}"; //not sure about this, but something like this anyway
    13. Class enumClass = Class.forName("net.minecraft.server." + version + ".PacketPlayOutTitle$EnumTitleAction");
    14. Field actionF = enumClass.getDeclaredField("ACTIONBAR");
    15. actionF.setAccessible(true);
    17. Constructor constructor = packet.getConstructor(enumClass, chatComponent, int.class, int.class, int.class);
    19. Object text = chatSerializer.getMethod("a", String.class).invoke(chatSerializer, message);
    20. Object packetFinal = constructor.newInstance(actionF.get(null), text, (int) fadeIn, (int) displayTime, (int) fadeOut);
    22. connection.getClass().getMethod("sendPacket", Class.forName("net.minecraft.server." + version + ".Packet")).invoke(connection, packetFinal);
    24. } catch (Exception ex) {
    25. ex.printStackTrace();
    26. }

    but this is probably not what @ericejs123 wants, because isn't the actionbar and the item name on a different line?
    ericejs123 likes this.
  7. Offline


    Actually, this is exactly what I was looking for. I forgot to update the thread, as I figured out through packets how to do this the next day of posting this thread. I have similar code, just typed differently and made it more into functions/methods for large-scale development. But your code seems to be exactly what I was looking for at the time! Thank you!

    Also on a side note, I went more indepth with reading about action bars and such. The itemname is not the same as the actionbar text area. Take a look at the screenshot I attached. This is EXACTLY what I was looking for :) I'm making a GPS location display through the actionbar text. This way, the itemname also shows while the player changes items in their hotbar.

    Attached Files:

    Last edited: Nov 13, 2018
  8. Offline


    that was why I wasn't sure about if this was what you wanted.

    but I edited my code to use it simpeler. (because I have a whole class around it, with every thing about text components, you don't need it for just simple text)
Thread Status:
Not open for further replies.

Share This Page