Skip to content

Commit a259137

Browse files
authored
Merge pull request #7 from Unbistrackted/master
Use IDoorPermissionProvider instead of DoorPermissionFlags
2 parents d85ea58 + d4bb089 commit a259137

7 files changed

Lines changed: 196 additions & 116 deletions

File tree

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
[![Github All Releases](https://img.shields.io/github/downloads/SebasCapo/RemoteKeycard/total.svg)](https://github.com/SebasCapo/RemoteKeycard/releases) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/SebasCapo/RemoteKeycard/graphs/commit-activity) [![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/SebasCapo/RemoteKeycard/blob/main/LICENSE)
2-
<a href="https://github.com/SebasCapo/RemoteKeycard/releases"><img src="https://img.shields.io/github/v/release/SebasCapo/RemoteKeycard?include_prereleases&label=Release" alt="Releases"></a>
3-
<a href="https://discord.gg/PyUkWTg"><img src="https://img.shields.io/discord/656673194693885975?color=%23aa0000&label=EXILED" alt="Support"></a>
4-
5-
# RemoteKeycard
6-
An Exiled (SCP:SL) Plugin that allows you to use your keycards without the need of having them on your hand all the time.
7-
1+
# RemoteKeycard ![Version](https://img.shields.io/github/v/release/Unbistrackted/RemoteKeycard?style=plastic&label=Version&color=dc3e3e) ![Downloads](https://img.shields.io/github/downloads/Unbistrackted/RemoteKeycard/total?style=plastic&label=Downloads&color=50f63f)
2+
A dedicated plugin that allows you to use your keycards without the need of having them on your hand all the time.

RemoteKeycard.sln

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30621.155
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RemoteKeycard", "RemoteKeycard\RemoteKeycard.csproj", "{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|Any CPU = Debug|Any CPU
1111
Debug|x64 = Debug|x64
12+
EXILED|Any CPU = EXILED|Any CPU
13+
EXILED|x64 = EXILED|x64
14+
LabAPI|Any CPU = LabAPI|Any CPU
15+
LabAPI|x64 = LabAPI|x64
1216
Release|Any CPU = Release|Any CPU
1317
Release|x64 = Release|x64
1418
EndGlobalSection
@@ -17,6 +21,14 @@ Global
1721
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Debug|Any CPU.Build.0 = Debug|x64
1822
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Debug|x64.ActiveCfg = Debug|x64
1923
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Debug|x64.Build.0 = Debug|x64
24+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.EXILED|Any CPU.ActiveCfg = EXILED|Any CPU
25+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.EXILED|Any CPU.Build.0 = EXILED|Any CPU
26+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.EXILED|x64.ActiveCfg = EXILED|x64
27+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.EXILED|x64.Build.0 = EXILED|x64
28+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.LabAPI|Any CPU.ActiveCfg = LabAPI|Any CPU
29+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.LabAPI|Any CPU.Build.0 = LabAPI|Any CPU
30+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.LabAPI|x64.ActiveCfg = LabAPI|x64
31+
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.LabAPI|x64.Build.0 = LabAPI|x64
2032
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Release|Any CPU.ActiveCfg = Release|Any CPU
2133
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Release|Any CPU.Build.0 = Release|Any CPU
2234
{D7C1787F-4490-4EAC-967B-AE0DAB13F39F}.Release|x64.ActiveCfg = Release|x64

RemoteKeycard/Config.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
namespace RemoteKeycard;
1+
#if EXILED
2+
using Exiled.API.Interfaces;
3+
#endif
24

35
using System.ComponentModel;
4-
using Exiled.API.Interfaces;
56

7+
namespace RemoteKeycard;
8+
9+
#if EXILED
610
public class Config : IConfig
11+
#else
12+
public class Config
13+
#endif
714
{
15+
/// <summary>
16+
/// Gets or sets a value indicating whether this plugin is enabled.
17+
/// </summary>
18+
public bool IsEnabled { get; set; } = true;
19+
20+
/// <summary>
21+
/// Gets or sets a value indicating whether debug messages should be shown.
22+
/// </summary>
23+
public bool Debug { get; set; } = false;
24+
825
/// <summary>
926
/// Whether Amnesia affects the usage of keycards.
1027
/// </summary>
@@ -40,14 +57,4 @@ public class Config : IConfig
4057
/// </summary>
4158
[Description("Toggle on/off exceptions/errors in console. (Enable this before reporting ANY bugs)")]
4259
public bool ShowExceptions { get; set; } = false;
43-
44-
/// <summary>
45-
/// Gets or sets a value indicating whether this plugin is enabled.
46-
/// </summary>
47-
public bool IsEnabled { get; set; } = true;
48-
49-
/// <summary>
50-
/// Gets or sets a value indicating whether debug messages should be shown.
51-
/// </summary>
52-
public bool Debug { get; set; } = false;
5360
}

RemoteKeycard/EventHandlers.cs

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
using Exiled.API.Enums;
1+
namespace RemoteKeycard;
22

3-
namespace RemoteKeycard;
4-
5-
using System;
3+
#if EXILED
64
using Exiled.API.Features;
75
using Exiled.Events.EventArgs.Player;
8-
using Interactables.Interobjects.DoorUtils;
9-
using Players = Exiled.Events.Handlers.Player;
6+
using PlayerEvents = Exiled.Events.Handlers.Player;
7+
#else
8+
using LabApi.Events.Handlers;
9+
using LabApi.Events.Arguments.PlayerEvents;
10+
using System.Linq;
11+
#endif
12+
using System;
13+
using MapGeneration.Distributors;
14+
using Log = LabApi.Features.Console.Logger;
1015

1116
public class EventHandlers
1217
{
@@ -26,38 +31,51 @@ public EventHandlers(Config config)
2631
/// </summary>
2732
public void Start()
2833
{
29-
Log.Debug("Registering Events");
30-
Players.InteractingDoor += OnDoorInteract;
31-
Players.UnlockingGenerator += OnGeneratorUnlock;
32-
Players.InteractingLocker += OnLockerInteract;
33-
Players.ActivatingWarheadPanel += OnWarheadUnlock;
34+
PlayerEvents.InteractingDoor += OnDoorInteract;
35+
PlayerEvents.UnlockingGenerator += OnGeneratorUnlock;
36+
PlayerEvents.InteractingLocker += OnLockerInteract;
37+
#if EXILED
38+
PlayerEvents.ActivatingWarheadPanel += OnWarheadUnlock;
39+
#else
40+
PlayerEvents.UnlockingWarheadButton += OnWarheadUnlock;
41+
#endif
3442
}
3543

3644
/// <summary>
3745
/// Unregisters all events used.
3846
/// </summary>
3947
public void Stop()
4048
{
41-
Players.InteractingDoor -= OnDoorInteract;
42-
Players.UnlockingGenerator -= OnGeneratorUnlock;
43-
Players.InteractingLocker -= OnLockerInteract;
44-
Players.ActivatingWarheadPanel -= OnWarheadUnlock;
49+
PlayerEvents.InteractingDoor -= OnDoorInteract;
50+
PlayerEvents.UnlockingGenerator -= OnGeneratorUnlock;
51+
PlayerEvents.InteractingLocker -= OnLockerInteract;
52+
#if EXILED
53+
PlayerEvents.ActivatingWarheadPanel -= OnWarheadUnlock;
54+
#else
55+
PlayerEvents.UnlockingWarheadButton -= OnWarheadUnlock;
56+
#endif
4557
}
4658

59+
#if EXILED
4760
private void OnDoorInteract(InteractingDoorEventArgs ev)
61+
#else
62+
private void OnDoorInteract(PlayerInteractingDoorEventArgs ev)
63+
#endif
4864
{
49-
Log.Debug("Door Interact Event");
65+
Log.Debug("Door Interact Event", Plugin.Instance.Config.Debug);
5066
try
5167
{
5268
if (!_config.AffectDoors)
5369
return;
5470

55-
Log.Debug(
56-
$"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(ev.Door.KeycardPermissions)}, Current Item: ${ev.Player.CurrentItem}");
57-
58-
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(ev.Door.KeycardPermissions) &&
59-
!ev.Door.IsLocked)
71+
Log.Debug($"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(ev.Door.Base)}, Current Item: ${ev.Player.CurrentItem}", Plugin.Instance.Config.Debug);
72+
#if EXILED
73+
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(ev.Door.Base) && !ev.Door.IsLocked)
6074
ev.IsAllowed = true;
75+
#else
76+
if (!ev.CanOpen && ev.Player.HasKeycardPermission(ev.Door.Base) && !ev.Door.IsLocked)
77+
ev.CanOpen = true;
78+
#endif
6179
}
6280
catch (Exception e)
6381
{
@@ -66,67 +84,86 @@ private void OnDoorInteract(InteractingDoorEventArgs ev)
6684
}
6785
}
6886

69-
private void OnWarheadUnlock(ActivatingWarheadPanelEventArgs ev)
87+
#if EXILED
88+
private void OnGeneratorUnlock(UnlockingGeneratorEventArgs ev)
89+
#else
90+
private void OnGeneratorUnlock(PlayerUnlockingGeneratorEventArgs ev)
91+
#endif
7092
{
71-
Log.Debug("Warhead Unlock Event");
93+
Log.Debug("Generator Unlock Event", Plugin.Instance.Config.Debug);
7294
try
7395
{
74-
if (!_config.AffectWarheadPanel)
96+
if (!_config.AffectGenerators)
7597
return;
7698

77-
Log.Debug(
78-
$"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(KeycardPermissions.AlphaWarhead)}");
79-
80-
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(KeycardPermissions.AlphaWarhead))
99+
Log.Debug($"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(ev.Generator.Base)}", Plugin.Instance.Config.Debug);
100+
#if EXILED
101+
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(ev.Generator.Base))
81102
ev.IsAllowed = true;
103+
#else
104+
if (!ev.CanOpen && ev.Player.HasKeycardPermission(ev.Generator.Base))
105+
ev.CanOpen = true;
106+
#endif
82107
}
83108
catch (Exception e)
84109
{
85110
if (_config.ShowExceptions)
86-
Log.Warn($"{nameof(OnWarheadUnlock)}: {e.Message}\n{e.StackTrace}");
111+
Log.Warn($"{nameof(OnGeneratorUnlock)}: {e.Message}\n{e.StackTrace}");
87112
}
88113
}
89114

