Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions EXILED/Exiled.API/Enums/FirearmType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Exiled.API.Enums
{
using System;

/// <summary>
/// Represents a firearm.
/// </summary>
Expand All @@ -18,81 +20,82 @@ namespace Exiled.API.Enums
/// <seealso cref="Extensions.ItemExtensions.GetWeaponAmmoType(FirearmType)"/>
/// <seealso cref="Extensions.ItemExtensions.TryGetAttachments(FirearmType, uint, out System.Collections.Generic.IEnumerable{Structs.AttachmentIdentifier})"/>
/// <seealso cref="Features.Items.Firearm.FirearmType"/>
[Flags]
public enum FirearmType
{
/// <summary>
/// Not a firearm.
/// </summary>
None,
None = 0,

/// <summary>
/// Represents the <see cref="ItemType.GunCOM15"/>.
/// </summary>
Com15,
Com15 = 1,

/// <summary>
/// Represents the <see cref="ItemType.GunCOM18"/>.
/// </summary>
Com18,
Com18 = 2,

/// <summary>
/// Represents the <see cref="ItemType.GunE11SR"/>.
/// </summary>
E11SR,
E11SR = 4,

/// <summary>
/// Represents the <see cref="ItemType.GunCrossvec"/>.
/// </summary>
Crossvec,
Crossvec = 8,

/// <summary>
/// Represents the <see cref="ItemType.GunFSP9"/>.
/// </summary>
FSP9,
FSP9 = 16,

/// <summary>
/// Represents the <see cref="ItemType.GunLogicer"/>.
/// </summary>
Logicer,
Logicer = 32,

/// <summary>
/// Represents the <see cref="ItemType.GunRevolver"/>.
/// </summary>
Revolver,
Revolver = 64,

/// <summary>
/// Represents the <see cref="ItemType.GunAK"/>.
/// </summary>
AK,
AK = 128,

/// <summary>
/// Represents the <see cref="ItemType.GunShotgun"/>.
/// </summary>
Shotgun,
Shotgun = 256,

/// <summary>
/// Represents the <see cref="ItemType.GunCom45"/>.
/// </summary>
Com45,
Com45 = 512,

/// <summary>
/// Represents the <see cref="ItemType.ParticleDisruptor"/>.
/// </summary>
ParticleDisruptor,
ParticleDisruptor = 1024,

/// <summary>
/// Represents the <see cref="ItemType.GunFRMG0"/>.
/// </summary>
FRMG0,
FRMG0 = 2048,

/// <summary>
/// Represents the <see cref="ItemType.GunA7"/>.
/// </summary>
A7,
A7 = 4096,

/// <summary>
/// Represents the <see cref="ItemType.GunSCP127"/>.
/// </summary>
Scp127,
Scp127 = 8192,
}
}
33 changes: 33 additions & 0 deletions EXILED/Exiled.API/Extensions/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// -----------------------------------------------------------------------
// <copyright file="IEnumerableExtensions.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System;
using System.Collections.Generic;

/// <summary>
/// A set of extensions for <see cref="IEnumerable{T}"/>.
/// </summary>
public static class IEnumerableExtensions
{
/// <summary>
/// Perform an action on each element of a collection.
/// </summary>
/// <typeparam name="T">Type of <see cref="IEnumerable{T}"/> elements.</typeparam>
/// <param name="enumerable"><see cref="IEnumerable{T}"/> in this collection, the elements will perform actions.</param>
/// <param name="action">Action that needs to be performed.</param>
public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
{
if (enumerable is null || action is null)
return;

foreach (T e in enumerable)
action(e);
}
Comment thread
louis1706 marked this conversation as resolved.
}
}
48 changes: 48 additions & 0 deletions EXILED/Exiled.API/Extensions/PlayerPermissionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// -----------------------------------------------------------------------
// <copyright file="PlayerPermissionsExtensions.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System.Collections.Generic;

