Skip to content

Commit 7720a3c

Browse files
authored
Merge pull request #30 from HerrMagiic/feature/tagsupportforservercommands
Feature/tagsupportforservercommands
2 parents 288917b + d36a596 commit 7720a3c

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

CustomCommands/Interfaces/IPluginUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace CustomCommands.Interfaces;
77
public interface IPluginUtilities
88
{
99
string[] SplitStringByCommaOrSemicolon(string str);
10-
void ExecuteServerCommands(Commands cmd);
10+
void ExecuteServerCommands(Commands cmd, CCSPlayerController player);
1111
bool RequiresPermissions(CCSPlayerController player, Permission permissions);
1212
}

CustomCommands/Services/PluginUtilities.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ namespace CustomCommands.Services;
1010
public class PluginUtilities : IPluginUtilities
1111
{
1212
private readonly IPluginGlobals PluginGlobals;
13+
private readonly IReplaceTagsFunctions ReplaceTagsFunctions;
1314

14-
public PluginUtilities(IPluginGlobals PluginGlobals)
15+
public PluginUtilities(IPluginGlobals PluginGlobals, IReplaceTagsFunctions ReplaceTagsFunctions)
1516
{
1617
this.PluginGlobals = PluginGlobals;
18+
this.ReplaceTagsFunctions = ReplaceTagsFunctions;
1719
}
1820

1921
public string[] SplitStringByCommaOrSemicolon(string str)
@@ -23,13 +25,13 @@ public string[] SplitStringByCommaOrSemicolon(string str)
2325
.ToArray();
2426
}
2527

26-
public void ExecuteServerCommands(Commands cmd)
28+
public void ExecuteServerCommands(Commands cmd, CCSPlayerController player)
2729
{
2830
if (cmd.ServerCommands.Count == 0) return;
2931

3032
foreach (var serverCommand in cmd.ServerCommands)
3133
{
32-
Server.ExecuteCommand(serverCommand);
34+
Server.ExecuteCommand(ReplaceTagsFunctions.ReplaceMessageTags(serverCommand, player));
3335
}
3436
}
3537
public bool RequiresPermissions(CCSPlayerController player, Permission permissions)

CustomCommands/Services/RegisterCommands.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void AddCommands(Commands com)
4141

4242
MessageManager.SendMessage(player, com);
4343

44-
PluginUtilities.ExecuteServerCommands(com);
44+
PluginUtilities.ExecuteServerCommands(com, player);
4545
});
4646
}
4747
}

CustomCommands/Services/ReplaceTagsFunction.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ public string ReplaceLanguageTags(string input)
6464
public string ReplaceMessageTags(string input, CCSPlayerController player)
6565
{
6666
SteamID steamId = new SteamID(player.SteamID);
67-
67+
6868
Dictionary<string, string> replacements = new()
6969
{
7070
{"{PREFIX}", PluginGlobals.Config.Prefix ?? "<PREFIX not found>"},
7171
{"{MAP}", NativeAPI.GetMapName() ?? "<MAP not found>"},
7272
{"{TIME}", DateTime.Now.ToString("HH:mm:ss") ?? "<TIME not found>"},
7373
{"{DATE}", DateTime.Now.ToString("dd.MM.yyyy") ?? "<DATE not found>"},
7474
{"{PLAYERNAME}", player.PlayerName ?? "<PLAYERNAME not found>"},
75+
{"{USERID}", player.UserId.ToString() ?? "<USERID not found>"},
7576
{"{STEAMID2}", steamId.SteamId2 ?? "<STEAMID2 not found>"},
7677
{"{STEAMID3}", steamId.SteamId3 ?? "<STEAMID3 not found>"},
7778
{"{STEAMID32}", steamId.SteamId32.ToString() ?? "<STEAMID32 not found>"},

Examples/ServerCommands.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,15 @@
4040
"@customcommands/surf"
4141
]
4242
}
43+
},
44+
{
45+
"Title": "Kickme",
46+
"Description": "command that kicks yourself",
47+
"Command": "kickme",
48+
"Message": "Getting Kicket",
49+
"PrintTo": 0,
50+
"ServerCommands": [
51+
"kick {PLAYERNAME}" // Tags work for commands as well
52+
]
4353
}
4454
]

0 commit comments

Comments
 (0)