コード例 #1
0
 public void RegisterCommands()
 {
     foreach (var command in Settings.Commands)
     {
         Logger.LogInfo($"[C] Registering command {command.CommandName}..");
         if (!CommandInjection.TryGetCommandMethodDelegateByTypeName(command.CommandName, out var del, out var instance))
         {
             Logger.LogError($"[C] Cannot register command {command.CommandName}. Delegate was null.");
             continue;
         }
         CommandHandler.RegisterCommand(command.Commands, del, (player, apiCommand) =>
         {
             if (command.Disabled)
             {
                 player.TS("command_disabled", command.CommandName);
                 return(false);
             }
             if (!player.GetExtendedPlayer().EnabledBypass)
             {
                 if (!command.AllowWhileDead && player.IsDead)
                 {
                     player.TS("command_failed_crimes", command.CommandName);
                     return(false);
                 }
                 if (!command.AllowWhileKO && player.IsKnockedOut)
                 {
                     player.TS("command_failed_crimes", command.CommandName);
                     return(false);
                 }
                 if (!command.AllowWhileCuffed && player.IsRestrained)
                 {
                     player.TS("command_failed_cuffed", command.CommandName);
                     return(false);
                 }
                 if (!command.AllowWhileJailed && player.job is Prisoner)
                 {
                     player.TS("command_failed_jail", command.CommandName);
                     return(false);
                 }
                 if (!command.AllowWithCrimes && player.wantedLevel != 0)
                 {
                     player.TS("command_failed_crimes", command.CommandName);
                     return(false);
                 }
             }
             return(true);
         }, command.CommandName);
     }
 }
コード例 #2
0
 public void RegisterCommands()
 {
     foreach (var command in Settings.Commands)
     {
         Logger.LogInfo($"[C] Registering command {command.CommandName}..");
         if (!CommandInjection.TryGetCommandMethodDelegateByTypeName(command.CommandName, out var del, out var instance))
         {
             Logger.LogError($"[C] Cannot register command {command.CommandName}. Delegate was null.");
             continue;
         }
         CommandHandler.RemoveCommand(command.CommandName);
         CommandHandler.RegisterCommand(command.CommandName, command.Commands, del, (player, apiCommand) =>
         {
             if (command.Disabled)
             {
                 player.SendChatMessage("Command disabled");
                 return(false);
             }
             // TODO: implement allowwhileX here
             return(true);
         }, instance.LastArgSpaces);
     }
 }