Compare commits

..
2 Commits
3 changed files with 47 additions and 16 deletions
+10 -1
View File
@@ -574,7 +574,11 @@ public static class ClaimLinkChatCommand
private static string DescribeClaim(string ownerPlayerUid, int claimIndex) private static string DescribeClaim(string ownerPlayerUid, int claimIndex)
{ {
if ( if (
!ClaimLinkModSystem.TryResolveOwnedClaim(ownerPlayerUid, claimIndex, out LandClaim? claim) !ClaimLinkModSystem.TryResolveOwnedClaim(
ownerPlayerUid,
claimIndex,
out LandClaim? claim
)
|| claim == null || claim == null
) )
return $"claim {claimIndex}"; return $"claim {claimIndex}";
@@ -644,4 +648,9 @@ public static class ClaimLinkChatCommand
public static TextCommandResult AdminInfo(TextCommandCallingArgs args) => public static TextCommandResult AdminInfo(TextCommandCallingArgs args) =>
TextCommandResult.Success("stub: claimlink admin info"); TextCommandResult.Success("stub: claimlink admin info");
internal static void OnPlayerDisconnect(IServerPlayer player)
{
PendingActions.Remove(player.PlayerUID);
}
} }
+16 -7
View File
@@ -12,7 +12,7 @@ public class ClaimLinkModSystem : ModSystem
internal static ClaimLinkRegistry Registry = null!; internal static ClaimLinkRegistry Registry = null!;
internal static IGroupManager Groups = null!; internal static IGroupManager Groups = null!;
internal static IWorldAccessor World = null!; internal static IWorldAccessor World = null!;
internal ClaimLinkCommandListener? cmdListener; internal ClaimLinkCommandListener? CmdListener;
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server; public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
@@ -24,17 +24,18 @@ public class ClaimLinkModSystem : ModSystem
Groups = api.Groups; Groups = api.Groups;
World = api.World; World = api.World;
cmdListener = new ClaimLinkCommandListener(); CmdListener = new ClaimLinkCommandListener();
CommandHookModSystem.Register(cmdListener); CommandHookModSystem.Register(CmdListener);
ClaimLinkChatCommand.Register(api); ClaimLinkChatCommand.Register(api);
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect; api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
api.Event.PlayerDisconnect += ClaimLinkChatCommand.OnPlayerDisconnect;
} }
public override void Dispose() public override void Dispose()
{ {
if (cmdListener != null) if (CmdListener != null)
CommandHookModSystem.Unregister(cmdListener); CommandHookModSystem.Unregister(CmdListener);
} }
private static IEnumerable<(int claimIndex, LandClaim claim)> EnumerateOwnedClaims( private static IEnumerable<(int claimIndex, LandClaim claim)> EnumerateOwnedClaims(
@@ -52,7 +53,11 @@ public class ClaimLinkModSystem : ModSystem
} }
} }
internal static bool TryResolveOwnedClaim(string ownerPlayerUid, int claimIndex, out LandClaim? claim) internal static bool TryResolveOwnedClaim(
string ownerPlayerUid,
int claimIndex,
out LandClaim? claim
)
{ {
foreach ((int index, LandClaim c) in EnumerateOwnedClaims(ownerPlayerUid)) foreach ((int index, LandClaim c) in EnumerateOwnedClaims(ownerPlayerUid))
{ {
@@ -67,7 +72,11 @@ public class ClaimLinkModSystem : ModSystem
return false; return false;
} }
internal static bool TryResolveClaimIndex(string ownerPlayerUid, LandClaim target, out int claimIndex) internal static bool TryResolveClaimIndex(
string ownerPlayerUid,
LandClaim target,
out int claimIndex
)
{ {
foreach ((int index, LandClaim c) in EnumerateOwnedClaims(ownerPlayerUid)) foreach ((int index, LandClaim c) in EnumerateOwnedClaims(ownerPlayerUid))
{ {
+21 -8
View File
@@ -80,7 +80,9 @@ public class ClaimLinkCommandListener : ICommandHookListener
private static void Claim(Caller caller, CmdArgs args, TextCommandResult? result) private static void Claim(Caller caller, CmdArgs args, TextCommandResult? result)
{ {
string word = args.PeekWord(); string? word = args.PeekWord();
if (word == null)
return;
if (claimSub.TryGetValue(word, out SubHandler? handler)) if (claimSub.TryGetValue(word, out SubHandler? handler))
{ {
@@ -91,15 +93,27 @@ public class ClaimLinkCommandListener : ICommandHookListener
private static void ClaimLoad(Caller caller, CmdArgs args, TextCommandResult? result) private static void ClaimLoad(Caller caller, CmdArgs args, TextCommandResult? result)
{ {
if (result == null || result.Status != EnumCommandStatus.Success || caller.Player == null)
return;
int? claimIndex = args.PopInt(); int? claimIndex = args.PopInt();
if (claimIndex == null || claimIndex < 0 || claimIndex > 999) if (caller.Player == null)
return; return;
ClaimLinkModSystem.Logger.Notification($"Claim Index Loaded = {claimIndex}"); ClaimLinkModSystem.Logger.Notification(
PendingLoads[caller.Player.PlayerUID] = (int)claimIndex; "CLAIM LOAD {0}",
result == null ? "BEFORE" : "AFTER"
);
if (
claimIndex != null
&& ClaimLinkModSystem.TryResolveOwnedClaim(
caller.Player.PlayerUID,
(int)claimIndex,
out _
)
)
{
PendingLoads[caller.Player.PlayerUID] = (int)claimIndex;
ClaimLinkModSystem.Logger.Notification($"Claim Index Loaded = {claimIndex}");
}
} }
private static void ClaimCancel(Caller caller, CmdArgs args, TextCommandResult? result) private static void ClaimCancel(Caller caller, CmdArgs args, TextCommandResult? result)
@@ -204,6 +218,5 @@ public class ClaimLinkCommandListener : ICommandHookListener
internal static void OnPlayerDisconnect(IServerPlayer player) internal static void OnPlayerDisconnect(IServerPlayer player)
{ {
PendingLoads.Remove(player.PlayerUID); PendingLoads.Remove(player.PlayerUID);
ClaimLinkChatCommand.PendingActions.Remove(player.PlayerUID);
} }
} }