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