mkremins / fanciful

Fancy Bukkit message formatting
MIT License
95 stars 82 forks source link

Spigot 1.7.10 - \n cartridge return? #70

Open CyberSecGuy opened 8 years ago

CyberSecGuy commented 8 years ago

Hi! I love Fanciful, and currently use it in a plugin of mine.

I'm using the following code to run a multi-lined reply, while keeping them all wrapped as 1 long line.

public FancyMessage linkNMS(Player player, String platform) {
    String line1 = ChatColor.STRIKETHROUGH + "                     " + ChatColor.RESET + " " + Main.Tag + ChatColor.RESET + " " + ChatColor.STRIKETHROUGH + "                     ";
    String line2 = "+ " + ChatColor.BLUE + "Update your URL using the command:";
    String line3 = "+ " + ChatColor.GREEN + "/yt " + ChatColor.RED + platform + ChatColor.GOLD + " <your link> " + ChatColor.AQUA + "[Click Me!]";
    String lb = "\n";
    String cmd = "";
    String tooltip = "";

    if (Main.Strummer.containsKey(player.getName())) {
        Streamer strum = Main.Strummer.get(player.getName());

        if (platform.equals("youtube")) {
            tooltip = "Current Link: " + strum.youtube;
            cmd = "/yt " + platform + " http://www.youtube.com/";
        }

        if (platform.equals("twitch")) {
            tooltip = "Current Link: " + strum.twitch;
            cmd = "/yt " + platform + " http://www.twitch.tv/";
        }

        if (platform.equals("twitter")) {
            tooltip = "Current Link: " + strum.twitter;
            cmd = "/yt " + platform + " http://www.twitter.com/";
        }
    }

    return new FancyMessage(line1).suggest(cmd).tooltip(tooltip).then(lb).then(line2).suggest(cmd).tooltip(tooltip).then(lb).then(line3).suggest(cmd).tooltip(tooltip);
}

In spigot 1.9.4 - the \n works perfectly fine as a line-break option, however when trying to support a 1.7.10 server, it prints a cartridge return. As seen below:

1.7.10 - http://i.imgur.com/shPUcNt.png 1.9.4 - http://i.imgur.com/vWwkRB9.png

These are from the exact same Jar file on both servers. Additionally to test if it is 1.7.10 Spigot I ran the following command as a debug

if (args[0].equals("fancy")) {
    Bukkit.getServer().broadcastMessage("This is a test \nAnother test?" + '\n' + "Cookies");                       
}

and it works just fine.

I'd rather not send back multiple fanciful messages, as it's pretty cool to have 1 big block that's clickable anywhere on the text, acting as 1 fanciful message, so my questions are the following:

Is there a better way to do this? Is there a built in line-break option for Fanciful API? Any idea why I'm getting a cartridge return on 1.7.10 but not 1.9.4?

mkremins commented 8 years ago

That's odd. Using \n is the canonical "right way" to insert linebreaks into the message text; I have no idea why it's behaving differently on two different Spigot versions.

Could you send me the JSON string of the FancyMessage on both Spigot versions? You can use FancyMessage.toJSONString() to get the JSON string and then print the result to the console.

Sir-Will commented 7 years ago

Same issue here, even /tellraw SirWill {"text":"test\n123"} causes this