Skip to content

Commit d289655

Browse files
Merge pull request #15 from Tosoks67/main
3 fixes, 1 new method
2 parents 6ace061 + e79bc7d commit d289655

File tree

10 files changed

+39
-22
lines changed

10 files changed

+39
-22
lines changed

ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class ForeachLoopContext : LoopContext
2424

2525
public override string KeywordName => "foreach";
2626
public override string Description =>
27-
"Repeats its body for each player in the player variable, assigning it its own custom variable.";
27+
"Repeats its body for each player in the player variable or a value in a collection variable, " +
28+
"assigning it its own custom variable.";
2829
public override string[] Arguments => ["[variable to assign the item]", "in", "[player/collection variable]"];
2930

3031
public override Dictionary<IExtendableStatement.Signal, Func<IEnumerator<float>>> RegisteredSignals { get; } = new();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.CollectionVariableMethods;
7+
8+
public class CollectionContainsMethod : ReturningMethod<BoolValue>
9+
{
10+
public override string Description => "Returns true if the value exists in the collection";
11+
12+
public override Argument[] ExpectedArguments { get; } =
13+
[
14+
new CollectionArgument("collection"),
15+
new AnyValueArgument("value to check")
16+
];
17+
18+
public override void Execute()
19+
{
20+
var collection = Args.GetCollection("collection");
21+
var value = Args.GetAnyValue("value to check");
22+
ReturnValue = new(collection.Contains(value));
23+
}
24+
}

Plugin/Commands/HelpSystem/DocsCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Text;
22
using CommandSystem;
33
using LabApi.Features.Permissions;
4-
using LabApi.Features.Wrappers;
54
using SER.Helpers.Exceptions;
65
using SER.Plugin.Commands.Interfaces;
76

@@ -13,8 +12,7 @@ public class DocsCommand : ICommand, IUsePermissions
1312
{
1413
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1514
{
16-
var player = Player.Get(sender);
17-
if (player is not null && player.HasPermissions(Permission))
15+
if (!sender.HasPermissions(Permission))
1816
{
1917
response = "You do not have permission to create documentation.";
2018
return false;

Plugin/Commands/MethodCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.Plugin.Commands.Interfaces;
54
using SER.ScriptSystem;
65
using SER.ScriptSystem.Structures;
@@ -15,8 +14,7 @@ public class MethodCommand : ICommand, IUsePermissions
1514

1615
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1716
{
18-
var player = Player.Get(sender);
19-
if (player is not null && player.HasPermissions(RunPermission))
17+
if (!sender.HasPermissions(RunPermission))
2018
{
2119
response = "You do not have permission to run scripts.";
2220
return false;

Plugin/Commands/ReloadCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.FlagSystem;
54
using SER.Plugin.Commands.Interfaces;
65

@@ -12,8 +11,7 @@ public class ReloadCommand : ICommand, IUsePermissions
1211
{
1312
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1413
{
15-
var player = Player.Get(sender);
16-
if (player is not null && player.HasPermissions(Permission))
14+
if (!sender.HasPermissions(Permission))
1715
{
1816
response = "You do not have permission to reload scripts.";
1917
return false;

Plugin/Commands/RunCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.Plugin.Commands.Interfaces;
54
using SER.ScriptSystem;
65
using SER.ScriptSystem.Structures;
@@ -13,8 +12,7 @@ public class RunCommand : ICommand, IUsePermissions
1312
{
1413
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1514
{
16-
var player = Player.Get(sender);
17-
if (player is not null && player.HasPermissions(Permission))
15+
if (!sender.HasPermissions(Permission))
1816
{
1917
response = "You do not have permission to run scripts.";
2018
return false;

Plugin/Commands/RunningScriptsCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.Plugin.Commands.Interfaces;
54
using SER.ScriptSystem;
65

@@ -12,8 +11,7 @@ public class RunningScriptsCommand : ICommand, IUsePermissions
1211
{
1312
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1413
{
15-
var player = Player.Get(sender);
16-
if (player is not null && player.HasPermissions(Permission))
14+
if (!sender.HasPermissions(Permission))
1715
{
1816
response = "You do not have permission see running scripts.";
1917
return false;

Plugin/Commands/StopAllCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.Plugin.Commands.Interfaces;
54
using SER.ScriptSystem;
65

@@ -12,8 +11,7 @@ public class StopAllCommand : ICommand, IUsePermissions
1211
{
1312
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1413
{
15-
var player = Player.Get(sender);
16-
if (player is not null && player.HasPermissions(Permission))
14+
if (!sender.HasPermissions(Permission))
1715
{
1816
response = "You do not have permission to stop scripts.";
1917
return false;

Plugin/Commands/StopCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using CommandSystem;
22
using LabApi.Features.Permissions;
3-
using LabApi.Features.Wrappers;
43
using SER.Plugin.Commands.Interfaces;
54
using SER.ScriptSystem;
65

@@ -12,8 +11,7 @@ public class StopCommand : ICommand, IUsePermissions
1211
{
1312
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
1413
{
15-
var player = Player.Get(sender);
16-
if (player is not null && player.HasPermissions(Permission))
14+
if (!sender.HasPermissions(Permission))
1715
{
1816
response = "You do not have permission to stop scripts.";
1917
return false;

ValueSystem/CollectionValue.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static CollectionValue Insert(CollectionValue collection, Value value)
9696

9797
throw new ScriptRuntimeError($"Inserted value {value.FriendlyName()} has to be the same type as the collection ({FriendlyName(type)}).");
9898
}
99+
public CollectionValue Insert(Value val) => CollectionValue.Insert(this, val);
99100

100101
/// <summary>
101102
/// Removes every match if <paramref name="amountToRemove"/> is -1
@@ -125,11 +126,16 @@ public static CollectionValue Remove(CollectionValue collection, Value value, in
125126

126127
return new CollectionValue(values);
127128
}
129+
public CollectionValue Remove(Value val, int amountToRemove = -1) => CollectionValue.Remove(this, val, amountToRemove);
128130

129131
public static CollectionValue RemoveAt(CollectionValue collection, int index)
130132
{
131133
return new CollectionValue(collection.CastedValues.Where((_, i) => i != index - 1));
132134
}
135+
public CollectionValue RemoveAt(int index) => CollectionValue.RemoveAt(this, index);
136+
137+
public static bool Contains(CollectionValue collection, Value value) => collection.CastedValues.Contains(value);
138+
public bool Contains(Value val) => CollectionValue.Contains(this, val);
133139

134140
public static CollectionValue operator +(CollectionValue lhs, CollectionValue rhs)
135141
{

0 commit comments

Comments
 (0)