90-
private void OnGeneratorUnlock(UnlockingGeneratorEventArgs ev)
115+
#if EXILED
116+
private void OnLockerInteract(InteractingLockerEventArgs ev)
91117
{
92-
Log.Debug("Generator Unlock Event");
118+
LockerChamber locker = ev.InteractingChamber?.Base;
119+
#else
120+
private void OnLockerInteract(PlayerInteractingLockerEventArgs ev)
121+
{
122+
LockerChamber locker = ev.Chamber?.Base;
123+
#endif
124+
Log.Debug("Locker Interact Event", Plugin.Instance.Config.Debug);
93125
try
94126
{
95-
if (!_config.AffectGenerators)
127+
if (!_config.AffectScpLockers)
96128
return;
97129

98-
Log.Debug(
99-
$"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(ev.Generator.KeycardPermissions)}");
100-
101-
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(ev.Generator.KeycardPermissions))
130+
Log.Debug($"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(locker)}", Plugin.Instance.Config.Debug);
131+
#if EXILED
132+
if (!ev.IsAllowed && locker != null && ev.Player.HasKeycardPermission(locker))
102133
ev.IsAllowed = true;
134+
#else
135+
if (!ev.CanOpen && locker != null && ev.Player.HasKeycardPermission(locker))
136+
ev.CanOpen = true;
137+
#endif
103138
}
104139
catch (Exception e)
105140
{
106141
if (_config.ShowExceptions)
107-
Log.Warn($"{nameof(OnGeneratorUnlock)}: {e.Message}\n{e.StackTrace}");
142+
Log.Warn($"{nameof(OnLockerInteract)}: {e.Message}\n{e.StackTrace}");
108143
}
109144
}
110145

111-
private void OnLockerInteract(InteractingLockerEventArgs ev)
146+
#if EXILED
147+
private void OnWarheadUnlock(ActivatingWarheadPanelEventArgs ev)
148+
#else
149+
private void OnWarheadUnlock(PlayerUnlockingWarheadButtonEventArgs ev)
150+
#endif
112151
{
113-
Log.Debug("Locker Interact Event");
152+
Log.Debug("Warhead Unlock Event", Plugin.Instance.Config.Debug);
114153
try
115154
{
116-
if (!_config.AffectScpLockers)
155+
if (!_config.AffectWarheadPanel)
117156
return;
118157

119-
Log.Debug(
120-
$"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(ev.InteractingChamber.RequiredPermissions, true)}");
158+
Log.Debug($"Allowed: {ev.IsAllowed}, Permission?: {ev.Player.HasKeycardPermission(AlphaWarheadActivationPanel.Instance)}", Plugin.Instance.Config.Debug);
121159

122-
if (!ev.IsAllowed && ev.InteractingChamber != null &&
123-
ev.Player.HasKeycardPermission(ev.InteractingChamber.RequiredPermissions, true))
160+
if (!ev.IsAllowed && ev.Player.HasKeycardPermission(AlphaWarheadActivationPanel.Instance))
124161
ev.IsAllowed = true;
125162
}
126163
catch (Exception e)
127164
{
128165
if (_config.ShowExceptions)
129-
Log.Warn($"{nameof(OnLockerInteract)}: {e.Message}\n{e.StackTrace}");
166+
Log.Warn($"{nameof(OnWarheadUnlock)}: {e.Message}\n{e.StackTrace}");
130167
}
131168
}
132169
}

RemoteKeycard/Extensions.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using Exiled.API.Enums;
2-
3-
namespace RemoteKeycard;
1+
namespace RemoteKeycard;
42

53
using System.Linq;
64
using CustomPlayerEffects;
5+
#if EXILED
76
using Exiled.API.Features;
87
using Exiled.API.Features.Items;
8+
#else
9+
using LabApi.Features.Wrappers;
10+
using Keycard = LabApi.Features.Wrappers.KeycardItem;
11+
#endif
912
using Interactables.Interobjects.DoorUtils;
1013

1114
public static class Extensions
@@ -15,18 +18,17 @@ public static class Extensions
1518
/// </summary>
1619
/// <param name="player"><see cref="Player" /> trying to interact.</param>
1720
/// <param name="permissions">The permission that's gonna be searched for.</param>
18-
/// <param name="requiresAllPermissions">Whether all permissions are required.</param>
1921
/// <returns>Whether the player has the required keycard.</returns>
20-
public static bool HasKeycardPermission(
21-
this Player player,
22-
KeycardPermissions permissions,
23-
bool requiresAllPermissions = false)
22+
public static bool HasKeycardPermission(this Player player, IDoorPermissionRequester permissions)
2423
{
25-
if (Plugin.Instance != null && Plugin.Instance.Config.AmnesiaMatters && player.IsEffectActive<AmnesiaVision>())
24+
if (Plugin.Instance.Config.AmnesiaMatters
25+
#if EXILED
26+
&& player.IsEffectActive<AmnesiaVision>())
27+
#else
28+
&& player.HasEffect<AmnesiaVision>())
29+
#endif
2630
return false;
2731

28-
return requiresAllPermissions
29-
? player.Items.Any(item => item is Keycard keycard && keycard.Permissions.HasFlag(permissions))
30-
: player.Items.Any(item => item is Keycard keycard && (keycard.Permissions & permissions) != 0);
32+
return player.Items.Any(item => item is Keycard keycard && item.Base is IDoorPermissionProvider keycardProvider && permissions.PermissionsPolicy.CheckPermissions(keycardProvider.GetPermissions(permissions)));
3133
}
3234
}

0 commit comments

Comments
 (0)