Skip to content

Commit

Permalink
Merge pull request #5 from IcePlugins/autoclosingdoors
Browse files Browse the repository at this point in the history
Add Auto Closing Doors
  • Loading branch information
ExtraJuiceMan authored May 30, 2020
2 parents d395070 + 90ce37d commit 160b6c3
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 44 deletions.
23 changes: 16 additions & 7 deletions BreakAndEnter.cs
Original file line number Diff line number Diff line change
@@ -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<BreakAndEnterConfig>
{
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
Expand All @@ -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
{
Expand Down
7 changes: 4 additions & 3 deletions BreakAndEnter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommandDestroy.cs" />
<Compile Include="CommandStorage.cs" />
<Compile Include="CommandDoor.cs" />
<Compile Include="BreakAndEnterConfig.cs" />
<Compile Include="BreakAndEnter.cs" />
<Compile Include="Commands\CommandDestroy.cs" />
<Compile Include="Commands\CommandDoor.cs" />
<Compile Include="Commands\CommandStorage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util.cs" />
</ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions BreakAndEnterConfig.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 0 additions & 2 deletions CommandDestroy.cs → Commands/CommandDestroy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 4 additions & 21 deletions CommandDoor.cs → Commands/CommandDoor.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"));
}
}
}
}
2 changes: 0 additions & 2 deletions CommandStorage.cs → Commands/CommandStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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("")]

Expand All @@ -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")]
15 changes: 11 additions & 4 deletions Util.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SDG.Unturned;

namespace ExtraConcentratedJuice.BreakAndEnter
{
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);
}
}
}

0 comments on commit 160b6c3

Please sign in to comment.