[TUTORIAL] Wordwrapping long messages

Discussion in 'Resources' started by Delocaz, Oct 27, 2012.

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

    Delocaz

    Sometimes you have to send a long message using Player.sendMessage(). If you do it normally, it would be cut like this:

    Code:
    "This is a long message. This is a long message. This is a lo
    ng message. This is a long message."
    Nobody wants that, right? To prevent that, you need to wordwrap it. If we do that, it cuts like this:

    Code:
    "This is a long message. This is a long message. This is a long
    message. This is a long message."
    Much better, right?
    To do this, I have made a short function for you guys that returns a String array with the lines correctly wrapped. Since sendMessage() also takes a String array, it's as simple as just sending whatever this function returns.

    So here it is:
    Code:java
    1. public static String[] wordWrap(String s) {
    2. return ChatPaginator.wordWrap(s, ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH);
    3. }


    Hope you like it!
     
    chaseoes, p000ison, Scizzr and 2 others like this.
  2. Offline

    Icyene

    Clever.
     
    hawkfalcon likes this.
  3. Offline

    Scizzr

    Oddly, I've never had a problem where Player.sendMessage() split the string in the middle of a word. Still a cool find in case I ever have that problem! :)
     
Thread Status:
Not open for further replies.

Share This Page