forked from Arrowkuu/TemporaryDestruction
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTemporaryDestruction.cs
122 lines (116 loc) · 5.97 KB
/
TemporaryDestruction.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
using System;
using Rocket.Core.Plugins;
using Rocket.API.Collections;
using SDG.Unturned;
using UnityEngine;
using System.Globalization;
using Rocket.Unturned.Chat;
using Rocket.API;
namespace arrowkuu.temporarydestruction
{
public class TemporaryDestruction : RocketPlugin<TemporaryDestructionConfiguration>
{
public static TemporaryDestruction Instance;
private DateTime one_date;
private DateTime second_date;
public bool secured = false;
private float timer;
private float structureArmorLowTier;
private float structureArmorHighTier;
private float barricadeArmorLowTier;
private float barricadeArmorHighTier;
protected override void Load()
{
Instance = this;
structureArmorLowTier = Provider.modeConfigData.Structures.Armor_Lowtier_Multiplier;
structureArmorHighTier = Provider.modeConfigData.Structures.Armor_Hightier_Multiplier;
barricadeArmorLowTier = Provider.modeConfigData.Barricades.Armor_Lowtier_Multiplier;
barricadeArmorHighTier = Provider.modeConfigData.Barricades.Armor_Hightier_Multiplier;
one_date = DateTime.ParseExact(Configuration.Instance.TimeFrom, "HH:mm:ss", CultureInfo.CurrentCulture);
second_date = DateTime.ParseExact(Configuration.Instance.TimeTo, "HH:mm:ss", CultureInfo.CurrentCulture);
}
protected override void Unload()
{
base.Unload();
}
public void Update()
{
if (Instance.State == PluginState.Loaded)
{
timer += Time.deltaTime;
if (timer >= 1)
{
DateTime actually = DateTime.Now;
if (one_date <= second_date)
{
if (!(actually >= one_date && actually <= second_date))
{
if (secured == true)
{
secured = false;
UnturnedChat.Say(Translations.Instance.Translate("protection_disabled"), Color.green);
Provider.modeConfigData.Structures.Armor_Lowtier_Multiplier = structureArmorLowTier;
Provider.modeConfigData.Structures.Armor_Hightier_Multiplier = structureArmorHighTier;
Provider.modeConfigData.Barricades.Armor_Lowtier_Multiplier = barricadeArmorLowTier;
Provider.modeConfigData.Barricades.Armor_Hightier_Multiplier = barricadeArmorHighTier;
}
}
else
{
if (secured == false)
{
secured = true;
UnturnedChat.Say(Translations.Instance.Translate("protection_enabled", Configuration.Instance.TimeFrom.Remove(5), Configuration.Instance.TimeTo.Remove(5)), Color.red);
Provider.modeConfigData.Structures.Armor_Lowtier_Multiplier = 0;
Provider.modeConfigData.Structures.Armor_Hightier_Multiplier = 0;
Provider.modeConfigData.Barricades.Armor_Lowtier_Multiplier = 0;
Provider.modeConfigData.Barricades.Armor_Hightier_Multiplier = 0;
}
}
}
else
{
if (!(actually >= one_date || actually <= second_date))
{
if (secured == true)
{
secured = false;
UnturnedChat.Say(Translations.Instance.Translate("protection_disabled"), Color.green);
Provider.modeConfigData.Structures.Armor_Lowtier_Multiplier = structureArmorLowTier;
Provider.modeConfigData.Structures.Armor_Hightier_Multiplier = structureArmorHighTier;
Provider.modeConfigData.Barricades.Armor_Lowtier_Multiplier = barricadeArmorLowTier;
Provider.modeConfigData.Barricades.Armor_Hightier_Multiplier = barricadeArmorHighTier;
}
}
else
{
if (secured == false)
{
secured = true;
UnturnedChat.Say(Translations.Instance.Translate("protection_enabled", Configuration.Instance.TimeFrom.Remove(5), Configuration.Instance.TimeTo.Remove(5)), Color.red);
Provider.modeConfigData.Structures.Armor_Lowtier_Multiplier = 0;
Provider.modeConfigData.Structures.Armor_Hightier_Multiplier = 0;
Provider.modeConfigData.Barricades.Armor_Lowtier_Multiplier = 0;
Provider.modeConfigData.Barricades.Armor_Hightier_Multiplier = 0;
}
}
}
timer = 0;
}
}
}
public override TranslationList DefaultTranslations
{
get
{
return new TranslationList()
{
{"protection_disabled","Structure protection has been disabled."},
{"protection_enabled","Structure protection has been enabled and it runs from {0} to {1}."},
{"protection_is_on", "Structure protection is now enabled."},
{"protection_is_off", "Structure protection is now disabled."}
};
}
}
}
}