Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b9ce36e
update:TPallow默认允许
THEXN Jun 29, 2025
d85cb33
add:TrCDK
THEXN Jun 29, 2025
b77b025
doc
THEXN Jun 29, 2025
c2645a5
doc:en
THEXN Jun 29, 2025
dfa44f5
fix:补药灌注我
THEXN Jun 29, 2025
0b8532a
fix:waring
THEXN Jun 29, 2025
f11d46d
重构
Controllerdestiny Jun 30, 2025
74ed183
LazyAPI命令系统支持可选参数
Controllerdestiny Jun 30, 2025
91cd490
docs(TrCDK): 修正更新日志格式
ACaiCat Jul 2, 2025
deb410b
refactor(EssentialsPlus): 用`REPLACE`替代`INSERT OR REPLACE`以兼容MySQL
ACaiCat Jul 2, 2025
c5a0a34
Merge branch 'UnrealMultiple:master' into master
THEXN Jul 3, 2025
e1420a5
Merge branch 'UnrealMultiple:master' into master
THEXN Jul 4, 2025
62b10ba
docs(TrCDK): 删除多余日志
ACaiCat Jul 4, 2025
8b72411
自动更新子模块 [skip ci]
actions-user Jul 5, 2025
1c19f73
自动更新子模块 [skip ci]
actions-user Jul 21, 2025
7c7c89b
Merge branch 'UnrealMultiple:master' into master
THEXN Jul 21, 2025
7987f58
update:作为基础插件,不再依赖LazyAPI
THEXN Aug 4, 2025
86786e1
Merge branch 'master' into master
ACaiCat Aug 25, 2025
d36efa7
feat(LazyAPI): add `HelpText` support
ACaiCat Aug 27, 2025
b102e4a
fix(LazyAPI): remove method target for `HelpTextAttribute`
ACaiCat Aug 27, 2025
89ee85a
feat(LazyAPI): add `UsageAttribute` to set custom usage
ACaiCat Aug 27, 2025
c3aaff2
Merge branch 'UnrealMultiple:master' into master
THEXN Sep 16, 2025
c065ae0
chore: 自动更新子模块
actions-user Sep 21, 2025
d2530c0
chore: 自动更新子模块
actions-user Sep 22, 2025
3bf350e
chore: 自动更新子模块
actions-user Sep 23, 2025
b30626f
Merge branch 'UnrealMultiple:master' into master
THEXN Nov 12, 2025
2ab5eff
Merge branch 'UnrealMultiple:master' into master
THEXN Dec 4, 2025
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
10 changes: 9 additions & 1 deletion Plugin.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
Expand Down Expand Up @@ -278,6 +277,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoClassificationQuickStac
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceGen", "src\SourceGen\SourceGen.csproj", "{E5E60819-4B13-4982-B345-358A4DBE9D3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrCDK", "src\TrCDK\TrCDK.csproj", "{D06CC8C7-7B77-428B-B5BA-A690C17DE382}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BossLock", "src\BossLock\BossLock.csproj", "{80ACB7F0-2820-44D5-B0CA-CC73444D880E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GhostView", "src\GhostView\GhostView.csproj", "{6ABEAB06-DC01-48AE-8119-9E25213C9949}"
Expand Down Expand Up @@ -1374,6 +1374,14 @@ Global
{E5E60819-4B13-4982-B345-358A4DBE9D3B}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E60819-4B13-4982-B345-358A4DBE9D3B}.Release|x64.ActiveCfg = Release|Any CPU
{E5E60819-4B13-4982-B345-358A4DBE9D3B}.Release|x64.Build.0 = Release|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Debug|x64.ActiveCfg = Debug|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Debug|x64.Build.0 = Debug|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Release|Any CPU.Build.0 = Release|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Release|x64.ActiveCfg = Release|Any CPU
{D06CC8C7-7B77-428B-B5BA-A690C17DE382}.Release|x64.Build.0 = Release|Any CPU
{80ACB7F0-2820-44D5-B0CA-CC73444D880E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80ACB7F0-2820-44D5-B0CA-CC73444D880E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80ACB7F0-2820-44D5-B0CA-CC73444D880E}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
39 changes: 21 additions & 18 deletions src/EssentialsPlus/Db/TpAllowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,23 @@ public bool ToggleTpAllow(TSPlayer player)

if (existing == null)
{
newState = true;
// 默认允许
newState = false;
this.TpAllows.Add(new TpAllow(player.Name, newState));

if (this.db.Query("INSERT OR REPLACE INTO TpAllows VALUES (@0, @1)",
player.Name, newState ? 1 : 0) > 0)
{
player.TPAllow = newState;
return true;
}
return false;
}
else
{
newState = !existing.IsEnabled;
existing.IsEnabled = newState;
}

if (this.db.Query("UPDATE TpAllows SET IsEnabled = @0 WHERE Name = @1",
newState ? 1 : 0, player.Name) > 0)
{
player.TPAllow = newState;
return true;
}
return false;
if (this.db.Query("REPLACE INTO TpAllows VALUES (@0, @1);",
player.Name, newState ? 1 : 0) > 0)
{
player.TPAllow = newState;
return true;
}
return false;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -136,12 +129,22 @@ public bool IsTpAllowed(TSPlayer player)
player.TPAllow = isEnabled;
return isEnabled;
}

