Compare commits
4
Commits
ce851148f0
...
93fe059754
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93fe059754 | ||
|
|
d586878325 | ||
|
|
b60b0b98b7 | ||
|
|
7e47f8d409 |
@@ -6,14 +6,24 @@ public struct CommandData
|
||||
{
|
||||
public readonly IServerPlayer? Sender;
|
||||
public readonly string FullCommand;
|
||||
public readonly bool IsPlayerCommand;
|
||||
public bool Cancel;
|
||||
public readonly string CommandName;
|
||||
private byte _flags;
|
||||
|
||||
private const byte FlagIsPlayerCommand = 1 << 0;
|
||||
private const byte FlagCancel = 1 << 1;
|
||||
|
||||
public bool IsPlayerCommand => (_flags & FlagIsPlayerCommand) != 0;
|
||||
public bool Cancel
|
||||
{
|
||||
get => (_flags & FlagCancel) != 0;
|
||||
set => _flags = value ? (byte)(_flags | FlagCancel) : (byte)(_flags & ~FlagCancel);
|
||||
}
|
||||
|
||||
public CommandData(IServerPlayer? sender, string fullCommand)
|
||||
{
|
||||
Sender = sender;
|
||||
FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty;
|
||||
IsPlayerCommand = sender != null;
|
||||
Cancel = false;
|
||||
CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty;
|
||||
_flags = sender != null ? FlagIsPlayerCommand : (byte)0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace CommandHook;
|
||||
|
||||
public delegate void CommandHookDelegate(ref CommandData data);
|
||||
@@ -1,14 +1,27 @@
|
||||
using Vintagestory.API.Server;
|
||||
using System.Collections.Generic;
|
||||
using Vintagestory.API.Common;
|
||||
using Vintagestory.API.Server;
|
||||
|
||||
namespace CommandHook;
|
||||
|
||||
public class CommandHookModSystem : ModSystem
|
||||
{
|
||||
private readonly Dictionary<string, List<CommandRegistration>> _registrations = new();
|
||||
|
||||
public override bool ShouldLoad(EnumAppSide forSide) => forSide == EnumAppSide.Server;
|
||||
|
||||
public override void StartServerSide(ICoreServerAPI api)
|
||||
{
|
||||
Mod.Logger.Notification("[CommandHook] Loaded");
|
||||
}
|
||||
|
||||
public void Register(string modId, CommandRegistration registration)
|
||||
{
|
||||
if (!_registrations.TryGetValue(modId, out var list))
|
||||
{
|
||||
list = new List<CommandRegistration>();
|
||||
_registrations[modId] = list;
|
||||
}
|
||||
list.Add(registration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace CommandHook;
|
||||
|
||||
public struct CommandRegistration
|
||||
{
|
||||
public readonly string CommandFilter;
|
||||
public readonly CommandHookDelegate? Before;
|
||||
public readonly CommandHookDelegate? After;
|
||||
|
||||
public CommandRegistration(
|
||||
string commandFilter,
|
||||
CommandHookDelegate? before,
|
||||
CommandHookDelegate? after
|
||||
)
|
||||
{
|
||||
CommandFilter = commandFilter;
|
||||
Before = before;
|
||||
After = after;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user