Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import gg.auroramc.aurora.api.util.NamespacedId;
import gg.auroramc.collections.AuroraCollections;
import gg.auroramc.collections.api.event.CollectionLevelUpEvent;
import gg.auroramc.collections.config.CollectionConfig;
import gg.auroramc.collections.hooks.HookManager;
import gg.auroramc.collections.hooks.worldguard.WorldGuardHook;
import gg.auroramc.collections.listener.BlockBreakListener;
Expand All @@ -40,6 +41,10 @@
import java.util.concurrent.CompletableFuture;

public class CollectionManager implements Listener {
private static final Comparator<Map.Entry<String, CollectionConfig>> COLLECTION_ID_COMPARATOR =
Comparator.<Map.Entry<String, CollectionConfig>>comparingInt(entry -> extractLeadingNumber(entry.getKey()))
.thenComparing(Map.Entry::getKey, String.CASE_INSENSITIVE_ORDER);

private final AuroraCollections plugin;
private final Map<String, Map<String, Collection>> categories = Maps.newConcurrentMap();
@Getter
Expand Down Expand Up @@ -160,7 +165,7 @@ public void reloadCollections() {
var config = plugin.getConfigManager().getCollections();
for (var category : config.entrySet()) {
var categoryMap = Maps.<String, Collection>newLinkedHashMap();
for (var collection : category.getValue().entrySet().stream().sorted(Map.Entry.comparingByKey()).toList()) {
for (var collection : category.getValue().entrySet().stream().sorted(COLLECTION_ID_COMPARATOR).toList()) {
categoryMap.put(collection.getKey(), new Collection(plugin, collection.getValue(), category.getKey(), collection.getKey()));
}
categories.put(category.getKey(), categoryMap);
Expand All @@ -174,6 +179,23 @@ public void reloadCollections() {
}
}

private static int extractLeadingNumber(String id) {
int end = 0;
while (end < id.length() && Character.isDigit(id.charAt(end))) {
end++;
}

if (end == 0) {
return Integer.MAX_VALUE;
}

try {
return Integer.parseInt(id.substring(0, end));
} catch (NumberFormatException ignored) {
return Integer.MAX_VALUE;
}
}

@EventHandler
public void onUserLoaded(AuroraUserLoadedEvent e) {
CompletableFuture.runAsync(() -> rewardAutoCorrector.correctRewards(e.getUser().getPlayer()));
Expand Down