sendRaw Message

Discussion in 'Spigot Plugin Development' started by NaJated, May 15, 2015.

  1. hey all, do I use raw message to send hoverable text ? I am trying to implement this into my auto broadcasting plugin, tx tx <3 ily
     
  2. The linked api is just available for Spigot, not for Bukkit, Bukkit does not have this feature.
    That means you have to use Spigot-API as dependency and not Bukkit.

    If you use maven you can easily get the dep code for the pom through https://hub.spigotmc.org/nexus if you search for spigot-api

    If you need a dl link for the latest version, here u are: https://hub.spigotmc.org/nexus/cont.../spigot-api-1.8.3-R0.1-20150502.231554-67.jar
     
  3. How would I go about adding placeholders for my plugin because I have a big string list with all the messages in. Thx :D


    kkkkk
     
    #4 NaJated, May 15, 2015
    Last edited by a moderator: May 15, 2015
  4. You mean all your messages are in your config? Well there is no and there will not be an offical way (one user suggested sth some time ago but it got denied) to convert strings to hoverable(etc.) messages. That means you either write your own converter for this (think currently no such thing exists) or define the messages needing advanced features (i mean hover event and so on) in your plugin directly
     
  5. Couldn't I like allow support for /tellraw @p ["",{"text":"Click to learn the feed command.","hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"Type /feed","color":"dark_red"}]}}}] or something?
     
  6. Yes that's possible, however you need to invoke the command by your plugin with Bukkit.dispatchCommand(Bukkit.getConsoleCommandSender(), command);
     
  7. You can grab the message from your configuration and parse it through all of your placeholders then proceed to use ChatComponent's TextComponent#fromLegacyText(String) method to turn your message into all of the necessary base components. From here you can create a HoverEvent to apply to all the BaseComponents you've created. Would look something like this:

    Code (Java):
    public void testMethod() {
        String configurationMessage =...; // Some message that you've grabbed from your config (or wherever)

        // Let's apply all of our placeholder
        configurationMessage = configurationMessage.replace("[placeholder]", /* Some data */)
                .replace("[placeholder2]", /* Some other data */); // etc. etc. apply your placeholders

        // Let's apply some color before turning it into BaseComponents
        configurationMessage = ChatColor.translateAlternateColorCodes('&', configurationMessage);

        // Now onto the BaseComponent stuff
        BaseComponent[] components = TextComponent.fromLegacyText(configurationMessage); // let the API transform it into JSON
        TextComponent hoverMessage = new TextComponent("This is a hover message!"); // This is the text that will appear when mouse is hovered over
        HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new BaseComponent[]{ hoverMessage }); // Create our hover event

        // Apply our hover event to all messages
        for (BaseComponent component : components) {
            component.setHoverEvent(hoverEvent);
        }

        // Send the message to some player
        Player player = ...; // Some player that we want to send the message too
        player.spigot().sendMessage(components);
    }
     
  8. Would not make hover event configurable not for the whole message
     
  9. You can have a specific criteria for if a component should have the hover event in that case. Perhaps something like a [hover] tag and when you iterate over all BaseComponents you can check if the particular component is a TextComponent and from there check if the component has the hover tag by using TextComponent#getText() and replacing the [hover] with whatever you want with TextComponent#setText(String#replace...)).

    If you're curious on an example of this being implemented, you check check out a branch of my Auctions plugin that adds an item tooltip to only a specific part of a message. The code can be found here: https://github.com/sainttx/Auctions...sages/handler/TextualMessageHandler.java#L214
     
  10. That's basically what I meant with converter.