Skip to content
This repository was archived by the owner on Apr 7, 2023. It is now read-only.

Commit be5354e

Browse files
committed
Now also offers persistant overwatch toggles
1 parent 953cd58 commit be5354e

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

ToggleTag/ToggleTag.cs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,23 @@ namespace ToggleTag
1818
[PluginDetails(
1919
author = "Karl Essinger",
2020
name = "ToggleTag",
21-
description = "Persistant toggeling of role tags.",
21+
description = "Persistant toggeling of role tags and overwatch.",
2222
id = "karlofduty.toggletag",
23-
version = "1.0.1",
23+
version = "1.0.2",
2424
SmodMajor = 3,
2525
SmodMinor = 1,
2626
SmodRevision = 19
2727
)]
2828
public class ToggleTag : Plugin
2929
{
3030
public HashSet<string> tagsToggled;
31+
public HashSet<string> overwatchToggled;
32+
33+
private readonly string defaultConfig =
34+
"{\n" +
35+
" \"tags\": [],\n" +
36+
" \"overwatch\": []\n" +
37+
"}";
3138

3239
public override void OnDisable()
3340
{
@@ -38,10 +45,13 @@ public override void OnEnable()
3845
{
3946
if(!File.Exists(FileManager.AppFolder + "toggletag.json"))
4047
{
41-
File.WriteAllText(FileManager.AppFolder + "toggletag.json", "[]");
48+
File.WriteAllText(FileManager.AppFolder + "toggletag.json", defaultConfig);
4249
}
43-
JArray jsonObject = JArray.Parse(File.ReadAllText(FileManager.AppFolder + "toggletag.json"));
44-
tagsToggled = new HashSet<string>(jsonObject.Values<string>());
50+
JToken jsonObject = JToken.Parse(File.ReadAllText(FileManager.AppFolder + "toggletag.json"));
51+
52+
53+
tagsToggled = new HashSet<string>(jsonObject.SelectToken("tags").Values<string>());
54+
overwatchToggled = new HashSet<string>(jsonObject.SelectToken("overwatch").Values<string>());
4555
}
4656

4757
public override void Register()
@@ -56,12 +66,21 @@ public void SaveTagsToFile()
5666
{
5767
// Save the state to file
5868
StringBuilder builder = new StringBuilder();
59-
builder.Append("[\n");
69+
builder.Append("{\n");
70+
builder.Append(" \"tags\":\n");
71+
builder.Append(" [\n");
6072
foreach (string line in tagsToggled)
6173
{
62-
builder.Append("\"" + line + "\"," + "\n");
74+
builder.Append(" \"" + line + "\"," + "\n");
75+
}
76+
builder.Append(" ],\n");
77+
builder.Append(" \"overwatch\":\n");
78+
builder.Append(" [\n");
79+
foreach (string line in overwatchToggled)
80+
{
81+
builder.Append(" \"" + line + "\"," + "\n");
6382
}
64-
builder.Append("]");
83+
builder.Append(" ]\n}");
6584
File.WriteAllText(FileManager.AppFolder + "toggletag.json", builder.ToString());
6685
}
6786

@@ -225,13 +244,13 @@ public void OnPlayerJoin(PlayerJoinEvent ev)
225244
if(plugin.tagsToggled.Contains(ev.Player.SteamId))
226245
{
227246
ev.Player.HideTag(true);
228-
plugin.Info("Tag hidden for " + ev.Player.Name);
229247
}
230248
else
231249
{
232250
ev.Player.HideTag(false);
233-
plugin.Info("Tag shown for " + ev.Player.Name);
234251
}
252+
253+
ev.Player.OverwatchMode = plugin.overwatchToggled.Contains(ev.Player.SteamId);
235254
}
236255
}
237256

@@ -245,13 +264,13 @@ public TagCommandHandler(ToggleTag plugin)
245264
public void OnAdminQuery(AdminQueryEvent ev)
246265
{
247266
// Check if user or console command
248-
if(ev.Admin == null || ev.Admin.SteamId == null)
267+
if (ev.Query == "REQUEST_DATA PLAYER_LIST SILENT" || ev.Admin == null || ev.Admin.SteamId == null)
249268
{
250269
return;
251270
}
252271

253272
// Check normal version of command
254-
if(ev.Query == "hidetag")
273+
if (ev.Query == "hidetag")
255274
{
256275
plugin.tagsToggled.Add(ev.Admin.SteamId);
257276
plugin.SaveTagsToFile();
@@ -261,6 +280,20 @@ public void OnAdminQuery(AdminQueryEvent ev)
261280
plugin.tagsToggled.Remove(ev.Admin.SteamId);
262281
plugin.SaveTagsToFile();
263282
}
283+
284+
// Check overwatch command
285+
else if (ev.Query.Split(' ')[0] == "overwatch" && ev.Query.Split(' ')[1] == ev.Admin.PlayerId.ToString() + ".")
286+
{
287+
if(ev.Query.Split(' ')[2] == "0")
288+
{
289+
plugin.overwatchToggled.Remove(ev.Admin.SteamId);
290+
}
291+
else
292+
{
293+
plugin.overwatchToggled.Add(ev.Admin.SteamId);
294+
}
295+
plugin.SaveTagsToFile();
296+
}
264297
}
265298
}
266299
}

0 commit comments

Comments
 (0)