diff --git a/BreakAndEnter.cs b/BreakAndEnter.cs index 8177d19..9924345 100644 --- a/BreakAndEnter.cs +++ b/BreakAndEnter.cs @@ -1,20 +1,21 @@ -using Rocket.Core.Logging; -using Rocket.Core.Plugins; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Rocket.Core.Plugins; +using System.Collections; using Rocket.API.Collections; +using SDG.Unturned; +using UnityEngine; +using Logger = Rocket.Core.Logging.Logger; namespace ExtraConcentratedJuice.BreakAndEnter { - public class BreakAndEnter : RocketPlugin + public class BreakAndEnter : RocketPlugin { public static BreakAndEnter instance; + private float _autoCloseDoorsDelay; protected override void Load() { instance = this; + _autoCloseDoorsDelay = instance.Configuration.Instance.AutoCloseDoorsDelay / 1000f; // Hello by name is Sven and your name sucks because it's just three random words combined // I had to paraphrase because I couldn't find the picture @@ -23,6 +24,14 @@ protected override void Load() Logger.Log("For help please visit https://iceplugins.xyz/BreakAndEnter/"); } + public void AutoCloseDoor(InteractableDoor door) => StartCoroutine(_AutoCloseDoor(door)); + + private IEnumerator _AutoCloseDoor(InteractableDoor door) + { + yield return new WaitForSeconds(_autoCloseDoorsDelay); + Util.ToggleDoor(door, false); + } + public override TranslationList DefaultTranslations => new TranslationList { diff --git a/BreakAndEnter.csproj b/BreakAndEnter.csproj index 2947156..53cc5c5 100644 --- a/BreakAndEnter.csproj +++ b/BreakAndEnter.csproj @@ -77,10 +77,11 @@ - - - + + + + diff --git a/BreakAndEnterConfig.cs b/BreakAndEnterConfig.cs new file mode 100644 index 0000000..6fb110d --- /dev/null +++ b/BreakAndEnterConfig.cs @@ -0,0 +1,16 @@ +using Rocket.API; + +namespace ExtraConcentratedJuice.BreakAndEnter +{ + public class BreakAndEnterConfig : IRocketPluginConfiguration + { + public bool AutoCloseDoors; + public int AutoCloseDoorsDelay; + + public void LoadDefaults() + { + AutoCloseDoors = false; + AutoCloseDoorsDelay = 2500; + } + } +} \ No newline at end of file diff --git a/CommandDestroy.cs b/Commands/CommandDestroy.cs similarity index 98% rename from CommandDestroy.cs rename to Commands/CommandDestroy.cs index 63f1ad7..0ac3ca3 100644 --- a/CommandDestroy.cs +++ b/Commands/CommandDestroy.cs @@ -3,9 +3,7 @@ using Rocket.Unturned.Player; using SDG.Framework.Utilities; using SDG.Unturned; -using System; using System.Collections.Generic; -using System.Reflection; using UnityEngine; namespace ExtraConcentratedJuice.BreakAndEnter diff --git a/CommandDoor.cs b/Commands/CommandDoor.cs similarity index 69% rename from CommandDoor.cs rename to Commands/CommandDoor.cs index a50e66c..269e3c9 100644 --- a/CommandDoor.cs +++ b/Commands/CommandDoor.cs @@ -1,14 +1,9 @@ using Rocket.API; -using Rocket.Core.Logging; using Rocket.Unturned.Chat; -using Rocket.Unturned.Effects; using Rocket.Unturned.Player; using SDG.Framework.Utilities; using SDG.Unturned; -using System; using System.Collections.Generic; -using System.Linq; -using System.Reflection; using UnityEngine; namespace ExtraConcentratedJuice.BreakAndEnter @@ -42,30 +37,18 @@ public void Execute(IRocketPlayer caller, string[] args) InteractableDoor door = hinge.door; bool open = !door.isOpen; - BarricadeManager.tryGetInfo(door.transform, out byte x, out byte y, out ushort plant, out ushort index, out BarricadeRegion region); - - door.updateToggle(open); - - BarricadeManager.instance.channel.send("tellToggleDoor", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[] - { - x, - y, - plant, - index, - open - }); + Util.ToggleDoor(door, open); UnturnedChat.Say(caller, Util.Translate("door_toggle", open ? "opened" : "closed")); + + if (open && BreakAndEnter.instance.Configuration.Instance.AutoCloseDoors) + BreakAndEnter.instance.AutoCloseDoor(door); } else - { UnturnedChat.Say(caller, Util.Translate("invalid_door")); - } } else - { UnturnedChat.Say(caller, Util.Translate("no_object")); - } } } } \ No newline at end of file diff --git a/CommandStorage.cs b/Commands/CommandStorage.cs similarity index 98% rename from CommandStorage.cs rename to Commands/CommandStorage.cs index 25f65b9..12e5809 100644 --- a/CommandStorage.cs +++ b/Commands/CommandStorage.cs @@ -3,9 +3,7 @@ using Rocket.Unturned.Player; using SDG.Framework.Utilities; using SDG.Unturned; -using System; using System.Collections.Generic; -using System.Reflection; using UnityEngine; namespace ExtraConcentratedJuice.BreakAndEnter diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c330cd4..cf7e887 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -8,9 +7,9 @@ [assembly: AssemblyTitle("BreakAndEnter")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyCompany("IcePlugins.xyz")] [assembly: AssemblyProduct("BreakAndEnter")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2017")] +[assembly: AssemblyCopyright("WTFPL")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -32,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/Util.cs b/Util.cs index 021f120..4bc4dbf 100644 --- a/Util.cs +++ b/Util.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using SDG.Unturned; namespace ExtraConcentratedJuice.BreakAndEnter { @@ -9,5 +6,15 @@ public static class Util { public static string Translate(string TranslationKey, params object[] Placeholders) => BreakAndEnter.instance.Translations.Instance.Translate(TranslationKey, Placeholders); + + public static void ToggleDoor(InteractableDoor door, bool open) + { + BarricadeManager.tryGetInfo(door.transform, out byte x, out byte y, out ushort plant, out ushort index, out BarricadeRegion region); + + door.updateToggle(open); + + BarricadeManager.instance.channel.send("tellToggleDoor", ESteamCall.ALL, + ESteamPacket.UPDATE_RELIABLE_BUFFER, x, y, plant, index, open); + } } }