Skip to content

Commit f7bf715

Browse files
improved the ComponentCollector
1 parent 480d628 commit f7bf715

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

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

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

6-
import java.util.Objects;
76
import java.util.Set;
87
import java.util.function.BiConsumer;
98
import java.util.function.BinaryOperator;
@@ -25,33 +24,25 @@ public ComponentCollector(@NotNull Component separator) {
2524

2625
@Override
2726
public @NotNull Supplier<Component[]> supplier() {
28-
return () -> new Component[1];
27+
return () -> new Component[] {Component.empty()};
2928
}
3029

3130
@Override
3231
public @NotNull BiConsumer<Component[], Component> accumulator() {
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-
};
32+
return (array, component) -> array[0] = array[0].append(separator).append(component);
3933
}
4034

4135
@Override
4236
public @NotNull BinaryOperator<Component[]> combiner() {
4337
return (left, right) -> {
44-
if (left[0] == null)
45-
left[0] = right[0];
46-
else
47-
left[0] = left[0].append(separator).append(right[0]);
38+
left[0] = left[0].append(separator).append(right[0]);
4839
return left;
4940
};
5041
}
5142

5243
@Override
5344
public @NotNull Function<Component[], Component> finisher() {
54-
return array -> Objects.requireNonNullElseGet(array[0], Component::empty);
45+
return array -> array[0];
5546
}
5647

5748
@Override

0 commit comments

Comments
 (0)