// 未找到记录时,默认允许传送并添加记录
var defaultAllowed = true;
this.TpAllows.Add(new TpAllow(player.Name, defaultAllowed));
this.db.Query("INSERT INTO TpAllows (Name, IsEnabled) VALUES (@0, @1)",
player.Name, defaultAllowed ? 1 : 0);
player.TPAllow = defaultAllowed;
return defaultAllowed;
}
catch (Exception ex)
{
TShock.Log.Error($"查询玩家 {player.Name} 的传送权限时发生错误: {ex}");
}
player.TPAllow = false;
return false;

// 异常情况下保持默认允许(可选,根据需求决定)
player.TPAllow = true;
return true;
}
}
2 changes: 1 addition & 1 deletion src/EssentialsPlus/EssentialsPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class EssentialsPlus : LazyPlugin
public override string Description => GetString("增强版Essentials");

public override string Name => System.Reflection.Assembly.GetExecutingAssembly().GetName().Name!;
public override Version Version => new Version(1, 0, 9);
public override Version Version => new Version(1, 1, 0);


public EssentialsPlus(Main game)
Expand Down
2 changes: 2 additions & 0 deletions src/EssentialsPlus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
```

## 更新日志
### v1.1.0
- Tpallow默认允许传送
### v1.0.9
- 数据库记录玩家tpallow状态
### v1.0.7
Expand Down
2 changes: 1 addition & 1 deletion src/Ezperm/Ezperm.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\template.targets" />

Expand Down
10 changes: 10 additions & 0 deletions src/LazyAPI/Attributes/CommonAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public class AliasAttribute(params string[] aliases) : Attribute
public HashSet<string> alias = [.. aliases];
}

[AttributeUsage(AttributeTargets.Class)]
public class HelpTextAttribute(string helpText) : Attribute
{
public string helpText = helpText;
}

[AttributeUsage(AttributeTargets.Method)]
public class UsageAttribute(string usage) : Attribute
{
public string usage = usage;
}
6 changes: 4 additions & 2 deletions src/LazyAPI/Commands/Command.HelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public HelpCommand(Command parent, string infoPrefix)
{
this.parent = parent;
this.permissions = [];
this.info = infoPrefix + "help";
this.usage = GetString($"{infoPrefix}help - list available usages");
}

public override ParseResult TryParse(CommandArgs args, int current)
Expand All @@ -27,7 +27,9 @@ public override ParseResult TryParse(CommandArgs args, int current)
}

args.Player.SendInfoMessage(GetString("available usage:"));
foreach (var sub in this.parent._dict.Values.SelectMany(subs => subs).Concat(this.parent._main).Distinct()
foreach (var sub in this.parent._dict.Values
.SelectMany(subs => subs)
.Concat(this.parent._main).Distinct()
.Where(sub => sub.CanExec(args.Player)))
{
args.Player.SendInfoMessage(sub.ToString());
Expand Down
2 changes: 1 addition & 1 deletion src/LazyAPI/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal partial class Command : CommandBase

public Command(MemberInfo type, string infoPrefix) : base(type)
{
this.info = $"{infoPrefix} <...>";
this.usage = CommandHelper.GetCommandUsage(type) ?? $"{infoPrefix} <...>";
this._infoPrefix = infoPrefix;
}

Expand Down
6 changes: 3 additions & 3 deletions src/LazyAPI/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ protected internal readonly struct ParseResult(CommandBase current, int num)

protected string[] permissions;
private readonly bool _realPlayer;
protected string? info;
internal string? usage;

public abstract ParseResult TryParse(CommandArgs args, int current);
public override string? ToString()
{
return this.info;
return this.usage;
}

protected CommandBase(MemberInfo member)
Expand Down Expand Up @@ -68,6 +68,6 @@ protected bool CheckPlayer(TSPlayer plr)
}
protected ParseResult GetResult(int num)
{
return new(this, num);
return new ParseResult(this, num);
}
}
24 changes: 22 additions & 2 deletions src/LazyAPI/Commands/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static Command BuildTree(Type type, string prefix)
{
var al = GetAlias(func).ToArray();
CommandBase sub = func.GetCustomAttribute<FlexibleAttribute>() != null ? new FlexibleCommand(func, prefix + AliasToString(al)) : new SingleCommand(func, prefix + AliasToString(al));

foreach (var alias in al)
{
result.Add(alias, sub);
Expand All @@ -68,6 +69,11 @@ private static Command BuildTree(Type type, string prefix)

private static void ParseCommand(Command tree, CommandArgs args)
{
if (args.Parameters.Count == 0)
{
args.Parameters.Add("help");
}

var result = tree.TryParse(args, 0);
if (result.unmatched == 0)
{
Expand Down Expand Up @@ -96,6 +102,16 @@ private static IEnumerable<string> GetCommandAlias(MemberInfo info)

yield return info.Name.ToLower();
}

internal static string? GetCommandUsage(MemberInfo info)
{
return info.GetCustomAttributes<UsageAttribute>().Select(a => a.usage).FirstOrDefault();
}

private static string GetCommandHelpText(MemberInfo info)
{
return info.GetCustomAttributes<HelpTextAttribute>().Select(a => a.helpText).FirstOrDefault() ?? GetString("No help available.");
}


internal static string[] Register(Type type)
Expand All @@ -105,10 +121,14 @@ internal static string[] Register(Type type)
Console.WriteLine($"Command `{type.FullName}` should be static");
}
var names = GetCommandAlias(type).ToArray();
var helpText = GetCommandHelpText(type);
var tree = BuildTree(type, AliasToString(names));

TShockAPI.Commands.ChatCommands.Add(new TShockAPI.Command(args => ParseCommand(tree, args),
names));
names)
{
HelpText = helpText
});

return names;
}
Expand Down
14 changes: 7 additions & 7 deletions src/LazyAPI/Commands/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ private static bool TryParseAccount(string arg, out object obj)

private static readonly Dictionary<Type, string> friendlyName = new()
{
[typeof(bool)] = "bool",
[typeof(int)] = "int",
[typeof(long)] = "long",
[typeof(string)] = "str",
[typeof(DateTime)] = "date",
[typeof(TSPlayer)] = "player",
[typeof(UserAccount)] = "account"
[typeof(bool)] = GetString("bool"),
[typeof(int)] = GetString("int"),
[typeof(long)] = GetString("long"),
[typeof(string)] = GetString("str"),
[typeof(DateTime)] = GetString("date"),
[typeof(TSPlayer)] = GetString("player"),
[typeof(UserAccount)] = GetString("account")
};

public static Parser GetParser(Type type)
Expand Down
42 changes: 32 additions & 10 deletions src/LazyAPI/Commands/FlexibleCommand.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,75 @@
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using TShockAPI;

namespace LazyAPI.Commands;
internal class FlexibleCommand : CommandBase
{
private readonly CommandParser.Parser[] argParsers;
private readonly (CommandParser.Parser, object?)[] defaultParsers;
private readonly FastReflectionHelper.FastInvoker method;

public FlexibleCommand(MethodInfo method, string infoPrefix) : base(method)
{
var param = method.GetParameters();
var ap = new List<CommandParser.Parser>();
var dp = new List<(CommandParser.Parser, object?)>();
var sb = new StringBuilder();
sb.Append(infoPrefix);

foreach (var p in param.Skip(1))
{
ap.Add(CommandParser.GetParser(p.ParameterType));
sb.Append($"<{p.Name}: {CommandParser.GetFriendlyName(p.ParameterType)}> ");
if (p.IsOptional)
{
dp.Add((CommandParser.GetParser(p.ParameterType), p.DefaultValue));
sb.Append(@$"[{p.Name}:{CommandParser.GetFriendlyName(p.ParameterType)}] ");
}
else
{
ap.Add(CommandParser.GetParser(p.ParameterType));
sb.Append($"<{p.Name}:{CommandParser.GetFriendlyName(p.ParameterType)}> ");
}
}

this.argParsers = [.. ap];
this.info = sb.ToString();
this.defaultParsers = [.. dp];
this.usage = CommandHelper.GetCommandUsage(method) ?? sb.ToString();
this.method = method.GetFastInvoker();
}

public override ParseResult TryParse(CommandArgs args, int current)
{
var p = args.Parameters;
var n = this.argParsers.Length;
var d = this.defaultParsers.Length;
if (p.Count < n + current)
{
return this.GetResult(Math.Abs(n + current - p.Count));
}

var a = new object?[n + 1];
var a = new object?[n + d + 1];
a[0] = args;
var unmatched = this.argParsers.Where((t, i) => !t(p[current + i], out a[i + 1])).Count();
if (unmatched != 0)
{
return this.GetResult(unmatched);
}

if (this.defaultParsers.Where((t, i) =>
{
var (k, v) = t;
if (p.Count <= n + i + 1)
{
a[n + i + 1] = v;
return false;
}
else
{
return !k(p[current + n + i], out a[n + i + 1]);
}
}).Any())
{
return this.GetResult(0);
}
if (this.CheckPlayer(args.Player))
{
this.method(null, a);
Expand Down
2 changes: 1 addition & 1 deletion src/LazyAPI/Commands/SingleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SingleCommand(MethodInfo method, string infoPrefix) : base(method)
}

this.argParsers = [.. ap];
this.info = sb.ToString();
this.usage = CommandHelper.GetCommandUsage(method) ?? sb.ToString();
this.method = method.GetFastInvoker();
}

Expand Down
21 changes: 21 additions & 0 deletions src/LazyAPI/Extensions/TSPlayerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ public static void SendPlayerSlot(this TSPlayer player, int slot)
player.SendData(PacketTypes.PlayerSlot, "", slot);
}

public static void ExecCommand(this TSPlayer player, string cmd)
{
try
{
player.tempGroup = new SuperAdminGroup();
TShockAPI.Commands.HandleCommand(player, cmd.SFormat(player.Name));
}
finally
{
player.tempGroup = null;
}
}

public static void ExecCommand(this TSPlayer player, IEnumerable<string> cmds)
{
foreach (var cmd in cmds)
{
player.ExecCommand(cmd);
}
}

public static Dictionary<string, bool> GetProgress(this TSPlayer Player)
{
return GameProgress.DefaultProgressNames
Expand Down
2 changes: 1 addition & 1 deletion src/LazyAPI/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class PluginContainer : LazyPlugin
{
public override string Author => "cc004 & members of UnrealMultiple";

public override Version Version => new Version(1, 0, 2, 1);
public override Version Version => new Version(1, 0, 2, 2);

public PluginContainer(Main game) : base(game) { }
public override void Initialize()
Expand Down
Loading
Loading