mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
SPIGOT-6762: ChatPaginator.wordWrap only transfers one modifier
By: md_5 <git@md-5.net>
This commit is contained in:
parent
283a637a66
commit
e887c31580
2 changed files with 47 additions and 41 deletions
|
@ -133,17 +133,12 @@ public class ChatPaginator {
|
|||
}
|
||||
|
||||
// Iterate over the wrapped lines, applying the last color from one line to the beginning of the next
|
||||
if (lines.get(0).length() == 0 || lines.get(0).charAt(0) != ChatColor.COLOR_CHAR) {
|
||||
lines.set(0, ChatColor.WHITE + lines.get(0));
|
||||
}
|
||||
for (int i = 1; i < lines.size(); i++) {
|
||||
final String pLine = lines.get(i - 1);
|
||||
final String subLine = lines.get(i);
|
||||
|
||||
char color = pLine.charAt(pLine.lastIndexOf(ChatColor.COLOR_CHAR) + 1);
|
||||
if (subLine.length() == 0 || subLine.charAt(0) != ChatColor.COLOR_CHAR) {
|
||||
lines.set(i, ChatColor.getByChar(color) + subLine);
|
||||
}
|
||||
String color = ChatColor.getLastColors(pLine);
|
||||
lines.set(i, color + subLine);
|
||||
}
|
||||
|
||||
return lines.toArray(new String[lines.size()]);
|
||||
|
|
|
@ -22,8 +22,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 22);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[0], is("123456789 123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -33,8 +33,8 @@ public class ChatPaginatorTest {
|
|||
|
||||
assertThat(lines.length, is(3));
|
||||
assertThat(lines[0], is(ChatColor.RED + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + ChatColor.RED + "123456789"));
|
||||
assertThat(lines[2], is(ChatColor.RED + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + ChatColor.RED + ChatColor.RED + "123456789"));
|
||||
assertThat(lines[2], is(ChatColor.RED.toString() + ChatColor.RED + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -43,8 +43,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 12345"));
|
||||
assertThat(lines[0], is("123456789 123456789"));
|
||||
assertThat(lines[1], is("123456789 12345"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,8 +53,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789 123456789"));
|
||||
assertThat(lines[0], is("123456789"));
|
||||
assertThat(lines[1], is("123456789 123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -63,8 +63,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[0], is("12345678 23456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,8 +73,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "12345678 23456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[0], is("12345678 23456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,12 +83,12 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 6);
|
||||
|
||||
assertThat(lines.length, is(6));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[2], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[3], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[4], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[5], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[0], is("123456"));
|
||||
assertThat(lines[1], is("789"));
|
||||
assertThat(lines[2], is("123456"));
|
||||
assertThat(lines[3], is("789"));
|
||||
assertThat(lines[4], is("123456"));
|
||||
assertThat(lines[5], is("789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -97,13 +97,13 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 6);
|
||||
|
||||
assertThat(lines.length, is(7));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "1234"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[2], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[3], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[4], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[5], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(lines[6], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(lines[0], is("1234"));
|
||||
assertThat(lines[1], is("123456"));
|
||||
assertThat(lines[2], is("789"));
|
||||
assertThat(lines[3], is("123456"));
|
||||
assertThat(lines[4], is("789"));
|
||||
assertThat(lines[5], is("123456"));
|
||||
assertThat(lines[6], is("789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -112,8 +112,8 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 19);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123456789"));
|
||||
assertThat(lines[0], is("123456789"));
|
||||
assertThat(lines[1], is("123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,8 +131,19 @@ public class ChatPaginatorTest {
|
|||
String[] lines = ChatPaginator.wordWrap(rawString, 5);
|
||||
|
||||
assertThat(lines.length, is(2));
|
||||
assertThat(lines[0], is(ChatColor.WHITE.toString() + "123 1"));
|
||||
assertThat(lines[1], is(ChatColor.WHITE.toString() + "123"));
|
||||
assertThat(lines[0], is("123 1"));
|
||||
assertThat(lines[1], is("123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWordWrap13() {
|
||||
String rawString = ChatColor.RED + "123456789 " + ChatColor.RED + ChatColor.BOLD + "123456789 " + ChatColor.RED + "123456789";
|
||||
String[] lines = ChatPaginator.wordWrap(rawString, 16);
|
||||
|
||||
assertThat(lines.length, is(3));
|
||||
assertThat(lines[0], is(ChatColor.RED + "123456789"));
|
||||
assertThat(lines[1], is(ChatColor.RED.toString() + ChatColor.RED + ChatColor.BOLD + "123456789"));
|
||||
assertThat(lines[2], is(ChatColor.RED.toString() + ChatColor.BOLD + ChatColor.RED + "123456789"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -143,8 +154,8 @@ public class ChatPaginatorTest {
|
|||
assertThat(page.getPageNumber(), is(1));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(2));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "1234"));
|
||||
assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(page.getLines()[0], is("1234"));
|
||||
assertThat(page.getLines()[1], is("123456"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -155,8 +166,8 @@ public class ChatPaginatorTest {
|
|||
assertThat(page.getPageNumber(), is(2));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(2));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(page.getLines()[1], is(ChatColor.WHITE.toString() + "123456"));
|
||||
assertThat(page.getLines()[0], is("789"));
|
||||
assertThat(page.getLines()[1], is("123456"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,6 +178,6 @@ public class ChatPaginatorTest {
|
|||
assertThat(page.getPageNumber(), is(4));
|
||||
assertThat(page.getTotalPages(), is(4));
|
||||
assertThat(page.getLines().length, is(1));
|
||||
assertThat(page.getLines()[0], is(ChatColor.WHITE.toString() + "789"));
|
||||
assertThat(page.getLines()[0], is("789"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue