forked from ScriptedEvents/ScriptedEvents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerCollection.cs
More file actions
91 lines (77 loc) · 2.7 KB
/
PlayerCollection.cs
File metadata and controls
91 lines (77 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace ScriptedEvents.Structures
{
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Exiled.API.Features;
/// <summary>
/// Indicates a read-only collection of players.
/// </summary>
public class PlayerCollection : IEnumerable<Player>
{
private readonly List<Player> players;
/// <summary>
/// Initializes a new instance of the <see cref="PlayerCollection"/> class.
/// </summary>
/// <param name="newPlayers">The list of players.</param>
/// <param name="success">Whether or not the player retrieval was successful.</param>
/// <param name="message">The error message, if <paramref name="success"/> is <see langword="false"/>.</param>
public PlayerCollection(List<Player> newPlayers, bool success = true, string message = "")
{
players = newPlayers ?? new();
Success = success;
Message = message;
}
public PlayerCollection()
{
players = new();
Success = true;
Message = string.Empty;
}
/// <summary>
/// Gets the length of the collection.
/// </summary>
public int Length => players.Count();
/// <summary>
/// Gets a value indicating whether or not the player retrieval was successful.
/// </summary>
public bool Success { get; }
/// <summary>
/// Gets the error message, if <see cref="Success"/> is <see langword="false"/>.
/// </summary>
public string Message { get; }
/// <summary>
/// Gets a player at a specific index in the list.
/// </summary>
/// <param name="index">The index.</param>
/// <returns>The player.</returns>
public Player this[int index]
=> players[index];
/// <inheritdoc/>
public IEnumerator<Player> GetEnumerator()
{
return players.GetEnumerator();
}
/// <inheritdoc/>
IEnumerator IEnumerable.GetEnumerator()
{
return players.GetEnumerator();
}
/// <summary>
/// Returns the internal list of players.
/// </summary>
/// <returns>A list of players.</returns>
public List<Player> GetInnerList()
{
return players;
}
/// <summary>
/// Returns the internal array of players.
/// </summary>
/// <returns>An array of players.</returns>
public Player[] GetArray()
{
return GetInnerList().ToArray();
}
}
}