diff --git a/dist/localization.json b/dist/localization.json
index 08516ad4..bf4c8ceb 100644
--- a/dist/localization.json
+++ b/dist/localization.json
@@ -121,7 +121,8 @@
"warn_expired": "expired warn",
"active_warns_count": "Active Warns: {0} Warns",
"expired_warns_count": "Expired Warns: {0} Warns",
- "kit_price_automatically_calculated": "Automatic Kit Price: {0}$"
+ "kit_price_automatically_calculated": "Automatic Kit Price: {0}$",
+ "player_giveammo_fail": "You do not have a weapon that needs ammo in your hands!"
},
"BR": {
"arrested": "Preso {0}.",
diff --git a/dist/settings.json b/dist/settings.json
index 523a48cb..5ae965b5 100644
--- a/dist/settings.json
+++ b/dist/settings.json
@@ -7,7 +7,8 @@
// This does not change already Registerd ones
"LimitNames": false,
// This forbbids pressing Register when the Account already was registerd once.
- "DisableAccountOverwrite": false
+ "DisableAccountOverwrite": false,
+ "SaveInterval": 15
},
"KeptItemsOnDeath": {
"KeepAllItemsOnDeath": false,
@@ -425,6 +426,13 @@
"Commands": [
"deletekit"
]
+ },
+ {
+ "CommandName": "GiveAmmo",
+ "Commands": [
+ "giveammo",
+ "ga"
+ ]
}
]
}
diff --git a/src/BPEssentials/BPEssentials.csproj b/src/BPEssentials/BPEssentials.csproj
index ff7b9825..412b8c61 100644
--- a/src/BPEssentials/BPEssentials.csproj
+++ b/src/BPEssentials/BPEssentials.csproj
@@ -295,6 +295,7 @@
+
diff --git a/src/BPEssentials/Commands/Misc/Launch.cs b/src/BPEssentials/Commands/Misc/Launch.cs
index 3a1a054e..562bb6d8 100644
--- a/src/BPEssentials/Commands/Misc/Launch.cs
+++ b/src/BPEssentials/Commands/Misc/Launch.cs
@@ -7,10 +7,10 @@ namespace BPEssentials.Commands
{
public class Launch : Command
{
- public void Invoke(ShPlayer player, ShPlayer target = null)
+ public void Invoke(ShPlayer player, ShPlayer target = null, float thrust = 6500f)
{
target = target ?? player;
- target.svPlayer.SvForce(new UnityEngine.Vector3(0f, 6500f, 0f));
+ target.svPlayer.SvForce(new UnityEngine.Vector3(0f, thrust, 0f));
target.TS("target_launched");
player.TS("player_launched", target.username.CleanerMessage());
}
diff --git a/src/BPEssentials/Commands/Player/Inventory/GiveAmmo.cs b/src/BPEssentials/Commands/Player/Inventory/GiveAmmo.cs
new file mode 100644
index 00000000..c9173f4e
--- /dev/null
+++ b/src/BPEssentials/Commands/Player/Inventory/GiveAmmo.cs
@@ -0,0 +1,27 @@
+using BPEssentials.Abstractions;
+using BPEssentials.ExtensionMethods;
+using BPEssentials.Utils;
+
+using BrokeProtocol.Entities;
+using BrokeProtocol.Utility;
+using System.Linq;
+
+namespace BPEssentials.Commands
+{
+ public class GiveAmmo : Command
+ {
+ public void Invoke(ShPlayer player, int amount = 1, ShPlayer target = null)
+ {
+ target = target ?? player;
+
+ if (!target.curEquipable || !target.curEquipable.AmmoItem)
+ {
+ player.TS("player_giveammo_fail");
+ }
+
+ var item = target.curEquipable.AmmoItem;
+ target.TransferItem(DeltaInv.AddToMe, item.index, amount, true);
+ player.TS("player_give", target.username.CleanerMessage(), item.itemName, amount.ToString());
+ }
+ }
+}
diff --git a/src/BPEssentials/Commands/Server/Save.cs b/src/BPEssentials/Commands/Server/Save.cs
index 2fa8b648..d13d0291 100644
--- a/src/BPEssentials/Commands/Server/Save.cs
+++ b/src/BPEssentials/Commands/Server/Save.cs
@@ -1,29 +1,15 @@
using BPEssentials.Abstractions;
-using BPEssentials.ExtensionMethods;
-
-using BrokeProtocol.Collections;
using BrokeProtocol.Entities;
-using Newtonsoft.Json;
-using System.Linq;
namespace BPEssentials.Commands
{
public class Save : Command
{
- public void StartSaveTimer()
- {
-
- var Tmer = new System.Timers.Timer(); // TODO: Disposing the timer seems to break
- Tmer.Elapsed += (sender, e) => Run();
- Tmer.Interval = 15 * 60 * 1000;
- Tmer.Enabled = true;
-
- }
-
public void Invoke(ShPlayer player)
{
Run();
}
+
public void Run()
{
Core.Instance.Logger.Log("Saving Game Status");
diff --git a/src/BPEssentials/Configuration/Models/SettingsModel.cs b/src/BPEssentials/Configuration/Models/SettingsModel.cs
index 5b15e3f5..e6974d93 100644
--- a/src/BPEssentials/Configuration/Models/SettingsModel.cs
+++ b/src/BPEssentials/Configuration/Models/SettingsModel.cs
@@ -91,7 +91,7 @@ public class General
{
public string Version { get; set; }
- public int AnnounceInterval { get; set; }
+ public int SaveInterval { get; set; } = 15;
public bool LocalChatOverHead { get; set; } = true;
diff --git a/src/BPEssentials/Core.cs b/src/BPEssentials/Core.cs
index a0f7a181..8a1bea5e 100644
--- a/src/BPEssentials/Core.cs
+++ b/src/BPEssentials/Core.cs
@@ -82,7 +82,6 @@ public Core()
EventsHandler.Add("bpe:reload", new Action(OnReloadRequestAsync));
EventsHandler.Add("bpe:version", new Action(OnVersionRequest));
- new Commands.Save().StartSaveTimer();
Logger.LogInfo($"BP Essentials {(IsDevelopmentBuild() ? "[DEVELOPMENT-BUILD] " : "")}v{Version} loaded in successfully!");
}
diff --git a/src/BPEssentials/Events/OnRegister.cs b/src/BPEssentials/Events/OnRegister.cs
index 1a0ed513..1cb7d2a4 100644
--- a/src/BPEssentials/Events/OnRegister.cs
+++ b/src/BPEssentials/Events/OnRegister.cs
@@ -11,60 +11,20 @@ namespace BPEssentials.RegisteredEvents
public class OnRegiser : IScript
{
- [Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Override)]
- public void OnTryRegister(SvManager svManager, ConnectionData connectionData)
+ [Target(GameSourceEvent.ManagerTryRegister, ExecutionMode.Test)]
+ public bool OnTryRegister(SvManager svManager, ConnectionData connectionData)
{
- if (ValidateUser(svManager, connectionData))
+ if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
{
- if (svManager.TryGetUserData(connectionData.username, out User playerData))
- {
- if(Core.Instance.Settings.General.DisableAccountOverwrite)
- {
- svManager.RegisterFail(connectionData.connection, "This Name has already been registerd and this Server has disabled overwriting Accounts!");
- return;
- }
- if (playerData.PasswordHash != connectionData.passwordHash)
- {
- svManager.RegisterFail(connectionData.connection, "Invalid credentials");
- return;
- }
- }
-
- if (!connectionData.username.ValidCredential())
- {
- svManager.RegisterFail(connectionData.connection, $"Name cannot be registered (min: {Util.minCredential}, max: {Util.maxCredential})");
- return;
- }
- // -- BPE EXTEND
- if (Core.Instance.Settings.General.LimitNames && !Regex.IsMatch(connectionData.username, @"^[a-zA-Z0-9_-]+$"))
- {
- svManager.RegisterFail(connectionData.connection, $"Your Username can only contain letters: A-Z a-z 0-9 _ -");
- return;
- }
- // BPE EXTEND --
- svManager.AddNewPlayer(connectionData, playerData?.Persistent);
- }
- }
-
- public bool ValidateUser(SvManager svManager, ConnectionData authData)
- {
- if (!svManager.HandleWhitelist(authData.username))
- {
- svManager.RegisterFail(authData.connection, "Account not whitelisted");
+ svManager.RegisterFail(connectionData.connection, $"Your username can only contain the following characters: A-Z a-z 0-9 _ -");
return false;
}
-
- // Don't allow multi-boxing, WebAPI doesn't prevent this
- foreach (ShPlayer p in EntityCollections.Humans)
+ if (svManager.TryGetUserData(connectionData.username, out var user) && Core.Instance.Settings.General.DisableAccountOverwrite)
{
- if (p.username == authData.username)
- {
- svManager.RegisterFail(authData.connection, "Account still logged in");
- return false;
- }
+ svManager.RegisterFail(connectionData.connection, "This name has already been registered and this server has disabled overwriting accounts!");
+ return false;
}
-
return true;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/BPEssentials/Events/OnStarted.cs b/src/BPEssentials/Events/OnStarted.cs
index 36885312..ddec522a 100644
--- a/src/BPEssentials/Events/OnStarted.cs
+++ b/src/BPEssentials/Events/OnStarted.cs
@@ -1,4 +1,5 @@
-using BrokeProtocol.API;
+using BPCoreLib.Util;
+using BrokeProtocol.API;
using BrokeProtocol.Entities;
using BrokeProtocol.Managers;
using BrokeProtocol.Utility;
@@ -13,6 +14,7 @@ public class OnStarted : IScript
public void OnEvent(SvManager svManager)
{
Core.Instance.SvManager = svManager;
+ Core.Instance.SvManager.StartCoroutine(Interval.Start(Core.Instance.Settings.General.SaveInterval * 60 * 1000, new Commands.Save().Run));
}
}
}