refactor: unlink no longer needs a groupname arg
A claim can only belong to one claim link at a time, so it resolves via the new Registry.FindLinkContaining(playerUid, claimIndex).
This commit is contained in:
@@ -69,7 +69,7 @@ public static class ClaimLinkChatCommand
|
|||||||
Array.Empty<ICommandArgumentParser>(), true, Cancel),
|
Array.Empty<ICommandArgumentParser>(), true, Cancel),
|
||||||
|
|
||||||
new(new[] { "unlink", "ul" }, "Remove a claim you own from its claim link (requires confirm).",
|
new(new[] { "unlink", "ul" }, "Remove a claim you own from its claim link (requires confirm).",
|
||||||
new ICommandArgumentParser[] { p.Word("groupname"), p.IntRange("claim", 0, 999) }, true, Unlink),
|
new ICommandArgumentParser[] { p.IntRange("claim", 0, 999) }, true, Unlink),
|
||||||
|
|
||||||
new(new[] { "kick" }, "Force-unlink all of a player's claims from the link (Owner/Op, requires confirm).",
|
new(new[] { "kick" }, "Force-unlink all of a player's claims from the link (Owner/Op, requires confirm).",
|
||||||
new ICommandArgumentParser[] { p.Word("groupname"), p.OnlinePlayer("playername") }, true, Kick),
|
new ICommandArgumentParser[] { p.Word("groupname"), p.OnlinePlayer("playername") }, true, Kick),
|
||||||
@@ -239,23 +239,18 @@ public static class ClaimLinkChatCommand
|
|||||||
|
|
||||||
public static TextCommandResult Unlink(TextCommandCallingArgs args)
|
public static TextCommandResult Unlink(TextCommandCallingArgs args)
|
||||||
{
|
{
|
||||||
string groupName = (string)args[0];
|
int claimIndex = (int)args[0];
|
||||||
int claimIndex = (int)args[1];
|
|
||||||
|
|
||||||
TextCommandResult? err = TryResolveGroup(groupName, out PlayerGroup group);
|
|
||||||
if (err != null) return err;
|
|
||||||
|
|
||||||
err = TryResolveClaimLink(group, out ClaimLink link);
|
|
||||||
if (err != null) return err;
|
|
||||||
|
|
||||||
string playerUid = args.Caller.Player.PlayerUID;
|
string playerUid = args.Caller.Player.PlayerUID;
|
||||||
|
|
||||||
ClaimLinkMember? member = link.Members.Find(m => m.OwnerPlayerUid == playerUid);
|
ClaimLink? link = ClaimLinkModSystem.Registry.FindLinkContaining(playerUid, claimIndex);
|
||||||
if (member == null || !member.LocalClaimIndices.Contains(claimIndex))
|
if (link == null)
|
||||||
return TextCommandResult.Error($"Claim {claimIndex} is not linked into '{groupName}' by you.");
|
return TextCommandResult.Error($"Claim {claimIndex} is not linked into any claim link by you.");
|
||||||
|
|
||||||
|
string groupName = ClaimLinkModSystem.Groups.PlayerGroupsById[link.GroupId].Name;
|
||||||
|
|
||||||
return Stage(playerUid, $"Claim {claimIndex} will be unlinked from '{groupName}'.", () =>
|
return Stage(playerUid, $"Claim {claimIndex} will be unlinked from '{groupName}'.", () =>
|
||||||
{
|
{
|
||||||
|
ClaimLinkMember member = link.Members.Find(m => m.OwnerPlayerUid == playerUid)!;
|
||||||
member.LocalClaimIndices.Remove(claimIndex);
|
member.LocalClaimIndices.Remove(claimIndex);
|
||||||
if (member.LocalClaimIndices.Count == 0)
|
if (member.LocalClaimIndices.Count == 0)
|
||||||
link.Members.Remove(member);
|
link.Members.Remove(member);
|
||||||
|
|||||||
@@ -44,14 +44,16 @@ public class ClaimLinkRegistry
|
|||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsClaimLinked(string ownerPlayerUid, int localIndex)
|
public bool IsClaimLinked(string ownerPlayerUid, int localIndex) => FindLinkContaining(ownerPlayerUid, localIndex) != null;
|
||||||
|
|
||||||
|
public ClaimLink? FindLinkContaining(string ownerPlayerUid, int localIndex)
|
||||||
{
|
{
|
||||||
foreach (ClaimLink link in byGroupId.Values)
|
foreach (ClaimLink link in byGroupId.Values)
|
||||||
foreach (ClaimLinkMember member in link.Members)
|
foreach (ClaimLinkMember member in link.Members)
|
||||||
if (member.OwnerPlayerUid == ownerPlayerUid && member.LocalClaimIndices.Contains(localIndex))
|
if (member.OwnerPlayerUid == ownerPlayerUid && member.LocalClaimIndices.Contains(localIndex))
|
||||||
return true;
|
return link;
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
|
|||||||
Reference in New Issue
Block a user