Skip to content

Commit 082cb8f

Browse files
Revert "improved the ComponentCollector"
This reverts commit f7bf715.
1 parent 9a25d99 commit 082cb8f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/collector/ComponentCollector.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.text.Component;
44
import org.jetbrains.annotations.NotNull;
55

6+
import java.util.Objects;
67
import java.util.Set;
78
import java.util.function.BiConsumer;
89
import java.util.function.BinaryOperator;
@@ -24,25 +25,33 @@ public ComponentCollector(@NotNull Component separator) {
2425

2526
@Override
2627
public @NotNull Supplier<Component[]> supplier() {
27-
return () -> new Component[] {Component.empty()};
28+
return () -> new Component[1];
2829
}
2930

3031
@Override
3132
public @NotNull BiConsumer<Component[], Component> accumulator() {
32-
return (array, component) -> array[0] = array[0].append(separator).append(component);
33+
return (array, component) -> {
34+
if (array[0] == null)
35+
array[0] = component;
36+
else
37+
array[0] = array[0].append(separator).append(component);
38+
};
3339
}
3440

3541
@Override
3642
public @NotNull BinaryOperator<Component[]> combiner() {
3743
return (left, right) -> {
38-
left[0] = left[0].append(separator).append(right[0]);
44+
if (left[0] == null)
45+
left[0] = right[0];
46+
else
47+
left[0] = left[0].append(separator).append(right[0]);
3948
return left;
4049
};
4150
}
4251

4352
@Override
4453
public @NotNull Function<Component[], Component> finisher() {
45-
return array -> array[0];
54+
return array -> Objects.requireNonNullElseGet(array[0], Component::empty);
4655
}
4756

4857
@Override

0 commit comments

Comments
 (0)