generated from AriasCreations/vsmodtemplate
209 lines
No EOL
7.1 KiB
C#
209 lines
No EOL
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Vintagestory.API.Common;
|
|
using Vintagestory.API.Config;
|
|
using Vintagestory.API.Server;
|
|
|
|
namespace AriasServerUtils
|
|
{
|
|
public class Events
|
|
{
|
|
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" })));
|
|
}
|
|
|
|
internal static TextCommandResult HandleClearSpawn(TextCommandCallingArgs args)
|
|
{
|
|
ServerUtilities.config.Spawn = null;
|
|
ServerUtilities.MarkDirty();
|
|
|
|
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:rmspawn"));
|
|
}
|
|
|
|
internal static TextCommandResult HandleDelHome(TextCommandCallingArgs args)
|
|
{
|
|
string homeName = "default";
|
|
if (args.ArgCount > 0)
|
|
{
|
|
homeName = args[0] as string ?? "default";
|
|
}
|
|
|
|
if (args.Caller.Player is IServerPlayer isp)
|
|
{
|
|
PlayerStorage data = ServerUtilities.GetPlayerData(isp);
|
|
if (data.Homes.ContainsKey(homeName))
|
|
{
|
|
data.Homes.Remove(homeName);
|
|
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-del"));
|
|
ServerUtilities.MarkDirty();
|
|
}
|
|
else
|
|
{
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-no"));
|
|
}
|
|
}
|
|
|
|
return TextCommandResult.Success();
|
|
}
|
|
|
|
internal static TextCommandResult HandleGoHome(TextCommandCallingArgs args)
|
|
{
|
|
string homeName = "default";
|
|
if (args.ArgCount > 0)
|
|
{
|
|
homeName = args[0] as string ?? "default";
|
|
}
|
|
|
|
if (args.Caller.Player is IServerPlayer isp)
|
|
{
|
|
PlayerStorage data = ServerUtilities.GetPlayerData(isp);
|
|
if (data.Homes.ContainsKey(homeName))
|
|
{
|
|
data.Homes[homeName].Location.Merge(isp.Entity);
|
|
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-tp"));
|
|
}
|
|
else
|
|
{
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-no"));
|
|
}
|
|
}
|
|
|
|
return TextCommandResult.Success();
|
|
}
|
|
|
|
internal static TextCommandResult HandleListHomes(TextCommandCallingArgs args)
|
|
{
|
|
if (args.Caller.Player is IServerPlayer isp)
|
|
{
|
|
PlayerStorage data = ServerUtilities.GetPlayerData(isp);
|
|
|
|
List<string> lTmp = new List<string>();
|
|
foreach (var entry in data.Homes)
|
|
{
|
|
lTmp.Add(entry.Key);
|
|
}
|
|
|
|
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-list", data.Homes.Count, string.Join(", ", lTmp)));
|
|
|
|
}
|
|
|
|
return TextCommandResult.Success();
|
|
}
|
|
|
|
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 HandleSetHome(TextCommandCallingArgs args)
|
|
{
|
|
bool isOp = args.Caller.HasPrivilege(Privilege.controlserver);
|
|
string homeName = "default";
|
|
if (args.ArgCount > 0)
|
|
{
|
|
homeName = args[0] as string ?? "default";
|
|
}
|
|
|
|
if (args.Caller.Player is IServerPlayer isp)
|
|
{
|
|
bool bypass = isOp && ServerUtilities.config.AdminsBypassMaxHomes;
|
|
var data = ServerUtilities.GetPlayerData(isp);
|
|
|
|
if (bypass || data.Homes.Count < ServerUtilities.config.MaxHomes || data.Homes.ContainsKey(homeName))
|
|
{
|
|
data.Homes[homeName] = Home.MakeHome(args.Caller.Player.Entity, homeName);
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-set"));
|
|
|
|
}
|
|
else
|
|
{
|
|
ServerUtilities.SendMessageTo(isp, Lang.Get($"{ServerUtilities.MOD_ID}:home-max"));
|
|
}
|
|
|
|
|
|
ServerUtilities.MarkDirty();
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
internal static TextCommandResult HandleUpdateASU(TextCommandCallingArgs args)
|
|
{
|
|
|
|
if (args[0] is int maxHomes)
|
|
{
|
|
|
|
ServerUtilities.config.MaxHomes = maxHomes;
|
|
if (args[1] is bool bypass)
|
|
{
|
|
ServerUtilities.config.AdminsBypassMaxHomes = bypass;
|
|
}
|
|
|
|
ServerUtilities.MarkDirty();
|
|
return TextCommandResult.Success(Lang.Get($"{ServerUtilities.MOD_ID}:updatedconfig"));
|
|
|
|
}
|
|
|
|
return TextCommandResult.Success();
|
|
|
|
}
|
|
}
|
|
} |