Skip to content

Commit 850e5b9

Browse files
committed
This method, new Script properties
1 parent bf0b932 commit 850e5b9

File tree

11 files changed

+88
-14
lines changed

11 files changed

+88
-14
lines changed

Code/EventSystem/EventHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static void OnNonArgumentedEvent(string evName)
145145
continue;
146146
}
147147

148-
script.Run();
148+
script.Run(RunContext.Event);
149149
}
150150
}
151151

@@ -179,7 +179,7 @@ private static void OnArgumentedEvent<T>(string evName, T ev) where T : EventArg
179179
}
180180

181181
script.AddVariables(variables);
182-
var isAllowed = script.RunForEvent();
182+
var isAllowed = script.RunForEvent(RunContext.Event);
183183
if (isAllowed.HasValue && ev is ICancellableEvent cancellable1)
184184
cancellable1.IsAllowed = isAllowed.Value;
185185
}

Code/FlagSystem/Flags/CustomCommandFlag.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static Result RunAttachedScript(CustomCommand requestingCommand, ScriptEx
222222
script.AddVariable(new LiteralVariable<TextValue>(name, slice.Value));
223223
}
224224

225-
script.Run();
225+
script.Run(RunContext.Command);
226226
return true;
227227
}
228228

Code/MethodSystem/Methods/ScriptMethods/RunFuncMethod.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using SER.Code.Helpers.Extensions;
88
using SER.Code.MethodSystem.BaseMethods;
99
using SER.Code.MethodSystem.MethodDescriptors;
10+
using SER.Code.ScriptSystem;
1011
using SER.Code.ValueSystem;
1112
using SER.Code.VariableSystem.Bases;
1213

@@ -82,6 +83,6 @@ public override void Execute()
8283
scriptToRun.AddVariable(variable);
8384
}
8485

85-
scriptToRun.Run();
86+
scriptToRun.Run(RunContext.Script, Script);
8687
}
8788
}

Code/MethodSystem/Methods/ScriptMethods/RunScriptAndWaitMethod.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using SER.Code.ArgumentSystem.Arguments;
44
using SER.Code.ArgumentSystem.BaseArguments;
55
using SER.Code.MethodSystem.BaseMethods;
6+
using SER.Code.ScriptSystem;
67
using SER.Code.VariableSystem.Bases;
78

89
namespace SER.Code.MethodSystem.Methods.ScriptMethods;
@@ -29,7 +30,7 @@ public override IEnumerator<float> Execute()
2930
var variables = Args.GetRemainingArguments<Variable, VariableArgument>("variables to pass");
3031

3132
script.AddVariables(variables);
32-
script.Run();
33+
script.Run(RunContext.Script, Script);
3334

3435
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
3536
while (script.IsRunning)

Code/MethodSystem/Methods/ScriptMethods/RunScriptMethod.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using SER.Code.ArgumentSystem.Arguments;
33
using SER.Code.ArgumentSystem.BaseArguments;
44
using SER.Code.MethodSystem.BaseMethods;
5+
using SER.Code.ScriptSystem;
56
using SER.Code.VariableSystem.Bases;
67

78
namespace SER.Code.MethodSystem.Methods.ScriptMethods;
@@ -28,6 +29,6 @@ public override void Execute()
2829
var variables = Args.GetRemainingArguments<Variable, VariableArgument>("variables to pass");
2930

3031
script.AddVariables(variables);
31-
script.Run();
32+
script.Run(RunContext.Script, Script);
3233
}
3334
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.ArgumentSystem.Structures;
5+
using SER.Code.FlagSystem;
6+
using SER.Code.Helpers.Exceptions;
7+
using SER.Code.MethodSystem.BaseMethods;
8+
using SER.Code.ScriptSystem;
9+
using SER.Code.ValueSystem;
10+
11+
namespace SER.Code.MethodSystem.Methods.ScriptMethods;
12+
13+
[UsedImplicitly]
14+
public class ThisMethod : ReturningMethod
15+
{
16+
public override string Description => "Returns info about the current script";
17+
18+
public override Argument[] ExpectedArguments { get; } =
19+
[
20+
new OptionsArgument("info to receive",
21+
"flags",
22+
new("caller","The name of the script that called this script"),
23+
Option.Enum<RunContext>("context"),
24+
new("duration","The amount of time the script's been running for"),
25+
"name",
26+
new("path", "The path to the script on the local directory of the server"),
27+
new("variables",$"Returns a {nameof(CollectionValue)} containing the names of all the variables in the script"))
28+
];
29+
30+
public override TypeOfValue Returns => new TypesOfValue([
31+
typeof(CollectionValue),
32+
typeof(TextValue),
33+
typeof(DurationValue),
34+
]);
35+
36+
public override void Execute()
37+
{
38+
ReturnValue = Args.GetOption("info to receive") switch
39+
{
40+
"flags" => new CollectionValue(ScriptFlagHandler.GetScriptFlags(Script.Name)
41+
.Select(f => f.GetType().Name.Replace("Flag", ""))),
42+
"caller" => new TextValue(Script.Caller?.Name ?? "none"),
43+
"context" => new TextValue(Script.Context.ToString()),
44+
"duration" => new DurationValue(Script.TimeRunning),
45+
"name" => new TextValue(Script.Name),
46+
"path" => new TextValue(FileSystem.FileSystem.GetScriptPath(Script)),
47+
"variables" => new CollectionValue(Script.Variables.Select(v => v.Prefix + v.Name)),
48+
_ => throw new TosoksFuckedUpException("out of order")
49+
};
50+
}
51+
}

Code/MethodSystem/Methods/ScriptMethods/TriggerMethod.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using SER.Code.FlagSystem.Flags;
55
using SER.Code.Helpers.Exceptions;
66
using SER.Code.MethodSystem.BaseMethods;
7+
using SER.Code.ScriptSystem;
78
using SER.Code.ScriptSystem.Structures;
89

910
namespace SER.Code.MethodSystem.Methods.ScriptMethods;
@@ -27,12 +28,12 @@ public override void Execute()
2728

2829
foreach (var scriptName in scripts)
2930
{
30-
if (ScriptSystem.Script.CreateByScriptName(scriptName, ScriptExecutor.Get()).HasErrored(out var error, out var script))
31+
if (Script.CreateByScriptName(scriptName, ScriptExecutor.Get()).HasErrored(out var error, out var script))
3132
{
3233
throw new ScriptRuntimeError(this, error);
3334
}
3435

35-
script.Run();
36+
script.Run(RunContext.Script, Script);
3637
}
3738
}
3839
}

Code/Plugin/CommandEvents.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ public static void CaptureCommand(CommandExecutingEventArgs ev)
7474

7575
ev.Sender.Respond($"Running method '{methodName}'!");
7676
ev.IsAllowed = false;
77-
script.Run();
77+
script.Run(RunContext.Command);
7878
}
7979
}

Code/Plugin/Commands/MethodCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
2727
Executor = ScriptExecutor.Get(sender)
2828
};
2929

30-
script.Run();
30+
script.Run(RunContext.Command);
3131
response = "Method executed.";
3232
return true;
3333
}

Code/Plugin/Commands/RunCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
3232
return false;
3333
}
3434

35-
script.Run();
35+
script.Run(RunContext.Command);
3636
response = $"Script '{script.Name}' was requested to run";
3737
return true;
3838
}

0 commit comments

Comments
 (0)