diff --git a/ClaimLink/ClaimLinkChatCommand.cs b/ClaimLink/ClaimLinkChatCommand.cs index 8c6dd26..a89440a 100644 --- a/ClaimLink/ClaimLinkChatCommand.cs +++ b/ClaimLink/ClaimLinkChatCommand.cs @@ -113,7 +113,7 @@ public static class ClaimLinkChatCommand admin.EndSubCommand(); } - public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink new"); + public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlinknew"); public static TextCommandResult Link(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink link"); public static TextCommandResult Confirm(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink confirm"); public static TextCommandResult Cancel(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink cancel"); @@ -127,5 +127,49 @@ public static class ClaimLinkChatCommand public static TextCommandResult AdminUnlink(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin unlink"); public static TextCommandResult AdminKick(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin kick"); public static TextCommandResult AdminTransferOwnership(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin transferownership"); - public static TextCommandResult AdminInfo(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink admin info"); + public static TextCommandResult AdminInfo(TextCommandCallingArgs args) + { + ClaimLinkModSystem.Logger.Notification("Number of Claims: {0}", ClaimLinkModSystem.LandClaimAPI.All.Count); + foreach (LandClaim claim in ClaimLinkModSystem.LandClaimAPI.All) + { + string padding = new string('-', claim.Description.Length); + ClaimLinkModSystem.Logger.Notification("---{0}---", claim.Description); + ClaimLinkModSystem.Logger.Notification("Owner (Entity ID): {0}", claim.OwnedByEntityId); + ClaimLinkModSystem.Logger.Notification("Owner (Player UID): {0}", claim.OwnedByPlayerUid); + ClaimLinkModSystem.Logger.Notification("Last Known Owner Name: {0}", claim.LastKnownOwnerName); + ClaimLinkModSystem.Logger.Notification("Permitted Player Group IDs({0})", claim.PermittedPlayerGroupIds.Count); + foreach (var groupId in claim.PermittedPlayerGroupIds) + { + ClaimLinkModSystem.Logger.Notification(" <{0},{1}>", groupId.Key, groupId.Value); + } + ClaimLinkModSystem.Logger.Notification("Permitted Player UIDs({0})", claim.PermittedPlayerUids.Count); + foreach (var permittedPlayerUid in claim.PermittedPlayerUids) + { + ClaimLinkModSystem.Logger.Notification(" <{0},{1}>", permittedPlayerUid.Key, permittedPlayerUid.Value); + } + ClaimLinkModSystem.Logger.Notification("Permitted Player Last Known Player Name({0})", claim.PermittedPlayerLastKnownPlayerName.Count); + foreach (var permittedPlayerLastKnownPlayerName in claim.PermittedPlayerLastKnownPlayerName) + { + ClaimLinkModSystem.Logger.Notification(" <{0},{1}>", permittedPlayerLastKnownPlayerName.Key, permittedPlayerLastKnownPlayerName.Value); + } + ClaimLinkModSystem.Logger.Notification("Owner (Player Group UID): {0}", claim.OwnedByPlayerGroupUid); + ClaimLinkModSystem.Logger.Notification("Protection Level: {0}", claim.ProtectionLevel); + ClaimLinkModSystem.Logger.Notification("Center: ({0}, {1}, {2})", claim.Center.X, claim.Center.Y, claim.Center.Z); + ClaimLinkModSystem.Logger.Notification("Size XYZ: ({0})", claim.SizeXYZ); + ClaimLinkModSystem.Logger.Notification("Size XZ: ({0})", claim.SizeXZ); + ClaimLinkModSystem.Logger.Notification("Areas ({0}):", claim.Areas.Count); + for (int i = 0; i < claim.Areas.Count; i++) + { + var area = claim.Areas[i]; + ClaimLinkModSystem.Logger.Notification( + " [{0}] Min: ({1}, {2}, {3}) Max: ({4}, {5}, {6})", + i, area.X1, area.Y1, area.Z1, area.X2, area.Y2, area.Z2 + ); + } + ClaimLinkModSystem.Logger.Notification("---{0}---\n", padding); + } + + + return TextCommandResult.Success("stub: claimlink admin info"); + } } diff --git a/ClaimLink/ClaimLinkModSystem.cs b/ClaimLink/ClaimLinkModSystem.cs index 69a63ef..90850e8 100644 --- a/ClaimLink/ClaimLinkModSystem.cs +++ b/ClaimLink/ClaimLinkModSystem.cs @@ -6,16 +6,22 @@ namespace ClaimLink; public class ClaimLinkModSystem : ModSystem { + internal static ILandClaimAPI LandClaimAPI; + internal static ILogger Logger; internal ClaimLinkCommandListener? cmdListener; public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; public override void StartServerSide(ICoreServerAPI api) { + LandClaimAPI = api.World.Claims; + Logger = api.Logger; + cmdListener = new ClaimLinkCommandListener(); CommandHookModSystem.Register(cmdListener); - ClaimLinkChatCommand.Register(api); + + api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect; } public override void Dispose() diff --git a/ClaimLink/LandCommandListener.cs b/ClaimLink/LandCommandListener.cs index aff0e6b..73f3c38 100644 --- a/ClaimLink/LandCommandListener.cs +++ b/ClaimLink/LandCommandListener.cs @@ -1,6 +1,7 @@ using Vintagestory.API.Common; using System.Collections.Generic; using CommandHook; +using Vintagestory.API.Server; namespace ClaimLink; @@ -12,13 +13,77 @@ public class ClaimLinkCommandListener : ICommandHookListener public CommandRegistration Registration => new(Before, After); + private static Dictionary pendingLoads = new Dictionary(); + private TextCommandResult? Before(TextCommandCallingArgs args) { + CmdArgs rawArgs = args.RawArgs.Clone(); + + while (rawArgs.Length > 0) + { + switch (rawArgs.PeekWord()) + { + case "claim": + rawArgs.PopWord(); + handleClaim(args.Caller, rawArgs); + break; + default: + rawArgs.PopWord(); + break; + } + } + return null; } private void After(TextCommandCallingArgs args, TextCommandResult result) { } + + private void handleClaim(Caller caller, CmdArgs args) + { + switch (args.PeekWord()) + { + case "load": + if (caller.Player == null) + break; + + args.PopWord(); + int? claimIndex = args.PopInt(); + if (claimIndex == null || claimIndex < 0 || claimIndex > 999) + break; + + List claims = ClaimLinkModSystem.LandClaimAPI.All, ownedClaims = new List(); + List globalIndex = new List(); + for (int i = 0; i < claims.Count; ++i) + { + if (claims[i].OwnedByPlayerUid != caller.Player.PlayerUID) + continue; + + globalIndex.Add(i); + ownedClaims.Add(claims[i]); + } + + if (claimIndex >= ownedClaims.Count) + break; + + pendingLoads[caller.Player.PlayerUID] = globalIndex[(int)claimIndex]; + break; + case "cancel": + if (caller.Player == null) + break; + + args.PopWord(); + pendingLoads.Remove(caller.Player.PlayerUID); + break; + default: + break; + } + } + + internal static void OnPlayerDisconnect(IServerPlayer player) + { + pendingLoads.Remove(player.PlayerUID); + } }