From c55787ce4048a7f59c04f312c6bb8563e24cdd32 Mon Sep 17 00:00:00 2001 From: anth64 Date: Thu, 23 Jul 2026 07:57:39 +0200 Subject: [PATCH] feat: react to /group confirmdisband and recheck live membership on link confirm --- ClaimLink/ClaimLinkChatCommand.cs | 7 +++ ...dCommandListener.cs => CommandListener.cs} | 53 +++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) rename ClaimLink/{LandCommandListener.cs => CommandListener.cs} (73%) diff --git a/ClaimLink/ClaimLinkChatCommand.cs b/ClaimLink/ClaimLinkChatCommand.cs index 2d68204..80b8196 100644 --- a/ClaimLink/ClaimLinkChatCommand.cs +++ b/ClaimLink/ClaimLinkChatCommand.cs @@ -326,6 +326,13 @@ public static class ClaimLinkChatCommand $"{claimDesc} will be linked into '{groupName}'.", () => { + bool stillMember = + ClaimLinkModSystem + .PlayerData.GetPlayerDataByUid(playerUid) + ?.PlayerGroupMemberships.ContainsKey(groupId) == true; + if (!stillMember) + return TextCommandResult.Error($"You are no longer a member of '{groupName}'."); + bool success = ClaimLinkModSystem.Registry.AddEntry(playerUid, groupId, claimIndex); return success ? TextCommandResult.Success($"Linked {claimDesc} to '{groupName}'.") diff --git a/ClaimLink/LandCommandListener.cs b/ClaimLink/CommandListener.cs similarity index 73% rename from ClaimLink/LandCommandListener.cs rename to ClaimLink/CommandListener.cs index 69b62db..ba3fed1 100644 --- a/ClaimLink/LandCommandListener.cs +++ b/ClaimLink/CommandListener.cs @@ -9,11 +9,12 @@ public class ClaimLinkCommandListener : ICommandHookListener { public string ModId => "claimlink"; - public IReadOnlyList Commands => new[] { "land" }; + public IReadOnlyList Commands => new[] { "land", "group" }; public CommandRegistration Registration => new(Before, After); internal static Dictionary PendingLoads = new Dictionary(); + internal static Dictionary PendingDisbands = new Dictionary(); private delegate void SubHandler(Caller caller, CmdArgs args); @@ -32,15 +33,23 @@ public class ClaimLinkCommandListener : ICommandHookListener ["cancel"] = ClaimCancel, }; + private static readonly Dictionary groupTopLevel = new() + { + ["confirmdisband"] = GroupConfirmDisband, + }; + private static void Dispatch(TextCommandCallingArgs args) { + Dictionary table = + args.Command?.Name == "group" ? groupTopLevel : topLevel; + CmdArgs rawArgs = args.RawArgs.Clone(); while (rawArgs.Length > 0) { string word = rawArgs.PeekWord(); - if (topLevel.TryGetValue(word, out SubHandler? handler)) + if (table.TryGetValue(word, out SubHandler? handler)) { rawArgs.PopWord(); handler(args.Caller, rawArgs); @@ -58,7 +67,45 @@ public class ClaimLinkCommandListener : ICommandHookListener return null; } - private void After(TextCommandCallingArgs args, TextCommandResult result) { } + private void After(TextCommandCallingArgs args, TextCommandResult result) + { + if (args.Caller.Player == null) + return; + + string uid = args.Caller.Player.PlayerUID; + if (!PendingDisbands.TryGetValue(uid, out int groupId)) + return; + + PendingDisbands.Remove(uid); + + if (ClaimLinkModSystem.Groups.PlayerGroupsById.ContainsKey(groupId)) + return; + + if (!ClaimLinkModSystem.Registry.Exists(groupId)) + return; + + foreach (string memberUid in ClaimLinkModSystem.Registry.MemberUidsForGroup(groupId)) + ClaimLinkChatCommand.PendingActions.Remove(memberUid); + + ClaimLinkModSystem.Registry.Remove(groupId); + } + + private static void GroupConfirmDisband(Caller caller, CmdArgs args) + { + if (caller.Player == null) + return; + + string? name = args.PopWord(); + int? groupId = + name != null + ? ClaimLinkModSystem.Groups.GetPlayerGroupByName(name)?.Uid + : caller.FromChatGroupId; + + if (groupId == null) + return; + + PendingDisbands[caller.Player.PlayerUID] = (int)groupId; + } private static void Claim(Caller caller, CmdArgs args) {