use of org.spongepowered.api.command.registrar.CommandRegistrar in project SpongeCommon by SpongePowered.
the class SpongeCommandManager method init.
public void init() {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final Set<TypeToken<?>> usedTokens = new HashSet<>();
Sponge.game().registry(RegistryTypes.COMMAND_REGISTRAR_TYPE).streamEntries().forEach(entry -> {
final CommandRegistrarType<?> type = entry.value();
// someone's gonna do it, let's not let them take us down.
final TypeToken<?> handledType = type.handledType();
if (handledType == null) {
SpongeCommon.logger().error("Registrar '{}' did not provide a handledType, skipping...", type.getClass());
} else if (usedTokens.add(handledType)) {
// we haven't done it yet
// Add the command registrar
final CommandRegistrar<?> registrar = type.create(this);
this.knownRegistrars.put(GenericTypeReflector.erase(type.handledType().getType()), registrar);
if (registrar instanceof BrigadierCommandRegistrar) {
this.brigadierRegistrar = (BrigadierCommandRegistrar) registrar;
} else if (registrar instanceof SpongeParameterizedCommandRegistrar) {
this.registerInternalCommands((SpongeParameterizedCommandRegistrar) registrar);
}
this.game.eventManager().post(this.createEvent(cause, this.game, registrar));
} else {
SpongeCommon.logger().warn("Command type '{}' has already been collected, skipping request from {}", handledType.toString(), type.getClass());
}
});
if (this.brigadierRegistrar == null) {
throw new IllegalStateException("Brigadier registrar was not detected");
}
}
Aggregations