Skip to content

Commit

Permalink
Fix issues with extras and replacer
Browse files Browse the repository at this point in the history
- Fixes a potential NPE when no extra is set but colors are included in replacements
- Fixes that extras get replaced twice if colors are included in replacements
  • Loading branch information
Phoenix616 committed Jan 16, 2022
1 parent 2decc97 commit 0208f75
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/de/themoep/minedown/Replacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,18 @@ public BaseComponent[] replaceIn(List<BaseComponent> components) {
((TextComponent) component).setText("");
List<BaseComponent> extra = new ArrayList<>();
Collections.addAll(extra, replacedComponent);
extra.addAll(component.getExtra());
if (component.getExtra() != null) {
Collections.addAll(extra, replaceIn(component.getExtra()));
}
component.setExtra(extra);
} else {
((TextComponent) component).setText(replaced);
if (component.getExtra() != null) {
component.setExtra(Arrays.asList(replaceIn(component.getExtra())));
}
}
} else if (component.getExtra() != null) {
component.setExtra(Arrays.asList(replaceIn(component.getExtra())));
}
if (component instanceof TranslatableComponent) {
((TranslatableComponent) component).setTranslate(replaceIn(((TranslatableComponent) component).getTranslate()));
Expand Down Expand Up @@ -257,9 +264,6 @@ public BaseComponent[] replaceIn(List<BaseComponent> components) {
}
}
}
if (component.getExtra() != null) {
component.setExtra(Arrays.asList(replaceIn(component.getExtra())));
}

// Component replacements
List<BaseComponent> replacedComponents = new ArrayList<>();
Expand Down

0 comments on commit 0208f75

Please sign in to comment.