generated from AriasCreations/vsmodtemplate
131 lines
No EOL
3.7 KiB
C#
131 lines
No EOL
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.ConstrainedExecution;
|
|
using Vintagestory.API.Server;
|
|
|
|
namespace AriasServerUtils
|
|
{
|
|
public enum ModConfigType
|
|
{
|
|
Global,
|
|
World
|
|
}
|
|
|
|
[Serializable]
|
|
public class ASUModConfig
|
|
{
|
|
private readonly static Dictionary<CooldownType, string> m_defaultCD = new Dictionary<CooldownType, string>{
|
|
|
|
{ CooldownType.Home, "5s" },
|
|
{ CooldownType.Warp, "10s" },
|
|
{ CooldownType.Spawn, "5s" },
|
|
{ CooldownType.RTP, "30s" },
|
|
{ CooldownType.Back, "5s" }
|
|
};
|
|
|
|
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 int PlayerSleepingPercentage { get; set; } = 50;
|
|
public int MaxRTPBlockDistance { get; set; } = 5000;
|
|
public Dictionary<CooldownType, string> Cooldowns { get; set; } = new Dictionary<CooldownType, string>
|
|
{
|
|
{ CooldownType.Home, "5s" },
|
|
{ CooldownType.Warp, "10s" },
|
|
{ CooldownType.Spawn, "5s" },
|
|
{ CooldownType.RTP, "30s" },
|
|
{ CooldownType.Back, "5s" }
|
|
};
|
|
|
|
public Dictionary<CooldownType, string> GetDefaultCooldowns()
|
|
{
|
|
return m_defaultCD;
|
|
}
|
|
|
|
public void SanityCheckCooldowns()
|
|
{
|
|
foreach (var cd in GetDefaultCooldowns())
|
|
{
|
|
if (!Cooldowns.ContainsKey(cd.Key))
|
|
{
|
|
Cooldowns.Add(cd.Key, cd.Value);
|
|
ServerUtilities.MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public PlayerPosition Spawn { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public enum CooldownType
|
|
{
|
|
Home, // Default: 5s
|
|
Warp, // Default 10s
|
|
Spawn, // Default 5s
|
|
RTP, // Default 30s
|
|
Back // Default 5s
|
|
}
|
|
|
|
[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<string, Warp> warps = new Dictionary<string, Warp>();
|
|
}
|
|
|
|
|
|
public class BackCaches
|
|
{
|
|
private const int MaxCacheSize = 10;
|
|
private readonly Dictionary<string, LinkedList<PlayerPosition>> playerCache = new();
|
|
|
|
public void AddPosition(string playerName, PlayerPosition position)
|
|
{
|
|
if (!playerCache.TryGetValue(playerName, out var positions))
|
|
{
|
|
positions = new LinkedList<PlayerPosition>();
|
|
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
|
|
}
|
|
}
|
|
} |