/// <summary>
/// A set of extensions for <see cref="PlayerPermissions"/>.
/// </summary>
public static class PlayerPermissionsExtensions
{
/// <summary>
/// Checks whether the current permissions contain any of the permissions specified in the mask.
/// </summary>
/// <param name="playerPermissions">The current permissions to check.</param>
/// <param name="mask">The mask of permissions to test against.</param>
/// <returns><see langword="true"/> if the current permissions contain at least one permission from the mask; otherwise, <see langword="false"/>.</returns>
public static bool HasAnyPermission(this PlayerPermissions playerPermissions, PlayerPermissions mask)
{
return (playerPermissions & mask) != 0;
}

/// <summary>
/// Checks whether the current permissions contain any of the permissions specified in the collection.
/// </summary>
/// <param name="playerPermissions">The current permissions to check.</param>
/// <param name="collectionPlayerPermissions">The collection of permissions to test against.</param>
/// <returns><see langword="true"/> if the current permissions contain at least one permission from the collection; otherwise, <see langword="false"/>.</returns>
public static bool HasAnyPermission(this PlayerPermissions playerPermissions, IEnumerable<PlayerPermissions> collectionPlayerPermissions)
{
if (collectionPlayerPermissions is null)
return false;

foreach (PlayerPermissions perm in collectionPlayerPermissions)
{
if (playerPermissions.HasAnyPermission(perm))
return true;
}

return false;
}
}
}
27 changes: 27 additions & 0 deletions EXILED/Exiled.API/Extensions/RandomExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// -----------------------------------------------------------------------
// <copyright file="RandomExtensions.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System;

/// <summary>
/// A set of extensions for <see cref="Random"/>.
/// </summary>
public static class RandomExtensions
{
/// <summary>
/// Generate a random bool.
/// </summary>
/// <param name="rnd"><see cref="Random"/> object.</param>
/// <returns>Random boolean value.</returns>
public static bool NextBool(this Random rnd)
{
return (rnd.Next() & 1) == 0;
}
Comment on lines +22 to +25

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is very badly optimised

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is very badly optimised

I don't see any particular problem here, but you can do it like this:
(rnd.Next() & 1) == 0

}
}
40 changes: 40 additions & 0 deletions EXILED/Exiled.API/Extensions/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// -----------------------------------------------------------------------
// <copyright file="TimeSpanExtensions.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using System;

/// <summary>
/// A set of extensions for <see cref="TimeSpan"/>.
/// </summary>
public static class TimeSpanExtensions
{
/// <summary>
/// Converts a TimeSpan object to a human-readable format.
/// </summary>
/// <param name="timeSpan"><see cref="TimeSpan"/> object.</param>
/// <returns>A <see cref="TimeSpan"/> object in string representation.</returns>
public static string ToHumanReadable(this TimeSpan timeSpan)
{
if (timeSpan < TimeSpan.Zero)
return "-" + timeSpan.Negate().ToHumanReadable();

int days = timeSpan.Days;
int hours = timeSpan.Hours;
int minutes = timeSpan.Minutes;
int seconds = timeSpan.Seconds;

if (days > 0)
return $"{days}:{hours:D2}:{minutes:D2}:{seconds:D2}";
else if (hours > 0)
return $"{hours:D2}:{minutes:D2}:{seconds:D2}";
else
return $"{minutes}:{seconds:D2}";
}
Comment on lines +22 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it handle differences like language/ 24h or 12h Am/Pm

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it handle differences like language/ 24h or 12h Am/Pm

Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.

It's an API meant for many people to use. A lot of this code is pretty pointless or not helpful to many people.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal people use the 24-hour clock. In any case, I didn't intend for this method to be universal. If someone needs it, they can always add their own extension method to this class with a different name or a different overload. I don't see any problem with that.

It's an API meant for many people to use. A lot of this code is pretty pointless or not helpful to many people.

Write your own method and add it. Be sure to take into account the 250 official languages. Keep in mind that each language has its own vocabulary and grammar. I used one specific method for 99% of tasks. But you can add your own.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that why i don't see a point for HumanReadable on this one

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see why we need a TimeSpanExtensions, this is basic ToString stuff

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see why we need a TimeSpanExtensions, this is basic ToString stuff

And I repeat once again that the default ToString override isn't working as it should.

var timeSpan = TimeSpan.FromMinutes(1);
Log.Debug(timeSpan.ToString());
Log.Debug(timeSpan.ToString("c"));
Log.Debug(timeSpan.ToString("g"));
Log.Debug(timeSpan.ToString("G"));
Log.Debug(timeSpan.ToString(@"h\:mm\:ss"));
Log.Debug(timeSpan.ToString(@"m\:ss"));
Log.Debug(timeSpan.ToHumanReadable());
[2026-09-26 13:24:16.581 +03:00] [DEBUG] [ToolTestHelper] 00:01:00
[2026-09-26 13:24:16.596 +03:00] [DEBUG] [ToolTestHelper] 00:01:00
[2026-09-26 13:24:16.612 +03:00] [DEBUG] [ToolTestHelper] 0:01:00
[2026-09-26 13:24:16.628 +03:00] [DEBUG] [ToolTestHelper] 0:00:01:00.0000000
[2026-09-26 13:24:16.643 +03:00] [DEBUG] [ToolTestHelper] 0:01:00
[2026-09-26 13:24:16.658 +03:00] [DEBUG] [ToolTestHelper] 1:00
[2026-09-26 13:24:16.674 +03:00] [DEBUG] [ToolTestHelper] 01:00

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve slightly updated this method.

Log.Debug(TimeSpan.FromTicks(1).ToHumanReadable());
Log.Debug(TimeSpan.FromMilliseconds(1).ToHumanReadable());
Log.Debug(TimeSpan.FromSeconds(1).ToHumanReadable());
Log.Debug(TimeSpan.FromMinutes(1).ToHumanReadable());
Log.Debug(TimeSpan.FromHours(1).ToHumanReadable());
Log.Debug(TimeSpan.FromDays(1).ToHumanReadable());
Log.Debug(TimeSpan.FromDays(1).Negate().ToHumanReadable());
[2026-09-26 14:58:43.668 +03:00] [DEBUG] [ToolTestHelper] 0:00
[2026-09-26 14:58:43.683 +03:00] [DEBUG] [ToolTestHelper] 0:00
[2026-09-26 14:58:43.700 +03:00] [DEBUG] [ToolTestHelper] 0:01
[2026-09-26 14:58:43.715 +03:00] [DEBUG] [ToolTestHelper] 1:00
[2026-09-26 14:58:43.731 +03:00] [DEBUG] [ToolTestHelper] 01:00:00
[2026-09-26 14:58:43.746 +03:00] [DEBUG] [ToolTestHelper] 1:00:00:00
[2026-09-26 14:58:43.761 +03:00] [DEBUG] [ToolTestHelper] -1:00:00:00

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should live outside of EXILED, and "ToString override isn't working as it should." is false, and I'm pretty sure you can use Cultures and DateTime to better represent what you need

@PUDGE133 PUDGE133 Oct 5, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should live outside of EXILED, and "ToString override isn't working as it should." is false, and I'm pretty sure you can use Cultures and DateTime to better represent what you need

image image image

There is no way to reproduce this method using IFormatProvider. You are delirious.

}
}
54 changes: 54 additions & 0 deletions EXILED/Exiled.API/Extensions/Vector3Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="Vector3Extensions.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Extensions
{
using Exiled.API.Enums;
using Exiled.API.Features;

using UnityEngine;

/// <summary>
/// A set of extensions for <see cref="Vector3"/> that provide conversions between world space and
/// room‑relative local space.
/// </summary>
public static class Vector3Extensions
{
/// <summary>
/// Converts a world position to a position relative to the specified room's local coordinate system.
/// </summary>
/// <param name="worldPos">The world‑space position to convert.</param>
/// <param name="room">The room whose local space will be used as the reference.</param>
/// <returns>
/// The position expressed in the room's local space.
/// If the room is the <see cref="RoomType.Surface"/>, the original world position is returned unchanged.
/// </returns>
public static Vector3 FromWorldToRelativePos(this Vector3 worldPos, Room room)
{
if (room.Type == RoomType.Surface)
return worldPos;
return room.Transform.InverseTransformPoint(worldPos);
}

/// <summary>
/// Converts a position relative to the specified room's local space back to world space.
/// </summary>
/// <param name="relativePos">The local‑space position to convert.</param>
/// <param name="room">The room whose local space was used as the reference.</param>
/// <returns>
/// The position expressed in world space.
/// If the room is the <see cref="RoomType.Surface"/>, the original local position is returned unchanged
/// (since surface uses world coordinates directly).
/// </returns>
public static Vector3 FromRelativeToWorldPos(this Vector3 relativePos, Room room)
{
if (room.Type == RoomType.Surface)
return relativePos;
Comment on lines +49 to +50

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surface is a functional room technically i only see the purpose of this for Unknown Room

Or if you do it with the surface let's do it to all non dynamic rooms (i prefer to only do it on null that would be unknown)

Surface and pocket

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surface is a functional room technically i only see the purpose of this for Unknown Room

Or if you do it with the surface let's do it to all non dynamic rooms (i prefer to only do it on null that would be unknown)

Surface and pocket

I don't understand what you didn't like about this code.

return room.Transform.TransformPoint(relativePos);
}
}
}
38 changes: 37 additions & 1 deletion EXILED/Exiled.API/Features/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@ public static Door Get(DoorVariant doorVariant)
public static T Get<T>(DoorVariant doorVariant)
where T : Door => Get(doorVariant) as T;

