diff --git a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java index bf54dad..3c3dc9c 100644 --- a/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java +++ b/lib/src/main/java/net/tomatentum/marinara/registry/InteractionRegistry.java @@ -1,6 +1,7 @@ package net.tomatentum.marinara.registry; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -57,7 +58,7 @@ public class InteractionRegistry { .toList(); SlashCommandDefinition[] defs = new ObjectAggregator( - i -> (RootCommandIdentifier)i.rootNode(), + i -> Arrays.asList((RootCommandIdentifier)i.rootNode()), SlashCommandDefinition::addIdentifier, SlashCommandDefinition::new) .aggregate(slashIdentifiers) diff --git a/lib/src/main/java/net/tomatentum/marinara/util/ObjectAggregator.java b/lib/src/main/java/net/tomatentum/marinara/util/ObjectAggregator.java index e16b88a..b02488f 100644 --- a/lib/src/main/java/net/tomatentum/marinara/util/ObjectAggregator.java +++ b/lib/src/main/java/net/tomatentum/marinara/util/ObjectAggregator.java @@ -5,25 +5,40 @@ import java.util.HashMap; import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Function; +import java.util.function.Supplier; public class ObjectAggregator { - private Function keySupplier; + private Function> keySupplier; private BiConsumer valueConsumer; private Function defaultGenerator; - public ObjectAggregator(Function keySupplier, BiConsumer valueConsumer, Function defaultGenerator) { + public ObjectAggregator( + Function> keySupplier, + BiConsumer valueConsumer, + Function defaultGenerator) { this.keySupplier = keySupplier; this.valueConsumer = valueConsumer; this.defaultGenerator = defaultGenerator; } + public ObjectAggregator( + Function> keySupplier, + BiConsumer valueConsumer, + Supplier defaultGenerator) { + this.keySupplier = keySupplier; + this.valueConsumer = valueConsumer; + this.defaultGenerator = _ -> defaultGenerator.get(); + } + public Collection aggregate(Iterable iterator) { Map map = new HashMap<>(); for (O element : iterator) { - K key = this.keySupplier.apply(element); - V value = map.getOrDefault(key, this.defaultGenerator.apply(key)); - this.valueConsumer.accept(value, element); - map.putIfAbsent(key, value); + Iterable keys = this.keySupplier.apply(element); + for (K key : keys) { + V value = map.getOrDefault(key, this.defaultGenerator.apply(key)); + this.valueConsumer.accept(value, element); + map.putIfAbsent(key, value); + } } return map.values(); }