Пример #1
0
        public void Register([NotNull] ICommand command)
        {
            Preconditions.NotNull(command.Name, "Command 'Name' cannot be null");

            var name = command.Name.ToLowerInvariant();

            if (CommandMap.ContainsKey(name))
            {
                UEssentials.Logger.LogError(
                    $"Could not register '{command.GetType().Name}' because there is already a command called '{name}'");
                return;
            }

            var configCommands = EssCore.Instance.CommandsConfig.Commands;

            if (configCommands.ContainsKey(command.Name))
            {
                var cmdEntry = configCommands[command.Name];

                command.Aliases = cmdEntry.Aliases ?? new string[0];

                if (cmdEntry.Description != null)
                {
                    command.Description = cmdEntry.Description;
                }
                if (cmdEntry.Usage != null)
                {
                    command.Usage = cmdEntry.Usage;
                }
            }

            var adapter = new CommandAdapter(command);

            _rocketCommands.Add(new RocketCommandManager.RegisteredRocketCommand(name, adapter));
            CommandMap.Add(name.ToLowerInvariant(), command);

            if (command is EssCommand)
            {
                _onRegisteredMethod?.Invoke(command, ReflectionUtil.EMPTY_ARGS);
            }

            var aliases = command.Aliases;

            if (aliases == null || aliases.Length == 0)
            {
                return;
            }

            foreach (var alias in aliases)
            {
                _rocketCommands.Add(new RocketCommandManager.RegisteredRocketCommand(
                                        alias.ToLowerInvariant(), new CommandAdapter.CommandAliasAdapter(command, alias)));
            }
        }
Пример #2
0
        public void Register(ICommand command)
        {
            Preconditions.NotNull(command, "Command cannot be null");
            Preconditions.NotNull(command.Name, "Command name cannot be null");

            var name = command.Name.ToLowerInvariant();

            if (CommandMap.ContainsKey(name))
            {
                UEssentials.Logger.LogError($"Could not register '{command.GetType().Name}' because there is already a command called '{name}'");
                return;
            }

            var configCommands = EssCore.Instance.CommandsConfig.Commands;

            if (configCommands.ContainsKey(command.Name))
            {
                command.Aliases = configCommands[command.Name].Aliases ?? new string[0];
            }

            var adapter = new CommandAdapter(command);

            _rocketCommands.Add(new RocketCommandManager.RegisteredRocketCommand(name, adapter));
            CommandMap.Add(name, command);

            if (command is EssCommand)
            {
                AccessorFactory.AccessMethod <EssCommand>(command, "OnRegistered").Invoke();
            }

            var aliases = command.Aliases;

            if (aliases == null || aliases.Length == 0)
            {
                return;
            }

            foreach (var alias in aliases)
            {
                _rocketCommands.Add(new RocketCommandManager.RegisteredRocketCommand(
                                        alias.ToLowerInvariant(), new CommandAdapter.CommandAliasAdapter(command, alias)));
            }
        }