Skip to content

Commit 67b71f7

Browse files
committed
Merged develop branch into master (well not really just copied files lol)
1 parent 1e63097 commit 67b71f7

File tree

12 files changed

+75
-45
lines changed

12 files changed

+75
-45
lines changed

source/BP-Essentials/Chat/Announce.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ namespace BP_Essentials.Chat
1111
{
1212
class Announce : EssentialsCorePlugin
1313
{
14-
public static void Run(object man)
14+
public static void Run()
1515
{
1616
try
1717
{
18-
var svManager = (SvManager)man;
19-
_Timer.Elapsed += (sender, e) => OnTime(svManager);
18+
_Timer.Elapsed += (sender, e) => OnTime();
2019
_Timer.Interval = TimeBetweenAnnounce * 1000;
2120
_Timer.Enabled = true;
2221
}
@@ -26,10 +25,9 @@ public static void Run(object man)
2625
}
2726
}
2827

29-
private static void OnTime(object onetMan)
28+
private static void OnTime()
3029
{
31-
var svManager = (SvManager)onetMan;
32-
foreach (var player in svManager.players)
30+
foreach (var player in SvMan.players)
3331
foreach (var line in Announcements[AnnounceIndex].Split(new[] { "\\r\\n", "\\r", "\\n" }, StringSplitOptions.None))
3432
player.Value.svPlayer.Send(SvSendType.Self, Channel.Reliable, ClPacket.GameMessage, line);
3533
Debug.Log($"{SetTimeStamp.Run()}[INFO] Announcement made...");

source/BP-Essentials/Chat/Commands/Admin/Ban.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void Run(SvPlayer player, string message)
1616
return;
1717
}
1818
LogMessage.LogOther($"{SetTimeStamp.Run()}[INFO] {shPlayer.username} Got banned by {player.playerData.username} (Reason: {arg2}");
19-
player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"<color={argColor}>{shPlayer.username}</color> <color={warningColor}>Just got banned by</color> <color={argColor}>{player.playerData.username}</color> <color={warningColor}>(Reason: <color={argColor}>{arg2}</color><color={warningColor}>)</color>");
19+
player.Send(SvSendType.All, Channel.Unsequenced, ClPacket.GameMessage, $"<color={argColor}>{shPlayer.username}</color> <color={warningColor}>Just got banned by</color> <color={argColor}>{player.playerData.username}</color> <color={warningColor}>(Reason: </color><color={argColor}>{arg2}</color><color={warningColor}>)</color>");
2020
SendDiscordMessage.BanMessage(shPlayer.username, player.playerData.username, arg2);
2121
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Banned</color> <color={argColor}>{shPlayer.username}</color><color={infoColor}>. (Reason: {arg2})</color>");
2222
player.svManager.AddBanned(shPlayer);

source/BP-Essentials/Chat/Commands/Admin/CreateKit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public static void Run(SvPlayer player, string message)
2323
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>Cannot convert {arg1} to a integer.</color>");
2424
return;
2525
}
26+
if (arg1i < 0)
27+
{
28+
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>The delay must be a positive number (0 to disable)</color>");
29+
return;
30+
}
2631
var file = Path.Combine(KitDirectory, $"{arg2}.json");
2732
if (File.Exists(file))
2833
{

source/BP-Essentials/Chat/Commands/Admin/DebugCommands.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public static void Run(SvPlayer player, string message)
9393
foreach (var currPlayer in FindObjectsOfType<SvPlayer>())
9494
currPlayer.SvReset(shPlayer.GetPosition(), shPlayer.GetRotation(), shPlayer.GetPlaceIndex());
9595
}
96+
else if (arg == "addcrimes")
97+
{
98+
player.SvAddCrime(CrimeIndex.Murder, null);
99+
}
96100
else
97101
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, "/debug location/getplayerhash/getspaceindex/createidlist/jobarray");
98102
}

source/BP-Essentials/Chat/Commands/Everyone/GetKit.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public static void Run(SvPlayer player, string message)
2525
return;
2626
}
2727
var obj = listKits.FirstOrDefault(x => x.Name == arg1);
28+
if (!HasPermission.Run(player, obj.ExecutableBy, false, player.player.job.jobIndex))
29+
{
30+
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>You do not have access to that kit.</color>");
31+
return;
32+
}
2833
if (obj.Disabled)
2934
{
3035
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>That kit is currently disabled.</color>");
@@ -39,7 +44,8 @@ public static void Run(SvPlayer player, string message)
3944
{
4045
player.player.TransferItem(DeltaInv.AddToMe, item.Id, item.Amount, true);
4146
}
42-
player.StartCoroutine(Kits.KitCooldown(player, obj));
47+
if (obj.Delay > 0)
48+
player.StartCoroutine(Kits.KitCooldown(player.player.username, obj));
4349
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>You've been given the kit</color> <color={argColor}>{arg1}</color><color={infoColor}>.</color>");
4450
}
4551
}

source/BP-Essentials/Chat/Commands/Everyone/ListKits.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ListKits : EssentialsChatPlugin
1212
{
1313
public static void Run(SvPlayer player)
1414
{
15-
var kits = listKits.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy)).Select(n=>n.Name).ToArray();
15+
var kits = listKits.Where(x => !x.Disabled && HasPermission.Run(player, x.ExecutableBy, false, player.player.job.jobIndex)).Select(n=>n.Name).ToArray();
1616
player.Send(SvSendType.Self, Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Kits you can obtain ({kits.Length}):</color> <color={argColor}>{(kits == null || kits.Length == 0 ? "none" : string.Join(", ", kits))}</color>");
1717
}
1818
}

