diff --git a/EXILED/Exiled.API/Features/Map.cs b/EXILED/Exiled.API/Features/Map.cs index 14f6d8214..24edcc90c 100644 --- a/EXILED/Exiled.API/Features/Map.cs +++ b/EXILED/Exiled.API/Features/Map.cs @@ -57,11 +57,6 @@ public static class Map /// internal static readonly List TeleportsValue = new(8); - /// - /// A list of s on the map. - /// - internal static readonly List ToysValue = new(); - private static TantrumEnvironmentalHazard tantrumPrefab; private static Scp939AmnesticCloudInstance amnesticCloudPrefab; @@ -130,7 +125,7 @@ DecontaminationController.Singleton.NetworkDecontaminationOverride is Decontamin /// /// Gets all objects. /// - public static ReadOnlyCollection Toys { get; } = ToysValue.AsReadOnly(); + public static ReadOnlyCollection Toys => AdminToy.BaseToAdminToy.Values.ToList().AsReadOnly(); // TODO: Obsolete it and make people use AdminToy.List /// /// Gets or sets the current seed of the map. diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index fdbe03da1..2139059e9 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -7,6 +7,7 @@ namespace Exiled.API.Features.Toys { + using System.Collections.Generic; using System.Linq; using AdminToys; @@ -14,6 +15,7 @@ namespace Exiled.API.Features.Toys using Enums; using Exiled.API.Interfaces; using Footprinting; + using InventorySystem.Items; using Mirror; using UnityEngine; @@ -23,6 +25,11 @@ namespace Exiled.API.Features.Toys /// public abstract class AdminToy : IWorldSpace { + /// + /// A dictionary of all 's that have been converted into . + /// + internal static readonly Dictionary BaseToAdminToy = new(new ComponentsEqualityComparer()); + /// /// Initializes a new instance of the class. /// @@ -33,9 +40,14 @@ internal AdminToy(AdminToyBase toyAdminToyBase, AdminToyType type) AdminToyBase = toyAdminToyBase; ToyType = type; - Map.ToysValue.Add(this); + BaseToAdminToy.Add(toyAdminToyBase, this); } + /// + /// Gets a list of all 's on the server. + /// + public static IReadOnlyCollection List => BaseToAdminToy.Values; + /// /// Gets the original . /// @@ -130,7 +142,22 @@ public bool IsStatic /// /// The instance. /// The corresponding instance. - public static AdminToy Get(AdminToyBase adminToyBase) => Map.Toys.FirstOrDefault(x => x.AdminToyBase == adminToyBase); + public static AdminToy Get(AdminToyBase adminToyBase) + { + if (adminToyBase == null) + return null; + + if (BaseToAdminToy.TryGetValue(adminToyBase, out AdminToy adminToy)) + return adminToy; + + return adminToyBase switch + { + LightSourceToy lightSourceToy => new Light(lightSourceToy), + PrimitiveObjectToy primitiveObjectToy => new Primitive(primitiveObjectToy), + ShootingTarget shootingTarget => new ShootingTargetToy(shootingTarget), + _ => throw new System.NotImplementedException() + }; + } /// /// Spawns the toy into the game. Use to remove it. @@ -147,7 +174,7 @@ public bool IsStatic /// public void Destroy() { - Map.ToysValue.Remove(this); + BaseToAdminToy.Remove(AdminToyBase); NetworkServer.Destroy(AdminToyBase.gameObject); } } diff --git a/EXILED/Exiled.Events/Handlers/Internal/SceneUnloaded.cs b/EXILED/Exiled.Events/Handlers/Internal/SceneUnloaded.cs index 9bcb75cc8..4ecdc5f93 100644 --- a/EXILED/Exiled.Events/Handlers/Internal/SceneUnloaded.cs +++ b/EXILED/Exiled.Events/Handlers/Internal/SceneUnloaded.cs @@ -8,7 +8,7 @@ namespace Exiled.Events.Handlers.Internal { using API.Features; - + using Exiled.API.Features.Toys; using UnityEngine.SceneManagement; #pragma warning disable SA1611 // Element parameters should be documented @@ -35,7 +35,7 @@ public static void OnSceneUnloaded(Scene _) { Player.UserIdsCache.Clear(); Player.Dictionary.Clear(); - Map.ToysValue.Clear(); + AdminToy.BaseToAdminToy.Clear(); } } } \ No newline at end of file