Пример #1
0
        public override void OnLoad()
        {
            var uconomyPlugin   = R.Plugins.GetPlugins().FirstOrDefault(c => c.Name.EqualsIgnoreCase("uconomy"));
            var uconomyType     = uconomyPlugin.GetType().Assembly.GetType("fr34kyn01535.Uconomy.Uconomy");
            var uconomyInstance = uconomyType.GetField("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(uconomyPlugin);

            var databaseInstance = uconomyInstance.GetType().GetField("Database").GetValue(uconomyInstance);

            _getBalanceMethod      = AccessorFactory.AccessMethod <decimal>(databaseInstance, "GetBalance");
            _increaseBalanceMethod = AccessorFactory.AccessMethod <decimal>(databaseInstance, "IncreaseBalance");
        }
Пример #2
0
 private void UnregisterWhere(Func <CommandAdapter, bool> predicate)
 {
     _rocketCommands.RemoveAll(cmd => {
         if (cmd.Command is CommandAdapter && predicate((CommandAdapter)cmd.Command))
         {
             var command = ((CommandAdapter)cmd.Command).Command;
             if (command  is EssCommand)
             {
                 AccessorFactory.AccessMethod <EssCommand>(command, "OnUnregistered").Invoke();
             }
             return(true);
         }
         return(false);
     });
 }
Пример #3
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)));
            }
        }