source/BP-Essentials/EssentialsCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public static void StartServer(SvManager svManager)
3131
try
3232
{
3333
SvMan = svManager;
34-
Reload.Run(true);
34+
Kits.StartKitTimer();
35+
Reload.Run(true, null, true);
3536
CheckAutoReloadFile.Run(AutoReloader);
3637
if (EssentialsVariablesPlugin.Version != LocalVersion)
3738
{
@@ -69,8 +70,7 @@ public static void StartServer(SvManager svManager)
6970
}
7071
if (Announcements.Length != 0)
7172
{
72-
var thread = new Thread(new ParameterizedThreadStart(Chat.Announce.Run));
73-
thread.Start(svManager);
73+
Chat.Announce.Run();
7474
Debug.Log(SetTimeStamp.Run() + "[INFO] Announcer started successfully!");
7575
}
7676
else

source/BP-Essentials/EssentialsVariables.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BP_Essentials
77
{
88
public class EssentialsVariablesPlugin : EssentialsCorePlugin
99
{
10-
public const string Version = "2.5.3";
10+
public const string Version = "2.5.4";
1111
public static bool isPreRelease;
1212

1313
// Generic Constants

source/BP-Essentials/Methods/FileHandler/Kits.cs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BP_Essentials
1212
{
1313
public class Kits
1414
{
15-
public static void LoadAllKits()
15+
public static void LoadAllKits(bool firstLoad = false)
1616
{
1717
if (DebugLevel >= 1)
1818
Debug.Log($"{SetTimeStamp.Run()}[INFO] Loading kits..");
@@ -26,6 +26,9 @@ public static void LoadAllKits()
2626
continue;
2727
}
2828
listKits.Add(obj);
29+
if (firstLoad)
30+
foreach (var player in obj.CurrentlyInCooldown)
31+
SvMan.StartCoroutine(KitCooldown(player.Key, obj));
2932
if (DebugLevel >= 1)
3033
Debug.Log($"{SetTimeStamp.Run()}[INFO] Loaded kit: {obj.Name}");
3134
}
@@ -46,20 +49,43 @@ public static void CreateKit(SvPlayer player, string name, int delay, string fil
4649
File.WriteAllText(fileName, JsonConvert.SerializeObject(obj, Formatting.Indented));
4750
listKits.Add(obj);
4851
}
49-
50-
public static IEnumerator KitCooldown(SvPlayer player, Kits_Json.Kits_RootObj kit)
52+
public static void StartKitTimer()
5153
{
52-
if (!kit.CurrentlyInCooldown.ContainsKey(player.player.username))
53-
kit.CurrentlyInCooldown.Add(player.player.username, kit.Delay);
54-
var passedTime = 0f;
55-
while (passedTime < kit.Delay)
54+
try
55+
{
56+
_Timer.Elapsed += (sender, e) => {
57+
foreach (var kit in listKits)
58+
{
59+
var path = Path.Combine(KitDirectory, $"{kit.Name}.json");
60+
if (File.Exists(path))
61+
File.WriteAllText(path, JsonConvert.SerializeObject(kit, Formatting.Indented));
62+
}
63+
};
64+
_Timer.Interval = 30 * 60 * 1000; // Save every 30 minutes
65+
_Timer.Enabled = true;
66+
}
67+
catch (Exception ex)
68+
{
69+
ErrorLogging.Run(ex);
70+
}
71+
}
72+
public static IEnumerator KitCooldown(string username, Kits_Json.Kits_RootObj kit)
73+
{
74+
if (!kit.CurrentlyInCooldown.ContainsKey(username))
75+
kit.CurrentlyInCooldown.Add(username, kit.Delay);
76+
var path = Path.Combine(KitDirectory, $"{kit.Name}.json");
77+
File.WriteAllText(path, JsonConvert.SerializeObject(kit, Formatting.Indented));
78+
var passedTime = 0;
79+
while (passedTime <= kit.Delay)
5680
{
57-
yield return new WaitForSeconds(1);
5881
++passedTime;
59-
--kit.CurrentlyInCooldown[player.player.username];
82+
--kit.CurrentlyInCooldown[username];
83+
yield return new WaitForSeconds(1);
6084
}
61-
if (kit.CurrentlyInCooldown.ContainsKey(player.player.username))
62-
kit.CurrentlyInCooldown.Remove(player.player.username);
85+
if (kit.CurrentlyInCooldown.ContainsKey(username))
86+
kit.CurrentlyInCooldown.Remove(username);
87+
if (File.Exists(path))
88+
File.WriteAllText(path, JsonConvert.SerializeObject(kit, Formatting.Indented));
6389
}
6490
}
6591
}

source/BP-Essentials/Methods/FileHandler/ReadFile.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ public static void Run(string fileName)
241241
_Timer.Interval = TimeBetweenAnnounce * 1000;
242242
_Timer.Enabled = true;
243243
}
244-
BlockedSpawnIds = m.Misc.BlockSpawnBot.Split(',').Select(int.Parse).ToArray();
244+
if (m.Misc.EnableBlockSpawnBot)
245+
BlockedSpawnIds = m.Misc.BlockSpawnBot.Split(',').Select(int.Parse).ToArray();
245246
GodModeLevel = m.Misc.GodModeLevel;
246247

247248
foreach (var currJob in m.WhitelistedJobs)

0 commit comments

Comments
 (0)