Skip to content

Commit e8875e8

Browse files
committed
ReplaceTextInVariable, ServerInfo methods
1 parent 955c719 commit e8875e8

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
3+
using SER.Code.ArgumentSystem.Arguments;
4+
using SER.Code.ArgumentSystem.BaseArguments;
5+
using SER.Code.Helpers.Exceptions;
6+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
7+
using SER.Code.ValueSystem;
8+
9+
namespace SER.Code.MethodSystem.Methods.ServerMethods;
10+
11+
[UsedImplicitly]
12+
public class ServerInfoMethod : ReturningMethod
13+
{
14+
public override string Description => "Returns info about the server.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new OptionsArgument("info",
19+
"ip",
20+
"port",
21+
"name",
22+
"maxPlayers",
23+
"tps",
24+
"isVerified")
25+
];
26+
27+
public override TypeOfValue Returns => new TypesOfValue([
28+
typeof(TextValue),
29+
typeof(NumberValue),
30+
typeof(BoolValue)
31+
]);
32+
33+
public override void Execute()
34+
{
35+
ReturnValue = Args.GetOption("info") switch
36+
{
37+
"ip" => new TextValue(Server.IpAddress),
38+
"port" => new NumberValue(Server.Port),
39+
"name" => new TextValue(Server.ServerListName),
40+
"maxplayers" => new NumberValue(Server.MaxPlayers),
41+
"tps" => new NumberValue((decimal)Server.Tps),
42+
"isverified" => new BoolValue(CustomNetworkManager.IsVerified),
43+
_ => throw new TosoksFuckedUpException("out of order")
44+
};
45+
}
46+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.Helpers.Exceptions;
5+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
6+
using SER.Code.MethodSystem.MethodDescriptors;
7+
using SER.Code.ValueSystem;
8+
using SER.Code.VariableSystem.Variables;
9+
10+
namespace SER.Code.MethodSystem.Methods.TextMethods;
11+
12+
[UsedImplicitly]
13+
public class ReplaceTextInVariableMethod : SynchronousMethod, ICanError
14+
{
15+
public override string Description => "Replaces given values in a given text variable.";
16+
17+
public string[] ErrorReasons =>
18+
[
19+
"The given variable is not a text variable."
20+
];
21+
22+
public override Argument[] ExpectedArguments { get; } =
23+
[
24+
new LiteralVariableArgument("text variable to perform the replacement on"),
25+
new TextArgument("text to replace"),
26+
new TextArgument("replacement text")
27+
];
28+
29+
public override void Execute()
30+
{
31+
var variable = Args.GetLiteralVariable("text variable to perform the replacement on");
32+
var text = Args.GetText("text to replace");
33+
var replacement = Args.GetText("replacement text");
34+
35+
if ((LiteralValue)variable is not TextValue textValue)
36+
throw new ScriptRuntimeError(this, ErrorReasons[0]);
37+
38+
Script.AddVariable(
39+
new LiteralVariable(
40+
variable.Name,
41+
new TextValue(textValue.Value.Replace(text, replacement))));
42+
43+
}
44+
}

0 commit comments

Comments
 (0)