Code message lines

Discussion in 'Spigot Plugin Development' started by Yolo_Always_4_7, May 28, 2017.

  1. Hello there! i'm just adding something into my plugin, but don't know how to add lines of messages, like this:
    Code (Text):
    player.sendMessage(ChatColor.RED + ChatColor.BOLD + "        <plugin name> Help:")
    player.sendMessage(ChatColor.RED + "/kits" + ChatColor.DARK_GRAY + " //" + ChatColor.GRAY + "Opens up the kits gui menu!")
     
  2. What do you mean add lines of messages?
     
  3. You mean a NEW line? Use \n
     
  4. I mean so it turns out like this:
    SpigotMC Help:
    /kits - opens up the kits gui menu
    /rawr - become a fierce dinosaur!
     
    #4 Yolo_Always_4_7, May 28, 2017
    Last edited: May 28, 2017
  5. You could just add \n Which puts the text after it on a new line

    EDIT: Just so you know, dinosaur is spelled wrong :)
     
  6. Code (Text):
    player.sendMessage("    SpigotMC Help:    ");
    player.sendMessage("/kits - opens up the kits gui menu");
    player.sendMessage("/rawr - become a fierce dinasaur!");
     
     
  7. Sorry didn't bother to check through the spellings. I'm awake quite late, where I live, and I haven't eaten all day. So yeah...
     
  8. player.sendMessage("SpigotMC Help:\r\n/Cmd - Blah\r\n/cmd2 - blah");
     
  9. This is bad practice.
    Use line.separator instead,
    Code (Java):
    String separator = System.getProperty("line.separator");
     
    • Like Like x 1
  10. I'd also like to note that with the advent of Java 7, you can use System.lineSeparator()
     
    • Like Like x 1
    • Useful Useful x 1
  11. First go to sleep, no first eat then go to sleep
    Then when you wake up visit the Oracle Java tutorials website to refresh your memory

    Then,,,, Ok then you can add lines in many ways
    You can display it one by one or have the \n tab where the indent would be a line and keep writing see tutorials about it there are heaps online
     
  12. To the contrary to all of the above answers, I'd personally just use a message builder.

    Create a simple helper class for the player.

    HelperPlayer h = new HelperPlayer(Player#);

    Inside this helper class there would be a method

    sendMessage(String... messages) {
    // create a list from this array using Collections.
    for (String s : thisList) {
    getPlayer().sendMessage(s);
    }
    }

    Then h.sendMessage("line 1", "line 2", line 3", "etc");
     
  13. @ExpDev Personally, I would rather use just simple "\n", but that is my opinion. I know It is not that good of a practice, but I just find it easier.
     
  14. You should still either use a language like Kotlin (a lot of work for something small) or just .replace on the string to use the line separator, thus not \n but e.g. "hi{line}there" and then call #replace("{line"}, System.lineSeparator()) on it.
     
  15. You can use this:
    Code (Text):

    player.sendMessage(ChatColor.RED + ChatColor.BOLD + "        <plugin name> Help:")
    player.sendMessage(ChatColor.RED + "/kits" + ChatColor.DARK_GRAY + " //" + ChatColor.GRAY + "Opens up the kits gui menu!");
    player.sendMessage(ChatColor.RED + "/rawr" + ChatColor.DARK_GRAY + " //" + ChatColor.GRAY + "Become a fierce dinasaur!!");
     
  16. Ohh ok, thanks for this!
     
  17. Yeh if u wanna be repetitive and boring.
     
    • Funny Funny x 1
  18. So doing this would work:
    player.sendMessage("Rawr\nRawr2")
     
  19. Yeah, it would work perfectly fine.
     
  20. Thanks. I just wanted a simple way to do it. As long as it does what it needs to, then that's fine.