Fix case when the second section goes further when combining
And added a test for it
This commit is contained in:
parent
43525bd93c
commit
e4b47efd3f
3 changed files with 13 additions and 8 deletions
2
pom.xml
2
pom.xml
|
@ -213,7 +213,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.palmergames.bukkit.towny</groupId>
|
<groupId>com.palmergames.bukkit.towny</groupId>
|
||||||
<artifactId>Towny</artifactId>
|
<artifactId>Towny</artifactId>
|
||||||
<version>0.95.2.0</version>
|
<version>0.96.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
<!-- <dependency> <groupId>au.com.mineauz</groupId> <artifactId>Minigames</artifactId>
|
||||||
|
|
|
@ -120,22 +120,25 @@ public final class ChatFormatter {
|
||||||
sortSections(sections);
|
sortSections(sections);
|
||||||
continue;
|
continue;
|
||||||
} else if (firstSection.End >= lastSection.Start && firstSection.Start <= lastSection.End) {
|
} else if (firstSection.End >= lastSection.Start && firstSection.Start <= lastSection.End) {
|
||||||
int firstSectEnd = firstSection.End;
|
int middleStart = lastSection.Start;
|
||||||
firstSection.End = lastSection.Start - 1;
|
// |----|-- |------|
|
||||||
int lastSectEnd = lastSection.End;
|
// --|----| -|----|-
|
||||||
FormattedSection section = new FormattedSection(firstSection.Settings, lastSection.Start, lastSectEnd,
|
int middleEnd = Math.min(lastSection.End, firstSection.End);
|
||||||
|
int lastSectEnd = Math.max(lastSection.End, firstSection.End);
|
||||||
|
FormattedSection section = new FormattedSection(firstSection.Settings, middleStart, middleEnd,
|
||||||
firstSection.Matches);
|
firstSection.Matches);
|
||||||
section.Settings.copyFrom(lastSection.Settings);
|
section.Settings.copyFrom(lastSection.Settings);
|
||||||
section.Matches.addAll(lastSection.Matches);
|
section.Matches.addAll(lastSection.Matches);
|
||||||
sections.add(i, section);
|
sections.add(i, section);
|
||||||
|
|
||||||
if (firstSectEnd > lastSection.End) { //Copy first section info to last as the lastSection initially cuts the firstSection in half
|
if (firstSection.End > lastSection.End) { //Copy first section info to last as the lastSection initially cuts the firstSection in half
|
||||||
lastSection.Settings = FormatSettings.builder().build();
|
lastSection.Settings = FormatSettings.builder().build();
|
||||||
lastSection.Settings.copyFrom(firstSection.Settings);
|
lastSection.Settings.copyFrom(firstSection.Settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSection.Start = lastSectEnd + 1;
|
firstSection.End = middleStart - 1;
|
||||||
lastSection.End = firstSectEnd;
|
lastSection.Start = middleEnd + 1;
|
||||||
|
lastSection.End = lastSectEnd;
|
||||||
|
|
||||||
Predicate<FormattedSection> removeIfNeeded = s -> {
|
Predicate<FormattedSection> removeIfNeeded = s -> {
|
||||||
if (s.Start < 0 || s.End < 0 || s.Start > s.End) {
|
if (s.Start < 0 || s.End < 0 || s.Start > s.End) {
|
||||||
|
|
|
@ -85,6 +85,8 @@ public class ChatFormatIT {
|
||||||
space, new TellrawPart("rainbow").setColor(Color.Gold), space, new TellrawPart("text").setColor(Color.Yellow),
|
space, new TellrawPart("rainbow").setColor(Color.Gold), space, new TellrawPart("text").setColor(Color.Yellow),
|
||||||
space, new TellrawPart("for").setColor(Color.Green), space, new TellrawPart("testing.").setColor(Color.Blue),
|
space, new TellrawPart("for").setColor(Color.Green), space, new TellrawPart("testing.").setColor(Color.Blue),
|
||||||
space, new TellrawPart("O").setColor(Color.DarkPurple)).setRainbowMode());
|
space, new TellrawPart("O").setColor(Color.DarkPurple)).setRainbowMode());
|
||||||
|
list.add(new ChatFormatIT(sender, "***test*** test", new TellrawPart("test").setColor(Color.White)
|
||||||
|
.setItalic(true).setBold(true), new TellrawPart(" test").setColor(Color.White)));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue