Skip to content

Commit 160b6c3

Browse files
Merge pull request #5 from IcePlugins/autoclosingdoors
Add Auto Closing Doors
2 parents d395070 + 90ce37d commit 160b6c3

File tree

8 files changed

+55
-44
lines changed

8 files changed

+55
-44
lines changed

BreakAndEnter.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
using Rocket.Core.Logging;
2-
using Rocket.Core.Plugins;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
1+
using Rocket.Core.Plugins;
2+
using System.Collections;
73
using Rocket.API.Collections;
4+
using SDG.Unturned;
5+
using UnityEngine;
6+
using Logger = Rocket.Core.Logging.Logger;
87

98
namespace ExtraConcentratedJuice.BreakAndEnter
109
{
11-
public class BreakAndEnter : RocketPlugin
10+
public class BreakAndEnter : RocketPlugin<BreakAndEnterConfig>
1211
{
1312
public static BreakAndEnter instance;
13+
private float _autoCloseDoorsDelay;
1414

1515
protected override void Load()
1616
{
1717
instance = this;
18+
_autoCloseDoorsDelay = instance.Configuration.Instance.AutoCloseDoorsDelay / 1000f;
1819

1920
// Hello by name is Sven and your name sucks because it's just three random words combined
2021
// I had to paraphrase because I couldn't find the picture
@@ -23,6 +24,14 @@ protected override void Load()
2324
Logger.Log("For help please visit https://iceplugins.xyz/BreakAndEnter/");
2425
}
2526

27+
public void AutoCloseDoor(InteractableDoor door) => StartCoroutine(_AutoCloseDoor(door));
28+
29+
private IEnumerator _AutoCloseDoor(InteractableDoor door)
30+
{
31+
yield return new WaitForSeconds(_autoCloseDoorsDelay);
32+
Util.ToggleDoor(door, false);
33+
}
34+
2635
public override TranslationList DefaultTranslations =>
2736
new TranslationList
2837
{

BreakAndEnter.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@
7777
</Reference>
7878
</ItemGroup>
7979
<ItemGroup>
80-
<Compile Include="CommandDestroy.cs" />
81-
<Compile Include="CommandStorage.cs" />
82-
<Compile Include="CommandDoor.cs" />
80+
<Compile Include="BreakAndEnterConfig.cs" />
8381
<Compile Include="BreakAndEnter.cs" />
82+
<Compile Include="Commands\CommandDestroy.cs" />
83+
<Compile Include="Commands\CommandDoor.cs" />
84+
<Compile Include="Commands\CommandStorage.cs" />
8485
<Compile Include="Properties\AssemblyInfo.cs" />
8586
<Compile Include="Util.cs" />
8687
</ItemGroup>

BreakAndEnterConfig.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Rocket.API;
2+
3+
namespace ExtraConcentratedJuice.BreakAndEnter
4+
{
5+
public class BreakAndEnterConfig : IRocketPluginConfiguration
6+
{
7+
public bool AutoCloseDoors;
8+
public int AutoCloseDoorsDelay;
9+
10+
public void LoadDefaults()
11+
{
12+
AutoCloseDoors = false;
13+
AutoCloseDoorsDelay = 2500;
14+
}
15+
}
16+
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using Rocket.Unturned.Player;
44
using SDG.Framework.Utilities;
55
using SDG.Unturned;
6-
using System;
76
using System.Collections.Generic;
8-
using System.Reflection;
97
using UnityEngine;
108

119
namespace ExtraConcentratedJuice.BreakAndEnter

CommandDoor.cs renamed to Commands/CommandDoor.cs

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
using Rocket.API;
2-
using Rocket.Core.Logging;
32
using Rocket.Unturned.Chat;
4-
using Rocket.Unturned.Effects;
53
using Rocket.Unturned.Player;
64
using SDG.Framework.Utilities;
75
using SDG.Unturned;
8-
using System;
96
using System.Collections.Generic;
10-
using System.Linq;
11-
using System.Reflection;
127
using UnityEngine;
138

149
namespace ExtraConcentratedJuice.BreakAndEnter
@@ -42,30 +37,18 @@ public void Execute(IRocketPlayer caller, string[] args)
4237
InteractableDoor door = hinge.door;
4338
bool open = !door.isOpen;
4439

45-
BarricadeManager.tryGetInfo(door.transform, out byte x, out byte y, out ushort plant, out ushort index, out BarricadeRegion region);
46-
47-
door.updateToggle(open);
48-
49-
BarricadeManager.instance.channel.send("tellToggleDoor", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
50-
{
51-
x,
52-
y,
53-
plant,
54-
index,
55-
open
56-
});
40+
Util.ToggleDoor(door, open);
5741

5842
UnturnedChat.Say(caller, Util.Translate("door_toggle", open ? "opened" : "closed"));
43+
44+
if (open && BreakAndEnter.instance.Configuration.Instance.AutoCloseDoors)
45+
BreakAndEnter.instance.AutoCloseDoor(door);
5946
}
6047
else
61-
{
6248
UnturnedChat.Say(caller, Util.Translate("invalid_door"));
63-
}
6449
}
6550
else
66-
{
6751
UnturnedChat.Say(caller, Util.Translate("no_object"));
68-
}
6952
}
7053
}
7154
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using Rocket.Unturned.Player;
44
using SDG.Framework.Utilities;
55
using SDG.Unturned;
6-
using System;
76
using System.Collections.Generic;
8-
using System.Reflection;
97
using UnityEngine;
108

119
namespace ExtraConcentratedJuice.BreakAndEnter

Properties/AssemblyInfo.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
@@ -8,9 +7,9 @@
87
[assembly: AssemblyTitle("BreakAndEnter")]
98
[assembly: AssemblyDescription("")]
109
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("Microsoft")]
10+
[assembly: AssemblyCompany("IcePlugins.xyz")]
1211
[assembly: AssemblyProduct("BreakAndEnter")]
13-
[assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
12+
[assembly: AssemblyCopyright("WTFPL")]
1413
[assembly: AssemblyTrademark("")]
1514
[assembly: AssemblyCulture("")]
1615

@@ -32,5 +31,5 @@
3231
// You can specify all the values or you can default the Build and Revision Numbers
3332
// by using the '*' as shown below:
3433
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("1.1.0.0")]
35+
[assembly: AssemblyFileVersion("1.1.0.0")]

Util.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
1+
using SDG.Unturned;
52

63
namespace ExtraConcentratedJuice.BreakAndEnter
74
{
85
public static class Util
96
{
107
public static string Translate(string TranslationKey, params object[] Placeholders) =>
118
BreakAndEnter.instance.Translations.Instance.Translate(TranslationKey, Placeholders);
9+
10+
public static void ToggleDoor(InteractableDoor door, bool open)
11+
{
12+
BarricadeManager.tryGetInfo(door.transform, out byte x, out byte y, out ushort plant, out ushort index, out BarricadeRegion region);
13+
14+
door.updateToggle(open);
15+
16+
BarricadeManager.instance.channel.send("tellToggleDoor", ESteamCall.ALL,
17+
ESteamPacket.UPDATE_RELIABLE_BUFFER, x, y, plant, index, open);
18+
}
1219
}
1320
}

0 commit comments

Comments
 (0)