feat: react to /group confirmdisband and recheck live membership on link confirm

This commit is contained in:
2026-07-23 07:57:39 +02:00
parent b10d3a0f55
commit c55787ce40
2 changed files with 57 additions and 3 deletions
+7
View File
@@ -326,6 +326,13 @@ public static class ClaimLinkChatCommand
$"{claimDesc} will be linked into '{groupName}'.", $"{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); bool success = ClaimLinkModSystem.Registry.AddEntry(playerUid, groupId, claimIndex);
return success return success
? TextCommandResult.Success($"Linked {claimDesc} to '{groupName}'.") ? TextCommandResult.Success($"Linked {claimDesc} to '{groupName}'.")
@@ -9,11 +9,12 @@ public class ClaimLinkCommandListener : ICommandHookListener
{ {
public string ModId => "claimlink"; public string ModId => "claimlink";
public IReadOnlyList<string> Commands => new[] { "land" }; public IReadOnlyList<string> Commands => new[] { "land", "group" };
public CommandRegistration Registration => new(Before, After); public CommandRegistration Registration => new(Before, After);
internal static Dictionary<string, int> PendingLoads = new Dictionary<string, int>(); internal static Dictionary<string, int> PendingLoads = new Dictionary<string, int>();
internal static Dictionary<string, int> PendingDisbands = new Dictionary<string, int>();
private delegate void SubHandler(Caller caller, CmdArgs args); private delegate void SubHandler(Caller caller, CmdArgs args);
@@ -32,15 +33,23 @@ public class ClaimLinkCommandListener : ICommandHookListener
["cancel"] = ClaimCancel, ["cancel"] = ClaimCancel,
}; };
private static readonly Dictionary<string, SubHandler> groupTopLevel = new()
{
["confirmdisband"] = GroupConfirmDisband,
};
private static void Dispatch(TextCommandCallingArgs args) private static void Dispatch(TextCommandCallingArgs args)
{ {
Dictionary<string, SubHandler> table =
args.Command?.Name == "group" ? groupTopLevel : topLevel;
CmdArgs rawArgs = args.RawArgs.Clone(); CmdArgs rawArgs = args.RawArgs.Clone();
while (rawArgs.Length > 0) while (rawArgs.Length > 0)
{ {
string word = rawArgs.PeekWord(); string word = rawArgs.PeekWord();
if (topLevel.TryGetValue(word, out SubHandler? handler)) if (table.TryGetValue(word, out SubHandler? handler))
{ {
rawArgs.PopWord(); rawArgs.PopWord();
handler(args.Caller, rawArgs); handler(args.Caller, rawArgs);
@@ -58,7 +67,45 @@ public class ClaimLinkCommandListener : ICommandHookListener
return null; 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) private static void Claim(Caller caller, CmdArgs args)
{ {