Ejemplo n.º 1
0
        private void CommandFriend(IPlayer player, string command, string[] args)
        {
            if (player.IsServer)
            {
                Message(player, "PlayersOnly", command);
                return;
            }

            if (config.UsePermissions && player.HasPermission(permUse))
            {
                Message(player, "NotAllowed", command);
                return;
            }

            if (args.Length <= 0 || args.Length == 1 && !args[0].Equals("list", StringComparison.OrdinalIgnoreCase))
            {
                Message(player, "UsageFriend", command);
                return;
            }

            switch (args[0].ToLower())
            {
                case "list":
                    string[] friendList = GetFriendList(player.Id);
                    if (friendList.Length > 0)
                    {
                        Message(player, "FriendList", $"{friendList.Length}/{config.MaxFriends}", string.Join(", ", friendList));
                    }
                    else
                    {
                        Message(player, "NoFriends");
                    }

                    return;

                case "+":
                case "add":
                    IPlayer target = FindPlayer(args[1], player);
                    if (target == null)
                    {
                        return;
                    }

                    if (player == target)
                    {
                        Message(player, "CannotAddSelf");
                        return;
                    }

                    PlayerData playerData = GetPlayerData(player.Id);
                    if (playerData.Friends.Count >= config.MaxFriends)
                    {
                        Message(player, "FriendListFull");
                        return;
                    }

                    if (playerData.Friends.Contains(target.Id))
                    {
                        Message(player, "AlreadyOnList", target.Name);
                        return;
                    }

                    AddFriend(player.Id, target.Id);
                    Message(player, "FriendAdded", target.Name);
                    return;

                case "-":
                case "remove":
                    string friend = FindFriend(args[1]);
                    if (string.IsNullOrEmpty(friend))
                    {
                        Message(player, "NotOnFriendList", args[1]);
                        return;
                    }

                    bool removed = RemoveFriend(player.Id, friend.ToString());
                    Message(player, removed ? "FriendRemoved" : "NotOnFriendList", args[1]);
                    return;
            }
        }