Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class ForeachLoopContext : LoopContext

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

public override Dictionary<IExtendableStatement.Signal, Func<IEnumerator<float>>> RegisteredSignals { get; } = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using SER.ArgumentSystem.Arguments;
using SER.ArgumentSystem.BaseArguments;
using SER.MethodSystem.BaseMethods;
using SER.ValueSystem;

namespace SER.MethodSystem.Methods.CollectionVariableMethods;

public class CollectionContainsMethod : ReturningMethod<BoolValue>
{
public override string Description => "Returns true if the value exists in the collection";

public override Argument[] ExpectedArguments { get; } =
[
new CollectionArgument("collection"),
new AnyValueArgument("value to check")
];

public override void Execute()
{
var collection = Args.GetCollection("collection");
var value = Args.GetAnyValue("value to check");
ReturnValue = new(collection.Contains(value));
}
}
4 changes: 1 addition & 3 deletions Plugin/Commands/HelpSystem/DocsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text;
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Helpers.Exceptions;
using SER.Plugin.Commands.Interfaces;

Expand All @@ -13,8 +12,7 @@ public class DocsCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission to create documentation.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/MethodCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Plugin.Commands.Interfaces;
using SER.ScriptSystem;
using SER.ScriptSystem.Structures;
Expand All @@ -15,8 +14,7 @@ public class MethodCommand : ICommand, IUsePermissions

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(RunPermission))
if (!sender.HasPermissions(RunPermission))
{
response = "You do not have permission to run scripts.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/ReloadCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.FlagSystem;
using SER.Plugin.Commands.Interfaces;

Expand All @@ -12,8 +11,7 @@ public class ReloadCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission to reload scripts.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Plugin.Commands.Interfaces;
using SER.ScriptSystem;
using SER.ScriptSystem.Structures;
Expand All @@ -13,8 +12,7 @@ public class RunCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission to run scripts.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/RunningScriptsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Plugin.Commands.Interfaces;
using SER.ScriptSystem;

Expand All @@ -12,8 +11,7 @@ public class RunningScriptsCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission see running scripts.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/StopAllCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Plugin.Commands.Interfaces;
using SER.ScriptSystem;

Expand All @@ -12,8 +11,7 @@ public class StopAllCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission to stop scripts.";
return false;
Expand Down
4 changes: 1 addition & 3 deletions Plugin/Commands/StopCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandSystem;
using LabApi.Features.Permissions;
using LabApi.Features.Wrappers;
using SER.Plugin.Commands.Interfaces;
using SER.ScriptSystem;

Expand All @@ -12,8 +11,7 @@ public class StopCommand : ICommand, IUsePermissions
{
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var player = Player.Get(sender);
if (player is not null && player.HasPermissions(Permission))
if (!sender.HasPermissions(Permission))
{
response = "You do not have permission to stop scripts.";
return false;
Expand Down
6 changes: 6 additions & 0 deletions ValueSystem/CollectionValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static CollectionValue Insert(CollectionValue collection, Value value)

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

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

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

public static CollectionValue RemoveAt(CollectionValue collection, int index)
{
return new CollectionValue(collection.CastedValues.Where((_, i) => i != index - 1));
}
public CollectionValue RemoveAt(int index) => CollectionValue.RemoveAt(this, index);

public static bool Contains(CollectionValue collection, Value value) => collection.CastedValues.Contains(value);
public bool Contains(Value val) => CollectionValue.Contains(this, val);

public static CollectionValue operator +(CollectionValue lhs, CollectionValue rhs)
{
Expand Down