garbagemule / MobArena

MobArena plugin for Minecraft
GNU General Public License v3.0
195 stars 151 forks source link

Sign text length doesn't account for color/formatting codes #790

Closed EpicKnarvik97 closed 1 month ago

EpicKnarvik97 commented 5 months ago

Bug report

Short description

When I use the default text of 'players to join' for the idle sign's fourth line, the sign displays correctly. When I add a color code so it becomes: '&fplayers to join', the last two letters in join are cut off, even though the displayed text will have the same length, and should not overflow the sign.

Reproduction steps

  1. Open signs.yml
  2. Add &f to info-idle's fourth line
  3. Make an info sign for an arena
  4. Observe that it says "players to jo" on the fourth line.

I tested with a custom plugin. It's not that Minecraft cuts off the text. The last two characters don't exist on the sign. Therefore, I believe some limit internally in MobArena cuts off text that would overflow a sign. It does, however, not account for color/formatting codes not actually taking any additional space (except for bold, perhaps).

The behavior seems to be the same with both color and formatting codes. It doesn't matter whether one uses '§' or '&'.

Details

Additional info

image image

garbagemule commented 1 month ago

Sorry for missing this issue.

There is indeed some truncation happening in MobArena, specifically right here in the sign rendering procedure. I'm pretty sure there is a reason for this truncation, most likely something to do with errors thrown by the API or the server itself when the length exceeds 15 characters. I'll take a look at it and see if it breaks anything to just omit it entirely, but there is a chance that it's just the visible characters that need to be truncated, in which case we may need to implement a custom truncation that doesn't count color codes as part of the string length. I feel like this is something the Bukkit API should handle for us somehow - it seems pretty whack that every plugin that renders stuff on signs would have to implement this kind of "low-level counting logic" for something so common.

garbagemule commented 1 month ago

Okay, it looks like we don't get any errors if we try to set sign text that's longer than what the server accepts, but instead, the server itself just truncates the line on a word basis, meaning it will render each word if it fits, and as soon as a word no longer fits on a line, it just stops rendering them all-together. Or at least kind of. If the line is just a single word that's too long to render, it truncates on character basis instead.

Here are some examples of what I tried and the results I got after removing the truncation in MobArena. The first block is the template used, and the second block is the result as shown on the sign in-game.

I will remove the truncation as it appears to be unnecessary, but I'll just run a quick test on older versions as well. This was on Paper 1.21. Edit: No errors on Paper 1.13.2 either. I think we're in the clear.


Test 1

- 'Waiting for players to join'
Waiting for             (words truncated despite more room on line)

Test 2

- 'Waitingforplayerstojoin'
Waitingforplayers       (some characters rendered, rest truncated)

Test 3

- '&eWaitingforplayerstojoin'
Waitingforplayers       (same as test 2, but yellow text)

Test 3

- '&aW&ba&ci&dt&ei&fngforplayerstojoin'
Waitingforplayers       (same as tests 2 and 3, but color vomit at first)

Test 4

- '&fWaiting for'
- '&fplayers to join'
  Waiting for           (white)
players to join         (white, not truncated)

Test 5

- '&a<arena-name>'
- '&c---------------'
- '&fWaiting for'
- '&fplayers to join'
      a1                (green)
---------------         (red)
  Waiting for           (white)
players to join         (white, not truncated)