diff --git a/ClaimLink/ClaimLinkChatCommand.cs b/ClaimLink/ClaimLinkChatCommand.cs index 3e50b29..1f30bfd 100644 --- a/ClaimLink/ClaimLinkChatCommand.cs +++ b/ClaimLink/ClaimLinkChatCommand.cs @@ -70,8 +70,8 @@ public static class ClaimLinkChatCommand new(new[] { "unlink", "ul" }, "Remove a claim you own from its claim link.", new ICommandArgumentParser[] { p.Word("groupname"), p.IntRange("claim", 0, 999) }, true, Unlink), - new(new[] { "kick" }, "Force-unlink another player's claim from the link (Owner/Op).", - new ICommandArgumentParser[] { p.OnlinePlayer("playername"), p.Word("claim") }, true, Kick), + new(new[] { "kick" }, "Force-unlink all of a player's claims from the link (Owner/Op).", + new ICommandArgumentParser[] { p.Word("groupname"), p.OnlinePlayer("playername") }, true, Kick), new(new[] { "delete" }, "Delete the claim link entirely (Owner).", new ICommandArgumentParser[] { p.Word("groupname") }, true, Delete), @@ -153,6 +153,14 @@ public static class ClaimLinkChatCommand return group.OwnerUID != player.PlayerUID ? TextCommandResult.Error($"You do not own the group '{group.Name}'.") : null; } + private static TextCommandResult? RequireOpOrOwner(IPlayer player, PlayerGroup group) + { + PlayerGroupMembership? membership = player.GetGroup(group.Uid); + return membership == null || membership.Level < EnumPlayerGroupMemberShip.Op + ? TextCommandResult.Error($"You must be an operator of '{group.Name}' to do that.") + : null; + } + public static TextCommandResult New(TextCommandCallingArgs args) { string groupName = (string)args[0]; @@ -259,7 +267,31 @@ public static class ClaimLinkChatCommand return TextCommandResult.Success($"Unlinked claim {claimIndex} from '{groupName}'."); } - public static TextCommandResult Kick(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink kick"); + public static TextCommandResult Kick(TextCommandCallingArgs args) + { + string groupName = (string)args[0]; + IPlayer target = (IPlayer)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; + + err = RequireOpOrOwner(args.Caller.Player, group); + if (err != null) return err; + + string targetUid = target.PlayerUID; + + ClaimLinkMember? member = link.Members.Find(m => m.OwnerPlayerUid == targetUid); + if (member == null) + return TextCommandResult.Error($"{target.PlayerName} has no claims linked into '{groupName}'."); + + link.Members.Remove(member); + ClaimLinkModSystem.Registry.Save(); + + return TextCommandResult.Success($"Kicked all of {target.PlayerName}'s claims from '{groupName}'."); + } public static TextCommandResult Delete(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink delete"); public static TextCommandResult TransferOwnership(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink transferownership"); public static TextCommandResult Info(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink info");