-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIAnnouncements.cs
2254 lines (2124 loc) · 125 KB
/
GUIAnnouncements.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Collections;
using UnityEngine;
using Oxide.Core;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Plugins;
namespace Oxide.Plugins
{
[Info("GUIAnnouncements", "JoeSheep", "1.23.88", ResourceId = 1222)]
[Description("Creates announcements with custom messages across the top of every player's screen in a banner.")]
class GUIAnnouncements : RustPlugin
{
#region Configuration
#region Plugin References
[PluginReference]
private Plugin Airstrike;
private bool PluginAirstrike = false;
#endregion
#region Permissions
const string PermAnnounce = "GUIAnnouncements.announce";
const string PermAnnounceToggle = "GUIAnnouncements.toggle";
const string PermAnnounceGetNextRestart = "GUIAnnouncements.getnextrestart";
const string PermAnnounceJoinLeave = "GUIAnnouncements.announcejoinleave";
#endregion
#region Global Declerations
private Dictionary<ulong, string> Exclusions = new Dictionary<ulong, string>();
private HashSet<ulong> JustJoined = new HashSet<ulong>();
private HashSet<ulong> GlobalTimerPlayerList = new HashSet<ulong>();
private Dictionary<BasePlayer, Timer> PrivateTimers = new Dictionary<BasePlayer, Timer>();
private Dictionary<BasePlayer, Timer> NewPlayerPrivateTimers = new Dictionary<BasePlayer, Timer>();
private Dictionary<BasePlayer, Timer> PlayerRespawnedTimers = new Dictionary<BasePlayer, Timer>();
private Timer PlayerTimer;
private Timer GlobalTimer;
private Timer NewPlayerTimer;
private Timer PlayerRespawnedTimer;
private Timer RealTimeTimer;
private bool RealTimeTimerStarted = false;
private Timer SixtySecondsTimer;
private Timer AutomaticAnnouncementsTimer;
private Timer GetNextRestartTimer;
private string LastHitPlayer = String.Empty;
private HashSet<uint> HeliNetIDs = new HashSet<uint>();
private bool ConfigUpdated;
private List<DateTime> RestartTimes = new List<DateTime>();
private Dictionary<DateTime, TimeSpan> CalcNextRestartDict = new Dictionary<DateTime, TimeSpan>();
private DateTime NextRestart;
List<TimeSpan> RestartAnnouncementsWhen = new List<TimeSpan>();
private int LastHour;
private int LastMinute;
private bool RestartCountdown;
private bool RestartJustScheduled = false;
private bool RestartScheduled = false;
private string RestartReason = String.Empty;
private List<string> RestartAnnouncementsWhenStrings;
private DateTime ScheduledRestart;
private TimeSpan AutomaticTimedAnnouncementsRepeat;
private bool RestartSuspended = false;
private bool DontCheckNextRestart = false;
private bool MuteBans = false;
private bool ConvertedBannerColor = true;
private bool ConvertedTextColor = true;
private bool Announcing = false;
private List<string> GameTimes = new List<string>();
private IEnumerator<List<string>> ATALEnum;
private List<List<string>> AutomaticTimedAnnouncementsList = new List<List<string>>();
string BannerTintGrey = "0.1 0.1 0.1 0.7";
string BannerTintRed = "0.5 0.1 0.1 0.7";
string BannerTintOrange = "0.95294 0.37255 0.06275 0.7";
string BannerTintYellow = "1 0.92 0.016 0.7";
string BannerTintGreen = "0.1 0.4 0.1 0.5";
string BannerTintCyan = "0 1 1 0.7";
string BannerTintBlue = "0.09020 0.07843 0.71765 0.7";
string BannerTintPurple = "0.53333 0.07843 0.77647 0.7";
string TextRed = "0.5 0.2 0.2";
string TextOrange = "0.8 0.5 0.1";
string TextYellow = "1 0.92 0.016";
string TextGreen = "0 1 0";
string TextCyan = "0 1 1";
string TextBlue = "0.09020 0.07843 0.71765";
string TextPurple = "0.53333 0.07843 0.77647";
string TextWhite = "1 1 1";
string BannerAnchorMaxX = "1.026 ";
string BannerAnchorMaxY = "0.9743";
string TABannerAnchorMaxY = "0.9743";
string BannerAnchorMinX = "-0.027 ";
string BannerAnchorMinY = "0.915";
string TABannerAnchorMinY = "0.915";
string TextAnchorMaxX = "0.868 ";
string TextAnchorMaxY = "0.9743";
string TATextAnchorMaxY = "0.9743";
string TextAnchorMinX = "0.131 ";
string TextAnchorMinY = "0.915";
string TATextAnchorMinY = "0.915";
#endregion
//============================================================================================================
#region Config Option Declerations
//Color List
public string bannerColorList { get; private set; } = "Grey, Red, Orange, Yellow, Green, Cyan, Blue, Purple";
public string textColorList { get; private set; } = "White, Red, Orange, Yellow, Green, Cyan, Blue, Purple";
//Airdrop Announcements
public bool airdropAnnouncement { get; private set; } = true;
public bool airdropAnnouncementLocation { get; private set; } = true;
public string airdropAnnouncementText { get; private set; } = "Airdrop en route!";
public string airdropAnnouncementTextWithCoords { get; private set; } = "Airdrop en route to x{x}, z{z}";
public string airdropAnnouncementBannerColor { get; private set; } = "Green";
public string airdropAnnouncementTextColor { get; private set; } = "Yellow";
//Automatic Game Time Announcements
public bool automaticGameTimeAnnouncements { get; private set; } = false;
public Dictionary<string, List<object>> automaticGameTimeAnnouncementsList { get; private set; } = new Dictionary<string, List<object>>
{
{"18:15", new List<object>{ "The in game time is 18:15 announcement 1.", "The in game time is 18:15 announcement 2.", "The in game time is 18:15 announcement 3." } },
{"00:00", new List<object>{ "The in game time is 00:00 announcement 1.", "The in game time is 00:00 announcement 2.", "The in game time is 00:00 announcement 3." } },
{"12:00", new List<object>{ "The in game time is 12:00 announcement 1.", "The in game time is 12:00 announcement 2.", "The in game time is 12:00 announcement 3." } },
};
public string automaticGameTimeAnnouncementsBannerColor { get; private set; } = "Grey";
public string automaticGameTimeAnnouncementsTextColor { get; private set; } = "White";
//Automatic Timed Announcements
public bool automaticTimedAnnouncements { get; private set; } = false;
public static List<object> automaticTimedAnnouncementsList { get; private set; } = new List<object>
{
new List<object>{ "1st Automatic Timed Announcement 1", "1st Automatic Timed Announcement 2" },
new List<object>{ "2nd Automatic Timed Announcement 1", "2nd Automatic Timed Announcement 2" },
new List<object>{ "3rd Automatic Timed Announcement 1", "3rd Automatic Timed Announcement 2" },
};
public string automaticTimedAnnouncementsRepeat { get; private set; } = "00:30:00";
public string automaticTimedAnnouncementsBannerColor { get; private set; } = "Grey";
public string automaticTimedAnnouncementsTextColor { get; private set; } = "White";
//Christmas Stocking Refill Announcement
public bool stockingRefillAnnouncement { get; private set; } = false;
public string stockingRefillAnnouncementText { get; private set; } = "Santa has refilled your stockings. Go check what you've got!";
public string stockingRefillAnnouncementBannerColor { get; private set; } = "Green";
public string stockingRefillAnnouncementTextColor { get; private set; } = "Red";
//General Settings
public float announcementDuration { get; private set; } = 10f;
public int fontSize { get; private set; } = 18;
public float fadeOutTime { get; private set; } = 0.5f;
public float fadeInTime { get; private set; } = 0.5f;
public static float adjustVPosition { get; private set; } = 0.0f;
//Global Join/Leave Announcements
public bool globalLeaveAnnouncements { get; private set; } = false;
public bool globalJoinAnnouncements { get; private set; } = false;
public bool globalJoinLeavePermissionOnly { get; private set; } = true;
public string globalLeaveText { get; private set; } = "{rank} {playername} has left.";
public string globalJoinText { get; private set; } = "{rank} {playername} has joined.";
public string globalLeaveAnnouncementBannerColor { get; private set; } = "Grey";
public string globalLeaveAnnouncementTextColor { get; private set; } = "White";
public string globalJoinAnnouncementBannerColor { get; private set; } = "Grey";
public string globalJoinAnnouncementTextColor { get; private set; } = "White";
//Helicopter Announcements
public bool helicopterSpawnAnnouncement { get; private set; } = true;
public bool helicopterDespawnAnnouncement { get; private set; } = false;
public bool helicopterDestroyedAnnouncement { get; private set; } = true;
public bool helicopterDestroyedAnnouncementWithDestroyer { get; private set; } = true;
public string helicopterSpawnAnnouncementText { get; private set; } = "Patrol Helicopter Inbound!";
public string helicopterDespawnAnnouncementText { get; private set; } = "The patrol helicopter has left.";
public string helicopterDestroyedAnnouncementText { get; private set; } = "The patrol helicopter has been taken down!";
public string helicopterDestroyedAnnouncementWithDestroyerText { get; private set; } = "{playername} got the last shot on the helicopter taking it down!";
public string helicopterSpawnAnnouncementBannerColor { get; private set; } = "Red";
public string helicopterSpawnAnnouncementTextColor { get; private set; } = "Orange";
public string helicopterDestroyedAnnouncementBannerColor { get; private set; } = "Red";
public string helicopterDestroyedAnnouncementTextColor { get; private set; } = "White";
public string helicopterDespawnAnnouncementBannerColor { get; private set; } = "Red";
public string helicopterDespawnAnnouncementTextColor { get; private set; } = "White";
//New Player Announcements
public bool newPlayerAnnouncements { get; private set; } = true;
public string newPlayerAnnouncementsBannerColor { get; private set; } = "Grey";
public string newPlayerAnnouncementsTextColor { get; private set; } = "White";
public Dictionary<int, List<object>> newPlayerAnnouncementsList { get; private set; } = new Dictionary<int, List<object>>
{
{1, new List<object>{ "1st Join {rank} {playername} New player announcement 1.", "1st Join {rank} {playername} New player announcement 2.", "1st Join {rank} {playername} New player announcement 3." } },
{2, new List<object>{ "2nd Join {rank} {playername} New player announcement 1.", "2nd Join {rank} {playername} New player announcement 2.", "2nd Join {rank} {playername} New player announcement 3." } },
{3, new List<object>{ "3rd Join {rank} {playername} New player announcement 1.", "3rd Join {rank} {playername} New player announcement 2.", "3rd Join {rank} {playername} New player announcement 3." } },
};
//Player Banned Announcement
public bool playerBannedAnnouncement { get; private set; } = false;
public string playerBannedAnnouncmentText { get; private set; } = "{playername} has been banned. {reason}.";
public string playerBannedAnnouncementBannerColor { get; private set; } = "Grey";
public string playerBannedAnnouncementTextColor { get; private set; } = "Red";
//Respawn Announcements
public bool respawnAnnouncements { get; private set; } = false;
public string respawnAnnouncementsBannerColor { get; private set; } = "Grey";
public string respawnAnnouncementsTextColor { get; private set; } = "White";
public List<object> respawnAnnouncementsList { get; private set; } = new List<object>
{
"{playername} Respawn announcement 1.",
"{playername} Respawn announcement 2.",
"{playername} Respawn announcement 3."
};
//Restart Announcements
public bool restartAnnouncements { get; private set; } = false;
public string restartAnnouncementsFormat { get; private set; } = "Restarting in {time}";
public string restartAnnouncementsBannerColor { get; private set; } = "Grey";
public string restartAnnouncementsTextColor { get; private set; } = "White";
public List<object> restartTimes { get; private set; } = new List<object>
{
"08:00:00",
"20:00:00"
};
public List<object> restartAnnouncementsWhen { get; private set; } = new List<object>
{
"12:00:00",
"11:00:00",
"10:00:00",
"09:00:00",
"08:00:00",
"07:00:00",
"06:00:00",
"05:00:00",
"04:00:00",
"03:00:00",
"02:00:00",
"01:00:00",
"00:45:00",
"00:30:00",
"00:15:00",
"00:05:00"
};
public bool restartServer { get; private set; } = false;
public string restartSuspendedAnnouncement { get; private set; } = "The restart in {time} has been suspended.";
public string restartCancelledAnnouncement { get; private set; } = "The restart in {time} has been cancelled.";
//Test Announcement
public float testAnnouncementDuration { get; private set; } = 10f;
public int testAnnouncementFontSize { get; private set; } = 18;
public float testAnnouncementFadeOutTime { get; private set; } = 0.5f;
public float testAnnouncementFadeInTime { get; private set; } = 0.5f;
public static float testAnnouncementAdjustVPosition { get; private set; } = 0.0f;
public string testAnnouncementBannerColor { get; private set; } = "Grey";
public string testAnnouncementsTextColor { get; private set; } = "White";
//Third Party Plugin Support
public bool doNotOverlayLustyMap { get; private set; } = false;
public string lustyMapPosition { get; private set; } = "Left";
//Welcome Announcement
public string welcomeAnnouncementText { get; private set; } = "Welcome {playername}! There are {playercount} player(s) online.";
public string welcomeBackAnnouncementText { get; private set; } = "Welcome back {playername}! There are {playercount} player(s) online.";
public string welcomeAnnouncementBannerColor { get; private set; } = "Grey";
public string welcomeAnnouncementTextColor { get; private set; } = "White";
public float welcomeAnnouncementDuration { get; private set; } = 20f;
public float welcomeAnnouncementDelay { get; private set; } = 0f;
public bool welcomeAnnouncement { get; private set; } = true;
public bool welcomeBackAnnouncement { get; private set; } = true;
#endregion
//============================================================================================================
#region LoadConfig
private void LoadGUIAnnouncementsConfig()
{
//Color List
bannerColorList = GetConfig("A List Of Available Colors To Use (DO NOT CHANGE)", "Banner Colors", bannerColorList);
if (bannerColorList != "Grey, Red, Orange, Yellow, Green, Cyan, Blue, Purple")
{
PrintWarning("Banner color list changed. Reverting changes.");
Config["A List Of Available Colors To Use(DO NOT CHANGE)", "Banner Colors"] = "Grey, Red, Orange, Yellow, Green, Cyan, Blue, Purple";
ConfigUpdated = true;
}
textColorList = GetConfig("A List Of Available Colors To Use (DO NOT CHANGE)", "Text Colors", textColorList);
if (textColorList != "White, Red, Orange, Yellow, Green, Cyan, Blue, Purple")
{
PrintWarning("Text color list changed. Reverting changes.");
Config["A List Of Available Colors To Use(DO NOT CHANGE)", "Text Colors"] = "White, Red, Orange, Yellow, Green, Cyan, Blue, Purple";
ConfigUpdated = true;
}
//Airdrop Announcements
airdropAnnouncementText = GetConfig("Public Airdrop Announcements", "Text", airdropAnnouncementText);
airdropAnnouncementTextWithCoords = GetConfig("Public Airdrop Announcements", "Text With Coords", airdropAnnouncementTextWithCoords);
airdropAnnouncementBannerColor = GetConfig("Public Airdrop Announcements", "Banner Color", airdropAnnouncementBannerColor);
ConvertBannerColor(airdropAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Airdrop Announcements - Banner Color: " + airdropAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Airdrop Announcements", "Banner Color"] = "Green";
ConfigUpdated = true;
}
airdropAnnouncementTextColor = GetConfig("Public Airdrop Announcements", "Text Color", airdropAnnouncementTextColor);
ConvertTextColor(airdropAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Airdrop Announcements - Text Color: " + airdropAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Airdrop Announcements", "Text Color"] = "Yellow";
ConfigUpdated = true;
}
airdropAnnouncement = GetConfig("Public Airdrop Announcements", "Enabled", true);
airdropAnnouncementLocation = GetConfig("Public Airdrop Announcements", "Show Location", false);
//Automatic Game Time Announcements
automaticGameTimeAnnouncements = GetConfig("Public Automatic Game Time Announcements", "Enabled", false);
automaticGameTimeAnnouncementsList = GetConfig("Public Automatic Game Time Announcements", "Announcement List (Show at this in game time : Announcements to show)", automaticGameTimeAnnouncementsList);
automaticGameTimeAnnouncementsBannerColor = GetConfig("Public Automatic Game Time Announcements", "Banner Color", automaticGameTimeAnnouncementsBannerColor);
ConvertBannerColor(automaticGameTimeAnnouncementsBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Automatic Game Time Announcements - Banner Color: " + automaticGameTimeAnnouncementsBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Automatic Game Time Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
automaticGameTimeAnnouncementsTextColor = GetConfig("Public Automatic Game Time Announcements", "Text Color", automaticGameTimeAnnouncementsTextColor);
ConvertTextColor(automaticGameTimeAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Automatic Game Time Announcements - Text Color: " + automaticGameTimeAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Public Automatic Game Time Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
//Automatic Timed Announcements
automaticTimedAnnouncements = GetConfig("Public Automatic Timed Announcements", "Enabled", false);
automaticTimedAnnouncementsList = GetConfig("Public Automatic Timed Announcements", "Announcement List", automaticTimedAnnouncementsList);
automaticTimedAnnouncementsBannerColor = GetConfig("Public Automatic Timed Announcements", "Banner Color", automaticTimedAnnouncementsBannerColor);
ConvertBannerColor(automaticTimedAnnouncementsBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Automatic Timed Announcements - Banner Color: " + automaticTimedAnnouncementsBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Automatic Timed Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
automaticTimedAnnouncementsTextColor = GetConfig("Public Automatic Timed Announcements", "Text Color", automaticTimedAnnouncementsTextColor);
ConvertTextColor(automaticTimedAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Automatic Timed Announcements - Text Color: " + automaticTimedAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Public Automatic Timed Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
automaticTimedAnnouncementsRepeat = GetConfig("Public Automatic Timed Announcements", "Show Every (HH:MM:SS)", automaticTimedAnnouncementsRepeat);
if (!TimeSpan.TryParse(automaticTimedAnnouncementsRepeat, out AutomaticTimedAnnouncementsRepeat))
{
PrintWarning("Config: \"Automatic Timed Announcements - Show Every (HH:MM:SS)\" is not of the correct format HH:MM:SS, or has numbers out of range and should not be higher than 23:59:59. Resetting to default.");
Config["Public Automatic Timed Announcements", "Show Every (HH:MM:SS)"] = "00:30:00";
ConfigUpdated = true;
}
//Christmas Stocking Refill Announcement
stockingRefillAnnouncement = GetConfig("Public Christmas Stocking Refill Announcement", "Enabled", false);
stockingRefillAnnouncementText = GetConfig("Public Christmas Stocking Refill Announcement", "Text", stockingRefillAnnouncementText);
stockingRefillAnnouncementBannerColor = GetConfig("Public Christmas Stocking Refill Announcement", "Banner Color", stockingRefillAnnouncementBannerColor);
ConvertBannerColor(stockingRefillAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Christmas Stocking Refill Announcement - Banner Color: " + stockingRefillAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Christmas Stocking Refill Announcement", "Banner Color"] = "Green";
ConfigUpdated = true;
}
stockingRefillAnnouncementTextColor = GetConfig("Public Christmas Stocking Refill Announcement", "Text Color", stockingRefillAnnouncementTextColor);
ConvertTextColor(stockingRefillAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Christmas Stocking Refill Announcement - Text Color: " + stockingRefillAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Christmas Stocking Refill Announcement", "Text Color"] = "Red";
ConfigUpdated = true;
}
//General Settings:
announcementDuration = GetConfig("General Settings", "Announcement Duration", 10f);
if (announcementDuration == 0)
{
PrintWarning("Config: \"General Settings - Announcement Duration\" set to 0, resetting to 10f.");
Config["General Settings", "Announcement Duration"] = 10f;
ConfigUpdated = true;
}
fontSize = GetConfig("General Settings", "Font Size", 18);
if (fontSize > 33 | fontSize == 0)
{
PrintWarning("Config: \"General Settings - Font Size\" greater than 28 or 0, resetting to 18.");
Config["General Settings", "Font Size"] = 18;
ConfigUpdated = true;
}
fadeInTime = GetConfig("General Settings", "Fade In Time", 0.5f);
if (fadeInTime > announcementDuration / 2)
{
PrintWarning("Config: \"General Settings - Fade In Time\" is greater than half of AnnouncementShowDuration, resetting to half of AnnouncementShowDuration.");
Config["General Settings", "Fade In Time"] = announcementDuration / 2;
ConfigUpdated = true;
}
fadeOutTime = GetConfig("General Settings", "Fade Out Time", 0.5f);
if (fadeOutTime > announcementDuration / 2)
{
PrintWarning("Config: \"General Settings - Fade Out Time\" is greater than half of AnnouncementShowDuration, resetting to half of AnnouncementShowDuration.");
Config["General Settings", "Fade Out Time"] = announcementDuration / 2;
ConfigUpdated = true;
}
adjustVPosition = GetConfig("General Settings", "Adjust Vertical Position", 0.0f);
if (adjustVPosition != 0f)
{
BannerAnchorMaxY = (float.Parse("0.9743") + adjustVPosition).ToString();
BannerAnchorMinY = (float.Parse("0.915") + adjustVPosition).ToString();
TextAnchorMaxY = (float.Parse("0.9743") + adjustVPosition).ToString();
TextAnchorMinY = (float.Parse("0.915") + adjustVPosition).ToString();
}
//Global Join/Leave Announcements
globalLeaveAnnouncements = GetConfig("Public Join/Leave Announcements", "Leave Enabled", false);
globalLeaveText = GetConfig("Public Join/Leave Announcements", "Leave Text", globalLeaveText);
globalLeaveAnnouncementBannerColor = GetConfig("Public Join/Leave Announcements", "Leave Banner Color", globalLeaveAnnouncementBannerColor);
ConvertBannerColor(globalLeaveAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Join/Leave Announcements - Leave Banner Color: " + globalLeaveAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Join/Leave Announcements", "Leave Banner Color"] = "Grey";
ConfigUpdated = true;
}
globalLeaveAnnouncementTextColor = GetConfig("Public Join/Leave Announcements", "Leave Text Color", globalLeaveAnnouncementTextColor);
ConvertTextColor(globalLeaveAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Join/Leave Announcements - Leave Text Color: " + globalLeaveAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Join/Leave Announcements", "Leave Text Color"] = "White";
ConfigUpdated = true;
}
globalJoinAnnouncements = GetConfig("Public Join/Leave Announcements", "Join Enabled", false);
globalJoinText = GetConfig("Public Join/Leave Announcements", "Join Text", globalJoinText);
globalJoinAnnouncementBannerColor = GetConfig("Public Join/Leave Announcements", "Join Banner Color", globalJoinAnnouncementBannerColor);
ConvertBannerColor(globalJoinAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Join/Leave Announcements - Join Banner Color: " + globalJoinAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Join/Leave Announcements", "Join Banner Color"] = "Grey";
ConfigUpdated = true;
}
globalJoinAnnouncementTextColor = GetConfig("Public Join/Leave Announcements", "Join Text Color", globalJoinAnnouncementTextColor);
ConvertTextColor(globalJoinAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Join/Leave Announcements - Join Text Color: " + globalJoinAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Join/Leave Announcements", "Join Text Color"] = "White";
ConfigUpdated = true;
}
globalJoinLeavePermissionOnly = GetConfig("Public Join/Leave Announcements", "Announce Only Players With Permission", globalJoinLeavePermissionOnly);
//Helicopter Announcements
helicopterSpawnAnnouncement = GetConfig("Public Helicopter Announcements", "Spawn", true);
helicopterSpawnAnnouncementText = GetConfig("Public Helicopter Announcements", "Spawn Text", helicopterSpawnAnnouncementText);
helicopterSpawnAnnouncementBannerColor = GetConfig("Public Helicopter Announcements", "Spawn Banner Color", helicopterSpawnAnnouncementBannerColor);
ConvertBannerColor(helicopterSpawnAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Helicopter Announcements - Spawn Banner Color: " + helicopterSpawnAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Spawn Banner Color"] = "Red";
ConfigUpdated = true;
}
helicopterSpawnAnnouncementTextColor = GetConfig("Public Helicopter Announcements", "Spawn Text Color", helicopterSpawnAnnouncementTextColor);
ConvertTextColor(helicopterSpawnAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Helicopter Announcements - Spawn Text Color: " + helicopterSpawnAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Spawn Text Color"] = "Orange";
ConfigUpdated = true;
}
helicopterDespawnAnnouncement = GetConfig("Public Helicopter Announcements", "Despawn", helicopterDespawnAnnouncement);
helicopterDespawnAnnouncementText = GetConfig("Public Helicopter Announcements", "Despawn Text", helicopterDespawnAnnouncementText);
helicopterDespawnAnnouncementBannerColor = GetConfig("Public Helicopter Announcements", "Despawn Banner Color", helicopterDespawnAnnouncementBannerColor);
ConvertBannerColor(helicopterDespawnAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Helicopter Announcements - Despawn Banner Color: " + helicopterDespawnAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Despawn Banner Color"] = "Red";
ConfigUpdated = true;
}
helicopterDespawnAnnouncementTextColor = GetConfig("Public Helicopter Announcements", "Despawn Text Color", helicopterDespawnAnnouncementTextColor);
ConvertTextColor(helicopterDespawnAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Helicopter Announcements - Despawn Text Color: " + helicopterDespawnAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Despawn Text Color"] = "White";
ConfigUpdated = true;
}
helicopterDestroyedAnnouncement = GetConfig("Public Helicopter Announcements", "Destroyed", true);
helicopterDestroyedAnnouncementWithDestroyer = GetConfig("Public Helicopter Announcements", "Show Destroyer", true);
helicopterDestroyedAnnouncementText = GetConfig("Public Helicopter Announcements", "Destroyed Text", helicopterDestroyedAnnouncementText);
helicopterDestroyedAnnouncementWithDestroyerText = GetConfig("Public Helicopter Announcements", "Destroyed Text With Destroyer", helicopterDestroyedAnnouncementWithDestroyerText);
helicopterDestroyedAnnouncementBannerColor = GetConfig("Public Helicopter Announcements", "Destroyed Banner Color", helicopterDestroyedAnnouncementBannerColor);
ConvertBannerColor(helicopterDestroyedAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Helicopter Announcements - Destroyed Banner Color: " + helicopterDestroyedAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Destroyed Banner Color"] = "Red";
ConfigUpdated = true;
}
helicopterDestroyedAnnouncementTextColor = GetConfig("Public Helicopter Announcements", "Destroyed Text Color", helicopterDestroyedAnnouncementTextColor);
ConvertTextColor(helicopterDestroyedAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Helicopter Announcements - Destroyed Text Color: " + helicopterDestroyedAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Helicopter Announcements", "Destroyed Text Color"] = "White";
ConfigUpdated = true;
}
//New Player Announcements
newPlayerAnnouncements = GetConfig("Private New Player Announcements", "Enabled", false);
newPlayerAnnouncementsBannerColor = GetConfig("Private New Player Announcements", "Banner Color", newPlayerAnnouncementsBannerColor);
ConvertBannerColor(newPlayerAnnouncementsBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Private New Player Announcements - Banner Color: " + newPlayerAnnouncementsBannerColor + "\" is not a valid color, resetting to default.");
Config["Private New Player Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
newPlayerAnnouncementsTextColor = GetConfig("Private New Player Announcements", "Text Color", newPlayerAnnouncementsTextColor);
ConvertTextColor(newPlayerAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Private New Player Announcements - Text Color: " + newPlayerAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Private New Player Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
newPlayerAnnouncementsList = GetConfig("Private New Player Announcements", "Announcements List (Show On This Many Joins : List To Show)", newPlayerAnnouncementsList);
//Player Banned Announcement
playerBannedAnnouncement = GetConfig("Public Player Banned Announcement", "Enabled", false);
playerBannedAnnouncmentText = GetConfig("Public Player Banned Announcement", "Text", playerBannedAnnouncmentText);
playerBannedAnnouncementBannerColor = GetConfig("Public Player Banned Announcement", "Banner Color", playerBannedAnnouncementBannerColor);
ConvertBannerColor(playerBannedAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Player Banned Announcement - Banner Color: " + playerBannedAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Player Banned Announcement", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
playerBannedAnnouncementTextColor = GetConfig("Public Player Banned Announcement", "Text Color", playerBannedAnnouncementTextColor);
ConvertTextColor(playerBannedAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Player Banned Announcement - Text Color: " + playerBannedAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Public Player Banned Announcement", "Text Color"] = "Red";
ConfigUpdated = true;
}
//Respawn Announcements
respawnAnnouncements = GetConfig("Private Respawn Announcements", "Enabled", false);
respawnAnnouncementsBannerColor = GetConfig("Private Respawn Announcements", "Banner Color", respawnAnnouncementsBannerColor);
ConvertBannerColor(respawnAnnouncementsBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Private Respawn Announcements - Banner Color: " + respawnAnnouncementsBannerColor + "\" is not a valid color, resetting to default.");
Config["Private Respawn Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
respawnAnnouncementsTextColor = GetConfig("Private Respawn Announcements", "Text Color", respawnAnnouncementsTextColor);
ConvertTextColor(respawnAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Private Respawn Announcements - Text Color: " + respawnAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Private Respawn Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
respawnAnnouncementsList = GetConfig("Private Respawn Announcements", "Announcements List", respawnAnnouncementsList);
//Restart Announcements
restartAnnouncements = GetConfig("Public Restart Announcements", "Enabled", restartAnnouncements);
restartTimes = GetConfig("Public Restart Announcements", "Restart At (HH:MM:SS)", restartTimes);
if (restartTimes.Contains("24:00:00"))
{
restartTimes[restartTimes.IndexOf("24:00:00")] = "00:00:00";
PrintWarning("\"Public Restart Announcements - Restart At (HH:MM:SS): \"24:00:00\" The 24th hour does not exist, converting to 00:00:00 (the same time)");
Config["Public Restart Announcements", "Restart Times"] = restartTimes;
ConfigUpdated = true;
}
restartAnnouncementsBannerColor = GetConfig("Public Restart Announcements", "Banner Color", restartAnnouncementsBannerColor);
ConvertBannerColor(restartAnnouncementsBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Public Restart Announcements - Banner Color: " + restartAnnouncementsBannerColor + "\" is not a valid color, resetting to default.");
Config["Public Restart Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
restartAnnouncementsTextColor = GetConfig("Public Restart Announcements", "Text Color", restartAnnouncementsTextColor);
ConvertTextColor(restartAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Public Restart Announcements - Text Color: " + restartAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Public Restart Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
restartAnnouncementsWhen = GetConfig("Public Restart Announcements", "Announce With Time Left (HH:MM:SS)", restartAnnouncementsWhen);
restartServer = GetConfig("Public Restart Announcements", "Restart My Server", false);
restartAnnouncementsFormat = GetConfig("Public Restart Announcements", "Restart Announcement Text", restartAnnouncementsFormat);
restartSuspendedAnnouncement = GetConfig("Public Restart Announcements", "Suspended Restart Text", restartSuspendedAnnouncement);
restartCancelledAnnouncement = GetConfig("Public Restart Announcements", "Cancelled Scheduled Restart Text", restartCancelledAnnouncement);
//Test Announcement
testAnnouncementFontSize = GetConfig("Private Test Announcement", "Font Size", testAnnouncementFontSize);
testAnnouncementDuration = GetConfig("Private Test Announcement", "Duration", testAnnouncementDuration);
testAnnouncementFadeInTime = GetConfig("Private Test Announcement", "Fade In Time", testAnnouncementFadeInTime);
testAnnouncementFadeOutTime = GetConfig("Private Test Announcement", "Fade Out Time", testAnnouncementFadeOutTime);
testAnnouncementAdjustVPosition = GetConfig("Private Test Announcement", "Adjust Vertical Position", testAnnouncementAdjustVPosition);
if (adjustVPosition != 0f)
{
TABannerAnchorMaxY = (float.Parse("0.9743") + adjustVPosition).ToString();
TABannerAnchorMinY = (float.Parse("0.915") + adjustVPosition).ToString();
TATextAnchorMaxY = (float.Parse("0.9743") + adjustVPosition).ToString();
TATextAnchorMinY = (float.Parse("0.915") + adjustVPosition).ToString();
}
testAnnouncementBannerColor = GetConfig("Private Test Announcement", "Banner Color", testAnnouncementBannerColor);
ConvertBannerColor(testAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Private Test Announcement - Banner Color: " + testAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Private Test Announcement", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
testAnnouncementsTextColor = GetConfig("Private Test Announcement", "Text Color", testAnnouncementsTextColor);
ConvertTextColor(testAnnouncementsTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Private Test Announcement - Text Color: " + testAnnouncementsTextColor + "\" is not a valid color, resetting to default.");
Config["Private Test Announcement", "Text Color"] = "White";
ConfigUpdated = true;
}
//Third Party Plugin Support
doNotOverlayLustyMap = GetConfig("Third Party Plugin Support", "Do Not Overlay LustyMap", false);
lustyMapPosition = GetConfig("Third Party Plugin Support", "LustyMap Position (Left/Right)", "Left");
if (lustyMapPosition.ToLower() != "left" && lustyMapPosition.ToLower() != "right" || lustyMapPosition == string.Empty || lustyMapPosition == null)
{
PrintWarning("Config: \"Third Party Plugin Support - LustyMap Position(Left / Right)\" is not left or right, resetting to left.");
Config["Third Party Plugin Support", "LustyMap Position (Left/Right)"] = "Left";
ConfigUpdated = true;
}
if (doNotOverlayLustyMap == true)
{
if (lustyMapPosition.ToLower() == "left")
BannerAnchorMinX = "0.131 ";
if (lustyMapPosition.ToLower() == "right")
BannerAnchorMaxX = "0.868 ";
}
//Welcome Announcements
welcomeAnnouncement = GetConfig("Private Welcome Announcements", "Enabled", true);
welcomeBackAnnouncement = GetConfig("Private Welcome Announcements", "Show Welcome Back If Player Has Been Here Before", true);
welcomeAnnouncementText = GetConfig("Private Welcome Announcements", "Welcome Text", welcomeAnnouncementText);
welcomeBackAnnouncementText = GetConfig("Private Welcome Announcements", "Welcome Back Text", welcomeBackAnnouncementText);
welcomeAnnouncementBannerColor = GetConfig("Private Welcome Announcements", "Banner Color", welcomeAnnouncementBannerColor);
ConvertBannerColor(welcomeAnnouncementBannerColor, true);
if (!ConvertedBannerColor)
{
ConvertedBannerColor = true;
PrintWarning("\"Private Welcome Announcements - Banner Color: " + welcomeAnnouncementBannerColor + "\" is not a valid color, resetting to default.");
Config["Private Welcome Announcements", "Banner Color"] = "Grey";
ConfigUpdated = true;
}
welcomeAnnouncementTextColor = GetConfig("Private Welcome Announcements", "Text Color", welcomeAnnouncementTextColor);
ConvertTextColor(welcomeAnnouncementTextColor, true);
if (!ConvertedTextColor)
{
ConvertedTextColor = true;
PrintWarning("\"Private Welcome Announcements - Text Color: " + welcomeAnnouncementTextColor + "\" is not a valid color, resetting to default.");
Config["Private Welcome Announcements", "Text Color"] = "White";
ConfigUpdated = true;
}
welcomeAnnouncementDuration = GetConfig("Private Welcome Announcements", "Duration", 20f);
if (welcomeAnnouncementDuration == 0)
{
PrintWarning("Config: \"Private Welcome Announcement - Duration\" set to 0, resetting to 20f.");
Config["Private Welcome Announcements", "Duration"] = 20f;
ConfigUpdated = true;
}
welcomeAnnouncementDelay = GetConfig("Private Welcome Announcements", "Delay", 0f);
if (ConfigUpdated)
{
Puts("Configuration file has been updated.");
SaveConfig();
}
}
protected override void LoadDefaultConfig() => PrintWarning("A new configuration file has been created.");
private T GetConfig<T>(string category, string setting, T defaultValue)
{
var data = Config[category] as Dictionary<string, object>;
object value;
if (data == null)
{
data = new Dictionary<string, object>();
Config[category] = data;
ConfigUpdated = true;
}
if (data.TryGetValue(setting, out value))
{
if (setting == "Announcements List (Show On This Many Joins : List To Show)" || setting == "Announcement List (Show at this in game time : Announcements to show)")
{
var keyType = typeof(T).GetGenericArguments()[0];
var valueType = typeof(T).GetGenericArguments()[1];
var dict = (IDictionary)Activator.CreateInstance(typeof(T));
foreach (var key in ((IDictionary)value).Keys)
{
dict.Add(Convert.ChangeType(key, keyType), Convert.ChangeType(((IDictionary)value)[key], valueType));
}
return (T)dict;
}
return (T)Convert.ChangeType(value, typeof(T));
}
value = defaultValue;
data[setting] = value;
ConfigUpdated = true;
return (T)Convert.ChangeType(value, typeof(T));
}
private List<string> ConvertObjectListToString(object value)
{
if (value is List<object>)
{
List<object> list = (List<object>)value;
List<string> strings = list.Select(s => (string)s).ToList();
return strings;
}
else return (List<string>)value;
}
#endregion
#endregion
//============================================================================================================
#region PlayerData
void SaveData() => Interface.Oxide.DataFileSystem.WriteObject("GUIAnnouncementsPlayerData", storedData);
void LoadSavedData()
{
storedData = Interface.Oxide.DataFileSystem.ReadObject<StoredData>("GUIAnnouncementsPlayerData");
if (storedData == null)
{
PrintWarning("GUIAnnouncement's datafile is null. Recreating data file...");
storedData = new StoredData();
SaveData();
timer.Once(5, () =>
{
PrintWarning("Reloading...");
Interface.Oxide.ReloadPlugin(Title);
});
}
}
class StoredData
{
public Dictionary<ulong, PlayerData> PlayerData = new Dictionary<ulong, PlayerData>();
public StoredData()
{
}
}
class PlayerData
{
public string Name;
public string UserID;
public int TimesJoined;
public bool Dead;
public PlayerData()
{
}
}
void CreatePlayerData(BasePlayer player)
{
var Data = new PlayerData();
Data.Name = player.displayName;
Data.UserID = player.userID.ToString();
Data.TimesJoined = 0;
storedData.PlayerData.Add(player.userID, Data);
SaveData();
}
StoredData storedData;
void OnServerSave() => SaveData();
private Dictionary<ulong, AnnouncementInfo> AnnouncementsData = new Dictionary<ulong, AnnouncementInfo>();
class AnnouncementInfo
{
public string BannerTintColor;
public string TextColor;
public string AnnouncementType;
public AnnouncementInfo()
{
}
}
void StoreAnnouncementData(BasePlayer player, string BannerTintColor, string TextColor, string AnnouncementType = null)
{
var Data = new AnnouncementInfo();
Data.BannerTintColor = BannerTintColor;
Data.TextColor = TextColor;
Data.AnnouncementType = AnnouncementType;
AnnouncementsData.Add(player.userID, Data);
}
#endregion
//============================================================================================================
#region Localization
void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
{"ChatCommandAnnounce", "announce"},
{"ChatCommandAnnounceTo", "announceto"},
{"ChatCommandAnnounceToGroup", "announcetogroup"},
{"ChatCommandAnnounceTest", "announcetest"},
{"ChatCommandDestroyAnnouncement", "destroyannouncement"},
{"ChatCommandMuteBans", "announcemutebans" },
{"ChatCommandAnnouncementsToggle", "announcementstoggle" },
{"ChatCommandScheduleRestart", "announceschedulerestart" },
{"ChatCommandSuspendRestart", "announcesuspendrestart" },
{"ChatCommandResumeRestart", "announceresumerestart" },
{"ChatCommandGetNextRestart", "announcegetnextrestart" },
{"ChatCommandCancelScheduledRestart", "announcecancelscheduledrestart" },
{"ChatCommandHelp", "announcehelp"},
{"ConsoleCommandAnnounce", "announce.announce"},
{"ConsoleCommandAnnounceTo", "announce.announceto"},
{"ConsoleCommandAnnounceToGroup", "announce.announcetogroup" },
{"ConsoleCommandDestroyAnnouncement", "announce.destroy"},
{"ConsoleCommandMuteBans", "announce.mutebans" },
{"ConsoleCommandAnnouncementsToggle", "announce.toggle"},
{"ConsoleCommandScheduleRestart", "announce.schedulerestart" },
{"ConsoleCommandSuspendRestart", "announce.suspendrestart" },
{"ConsoleCommandResumeRestart", "announce.resumerestart" },
{"ConsoleCommandGetNextRestart", "announce.getnextrestart" },
{"ConsoleCommandCancelScheduledRestart", "announce.cancelscheduledrestart" },
{"ConsoleCommandHelp", "announce.help"},
{"PlayerNotFound", "Player {playername} not found, check the name and if they are online."},
{"GroupNotFound", "Group {group} not found, check the name." },
{"NoPermission", "You do not possess the required permissions."},
{"ChatCommandAnnounceUsage", "Usage: /announce <message>."},
{"ChatCommandAnnounceToUsage", "Usage: /announceto <player> <message>."},
{"ChatCommandAnnounceToGroupUsage", "Usage: /announcetogroup <group> <message>"},
{"ChatCommandScheduleRestartUsage", "Usage: /announceschedulerestart <hh:mm:ss>." },
{"ConsoleCommandAnnounceUsage", "Usage: announce.announce <message>."},
{"ConsoleCommandAnnounceToUsage", "Usage: announce.announceto <player> <message>."},
{"ConsoleCommandAnnounceToGroupUsage", "Usage: announce.announcetogroup <group> <message>." },
{"ConsoleCommandAnnouncementsToggleUsage", "Usage: announce.toggle <player>."},
{"ConsoleCommandScheduleRestartUsage", "Usage: announce.schedulerestart <hh:mm:ss>." },
{"ServerAboutToRestart", "Your server is about to restart, there is no need to schedule a restart right now." },
{"RestartScheduled", "Restart scheduled in {time}{reason}." },
{"RestartAlreadyScheduled", "A restart has already been scheduled for {time}, please cancel that restart first with /announcecancelscheduledrestart or announce.cancelscheduledrestart." },
{"LaterThanNextRestart", "Restart not scheduled. Your time will be scheduled later than the next restart at {time}, please make sure you schedule a restart before {time}." },
{"RestartNotScheduled", "A restart has not been scheduled for you to cancel." },
{"ScheduledRestartCancelled", "A manually scheduled restart for {time} has been cancelled." },
{"Excluded", "{playername} has been excluded from announcements."},
{"ExcludedTo", "You have been excluded from announcements."},
{"Included", "{playername} is being included in announcements."},
{"IncludedTo", "You are being included in announcements."},
{"IsExcluded", "{playername} is currently excluded from announcements."},
{"YouAreExcluded", "You are excluded from announcements and cannot see that test announcement"},
{"BansMuted", "Ban announcements have been muted." },
{"BansUnmuted", "Ban announcements have been unmuted." },
{"PlayerHelp", "Chat commands: /announcementstoggle"},
{"AnnounceHelp", "Chat commands: /announce <message>, /announceto <player> <message>, /announcetogroup <group> <message>, /announcementstoggle [player], /destroyannouncement, /announceschedulerestart <time> [reason], /announcecancelscheduledrestart, /announcesuspendrestart, /announceresumerestart, /announcecancelrestart | Console commands: announce.announce <message>, announce.announceto <player> <message>, announce.announcetogroup <group> <message>, announce.toggle <player>, announce.destroy, announce.schedulerestart <time> [reason], announce.cancelscheduledrestart, announce.suspendrestart, announce.resumerestart, announce.cancelrestart."},
{"GetNextRestart", "Next restart is in {time1} at {time2}" },
{"RestartSuspendedChat", "The next restart at {time} has been suspended. Type /announceresumerestart to resume that restart." },
{"RestartSuspendedConsole", "The next restart at {time} has been suspended. Type announce.resumerestart to resume that restart." },
{"RestartResumed", "The previously suspended restart at {time} has been resumed." },
{"SuspendedRestartPassed", "The previously suspended restart at {time} has passed." },
{"Hours", "hours" },
{"Hour", "hour" },
{"Minutes", "minutes" },
{"Seconds", "seconds" },
{"Second", "second" },
}, this);
}
#endregion
//============================================================================================================
#region Initialization
void OnServerInitialized()
{
#if !RUST
throw new NotSupportedException("This plugin does not support this game.");
#endif
LoadGUIAnnouncementsConfig();
LoadSavedData();
LoadDefaultMessages();
permission.RegisterPermission(PermAnnounce, this);
permission.RegisterPermission(PermAnnounceToggle, this);
permission.RegisterPermission(PermAnnounceJoinLeave, this);
if (Airstrike != null)
{
PluginAirstrike = true;
Puts("Plugin Airstrike found.");
}
foreach (BasePlayer activePlayer in BasePlayer.activePlayerList)
{
if (!storedData.PlayerData.ContainsKey(activePlayer.userID))
{
CreatePlayerData(activePlayer);
storedData.PlayerData[activePlayer.userID].TimesJoined = storedData.PlayerData[activePlayer.userID].TimesJoined + 1;
SaveData();
}
}
foreach (BasePlayer sleepingPlayer in BasePlayer.sleepingPlayerList)
{
if (!storedData.PlayerData.ContainsKey(sleepingPlayer.userID))
{
CreatePlayerData(sleepingPlayer);
storedData.PlayerData[sleepingPlayer.userID].TimesJoined = storedData.PlayerData[sleepingPlayer.userID].TimesJoined + 1;
SaveData();
}
}
if (automaticGameTimeAnnouncements)
GameTimeAnnouncementsStart();
if (automaticTimedAnnouncements)
AutomaticTimedAnnouncementsStart();
if (restartAnnouncements)
RestartAnnouncementsStart();
cmd.AddChatCommand(Lang("ChatCommandAnnounce"), this, "cmdAnnounce");
cmd.AddChatCommand(Lang("ChatCommandAnnounceTo"), this, "cmdAnnounceTo");
cmd.AddChatCommand(Lang("ChatCommandAnnounceToGroup"), this, "cmdAnnounceToGroup");
cmd.AddChatCommand(Lang("ChatCommandAnnounceTest"), this, "cmdAnnounceTest");
cmd.AddChatCommand(Lang("ChatCommandDestroyAnnouncement"), this, "cmdDestroyAnnouncement");
cmd.AddChatCommand(Lang("ChatCommandMuteBans"), this, "cmdMuteBans");
cmd.AddChatCommand(Lang("ChatCommandAnnouncementsToggle"), this, "cmdAnnouncementsToggle");
cmd.AddChatCommand(Lang("ChatCommandScheduleRestart"), this, "cmdScheduleRestart");
cmd.AddChatCommand(Lang("ChatCommandSuspendRestart"), this, "cmdSuspendRestart");
cmd.AddChatCommand(Lang("ChatCommandResumeRestart"), this, "cmdResumeRestart");
cmd.AddChatCommand(Lang("ChatCommandGetNextRestart"), this, "cmdGetNextRestart");
cmd.AddChatCommand(Lang("ChatCommandCancelScheduledRestart"), this, "cmdCancelScheduledRestart");
cmd.AddChatCommand(Lang("ChatCommandCancelRestart"), this, "cmdCancelRestart");
cmd.AddChatCommand(Lang("ChatCommandHelp"), this, "cmdAnnounceHelp");
cmd.AddConsoleCommand(Lang("ConsoleCommandAnnounce"), this, "ccmdAnnounce");
cmd.AddConsoleCommand(Lang("ConsoleCommandAnnounceTo"), this, "ccmdAnnounceTo");
cmd.AddConsoleCommand(Lang("ConsoleCommandAnnounceToGroup"), this, "ccmdAnnounceToGroup");
cmd.AddConsoleCommand(Lang("ConsoleCommandDestroyAnnouncement"), this, "ccmdAnnounceDestroy");
cmd.AddConsoleCommand(Lang("ConsoleCommandMuteBans"), this, "ccmdMuteBans");
cmd.AddConsoleCommand(Lang("ConsoleCommandAnnouncementsToggle"), this, "ccmdAnnouncementsToggle");
cmd.AddConsoleCommand(Lang("ConsoleCommandScheduleRestart"), this, "ccmdScheduleRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandSuspendRestart"), this, "ccmdSuspendRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandResumeRestart"), this, "ccmdResumeRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandGetNextRestart"), this, "ccmdGetNextRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandCancelScheduledRestart"), this, "ccmdCancelScheduledRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandCancelRestart"), this, "ccmdCancelRestart");
cmd.AddConsoleCommand(Lang("ConsoleCommandHelp"), this, "ccmdAnnounceHelp");
}
#endregion
//============================================================================================================
#region GUI
[HookMethod("CreateAnnouncement")]
void CreateAnnouncement(string Msg, string bannerTintColor, string textColor, BasePlayer player = null, bool isWelcomeAnnouncement = false, bool isRestartAnnouncement = false, string group = null, bool isTestAnnouncement = false)
{