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)
{
if (
!ClaimLinkModSystem.TryResolveOwnedClaim(ownerPlayerUid, claimIndex, out LandClaim? claim)
!ClaimLinkModSystem.TryResolveOwnedClaim(
ownerPlayerUid,
claimIndex,
out LandClaim? claim
)
|| claim == null
)
return $"claim {claimIndex}";
@@ -644,4 +648,9 @@ public static class ClaimLinkChatCommand
public static TextCommandResult AdminInfo(TextCommandCallingArgs args) =>
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 IGroupManager Groups = null!;
internal static IWorldAccessor World = null!;
internal ClaimLinkCommandListener? cmdListener;
internal ClaimLinkCommandListener? CmdListener;
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
@@ -24,17 +24,18 @@ public class ClaimLinkModSystem : ModSystem
Groups = api.Groups;
World = api.World;
cmdListener = new ClaimLinkCommandListener();
CommandHookModSystem.Register(cmdListener);
CmdListener = new ClaimLinkCommandListener();
CommandHookModSystem.Register(CmdListener);
ClaimLinkChatCommand.Register(api);
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
api.Event.PlayerDisconnect += ClaimLinkChatCommand.OnPlayerDisconnect;
}
public override void Dispose()
{
if (cmdListener != null)
CommandHookModSystem.Unregister(cmdListener);
if (CmdListener != null)
CommandHookModSystem.Unregister(CmdListener);
}
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))
{
@@ -67,7 +72,11 @@ public class ClaimLinkModSystem : ModSystem
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))
{
+21 -8
View File
@@ -80,7 +80,9 @@ public class ClaimLinkCommandListener : ICommandHookListener
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))
{
@@ -91,15 +93,27 @@ public class ClaimLinkCommandListener : ICommandHookListener
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();
if (claimIndex == null || claimIndex < 0 || claimIndex > 999)
if (caller.Player == null)
return;
ClaimLinkModSystem.Logger.Notification($"Claim Index Loaded = {claimIndex}");
PendingLoads[caller.Player.PlayerUID] = (int)claimIndex;
ClaimLinkModSystem.Logger.Notification(
"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)
@@ -204,6 +218,5 @@ public class ClaimLinkCommandListener : ICommandHookListener
internal static void OnPlayerDisconnect(IServerPlayer player)
{
PendingLoads.Remove(player.PlayerUID);
ClaimLinkChatCommand.PendingActions.Remove(player.PlayerUID);
}
}