From e79bc7d213debcff289a1ffe4a9700d5f62224c2 Mon Sep 17 00:00:00 2001 From: Tosoks67 <126388095+Tosoks67@users.noreply.github.com> Date: Sun, 14 Dec 2025 23:22:50 +0100 Subject: [PATCH] 3 fixes, 1 new method fixed the foreach description fixed all the commands checking the player's permissions instead of the sender's added Contains to CollectionValue and added non-static variants of all static methods like Insert, Remove etc. new CollectionContains method --- .../Control/Loops/ForeachLoopContext.cs | 3 ++- .../CollectionContainsMethod.cs | 24 +++++++++++++++++++ Plugin/Commands/HelpSystem/DocsCommand.cs | 4 +--- Plugin/Commands/MethodCommand.cs | 4 +--- Plugin/Commands/ReloadCommand.cs | 4 +--- Plugin/Commands/RunCommand.cs | 4 +--- Plugin/Commands/RunningScriptsCommand.cs | 4 +--- Plugin/Commands/StopAllCommand.cs | 4 +--- Plugin/Commands/StopCommand.cs | 4 +--- ValueSystem/CollectionValue.cs | 6 +++++ 10 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 MethodSystem/Methods/CollectionVariableMethods/CollectionContainsMethod.cs diff --git a/ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs b/ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs index 6997a3d..6abf356 100644 --- a/ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs +++ b/ContextSystem/Contexts/Control/Loops/ForeachLoopContext.cs @@ -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>> RegisteredSignals { get; } = new(); diff --git a/MethodSystem/Methods/CollectionVariableMethods/CollectionContainsMethod.cs b/MethodSystem/Methods/CollectionVariableMethods/CollectionContainsMethod.cs new file mode 100644 index 0000000..8172f03 --- /dev/null +++ b/MethodSystem/Methods/CollectionVariableMethods/CollectionContainsMethod.cs @@ -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 +{ + 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)); + } +} \ No newline at end of file diff --git a/Plugin/Commands/HelpSystem/DocsCommand.cs b/Plugin/Commands/HelpSystem/DocsCommand.cs index ce870f0..78643ef 100644 --- a/Plugin/Commands/HelpSystem/DocsCommand.cs +++ b/Plugin/Commands/HelpSystem/DocsCommand.cs @@ -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; @@ -13,8 +12,7 @@ public class DocsCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/MethodCommand.cs b/Plugin/Commands/MethodCommand.cs index 938e81c..2756698 100644 --- a/Plugin/Commands/MethodCommand.cs +++ b/Plugin/Commands/MethodCommand.cs @@ -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; @@ -15,8 +14,7 @@ public class MethodCommand : ICommand, IUsePermissions public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/ReloadCommand.cs b/Plugin/Commands/ReloadCommand.cs index bfe564e..d49dfe8 100644 --- a/Plugin/Commands/ReloadCommand.cs +++ b/Plugin/Commands/ReloadCommand.cs @@ -1,6 +1,5 @@ using CommandSystem; using LabApi.Features.Permissions; -using LabApi.Features.Wrappers; using SER.FlagSystem; using SER.Plugin.Commands.Interfaces; @@ -12,8 +11,7 @@ public class ReloadCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/RunCommand.cs b/Plugin/Commands/RunCommand.cs index bbae0a4..92bff30 100644 --- a/Plugin/Commands/RunCommand.cs +++ b/Plugin/Commands/RunCommand.cs @@ -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; @@ -13,8 +12,7 @@ public class RunCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/RunningScriptsCommand.cs b/Plugin/Commands/RunningScriptsCommand.cs index 4ca5e80..b6d6369 100644 --- a/Plugin/Commands/RunningScriptsCommand.cs +++ b/Plugin/Commands/RunningScriptsCommand.cs @@ -1,6 +1,5 @@ using CommandSystem; using LabApi.Features.Permissions; -using LabApi.Features.Wrappers; using SER.Plugin.Commands.Interfaces; using SER.ScriptSystem; @@ -12,8 +11,7 @@ public class RunningScriptsCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/StopAllCommand.cs b/Plugin/Commands/StopAllCommand.cs index 98cc004..fe1cb26 100644 --- a/Plugin/Commands/StopAllCommand.cs +++ b/Plugin/Commands/StopAllCommand.cs @@ -1,6 +1,5 @@ using CommandSystem; using LabApi.Features.Permissions; -using LabApi.Features.Wrappers; using SER.Plugin.Commands.Interfaces; using SER.ScriptSystem; @@ -12,8 +11,7 @@ public class StopAllCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/Plugin/Commands/StopCommand.cs b/Plugin/Commands/StopCommand.cs index a822ddc..32702a8 100644 --- a/Plugin/Commands/StopCommand.cs +++ b/Plugin/Commands/StopCommand.cs @@ -1,6 +1,5 @@ using CommandSystem; using LabApi.Features.Permissions; -using LabApi.Features.Wrappers; using SER.Plugin.Commands.Interfaces; using SER.ScriptSystem; @@ -12,8 +11,7 @@ public class StopCommand : ICommand, IUsePermissions { public bool Execute(ArraySegment 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; diff --git a/ValueSystem/CollectionValue.cs b/ValueSystem/CollectionValue.cs index 8eb0617..d74f968 100644 --- a/ValueSystem/CollectionValue.cs +++ b/ValueSystem/CollectionValue.cs @@ -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); /// /// Removes every match if is -1 @@ -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) {