forked from iamsilk/SalvageModifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalvageModifierPlugin.cs
More file actions
112 lines (99 loc) · 4.88 KB
/
Copy pathSalvageModifierPlugin.cs
File metadata and controls
112 lines (99 loc) · 4.88 KB
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
using Rocket.API;
using Rocket.Core.Plugins;
using Rocket.Unturned;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System.Linq;
namespace SalvageModifier
{
public class SalvageModifierPlugin : RocketPlugin<SalvageModifierConfig>
{
public static SalvageModifierPlugin Instance { get; private set; }
protected override void Load()
{
Instance = this;
U.Events.OnPlayerConnected += SetPlayerSalvageTime;
if(Instance.Configuration.Instance.Items.Count != 0)
{
BarricadeDrop.OnSalvageRequested_Global += SRH;
StructureDrop.OnSalvageRequested_Global += SSRH;
}
foreach (SteamPlayer steamPlayer in Provider.clients.Where(x => x != null))
{
UnturnedPlayer player = UnturnedPlayer.FromSteamPlayer(steamPlayer);
SetPlayerSalvageTime(player);
}
Rocket.Core.Logging.Logger.Log("Plugin has been loaded.");
Rocket.Core.Logging.Logger.Log("This version is edited by JonHosting (2022) with micro-optimizations and a few changes, always put the salvage modification time on the top of permission list per group for the smoothest performance. Check config to see or change the permission for dynamic modification.\nThis version of the plugin compromised a bit of the user-friendly permission system for better microperformance, if you need help feel free to contact the JonHosting.com support team.");
Rocket.Core.Logging.Logger.Log("Original: https://github.com/IAmSilK/SalvageModifier");
}
protected override void Unload()
{
U.Events.OnPlayerConnected -= SetPlayerSalvageTime;
if (Instance.Configuration.Instance.Items.Count != 0)
{
BarricadeDrop.OnSalvageRequested_Global -= SRH;
StructureDrop.OnSalvageRequested_Global -= SSRH;
}
Instance = null;
}
private void SRH(BarricadeDrop barricade, SteamPlayer instigatorClient, ref bool shouldAllow) {
#if DEBUG
Rocket.Core.Logging.Logger.Log(instigatorClient.playerID + " Requests to salvage");
#endif
SetPlayerSalvageTime(UnturnedPlayer.FromSteamPlayer(instigatorClient));
}
private void SSRH(StructureDrop structure, SteamPlayer instigatorClient, ref bool shouldAllow)
{
#if DEBUG
Rocket.Core.Logging.Logger.Log(instigatorClient.playerID + " Requests to salvage");
#endif
SetPlayerSalvageTime(UnturnedPlayer.FromSteamPlayer(instigatorClient));
}
public static float GetSalvageTime(UnturnedPlayer player)
{
bool CarePerm = true;
float salvageTime = player.IsAdmin ? 1f : 8f;
if (Instance.Configuration.Instance.DefaultSalvageTime < salvageTime)
{
salvageTime = Instance.Configuration.Instance.DefaultSalvageTime;
}
if (Instance.Configuration.Instance.Items.Count != 0 && player.Player.equipment.itemID != 0) {
Item gg = Instance.Configuration.Instance.Items.Find(i => i.ItemID == player.Player.equipment.itemID);
if(gg != null)
{
salvageTime = gg.SalvageTime;
CarePerm = gg.PermissionsOverride;
}
}
// foreach (var permission in player.GetPermissions())
if (CarePerm)
{
System.Collections.Generic.List<Rocket.API.Serialisation.Permission> Perms = player.GetPermissions();
for (int i = 0; i < Perms.Count; i++)
{
// string perm = permission.Name;
if (Perms[i].Name.Length > Instance.Configuration.Instance.PermissionPrefix.Length && Perms[i].Name.Substring(0, Instance.Configuration.Instance.PermissionPrefix.Length) == Instance.Configuration.Instance.PermissionPrefix)
{
if (!float.TryParse(Perms[i].Name.Substring(Instance.Configuration.Instance.PermissionPrefix.Length), out float time))
{
Rocket.Core.Logging.Logger.Log("Invalid salvage time permission: " + Perms[i].Name);
continue;
}
if (time < salvageTime)
{
salvageTime = time;
break;
}
}
}
}
return salvageTime;
}
public static void SetPlayerSalvageTime(UnturnedPlayer player)
{
float salvageTime = GetSalvageTime(player);
player.Player.interact.sendSalvageTimeOverride(salvageTime);
}
}
}