(Free Code) Sending Perfectly Centered Chat Message

Discussion in 'Spigot Plugin Development' started by SirSpoodles, Oct 5, 2015.

  1. Font Info Enumeration: http://pastebin.com/9Be2DF2z
    Method to send: http://pastebin.com/BADd6K43

    Many just recommend using a StringUtils.center(string, int) or StringUtils.leftPad(string, int). But it didn't cut it to center messages perfectly, there was always something off due to character lengths and bold / multi colored text. So, after some thought, I figured mapping out the font length's was the best option to make this work well.

    And of course, client texturepacks, and chat settings are a competitor for this, but what are you going to do?

    Feel free too use the code, I like to share these types of things on the forum. <3

    #1 SirSpoodles, Oct 5, 2015
    Last edited: Oct 11, 2015
    • Useful x 104
    • Like x 19
    • Winner x 14
    • Agree x 3
    • Informative x 2
    • Friendly x 2
    • Creative x 2
  2. Great method! I haven't tested it yet, but it seems you have definitely put work into it and will work!
  3. Genuinely useful for default texts, but could use better calculations around different chat widths and bold text (I'm not certain it's always length + 1).
  4. Beautifully forged method, thank you very much for the code share!
    • Friendly Friendly x 1
  5. At least for every character in the enum, it is always length + 1. While it isn't perfect, this works a hell of a lot better than StringUtils.leftPad(), which was the objective.

    Hey I appreciate that good sir!

    Thank you :)
    • Friendly Friendly x 1
  6. Thanks! I've been needing something like this! It will come in handy!
  7. Thank you! This will come in handy!
  8. joshwenke

    Wiki Team

    This is really awesome. I'm going to switch all my hardcoded centered messages to this. So much easier!
  9. I'm actually going to post an update on this method since so many were interested. I wanted to make it so if the string is longer than 1 line, it'll also center the second line itself rather than just break everything. So, I'm going to go and do that tonight and post it here for those who want it.
    • Friendly Friendly x 3
    • Like Like x 2
    • Agree Agree x 1
    • Winner Winner x 1
  10. Perfect thanks <3
    • Agree Agree x 2
  11. damn dude. gg. 10/10
    • Funny Funny x 2
  12. I will have to try this on my small screen, as i have the chat size altered really curious to see if it changes to different chat sizes :D
  13. This will scale with different chat sizes, but if you change the length of the chatbox it will not scale.
  14. So, here's the updated code that will center text longer than 1 line. But personally, I would just stick with the first method. There are too many variables involved here that can break it. Like if the last word is longer than 10 or so characters it can break and move to the next line anyways.

    Although it does work fine most of the time, but the method at this point is getting long and unorganized just to send a chat message.

    Updated method: http://hastebin.com/uziyajirag.avrasm

    • Useful Useful x 1
  15. That is so awesome bro love you <3 Great method!!!!!! ^-^
  16. Awesome method! Thanks for sharing it with the community =D
  17. Thanks, I will try this out tomorrow :)
  18. eqx


    How do you use it? could you add a GitHub?
    • Agree Agree x 1
  19. Thanks a lot for sharing this :D
  20. How many characters can one line hold before it goes to the next one? Is it 57 or 58 characters?

Share This Page