Skip to content

Registration

Axwabo edited this page Apr 27, 2025 · 1 revision

Registering Commands & Options

The Axwabo.CommandSystem.Registration.CommandRegistrationProcessor takes care of registering commands and RA options.

To register everything in the current assembly, use one of the RegisterAll method overloads:

  • RegisterAll(object) calls the Type overload with the type of the object
    • Common pattern: CommandRegistrationProcessor.RegisterAll(this)
  • RegisterAll(Type) determines the assembly and resolver attributes based on the type
  • RegisterAll(Assembly) does not locate resolver attributes

Important

When your plugin is being disabled, make sure to call UnregisterAll

Granular Control

Begin by creating a processor instance using one of the Create method overloads. At this time, the processor only stores the target assembly with no types configured.

The Axwabo.CommandSystem.Registration.RegistrationExtensions class contains extension methods to configure the processor.

To add a type, call the processor's AddType method. Alternatively, the WithType and WithTypes extension methods can be used to add types to a processor.

Important

When manually adding a type, make sure it is a class and is not abstract. The type must be from the same assembly as the one used to create the processor.

The WithTypesFromOriginalAssembly extension method adds all applicable types from the processor's target assembly.

Calling the Execute method will perform registration of the specified types.

Tip

You can chain calls as each extension method returns the processor itself.

CommandRegistrationProcessor.Create(this)
    .WithTypesFromOriginalAssembly()
    .WithRegistrationAttributesFrom(GetType())
    .WithNameResolver(new CustomCommandNameResolver())
    .Execute(); // Execute does not return anything

Resolvers

Adding resolver attributes is easy with the use of the WithRegistrationAttributesFrom extension method. It takes the type which is annotated with resolver attributes and adds each applicable attribute.

Various extension methods exist to add a specific resolver to a CommandRegistrationProcessor - these allow full customizability over what resolvers are added.

The WithMultiplexResolverObject extension adds every resolver an object implements.

Caution

The parameter named type or the generic T parameter must implement the generic resolver interface. If the concrete type of the resolver is not known, call the non-generic method with the type obtained using GetType()

Extension method name Parameter type
WithNameResolver ICommandNameResolver
WithDescriptionResolver ICommandDescriptionResolver
WithAliasResolver ICommandAliasResolver
WithUsageResolver ICommandUsageResolver
WithPlayerOnlyResolver IPlayerOnlyResolver
WithPermissionResolver IAttributeBasedPermissionResolver
WithTargetingAffectedMultipleResolver IAffectedMultiplePlayersResolver
WithTargetingAffectedOneResolver IAffectedOnePlayerResolver
WithTargetingAffectedAllResolver IAffectedAllPlayersResolver
WithTargetingSelectionResolver ITargetSelectionResolver
WithTargetingCustomResultCompilerResolver IResultCompilerResolver
WithRemoteAdminOptionIdResolver IRemoteAdminOptionIdResolver
WithRemoteAdminOptionTextResolver IStaticOptionTextResolver
WithRemoteAdminOptionIconResolver IOptionIconResolver

Tip

Resolvers may access the RegisteringCommandType property to determine which command or option is being processed. The current CommandRegistrationProcessor is accessible via the Current static property.

Clone this wiki locally