Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0dcd599cf | ||
|
|
a130042206 |
@@ -25,7 +25,7 @@ public static class ChatCommandApiPatch
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
var sender = args.Caller.Player as IServerPlayer;
|
var sender = args.Caller.Player as IServerPlayer;
|
||||||
var data = new CommandData(sender, "/" + commandName);
|
var data = new CommandData(sender, commandName, "/" + commandName);
|
||||||
|
|
||||||
if (system.FireBefore(commandName, ref data))
|
if (system.FireBefore(commandName, ref data))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ public struct CommandData
|
|||||||
set => flags = value ? (byte)(flags | FlagCancel) : (byte)(flags & ~FlagCancel);
|
set => flags = value ? (byte)(flags | FlagCancel) : (byte)(flags & ~FlagCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandData(IServerPlayer? sender, string fullCommand)
|
public CommandData(IServerPlayer? sender, string commandName, string fullCommand)
|
||||||
{
|
{
|
||||||
Sender = sender;
|
Sender = sender;
|
||||||
FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty;
|
CommandName = commandName;
|
||||||
CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty;
|
FullCommand = fullCommand;
|
||||||
flags = sender != null ? FlagIsPlayerCommand : (byte)0;
|
flags = sender != null ? FlagIsPlayerCommand : (byte)0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,8 +109,8 @@ public class CommandHookModSystem : ModSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var wildcard in wildcards)
|
foreach (var wildcard in wildcards)
|
||||||
foreach (var mods in builder.Values)
|
foreach (var mods in builder.Values)
|
||||||
mods[wildcard.ModId] = wildcard.Registration;
|
mods[wildcard.ModId] = wildcard.Registration;
|
||||||
|
|
||||||
var pruned = new Dictionary<string, FrozenDictionary<string, CommandRegistration>>(
|
var pruned = new Dictionary<string, FrozenDictionary<string, CommandRegistration>>(
|
||||||
builder.Count
|
builder.Count
|
||||||
@@ -125,8 +125,14 @@ public class CommandHookModSystem : ModSystem
|
|||||||
internal bool FireBefore(string commandName, ref CommandData data)
|
internal bool FireBefore(string commandName, ref CommandData data)
|
||||||
{
|
{
|
||||||
if (registrations.TryGetValue(commandName, out var mods))
|
if (registrations.TryGetValue(commandName, out var mods))
|
||||||
|
{
|
||||||
foreach (var (_, reg) in mods)
|
foreach (var (_, reg) in mods)
|
||||||
|
{
|
||||||
reg.Before?.Invoke(ref data);
|
reg.Before?.Invoke(ref data);
|
||||||
|
if (data.Cancel)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return data.Cancel;
|
return data.Cancel;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
"modid": "commandhook",
|
"modid": "commandhook",
|
||||||
"name": "CommandHook",
|
"name": "CommandHook",
|
||||||
"description": "Exposes server command events for other mods to hook into.",
|
"description": "Exposes server command events for other mods to hook into.",
|
||||||
"authors": ["anth64"],
|
"authors": [
|
||||||
|
"anth64"
|
||||||
|
],
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"side": "Server",
|
"side": "Server",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
Reference in New Issue
Block a user