0

What's up? I am trying to build my plugin and I am getting error when calling the method via command from the server.

  public void Rob(IRocketPlayer caller, params string[] command)
        {
            try
            {
                if (command.Length == 1)
                {
                    UnturnedPlayer Caller = (UnturnedPlayer)caller;
                    UnturnedPlayer player = UnturnedPlayer.FromName(command[0]);
                    if (!recrentRobberies.ContainsKey(player.CSteamID))
                    {
                        if (UnturnedPlayer.FromName(command[0]) == null)
                        {
                            UnturnedChat.Say(caller, "The player is offline!");
                                }
                        else
                        {
                            Rob(command[0], Caller );
                        }
                    }
                    else
                    {
                        UnturnedChat.Say(caller , "You're on cooldown! Please try again later!");
                    }
                }
                if(command.Length == 1 && command[0] == "Assist")
                {
                    UnturnedPlayer player = UnturnedPlayer.FromName(command[0]);
                    Add(player);

                }

               if(command[0] == "Stop")
                {
                    Stop();
                }
            }
            catch (Exception ex) { Logger.Log(ex); }
        }

This is the error I am getting:

[Exception] ArrestPlugin >> Exception in Rob: System.NullReferenceException: Object reference not set to an instance of an object
  at ArrestPlugin.ArrestPlugin.Rob (System.String Player, Rocket.Unturned.Player.UnturnedPlayer player) [0x00000] in <filename unknown>:0 
  at ArrestPlugin.ArrestPlugin.Rob (IRocketPlayer caller, System.String[] command) [0x00000] in <filename unknown>:0 

Please help me fixing the problem.

Roy
  • 23
  • 7
  • @KevinWallis Give me a few minutes. – Roy Mar 02 '17 at 16:04
  • You are not checking at all that the parameters are correct. If either `caller` or `command` are null, or if `command` is an empty list, you will have severe problems. Why do you repeat the `command.Length == 1` validation instead of doing it only once? And why don't you validate that for "Stop"? – Andrew Mar 02 '17 at 16:14
  • Just add `if (caller == null || command == null || command.Length < 1) return;` at the beginning and remove the other validations. – Andrew Mar 02 '17 at 16:22

0 Answers0