Skip to content

Commit 0600258

Browse files
Create ClearPlayerDataMethod.cs
1 parent d0d1255 commit 0600258

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using SER.ArgumentSystem.Arguments;
2+
using SER.ArgumentSystem.BaseArguments;
3+
using SER.MethodSystem.BaseMethods;
4+
using SER.ValueSystem;
5+
6+
namespace SER.MethodSystem.Methods.PlayerDataMethods;
7+
8+
public class ClearPlayerDataMethod : SynchronousMethod
9+
{
10+
public override string? Description => "Clears data associated with specified players";
11+
12+
public override Argument[] ExpectedArguments =>
13+
[
14+
new PlayersArgument("players"),
15+
new TextArgument("key to clear")
16+
{
17+
DefaultValue = new(string.Empty, "all keys"),
18+
Description = "Don't provide this argument to clear all keys for players, provide if you want to clear specific key"
19+
}
20+
];
21+
22+
public override void Execute()
23+
{
24+
var players = Args.GetPlayers("players");
25+
var key = Args.GetText("key to clear");
26+
27+
var func = key.IsEmpty()
28+
? (Action<Dictionary<string, Value>>)(dict => dict.Clear())
29+
: dict => dict.Remove(key);
30+
31+
players.ForEach(p =>
32+
{
33+
if (SetPlayerDataMethod.PlayerData.TryGetValue(p, out var dict))
34+
{
35+
func(dict);
36+
}
37+
});
38+
}
39+
}

0 commit comments

Comments
 (0)