using System; using System.Collections.Generic; using Vintagestory.API.Server; namespace AriasServerUtils { public enum ModConfigType { Global, World } [Serializable] public class ASUModConfig { public int MaxHomes { get; set; } = 20; public bool AdminsBypassMaxHomes { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true; public int MaxBackCache { get; set; } = 10; public PlayerPosition Spawn { get; set; } } [Serializable] public class Warp { public PlayerPosition Location; public string CreatedBy; public DateTime CreatedAt; public static Warp Create(IServerPlayer player) { Warp warp = new Warp(); warp.Location = PlayerPosition.from(player.Entity); warp.CreatedBy = player.PlayerName; warp.CreatedAt = DateTime.Now; return warp; } } [Serializable] public class Warps { public Dictionary warps = new Dictionary(); } public class BackCaches { private const int MaxCacheSize = 10; private readonly Dictionary> playerCache = new(); public void AddPosition(string playerName, PlayerPosition position) { if (!playerCache.TryGetValue(playerName, out var positions)) { positions = new LinkedList(); playerCache[playerName] = positions; } if (positions.Count >= MaxCacheSize) { positions.RemoveFirst(); // Remove the oldest position } positions.AddLast(position.Clone()); // Add the new position } public PlayerPosition ReadAndPopNewestPosition(string playerName) { if (playerCache.TryGetValue(playerName, out var positions) && positions.Count > 0) { var newestPosition = positions.Last.Value; positions.RemoveLast(); // Remove the newest position return newestPosition; } return null; // Return null if no positions are available } } }