Compare commits
3
Commits
9206ecd6a9
...
a470456dcc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a470456dcc | ||
|
|
1baa20022b | ||
|
|
5c7fa58ea2 |
@@ -113,7 +113,7 @@ public static class ClaimLinkChatCommand
|
||||
admin.EndSubCommand();
|
||||
}
|
||||
|
||||
public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink new");
|
||||
public static TextCommandResult New(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlinknew");
|
||||
public static TextCommandResult Link(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink link");
|
||||
public static TextCommandResult Confirm(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink confirm");
|
||||
public static TextCommandResult Cancel(TextCommandCallingArgs args) => TextCommandResult.Success("stub: claimlink cancel");
|
||||
|
||||
@@ -6,16 +6,22 @@ namespace ClaimLink;
|
||||
|
||||
public class ClaimLinkModSystem : ModSystem
|
||||
{
|
||||
internal static ILandClaimAPI LandClaimAPI;
|
||||
internal static ILogger Logger;
|
||||
internal ClaimLinkCommandListener? cmdListener;
|
||||
|
||||
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
|
||||
|
||||
public override void StartServerSide(ICoreServerAPI api)
|
||||
{
|
||||
LandClaimAPI = api.World.Claims;
|
||||
Logger = api.Logger;
|
||||
|
||||
cmdListener = new ClaimLinkCommandListener();
|
||||
CommandHookModSystem.Register(cmdListener);
|
||||
|
||||
ClaimLinkChatCommand.Register(api);
|
||||
|
||||
api.Event.PlayerDisconnect += ClaimLinkCommandListener.OnPlayerDisconnect;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Vintagestory.API.Common;
|
||||
using System.Collections.Generic;
|
||||
using CommandHook;
|
||||
using Vintagestory.API.Server;
|
||||
|
||||
namespace ClaimLink;
|
||||
|
||||
@@ -12,13 +13,134 @@ public class ClaimLinkCommandListener : ICommandHookListener
|
||||
|
||||
public CommandRegistration Registration => new(Before, After);
|
||||
|
||||
private static Dictionary<string, int> pendingLoads = new Dictionary<string, int>();
|
||||
|
||||
private delegate void SubHandler(Caller caller, CmdArgs args);
|
||||
|
||||
private static readonly Dictionary<string, SubHandler> topLevel = new()
|
||||
{
|
||||
["claim"] = Claim,
|
||||
["free"] = Free,
|
||||
["info"] = Info,
|
||||
["list"] = List,
|
||||
["adminfree"] = AdminFree,
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, SubHandler> claimSub = new()
|
||||
{
|
||||
["load"] = ClaimLoad,
|
||||
["new"] = ClaimNew,
|
||||
["grant"] = ClaimGrant,
|
||||
["revoke"] = ClaimRevoke,
|
||||
["grantgroup"] = ClaimGrantGroup,
|
||||
["revokegroup"] = ClaimRevokeGroup,
|
||||
["start"] = ClaimStart,
|
||||
["end"] = ClaimEnd,
|
||||
["grow"] = ClaimGrow,
|
||||
["shrink"] = ClaimShrink,
|
||||
["add"] = ClaimAdd,
|
||||
["allowuseeveryone"] = ClaimAllowUseEveryone,
|
||||
["plevel"] = ClaimPLevel,
|
||||
["fullheight"] = ClaimFullHeight,
|
||||
["save"] = ClaimSave,
|
||||
["cancel"] = ClaimCancel,
|
||||
["download"] = ClaimDownload,
|
||||
};
|
||||
|
||||
private TextCommandResult? Before(TextCommandCallingArgs args)
|
||||
{
|
||||
CmdArgs rawArgs = args.RawArgs.Clone();
|
||||
|
||||
while (rawArgs.Length > 0)
|
||||
{
|
||||
string word = rawArgs.PeekWord();
|
||||
|
||||
if (topLevel.TryGetValue(word, out SubHandler handler))
|
||||
{
|
||||
rawArgs.PopWord();
|
||||
handler(args.Caller, rawArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
rawArgs.PopWord();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void After(TextCommandCallingArgs args, TextCommandResult result)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static void Claim(Caller caller, CmdArgs args)
|
||||
{
|
||||
string word = args.PeekWord();
|
||||
|
||||
if (claimSub.TryGetValue(word, out SubHandler handler))
|
||||
{
|
||||
args.PopWord();
|
||||
handler(caller, args);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClaimLoad(Caller caller, CmdArgs args)
|
||||
{
|
||||
if (caller.Player == null)
|
||||
return;
|
||||
|
||||
int? claimIndex = args.PopInt();
|
||||
if (claimIndex == null || claimIndex < 0 || claimIndex > 999)
|
||||
return;
|
||||
|
||||
List<LandClaim> claims = ClaimLinkModSystem.LandClaimAPI.All, ownedClaims = new List<LandClaim>();
|
||||
List<int> globalIndex = new List<int>();
|
||||
for (int i = 0; i < claims.Count; ++i)
|
||||
{
|
||||
if (claims[i].OwnedByPlayerUid != caller.Player.PlayerUID)
|
||||
continue;
|
||||
|
||||
globalIndex.Add(i);
|
||||
ownedClaims.Add(claims[i]);
|
||||
}
|
||||
|
||||
if (claimIndex >= ownedClaims.Count)
|
||||
return;
|
||||
|
||||
pendingLoads[caller.Player.PlayerUID] = globalIndex[(int)claimIndex];
|
||||
}
|
||||
|
||||
private static void ClaimCancel(Caller caller, CmdArgs args)
|
||||
{
|
||||
if (caller.Player == null)
|
||||
return;
|
||||
|
||||
pendingLoads.Remove(caller.Player.PlayerUID);
|
||||
}
|
||||
|
||||
private static void Free(Caller caller, CmdArgs args) { }
|
||||
private static void Info(Caller caller, CmdArgs args) { }
|
||||
private static void List(Caller caller, CmdArgs args) { }
|
||||
private static void AdminFree(Caller caller, CmdArgs args) { }
|
||||
|
||||
private static void ClaimNew(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimGrant(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimRevoke(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimGrantGroup(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimRevokeGroup(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimStart(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimEnd(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimGrow(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimShrink(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimAdd(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimAllowUseEveryone(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimPLevel(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimFullHeight(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimSave(Caller caller, CmdArgs args) { }
|
||||
private static void ClaimDownload(Caller caller, CmdArgs args) { }
|
||||
|
||||
internal static void OnPlayerDisconnect(IServerPlayer player)
|
||||
{
|
||||
pendingLoads.Remove(player.PlayerUID);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user