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(
|
||||||
new[] { "delete", "del" },
|
new[] { "delete", "del" },
|
||||||
"Delete a claim link.",
|
"Delete a claim link.",
|
||||||
new ICommandArgumentParser[] { p.Word("groupname") },
|
new ICommandArgumentParser[] { p.OptionalWord("groupname") },
|
||||||
false,
|
false,
|
||||||
AdminDelete
|
AdminDelete
|
||||||
),
|
),
|
||||||
new(
|
new(
|
||||||
new[] { "unlink" },
|
new[] { "unlink" },
|
||||||
"Unlink a claim.",
|
"Unlink a claim.",
|
||||||
new ICommandArgumentParser[] { p.OnlinePlayer("playername"), p.Word("claim") },
|
new ICommandArgumentParser[] { p.Word("playername"), p.IntRange("claim", 0, 999) },
|
||||||
false,
|
false,
|
||||||
AdminUnlink
|
AdminUnlink
|
||||||
),
|
),
|
||||||
new(
|
new(
|
||||||
new[] { "kick" },
|
new[] { "kick" },
|
||||||
"Force-unlink all of a player's claims.",
|
"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,
|
false,
|
||||||
AdminKick
|
AdminKick
|
||||||
),
|
),
|
||||||
@@ -766,14 +766,97 @@ public static class ClaimLinkChatCommand
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextCommandResult AdminDelete(TextCommandCallingArgs args) =>
|
public static TextCommandResult AdminDelete(TextCommandCallingArgs args)
|
||||||
TextCommandResult.Success("stub: claimlink admin delete");
|
{
|
||||||
|
TextCommandResult? err = TryResolveGroupArg(args, 0, out PlayerGroup group);
|
||||||
|
if (err != null)
|
||||||
|
return err;
|
||||||
|
|
||||||
public static TextCommandResult AdminUnlink(TextCommandCallingArgs args) =>
|
err = TryResolveClaimLink(group);
|
||||||
TextCommandResult.Success("stub: claimlink admin unlink");
|
if (err != null)
|
||||||
|
return err;
|
||||||
|
|
||||||
public static TextCommandResult AdminKick(TextCommandCallingArgs args) =>
|
int groupId = group.Uid;
|
||||||
TextCommandResult.Success("stub: claimlink admin kick");
|
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)
|
public static TextCommandResult AdminTransferOwnership(TextCommandCallingArgs args)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user