Search in sources :

Example 1 with SpongeParameterizedCommandRegistrar

use of org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar 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");
    }
}
Also used : BrigadierCommandRegistrar(org.spongepowered.common.command.registrar.BrigadierCommandRegistrar) SpongeParameterizedCommandRegistrar(org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar) TypeToken(io.leangen.geantyref.TypeToken) Cause(org.spongepowered.api.event.Cause) CommandCause(org.spongepowered.api.command.CommandCause) SpongeParameterizedCommandRegistrar(org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar) CommandRegistrar(org.spongepowered.api.command.registrar.CommandRegistrar) BrigadierCommandRegistrar(org.spongepowered.common.command.registrar.BrigadierCommandRegistrar) HashSet(java.util.HashSet)

Aggregations

TypeToken (io.leangen.geantyref.TypeToken)1 HashSet (java.util.HashSet)1 CommandCause (org.spongepowered.api.command.CommandCause)1 CommandRegistrar (org.spongepowered.api.command.registrar.CommandRegistrar)1 Cause (org.spongepowered.api.event.Cause)1 BrigadierCommandRegistrar (org.spongepowered.common.command.registrar.BrigadierCommandRegistrar)1 SpongeParameterizedCommandRegistrar (org.spongepowered.common.command.registrar.SpongeParameterizedCommandRegistrar)1