Hover over name and show messages

Discussion in 'Plugin Development' started by CullanP, Oct 28, 2014.

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

    CullanP

    I'm just curious how this could be done. To hover over a name to show json
     
  2. Offline

    ResultStatic

    GrandmaJam likes this.
  3. Offline

    CullanP

    Bump: Need something that works with 1.7.10
     
  4. Offline

    fireblast709

  5. Offline

    CullanP


    I understand how to send json messages, but how would I make a json message show when you hover over a playername that had just talked in chat. I've seen servers do this
     
  6. Offline

    fireblast709

  7. Offline

    CullanP

    I don't see anything in that thread pertaining to what I'm trying to do. I already understand how to send json messages. I just have no idea how I could send a json message through a playername when they talk in chat.
    I got this code from ResultStatic , but to my luck it only works on spigot 1.7.9 for some odd reason.
    Code:
    package main;
     
    import java.util.LinkedHashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
    import org.bukkit.craftbukkit.v1_7_R4.util.CraftChatMessage;
    import org.bukkit.entity.Player;
     
    import net.minecraft.server.v1_7_R4.ChatClickable;
    import net.minecraft.server.v1_7_R4.ChatComponentText;
    import net.minecraft.server.v1_7_R4.ChatHoverable;
    import net.minecraft.server.v1_7_R4.EntityPlayer;
    import net.minecraft.server.v1_7_R4.EnumClickAction;
    import net.minecraft.server.v1_7_R4.EnumHoverAction;
    import net.minecraft.server.v1_7_R4.IChatBaseComponent;
    import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
     
    public class FancyText {
     
     
        LinkedHashMap<String, MessageComponent> message = new LinkedHashMap<String, MessageComponent>();
     
     
        public FancyText addText(String text){
            this.message.put(text, new MessageComponent(text, null, null));
            return this;
        }
     
        public FancyText addClickableLink(String text,String link){
            this.message.put(link, new MessageComponent(text, link, EnumClickAction.OPEN_URL));
            return null;
     
     
     
        }
     
        public FancyText addRunnableCommand(String text, String command){
     
            this.message.put(text, new MessageComponent(text, command, EnumClickAction.RUN_COMMAND));
            return this;
        }
     
        public FancyText addChatSuggestion(String text,String suggestion){
     
            this.message.put(text, new MessageComponent(text, suggestion, EnumClickAction.SUGGEST_COMMAND));
     
            return this;
            }
     
     
        public FancyText addHoverEvent(String text, String hover){
     
            this.message.put(text, new MessageComponent(text,hover ,EnumHoverAction.SHOW_TEXT));
     
            return this;
            }
     
     
     
     
        public void sendToPlayer(Player player){
      CraftPlayer cp = (CraftPlayer)player;
      EntityPlayer ep = cp.getHandle();
            ChatComponentText master = new ChatComponentText("");
            for (String text: message.keySet()){
                for (IChatBaseComponent m: message.get(text).compile()) {
                    master.a(m);
                    }
     
                }
            ep.playerConnection.sendPacket(new PacketPlayOutChat(master));
            }
     
        public void sendToAllPlayers(){
            for (Player player: Bukkit.getOnlinePlayers()){
                this.sendToPlayer(player);
            }
        }
        public class MessageComponent {
     
            Enum<?> e;
            String data;
            String text;
            IChatBaseComponent[] chat;
     
            public MessageComponent(String text, String data, Enum<?> e){
            this.e = e;
            this.text = text;
            this.data = data;
            chat = CraftChatMessage.fromString(text);
            }
     
            public IChatBaseComponent[] compile(){
                for (IChatBaseComponent c: chat){
                if (data == null || e == null){
     
                    return chat;
                }
                    if (e instanceof EnumClickAction){
                    c.getChatModifier().setChatClickable(new ChatClickable((EnumClickAction) e, data));
                    }else if (e instanceof EnumHoverAction){
                        c.getChatModifier().a((new ChatHoverable((EnumHoverAction)e, new ChatComponentText(data))));
                    }
                }
     
                return chat;
            }
        }
    }
    
    If I compile that in spigot 1.7.9 I can make hoverevent show up in playernames, 1.7.10 just makes it show as blank text and since I want to stay on 1.8 I need a way for this to work on 1.7.10
     
  8. Offline

    fireblast709

    CullanP have you debugged the JSON that is being sent to the client?
     
  9. Offline

    CullanP

    I have no use in doing that. It makes no sense to me why in 1.7.9 it works and 1.7.10 it doesn't. They had to of changed something.
     
  10. Offline

    TheCodingCat

    there is a video that explains this. My friend said it worked great for him
     
  11. Offline

    fireblast709

    Which is why I ask you to debug :\
     
  12. Offline

    MineStein

  13. Offline

    CullanP

  14. Offline

    MineStein

    CullanP Okay, thanks for clarifying. You would cancel the chat event and broadcast the JSON. The thing is I'm not sure how to implement it inside of messages without making the entire text clickable. I'll test some stuff.
     
  15. CullanP You'd be better off seeking support where you acquired your server mod. :)
     
  16. Offline

    fireblast709

    MineStein you can 'glue' JSON parts together in the 'extra' part. That way you can make it so that the hover only works on the text part that is specified in that JSON block.
     
  17. Offline

    MineStein

    fireblast709 Yeah, I figured it would work somehow like that.
     
Thread Status:
Not open for further replies.

Share This Page