Files
ClaimLink/ClaimLink/ClaimLinkModSystem.cs
T

65 lines
1.8 KiB
C#

using System.Collections.Generic;
using CommandHook;
using Vintagestory.API.Common;
using Vintagestory.API.Server;
namespace ClaimLink;
public class ClaimLinkModSystem : ModSystem
{
internal static ILandClaimAPI LandClaimAPI = null!;
internal static ILogger Logger = null!;
internal static ClaimLinkRegistry Registry = null!;
internal static IGroupManager Groups = null!;
internal static IWorldAccessor World = null!;
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;
Registry = new ClaimLinkRegistry(api.WorldManager.SaveGame);
Groups = api.Groups;
World = api.World;
cmdListener = new ClaimLinkCommandListener();
CommandHookModSystem.Register(cmdListener);
ClaimLinkChatCommand.Register(api);
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
}
public override void Dispose()
{
if (cmdListener != null)
CommandHookModSystem.Unregister(cmdListener);
}
internal static bool TryResolveOwnedClaim(string ownerPlayerUid, int localIndex, out int globalIndex, out LandClaim? claim)
{
globalIndex = -1;
claim = null;
List<LandClaim> claims = LandClaimAPI.All;
int count = 0;
for (int i = 0; i < claims.Count; ++i)
{
if (claims[i].OwnedByPlayerUid != ownerPlayerUid)
continue;
if (count == localIndex)
{
globalIndex = i;
claim = claims[i];
return true;
}
count++;
}
return false;
}
}