feat: implement admin delete/unlink/kick, fix admin unlink claim arg type
This commit is contained in:
@@ -154,21 +154,21 @@ public static class ClaimLinkChatCommand
|
||||
new(
|
||||
new[] { "delete", "del" },
|
||||
"Delete a claim link.",
|
||||
new ICommandArgumentParser[] { p.Word("groupname") },
|
||||
new ICommandArgumentParser[] { p.OptionalWord("groupname") },
|
||||
false,
|
||||
AdminDelete
|
||||
),
|
||||
new(
|
||||
new[] { "unlink" },
|
||||
"Unlink a claim.",
|
||||
new ICommandArgumentParser[] { p.OnlinePlayer("playername"), p.Word("claim") },
|
||||
new ICommandArgumentParser[] { p.Word("playername"), p.IntRange("claim", 0, 999) },
|
||||
false,
|
||||
AdminUnlink
|
||||
),
|
||||
new(
|
||||
new[] { "kick" },
|
||||
"Force-unlink all of a player's claims.",
|
||||
new ICommandArgumentParser[] { p.Word("groupname"), p.OnlinePlayer("playername") },
|
||||
new ICommandArgumentParser[] { p.Word("groupname"), p.OptionalWord("playername") },
|
||||
false,
|
||||
AdminKick
|
||||
),
|
||||
@@ -766,14 +766,97 @@ public static class ClaimLinkChatCommand
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static TextCommandResult AdminDelete(TextCommandCallingArgs args) =>
|
||||
TextCommandResult.Success("stub: claimlink admin delete");
|
||||
public static TextCommandResult AdminDelete(TextCommandCallingArgs args)
|
||||
{
|
||||
TextCommandResult? err = TryResolveGroupArg(args, 0, out PlayerGroup group);
|
||||
if (err != null)
|
||||
return err;
|
||||
|
||||
public static TextCommandResult AdminUnlink(TextCommandCallingArgs args) =>
|
||||
TextCommandResult.Success("stub: claimlink admin unlink");
|
||||
err = TryResolveClaimLink(group);
|
||||
if (err != null)
|
||||
return err;
|
||||
|
||||
public static TextCommandResult AdminKick(TextCommandCallingArgs args) =>
|
||||
TextCommandResult.Success("stub: claimlink admin kick");
|
||||
int groupId = group.Uid;
|
||||
string groupName = group.Name;
|
||||
|
||||
RemovePendingActionsForGroup(groupId, "claim link was deleted");
|
||||
ClaimLinkModSystem.Registry.Remove(groupId);
|
||||
return TextCommandResult.Success($"'{groupName}' is no longer a claim link.");
|
||||
}
|
||||
|
||||
public static TextCommandResult AdminUnlink(TextCommandCallingArgs args)
|
||||
{
|
||||
string playerName = (string)args[0];
|
||||
int claimIndex = (int)args[1];
|
||||
|
||||
string? targetUid = ClaimLinkModSystem
|
||||
.PlayerData.GetPlayerDataByLastKnownName(playerName)
|
||||
?.PlayerUID;
|
||||
if (targetUid == null)
|
||||
return TextCommandResult.Error($"No such player '{playerName}'.");
|
||||
|
||||
int? groupId = ClaimLinkModSystem.Registry.FindGroupContaining(targetUid, claimIndex);
|
||||
if (groupId == null)
|
||||
return TextCommandResult.Error(
|
||||
$"Claim {claimIndex} is not linked into any claim link by {playerName}."
|
||||
);
|
||||
|
||||
string groupName = ClaimLinkModSystem.Groups.PlayerGroupsById[(int)groupId].Name;
|
||||
string claimDesc = DescribeClaim(targetUid, claimIndex);
|
||||
|
||||
ClaimLinkModSystem.Registry.RemoveEntry(targetUid, (int)groupId, claimIndex);
|
||||
return TextCommandResult.Success(
|
||||
$"Unlinked {claimDesc} from '{groupName}' (owned by {playerName})."
|
||||
);
|
||||
}
|
||||
|
||||
public static TextCommandResult AdminKick(TextCommandCallingArgs args)
|
||||
{
|
||||
string word1 = (string)args[0];
|
||||
string? word2 = args.Parsers[1].IsMissing ? null : (string)args[1];
|
||||
|
||||
string targetName;
|
||||
PlayerGroup group;
|
||||
if (word2 != null)
|
||||
{
|
||||
TextCommandResult? err = TryResolveGroup(word1, out group);
|
||||
if (err != null)
|
||||
return err;
|
||||
targetName = word2;
|
||||
}
|
||||
else
|
||||
{
|
||||
int chatGroupId = args.Caller.FromChatGroupId;
|
||||
if (!ClaimLinkModSystem.Groups.PlayerGroupsById.TryGetValue(chatGroupId, out group!))
|
||||
return TextCommandResult.Error(
|
||||
"No group specified and you are not sending this from a group chat channel."
|
||||
);
|
||||
targetName = word1;
|
||||
}
|
||||
|
||||
TextCommandResult? linkErr = TryResolveClaimLink(group);
|
||||
if (linkErr != null)
|
||||
return linkErr;
|
||||
|
||||
string? targetUid = ClaimLinkModSystem
|
||||
.PlayerData.GetPlayerDataByLastKnownName(targetName)
|
||||
?.PlayerUID;
|
||||
if (targetUid == null)
|
||||
return TextCommandResult.Error($"No such player '{targetName}'.");
|
||||
|
||||
string groupName = group.Name;
|
||||
|
||||
if (!ClaimLinkModSystem.Registry.HasAnyEntry(targetUid, group.Uid))
|
||||
return TextCommandResult.Error($"{targetName} has no claims linked in '{groupName}'.");
|
||||
|
||||
ClaimLinkModSystem.Registry.RemoveAllForPlayerInGroup(targetUid, group.Uid);
|
||||
CommandListener.PendingLoads.Remove(targetUid);
|
||||
PendingActions.Remove(targetUid);
|
||||
|
||||
return TextCommandResult.Success(
|
||||
$"Unlinked all claims of {targetName} from '{groupName}'."
|
||||
);
|
||||
}
|
||||
|
||||
public static TextCommandResult AdminTransferOwnership(TextCommandCallingArgs args)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user