Skip to content
49 changes: 49 additions & 0 deletions SecretAPI/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
namespace SecretAPI.Extensions
{
using Interactables.Interobjects.DoorUtils;
using LabApi.Features.Wrappers;

/// <summary>
/// Extensions related to the player.
/// </summary>
public static class PlayerExtensions
{
/// <summary>
/// Checks if a player has the permission.
/// </summary>
/// <param name="player">The player to check.</param>
/// <param name="permission">The permission to check.</param>
/// <returns>If player has permission.</returns>
public static bool HasGamePermission(this Player player, PlayerPermissions permission)
{
if (player.UserGroup == null)
return false;

PlayerPermissions currentPerms = (PlayerPermissions)player.UserGroup.Permissions;
return currentPerms.HasFlag(permission);
}

/// <summary>
/// Checks whether a player has permission to access a <see cref="IDoorPermissionRequester"/>.
/// </summary>
/// <param name="player">The player to check.</param>
/// <param name="requester">The requester to check the player for permissions on.</param>
/// <returns>Whether a valid permission was found.</returns>
public static bool HasDoorPermission(this Player player, IDoorPermissionRequester requester)
{
if (player.IsBypassEnabled)
return true;

if (player.RoleBase is IDoorPermissionProvider roleProvider && requester.PermissionsPolicy.CheckPermissions(roleProvider.GetPermissions(requester)))
return true;

foreach (Item? item in player.Items)
{
if (item?.Base is IDoorPermissionProvider itemProvider && requester.PermissionsPolicy.CheckPermissions(itemProvider.GetPermissions(requester)))
return true;
}

return false;
}
}
}
45 changes: 45 additions & 0 deletions SecretAPI/Extensions/Scp914Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace SecretAPI.Extensions
{
using System.Linq;
using LabApi.Features.Interfaces;
using LabApi.Features.Wrappers;
using Scp914;

/// <summary>
/// Extensions related to SCP-914.
/// </summary>
public static class Scp914Extensions
{
/// <summary>
/// Process Player like 914 Without Being in 914.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="heldOnly">If it should upgrade only the held item.</param>
/// <param name="setting">The knob setting.</param>
public static void Process914Player(this Player player, bool heldOnly, Scp914KnobSetting setting)
{
if (heldOnly)
{
Process914Item(player.CurrentItem, setting);
return;
}

foreach (Item? item in player.Items.ToList())
Process914Item(item, setting);
}

/// <summary>
/// Processes an item in 914.
/// </summary>
/// <param name="item">The item to process.</param>
/// <param name="setting">The setting to process the item on.</param>
public static void Process914Item(this Item? item, Scp914KnobSetting setting)
{
if (item == null)
return;

IScp914ItemProcessor? processor = Scp914.GetItemProcessor(item.Type);
processor?.UpgradeItem(setting, item);
}
}
}
2 changes: 2 additions & 0 deletions SecretAPI/Features/Effects/CustomPlayerEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public override void Start()
internal static void Initialize()
{
SecretApi.Harmony?.PatchCategory(nameof(CustomPlayerEffect), SecretApi.Assembly);
#pragma warning disable CS0618 // Type or member is obsolete
IGravityEffect.Initialize();
#pragma warning restore CS0618 // Type or member is obsolete
EffectsToRegister.Add(typeof(TemporaryDamageImmunity));
EffectsToRegister.Add(typeof(StaminaUsageDisablerEffect));
EffectsToRegister.Add(typeof(SprintDisablerEffect));
Expand Down
2 changes: 2 additions & 0 deletions SecretAPI/Features/Effects/GravityIncreaseEffect.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace SecretAPI.Features.Effects
{
using System;
using UnityEngine;

/// <summary>
/// Increases the gravity of the player.
/// </summary>
[Obsolete("This will be removed")]
public class GravityIncreaseEffect : CustomPlayerEffect, IGravityEffect
{
/// <inheritdoc />
Expand Down
5 changes: 4 additions & 1 deletion SecretAPI/Features/Effects/IGravityEffect.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
namespace SecretAPI.Features.Effects
{
using System;
using CustomPlayerEffects;
using LabApi.Events.Handlers;
using PlayerRoles.FirstPersonControl;
using UnityEngine;

/// <summary>
/// Handles an effect that affects gravity.
/// </summary>
[Obsolete("This will be removed in the future.")]
public interface IGravityEffect
{
/// <summary>
Expand All @@ -21,7 +24,7 @@ internal static void Initialize()
{
PlayerEvents.UpdatedEffect += ev =>
{
Vector3 multi = new(0f, -19.6f, 0f);
Vector3 multi = FpcGravityController.DefaultGravity;
bool isAffected = false;
foreach (StatusEffectBase effectBase in ev.Player.ActiveEffects)
{
Expand Down
3 changes: 2 additions & 1 deletion SecretAPI/Features/UserSettings/CustomSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private static void SendSettingsToPlayer(Player player, int version = 1)
ordered.AddRange(grouping.Select(setting => setting.Base));
}

ordered.AddRange(ServerSpecificSettingsSync.DefinedSettings);
if (ServerSpecificSettingsSync.DefinedSettings != null)
ordered.AddRange(ServerSpecificSettingsSync.DefinedSettings);

ServerSpecificSettingsSync.SendToPlayer(player.ReferenceHub, [.. ordered], version);
}
Expand Down
Loading