Skip to content

Commit

Permalink
AdminToy.List
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Aug 1, 2024
1 parent 596a425 commit 00f6d58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
7 changes: 1 addition & 6 deletions EXILED/Exiled.API/Features/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public static class Map
/// </summary>
internal static readonly List<PocketDimensionTeleport> TeleportsValue = new(8);

/// <summary>
/// A list of <see cref="AdminToy"/>s on the map.
/// </summary>
internal static readonly List<AdminToy> ToysValue = new();

private static TantrumEnvironmentalHazard tantrumPrefab;
private static Scp939AmnesticCloudInstance amnesticCloudPrefab;

Expand Down Expand Up @@ -130,7 +125,7 @@ DecontaminationController.Singleton.NetworkDecontaminationOverride is Decontamin
/// <summary>
/// Gets all <see cref="AdminToy"/> objects.
/// </summary>
public static ReadOnlyCollection<AdminToy> Toys { get; } = ToysValue.AsReadOnly();
public static ReadOnlyCollection<AdminToy> Toys => AdminToy.BaseToAdminToy.Values.ToList().AsReadOnly();

/// <summary>
/// Gets or sets the current seed of the map.
Expand Down
16 changes: 14 additions & 2 deletions EXILED/Exiled.API/Features/Toys/AdminToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

namespace Exiled.API.Features.Toys
{
using System.Collections.Generic;
using System.Linq;

using AdminToys;

using Enums;
using Exiled.API.Interfaces;
using Footprinting;
using InventorySystem.Items;
using Mirror;

using UnityEngine;
Expand All @@ -23,6 +25,11 @@ namespace Exiled.API.Features.Toys
/// </summary>
public abstract class AdminToy : IWorldSpace
{
/// <summary>
/// A dictionary of all <see cref="AdminToys.AdminToyBase"/>'s that have been converted into <see cref="AdminToy"/>.
/// </summary>
internal static readonly Dictionary<AdminToyBase, AdminToy> BaseToAdminToy = new(new ComponentsEqualityComparer());

/// <summary>
/// Initializes a new instance of the <see cref="AdminToy"/> class.
/// </summary>
Expand All @@ -33,9 +40,14 @@ internal AdminToy(AdminToyBase toyAdminToyBase, AdminToyType type)
AdminToyBase = toyAdminToyBase;
ToyType = type;

Map.ToysValue.Add(this);
BaseToAdminToy.Add(toyAdminToyBase, this);
}

/// <summary>
/// Gets a list of all <see cref="AdminToy"/>'s on the server.
/// </summary>
public static IEnumerable<AdminToy> List => BaseToAdminToy.Values;

/// <summary>
/// Gets the original <see cref="AdminToys.AdminToyBase"/>.
/// </summary>
Expand Down Expand Up @@ -147,7 +159,7 @@ public bool IsStatic
/// </summary>
public void Destroy()
{
Map.ToysValue.Remove(this);
BaseToAdminToy.Remove(AdminToyBase);
NetworkServer.Destroy(AdminToyBase.gameObject);
}
}
Expand Down

0 comments on commit 00f6d58

Please sign in to comment.