Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b10d3a0f55 | ||
|
|
b5ceba442a | ||
|
|
d248b772dc | ||
|
|
c8fc86069b | ||
|
|
2e4cc25b20 |
@@ -326,9 +326,12 @@ public static class ClaimLinkChatCommand
|
||||
$"{claimDesc} will be linked into '{groupName}'.",
|
||||
() =>
|
||||
{
|
||||
ClaimLinkModSystem.Registry.AddEntry(playerUid, groupId, claimIndex);
|
||||
|
||||
return TextCommandResult.Success($"Linked {claimDesc} to '{groupName}'.");
|
||||
bool success = ClaimLinkModSystem.Registry.AddEntry(playerUid, groupId, claimIndex);
|
||||
return success
|
||||
? TextCommandResult.Success($"Linked {claimDesc} to '{groupName}'.")
|
||||
: TextCommandResult.Error(
|
||||
$"Unable to link {claimIndex} to '{groupName}' it is currently being modified."
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -390,6 +393,7 @@ public static class ClaimLinkChatCommand
|
||||
{
|
||||
ClaimLinkModSystem.Registry.RemoveAllForPlayerInGroup(targetUid, group.Uid);
|
||||
ClaimLinkCommandListener.PendingLoads.Remove(targetUid);
|
||||
PendingActions.Remove(targetUid);
|
||||
|
||||
return TextCommandResult.Success(
|
||||
$"Unlinked all claims of {target.PlayerName} from '{groupName}'."
|
||||
@@ -508,6 +512,8 @@ public static class ClaimLinkChatCommand
|
||||
if (oldOwnerMembership != null)
|
||||
oldOwnerMembership.Level = EnumPlayerGroupMemberShip.Op;
|
||||
|
||||
PendingActions.Remove(oldOwnerUid);
|
||||
|
||||
string notice = $"'{group.Name}' is now owned by {target.PlayerName}.";
|
||||
|
||||
HashSet<string> notifyUids = ClaimLinkModSystem
|
||||
@@ -540,13 +546,19 @@ public static class ClaimLinkChatCommand
|
||||
if (err != null)
|
||||
return err;
|
||||
|
||||
return TextCommandResult.Success(FormatInfo(groupName, group.Uid));
|
||||
IPlayer player = args.Caller.Player;
|
||||
bool showDetails =
|
||||
player.HasPrivilege(Privilege.controlserver) || player.GetGroup(group.Uid) != null;
|
||||
|
||||
return TextCommandResult.Success(FormatInfo(groupName, group.Uid, showDetails));
|
||||
}
|
||||
|
||||
public static TextCommandResult List(TextCommandCallingArgs args)
|
||||
{
|
||||
List<int> groupIds = ClaimLinkModSystem
|
||||
.Registry.All.OrderByDescending(id => ClaimLinkModSystem.Registry.MemberCountForGroup(id))
|
||||
.Registry.All.OrderByDescending(id =>
|
||||
ClaimLinkModSystem.Registry.MemberCountForGroup(id)
|
||||
)
|
||||
.ToList();
|
||||
|
||||
if (groupIds.Count == 0)
|
||||
@@ -580,7 +592,7 @@ public static class ClaimLinkChatCommand
|
||||
return string.IsNullOrEmpty(claim.Description) ? $"claim {claimIndex}" : claim.Description;
|
||||
}
|
||||
|
||||
private static string FormatInfo(string groupName, int groupId)
|
||||
private static string FormatInfo(string groupName, int groupId, bool showDetails)
|
||||
{
|
||||
int memberCount = ClaimLinkModSystem.Registry.MemberCountForGroup(groupId);
|
||||
|
||||
@@ -592,6 +604,13 @@ public static class ClaimLinkChatCommand
|
||||
foreach (string uid in ClaimLinkModSystem.Registry.MemberUidsForGroup(groupId))
|
||||
{
|
||||
string name = ClaimLinkModSystem.World.PlayerByUid(uid)?.PlayerName ?? uid;
|
||||
|
||||
if (!showDetails)
|
||||
{
|
||||
sb.AppendLine($" {name}");
|
||||
continue;
|
||||
}
|
||||
|
||||
IEnumerable<string> claims = ClaimLinkModSystem
|
||||
.Registry.ClaimsForPlayerInGroup(uid, groupId)
|
||||
.Select(i => DescribeClaim(uid, i));
|
||||
|
||||
@@ -12,6 +12,7 @@ public class ClaimLinkModSystem : ModSystem
|
||||
internal static ClaimLinkRegistry Registry = null!;
|
||||
internal static IGroupManager Groups = null!;
|
||||
internal static IWorldAccessor World = null!;
|
||||
internal static IPlayerDataManager PlayerData = null!;
|
||||
internal ClaimLinkCommandListener? CmdListener;
|
||||
|
||||
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
|
||||
@@ -19,10 +20,11 @@ public class ClaimLinkModSystem : ModSystem
|
||||
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;
|
||||
Groups = api.Groups;
|
||||
Logger = api.Logger;
|
||||
PlayerData = api.PlayerData;
|
||||
Registry = new ClaimLinkRegistry(api.WorldManager.SaveGame);
|
||||
|
||||
CmdListener = new ClaimLinkCommandListener();
|
||||
CommandHookModSystem.Register(CmdListener);
|
||||
|
||||
@@ -63,14 +63,19 @@ public class ClaimLinkRegistry
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddEntry(string uid, int groupId, int claimIndex)
|
||||
public bool AddEntry(string uid, int groupId, int claimIndex)
|
||||
{
|
||||
if (ClaimLinkCommandListener.PendingLoads.ContainsKey(uid))
|
||||
return false;
|
||||
if (!Exists(groupId))
|
||||
return false;
|
||||
if (!entries.TryGetValue(uid, out var groups))
|
||||
entries[uid] = groups = new();
|
||||
if (!groups.TryGetValue(groupId, out var claims))
|
||||
groups[groupId] = claims = new();
|
||||
claims.Add(claimIndex);
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveEntry(string uid, int groupId, int claimIndex)
|
||||
@@ -93,6 +98,7 @@ public class ClaimLinkRegistry
|
||||
if (claims[i] > removedIndex)
|
||||
claims[i]--;
|
||||
}
|
||||
|
||||
Prune();
|
||||
Save();
|
||||
}
|
||||
@@ -119,6 +125,7 @@ public class ClaimLinkRegistry
|
||||
if (i >= 0)
|
||||
claims[i] = newIndex;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -135,10 +142,16 @@ public class ClaimLinkRegistry
|
||||
Save();
|
||||
}
|
||||
|
||||
public void ClearAllForPlayer(string uid)
|
||||
{
|
||||
entries.Remove(uid);
|
||||
Save();
|
||||
}
|
||||
|
||||
public IEnumerable<string> MemberUidsForGroup(int groupId)
|
||||
{
|
||||
foreach (var (uid, groups) in entries)
|
||||
if (groups.TryGetValue(groupId, out var claims) && claims.Count > 0)
|
||||
if (groups.ContainsKey(groupId))
|
||||
yield return uid;
|
||||
}
|
||||
|
||||
@@ -170,15 +183,15 @@ public class ClaimLinkRegistry
|
||||
{
|
||||
var entryList = new List<ClaimLinkEntrySaveData>();
|
||||
foreach (var (uid, groups) in entries)
|
||||
foreach (var (groupId, claims) in groups)
|
||||
entryList.Add(
|
||||
new ClaimLinkEntrySaveData
|
||||
{
|
||||
OwnerPlayerUid = uid,
|
||||
GroupId = groupId,
|
||||
ClaimIndicies = new(claims),
|
||||
}
|
||||
);
|
||||
foreach (var (groupId, claims) in groups)
|
||||
entryList.Add(
|
||||
new ClaimLinkEntrySaveData
|
||||
{
|
||||
OwnerPlayerUid = uid,
|
||||
GroupId = groupId,
|
||||
ClaimIndicies = new(claims),
|
||||
}
|
||||
);
|
||||
|
||||
saveGame.StoreData(
|
||||
SaveKey,
|
||||
|
||||
@@ -22,6 +22,7 @@ public class ClaimLinkCommandListener : ICommandHookListener
|
||||
["claim"] = Claim,
|
||||
["free"] = Free,
|
||||
["adminfree"] = AdminFree,
|
||||
["adminfreehere"] = AdminFreeHere,
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, SubHandler> claimSub = new()
|
||||
@@ -83,6 +84,7 @@ public class ClaimLinkCommandListener : ICommandHookListener
|
||||
|
||||
ClaimLinkModSystem.Registry.ClaimSaved(uid, pendingIndex);
|
||||
PendingLoads.Remove(uid);
|
||||
ClaimLinkChatCommand.PendingActions.Remove(uid);
|
||||
}
|
||||
|
||||
private static void ClaimLoad(Caller caller, CmdArgs args)
|
||||
@@ -119,9 +121,27 @@ public class ClaimLinkCommandListener : ICommandHookListener
|
||||
return;
|
||||
|
||||
ClaimLinkModSystem.Registry.ClaimRemoved(uid, (int)claimIndex);
|
||||
ClaimLinkChatCommand.PendingActions.Remove(uid);
|
||||
}
|
||||
|
||||
private static void AdminFree(Caller caller, CmdArgs args)
|
||||
{
|
||||
if (caller.Player == null)
|
||||
return;
|
||||
|
||||
string? name = args.PopWord();
|
||||
if (name == null)
|
||||
return;
|
||||
|
||||
string? uid = ClaimLinkModSystem.PlayerData.GetPlayerDataByLastKnownName(name)?.PlayerUID;
|
||||
if (uid == null)
|
||||
return;
|
||||
|
||||
ClaimLinkModSystem.Registry.ClearAllForPlayer(uid);
|
||||
ClaimLinkChatCommand.PendingActions.Remove(uid);
|
||||
}
|
||||
|
||||
private static void AdminFreeHere(Caller caller, CmdArgs args)
|
||||
{
|
||||
if (caller.Player == null)
|
||||
return;
|
||||
@@ -132,7 +152,10 @@ public class ClaimLinkCommandListener : ICommandHookListener
|
||||
|
||||
foreach (LandClaim c in claims)
|
||||
if (ClaimLinkModSystem.TryResolveClaimIndex(c.OwnedByPlayerUid, c, out int claimIndex))
|
||||
{
|
||||
ClaimLinkModSystem.Registry.ClaimRemoved(c.OwnedByPlayerUid, claimIndex);
|
||||
ClaimLinkChatCommand.PendingActions.Remove(c.OwnedByPlayerUid);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void OnPlayerDisconnect(IServerPlayer player)
|
||||
|
||||
Reference in New Issue
Block a user