generated from AriasCreations/vsmodtemplate
Release 1.0.3
Fix: Permissions on /homes Add: /back
This commit is contained in:
parent
1f43ffaa6c
commit
3e0896f5f9
5 changed files with 97 additions and 8 deletions
|
@ -20,6 +20,8 @@ namespace AriasServerUtils
|
|||
|
||||
internal static Dictionary<string, PlayerStorage> mPlayerData = new Dictionary<string, PlayerStorage>();
|
||||
|
||||
internal static BackCaches backCaches = new BackCaches();
|
||||
|
||||
internal static Warps serverWarps = new Warps();
|
||||
|
||||
|
||||
|
@ -87,7 +89,7 @@ namespace AriasServerUtils
|
|||
api.ChatCommands.Create("sethome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Creates a home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleSetHome);
|
||||
api.ChatCommands.Create("home").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Teleports you to home").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleGoHome);
|
||||
api.ChatCommands.Create("delhome").RequiresPlayer().WithArgs(parsers.OptionalWord("name")).WithDescription("Deletes a home entry").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleDelHome);
|
||||
api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.controlserver).HandleWith(Events.HandleListHomes);
|
||||
api.ChatCommands.Create("homes").RequiresPlayer().WithDescription("Lists your homes").RequiresPrivilege(Privilege.chat).HandleWith(Events.HandleListHomes);
|
||||
|
||||
api.ChatCommands.Create("asu")
|
||||
.RequiresPrivilege(Privilege.chat)
|
||||
|
@ -118,6 +120,14 @@ namespace AriasServerUtils
|
|||
.WithDescription("DANGER: This updates the flag allowing anybody to create warps, even non-admins. It is recommended to leave this alone. The default is true/on/yes")
|
||||
.HandleWith(Events.HandleUpdateASUMgrWarps)
|
||||
.EndSubCommand()
|
||||
.BeginSubCommand("maxback")
|
||||
.RequiresPrivilege(Privilege.controlserver)
|
||||
.WithArgs(
|
||||
parsers.OptionalInt("max")
|
||||
)
|
||||
.WithDescription("Max number of back positions cached for players")
|
||||
.HandleWith(Events.HandleUpdateASUMaxBack)
|
||||
.EndSubCommand()
|
||||
.EndSubCommand()
|
||||
.BeginSubCommand("help")
|
||||
.RequiresPrivilege(Privilege.chat)
|
||||
|
@ -129,6 +139,13 @@ namespace AriasServerUtils
|
|||
api.ChatCommands.Create("warp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Warp to the specified server warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarp);
|
||||
api.ChatCommands.Create("delwarp").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Deletes the specified warp").WithArgs(parsers.OptionalWord("name")).HandleWith(Events.HandleWarpDelete);
|
||||
api.ChatCommands.Create("warps").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Lists all server warps").HandleWith(Events.HandleWarpList);
|
||||
|
||||
api.ChatCommands.Create("back").RequiresPlayer().RequiresPrivilege(Privilege.chat).WithDescription("Returns you to the last location you were at").HandleWith(Events.HandleBack);
|
||||
}
|
||||
|
||||
public static void NewBackCacheForPlayer(IServerPlayer player)
|
||||
{
|
||||
backCaches.AddPosition(player.PlayerName, PlayerPosition.from(player.Entity));
|
||||
}
|
||||
|
||||
private void OnPlayerDC(IServerPlayer byPlayer)
|
||||
|
@ -172,6 +189,8 @@ namespace AriasServerUtils
|
|||
PlayerInventory inv = new PlayerInventory();
|
||||
var invMgr = player.InventoryManager;
|
||||
|
||||
NewBackCacheForPlayer(player);
|
||||
|
||||
|
||||
var iBackpackSlotNum = 0;
|
||||
foreach (var type in saveInvTypes)
|
||||
|
|
|
@ -12,7 +12,23 @@ namespace AriasServerUtils
|
|||
{
|
||||
internal static TextCommandResult HandleASU(TextCommandCallingArgs args)
|
||||
{
|
||||
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps" })));
|
||||
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:help", ServerUtilities.config.MaxHomes, ServerUtilities.config.AdminsBypassMaxHomes, ServerUtilities.config.MaxBackCache, string.Join(", ", new string[] { "setspawn", "spawn", "delspawn", "sethome", "home", "delhome", "homes", "restoreinv", "asu", "warp", "setwarp", "delwarp", "warps", "back" })));
|
||||
}
|
||||
|
||||
internal static TextCommandResult HandleBack(TextCommandCallingArgs args)
|
||||
{
|
||||
PlayerPosition pos = ServerUtilities.backCaches.ReadAndPopNewestPosition(args.Caller.Player.PlayerName);
|
||||
if (pos == null)
|
||||
{
|
||||
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:back-no"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Go back to old position
|
||||
pos.Merge(args.Caller.Player.Entity);
|
||||
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:back"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args)
|
||||
|
@ -63,6 +79,7 @@ namespace AriasServerUtils
|
|||
PlayerStorage data = ServerUtilities.GetPlayerData(isp);
|
||||
if (data.Homes.ContainsKey(homeName))
|
||||
{
|
||||
ServerUtilities.NewBackCacheForPlayer(isp);
|
||||
data.Homes[homeName].Location.Merge(isp.Entity);
|
||||
|
||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-tp"));
|
||||
|
@ -177,6 +194,7 @@ namespace AriasServerUtils
|
|||
if (args.Caller.Player is IServerPlayer isp)
|
||||
{
|
||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:tp-spawn"));
|
||||
ServerUtilities.NewBackCacheForPlayer(isp);
|
||||
|
||||
ServerUtilities.config.Spawn.Merge(args.Caller.Player.Entity);
|
||||
}
|
||||
|
@ -188,7 +206,7 @@ namespace AriasServerUtils
|
|||
internal static TextCommandResult HandleUpdateASUBypass(TextCommandCallingArgs args)
|
||||
{
|
||||
|
||||
if (args[1] is bool bypass)
|
||||
if (args[0] is bool bypass)
|
||||
{
|
||||
ServerUtilities.config.AdminsBypassMaxHomes = bypass;
|
||||
ServerUtilities.MarkDirty();
|
||||
|
@ -199,6 +217,19 @@ namespace AriasServerUtils
|
|||
|
||||
}
|
||||
|
||||
internal static TextCommandResult HandleUpdateASUMaxBack(TextCommandCallingArgs args)
|
||||
{
|
||||
if (args[0] is int max)
|
||||
{
|
||||
ServerUtilities.config.MaxBackCache = max;
|
||||
ServerUtilities.MarkDirty();
|
||||
|
||||
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig"));
|
||||
}
|
||||
|
||||
return TextCommandResult.Success();
|
||||
}
|
||||
|
||||
internal static TextCommandResult HandleUpdateASUMaxHomes(TextCommandCallingArgs args)
|
||||
{
|
||||
if (args[0] is int maxHomes)
|
||||
|
@ -231,7 +262,7 @@ namespace AriasServerUtils
|
|||
{
|
||||
if (ServerUtilities.serverWarps.warps.ContainsKey(name))
|
||||
{
|
||||
|
||||
ServerUtilities.NewBackCacheForPlayer(isp);
|
||||
ServerUtilities.serverWarps.warps[name].Location.Merge(isp.Entity);
|
||||
|
||||
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:warp-set", name));
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace AriasServerUtils
|
|||
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; }
|
||||
|
@ -45,4 +46,39 @@ namespace AriasServerUtils
|
|||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
"home-del": "Home deleted",
|
||||
"home-list": "You have [{0}] home(s)\n\n{1}",
|
||||
|
||||
"help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; Admins can bypass max homes: {1}\n{2}",
|
||||
"help": "All Aria's Server Utilities Commands: \n\nMax Homes: {0}; \nAdmins can bypass max homes: {1}\nMax back positions: {2}\n\n{3}",
|
||||
|
||||
"updatedconfig": "[ASU] server config updated",
|
||||
|
||||
|
@ -27,5 +27,8 @@
|
|||
"warp-no": "You lack permissions to manage a warp",
|
||||
"warp-fail": "Warp [{0}] does not exist",
|
||||
"warp-del": "Warp [{0}] deleted",
|
||||
"warp-list": "There are [{0}] total warps\n\n{1}"
|
||||
"warp-list": "There are [{0}] total warps\n\n{1}",
|
||||
|
||||
"back-no": "There's no position to go back to",
|
||||
"back": "You've been taken back to your last position"
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
"modid": "ariasserverutils",
|
||||
"name": "Aria's Server Utilities",
|
||||
"authors": ["zontreck"],
|
||||
"description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 04:14 PM",
|
||||
"version": "1.0.2",
|
||||
"description": "A collection of server utilities\n\nBuild Date: 01-18-2025 @ 09:22 PM",
|
||||
"version": "1.0.3",
|
||||
"dependencies": {
|
||||
"game": ""
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue