Skip to content

Commit

Permalink
use immutable list for color
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 3, 2024
1 parent 20fa19e commit 1217f4e
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/main/java/me/xginko/snowballfight/SnowballConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.xginko.snowballfight;

import com.google.common.collect.ImmutableList;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -55,23 +56,24 @@ public final class SnowballConfig {
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (colors.isEmpty()) {
colors.addAll(defaults.stream()
.map(string -> {
try {
return Color.fromRGB(
Integer.parseInt(string.substring(0, 2), 16),
Integer.parseInt(string.substring(2, 4), 16),
Integer.parseInt(string.substring(4, 6), 16));
} catch (Exception e) {
return Color.WHITE;
}
})
.distinct()
.collect(Collectors.toList()));
}

.collect(Collectors.collectingAndThen(Collectors.toList(), collected -> {
if (collected.isEmpty()) {
collected.addAll(defaults.stream()
.map(string -> {
try {
return Color.fromRGB(
Integer.parseInt(string.substring(0, 2), 16),
Integer.parseInt(string.substring(2, 4), 16),
Integer.parseInt(string.substring(4, 6), 16));
} catch (Exception e) {
return Color.WHITE;
}
})
.distinct()
.collect(Collectors.toList()));
}
return ImmutableList.copyOf(collected);
}));
structure();
}

Expand Down

0 comments on commit 1217f4e

Please sign in to comment.