Compare commits

..
3 Commits
Author SHA1 Message Date
anth64 a470456dcc refactor: revert claimlink admin info to a plain stub 2026-07-12 16:23:34 +02:00
anth64 1baa20022b feat: stub out full /land command surface as hook points
Table-drives dispatch for every vanilla /land subcommand (free,
info, list, adminfree, claim's new/grant/revoke/grow/shrink/etc.)
so each has a named hook to fill in.
2026-07-12 16:16:25 +02:00
anth64 5c7fa58ea2 feat: hook /land claim load/cancel and dump claim info via admin info
Intercepts vanilla /land claim load|cancel to track a per-player
pending claim selection, and wires LandClaimAPI/Logger through
ModSystem so admin info can dump full claim state for debugging.
2026-07-12 16:13:06 +02:00
3 changed files with 131 additions and 3 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ public static class ClaimLinkChatCommand
admin.EndSubCommand(); admin.EndSubCommand();
} }
public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink new"); public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlinknew");
public static TextCommandResult Link(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink link"); public static TextCommandResult Link(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink link");
public static TextCommandResult Confirm(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink confirm"); public static TextCommandResult Confirm(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink confirm");
public static TextCommandResult Cancel(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink cancel"); public static TextCommandResult Cancel(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink cancel");
+7 -1
View File
@@ -6,16 +6,22 @@ namespace ClaimLink;
public class ClaimLinkModSystem : ModSystem public class ClaimLinkModSystem : ModSystem
{ {
internal static ILandClaimAPI LandClaimAPI;
internal static ILogger Logger;
internal ClaimLinkCommandListener? cmdListener; internal ClaimLinkCommandListener? cmdListener;
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
public override void StartServerSide(ICoreServerAPI api) public override void StartServerSide(ICoreServerAPI api)
{ {
LandClaimAPI = api.World.Claims;
Logger = api.Logger;
cmdListener = new ClaimLinkCommandListener(); cmdListener = new ClaimLinkCommandListener();
CommandHookModSystem.Register(cmdListener); CommandHookModSystem.Register(cmdListener);
ClaimLinkChatCommand.Register(api); ClaimLinkChatCommand.Register(api);
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
} }
public override void Dispose() public override void Dispose()
+123 -1
View File
@@ -1,6 +1,7 @@
using Vintagestory.API.Common; using Vintagestory.API.Common;
using System.Collections.Generic; using System.Collections.Generic;
using CommandHook; using CommandHook;
using Vintagestory.API.Server;
namespace ClaimLink; namespace ClaimLink;
@@ -12,13 +13,134 @@ public class ClaimLinkCommandListener : ICommandHookListener
public CommandRegistration Registration => new(Before, After); public CommandRegistration Registration => new(Before, After);
private static Dictionary<string, int> pendingLoads = new Dictionary<string, int>();
private delegate void SubHandler(Caller caller, CmdArgs args);
private static readonly Dictionary<string, SubHandler> topLevel = new()
{
["claim"] = Claim,
["free"] = Free,
["info"] = Info,
["list"] = List,
["adminfree"] = AdminFree,
};
private static readonly Dictionary<string, SubHandler> claimSub = new()
{
["load"] = ClaimLoad,
["new"] = ClaimNew,
["grant"] = ClaimGrant,
["revoke"] = ClaimRevoke,
["grantgroup"] = ClaimGrantGroup,
["revokegroup"] = ClaimRevokeGroup,
["start"] = ClaimStart,
["end"] = ClaimEnd,
["grow"] = ClaimGrow,
["shrink"] = ClaimShrink,
["add"] = ClaimAdd,
["allowuseeveryone"] = ClaimAllowUseEveryone,
["plevel"] = ClaimPLevel,
["fullheight"] = ClaimFullHeight,
["save"] = ClaimSave,
["cancel"] = ClaimCancel,
["download"] = ClaimDownload,
};
private TextCommandResult? Before(TextCommandCallingArgs args) private TextCommandResult? Before(TextCommandCallingArgs args)
{ {
CmdArgs rawArgs = args.RawArgs.Clone();
while (rawArgs.Length > 0)
{
string word = rawArgs.PeekWord();
if (topLevel.TryGetValue(word, out SubHandler handler))
{
rawArgs.PopWord();
handler(args.Caller, rawArgs);
}
else
{
rawArgs.PopWord();
}
}
return null; return null;
} }
private void After(TextCommandCallingArgs args, TextCommandResult result) private void After(TextCommandCallingArgs args, TextCommandResult result)
{ {
} }
}
private static void Claim(Caller caller, CmdArgs args)
{
string word = args.PeekWord();
if (claimSub.TryGetValue(word, out SubHandler handler))
{
args.PopWord();
handler(caller, args);
}
}
private static void ClaimLoad(Caller caller, CmdArgs args)
{
if (caller.Player == null)
return;
int? claimIndex = args.PopInt();
if (claimIndex == null || claimIndex < 0 || claimIndex > 999)
return;
List<LandClaim> claims = ClaimLinkModSystem.LandClaimAPI.All, ownedClaims = new List<LandClaim>();
List<int> globalIndex = new List<int>();
for (int i = 0; i < claims.Count; ++i)
{
if (claims[i].OwnedByPlayerUid != caller.Player.PlayerUID)
continue;
globalIndex.Add(i);
ownedClaims.Add(claims[i]);
}
if (claimIndex >= ownedClaims.Count)
return;
pendingLoads[caller.Player.PlayerUID] = globalIndex[(int)claimIndex];
}
private static void ClaimCancel(Caller caller, CmdArgs args)
{
if (caller.Player == null)
return;
pendingLoads.Remove(caller.Player.PlayerUID);
}
private static void Free(Caller caller, CmdArgs args) { }
private static void Info(Caller caller, CmdArgs args) { }
private static void List(Caller caller, CmdArgs args) { }
private static void AdminFree(Caller caller, CmdArgs args) { }
private static void ClaimNew(Caller caller, CmdArgs args) { }
private static void ClaimGrant(Caller caller, CmdArgs args) { }
private static void ClaimRevoke(Caller caller, CmdArgs args) { }
private static void ClaimGrantGroup(Caller caller, CmdArgs args) { }
private static void ClaimRevokeGroup(Caller caller, CmdArgs args) { }
private static void ClaimStart(Caller caller, CmdArgs args) { }
private static void ClaimEnd(Caller caller, CmdArgs args) { }
private static void ClaimGrow(Caller caller, CmdArgs args) { }
private static void ClaimShrink(Caller caller, CmdArgs args) { }
private static void ClaimAdd(Caller caller, CmdArgs args) { }
private static void ClaimAllowUseEveryone(Caller caller, CmdArgs args) { }
private static void ClaimPLevel(Caller caller, CmdArgs args) { }
private static void ClaimFullHeight(Caller caller, CmdArgs args) { }
private static void ClaimSave(Caller caller, CmdArgs args) { }
private static void ClaimDownload(Caller caller, CmdArgs args) { }
internal static void OnPlayerDisconnect(IServerPlayer player)
{
pendingLoads.Remove(player.PlayerUID);
}
}