VSMod_AriasServerUtils/AriasServerUtils/EventHandler.cs
zontreck 5234415034 Begin to add a death inventory backup system
TODO: only take the backpack slots not the backpack contents; also exclude the character's clothing
2025-01-18 04:25:10 -07:00

75 lines
No EOL
2.5 KiB
C#

using System;
using Vintagestory.API.Common;
using Vintagestory.API.Config;
using Vintagestory.API.Server;
namespace AriasServerUtils
{
public class Events
{
internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args)
{
ServerUtilities.config.Spawn = null;
ServerUtilities.MarkDirty();
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:rmspawn"));
}
internal static TextCommandResult HandleReturnItems(TextCommandCallingArgs args)
{
IPlayer player = args[0] as IPlayer;
if (player is IServerPlayer isp)
{
if (ServerUtilities.backupInventory.ContainsKey(player.PlayerName))
isp.InventoryManager.DiscardAll();
else
{
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:nobackup"));
return TextCommandResult.Success();
}
foreach (var stack in ServerUtilities.backupInventory[player.PlayerName].Items)
{
isp.InventoryManager.TryGiveItemstack(stack.Clone());
}
}
return TextCommandResult.Success();
}
internal static TextCommandResult HandleSetSpawn(TextCommandCallingArgs args)
{
PlayerPosition pos = PlayerPosition.from(args.Caller.Entity);
ServerUtilities.config.Spawn = pos;
if (args.Caller.Player is IServerPlayer isp)
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:setspawn"));
ServerUtilities.MarkDirty();
return TextCommandResult.Success();
}
internal static TextCommandResult HandleSpawn(TextCommandCallingArgs args)
{
if (ServerUtilities.config.Spawn == null)
{
if (args.Caller.Player is IServerPlayer isp)
{
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:spawn-not-set"));
}
}
else
{
if (args.Caller.Player is IServerPlayer isp)
{
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:tp-spawn"));
ServerUtilities.config.Spawn.Merge(args.Caller.Player.Entity);
}
}
return TextCommandResult.Success();
}
}
}