/// <summary>
/// Gets the door object associated with a specific <see cref="ButtonVariant"/>.
/// </summary>
/// <param name="buttonVariant">The base-game <see cref="ButtonVariant"/>.</param>
/// <returns>A <see cref="Door"/> wrapper object.</returns>
public static Door Get(ButtonVariant buttonVariant)
{
if (buttonVariant == null || buttonVariant.ParentDoor == null)
return null;

return Get(buttonVariant.ParentDoor);
}

/// <summary>
/// Gets the <see cref="Door"/> by <see cref="ButtonVariant"/>.
/// </summary>
/// <param name="buttonVariant">The <see cref="ButtonVariant"/> to convert into an door.</param>
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
/// <returns>The door wrapper for the given <see cref="ButtonVariant"/>.</returns>
public static T Get<T>(ButtonVariant buttonVariant)
where T : Door => Get(buttonVariant) as T;

/// <summary>
/// Gets a <see cref="Door"/> given the specified <see cref="DoorType"/>.
/// </summary>
Expand Down Expand Up @@ -378,7 +400,21 @@ public static T Get<T>(string name)
/// </summary>
/// <param name="gameObject">The base-game <see cref="UnityEngine.GameObject"/>.</param>
/// <returns>The <see cref="Door"/> with the given name or <see langword="null"/> if not found.</returns>
public static Door Get(GameObject gameObject) => gameObject is null ? null : Get(gameObject.GetComponentInParent<DoorVariant>());
public static Door Get(GameObject gameObject)
{
if (gameObject == null)
return null;

DoorVariant doorVariant = gameObject.GetComponentInParent<DoorVariant>();
if (doorVariant != null)
return Get(doorVariant);

ButtonVariant buttonVariant = gameObject.GetComponent<ButtonVariant>();
if (buttonVariant != null && buttonVariant.ParentDoor != null)
return Get(gameObject.GetComponent<ButtonVariant>().ParentDoor);

return null;
}

/// <summary>
/// Returns the closest <see cref="Door"/> to the given <paramref name="position"/>.
Expand Down
Loading
Loading