Skip to content

Commit 7ed04d5

Browse files
committed
Better AdminToy::Get()
1 parent 00f6d58 commit 7ed04d5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

EXILED/Exiled.API/Features/Toys/AdminToy.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,22 @@ public bool IsStatic
142142
/// </summary>
143143
/// <param name="adminToyBase">The <see cref="AdminToys.AdminToyBase"/> instance.</param>
144144
/// <returns>The corresponding <see cref="AdminToy"/> instance.</returns>
145-
public static AdminToy Get(AdminToyBase adminToyBase) => Map.Toys.FirstOrDefault(x => x.AdminToyBase == adminToyBase);
145+
public static AdminToy Get(AdminToyBase adminToyBase)
146+
{
147+
if (adminToyBase == null)
148+
return null;
149+
150+
if (BaseToAdminToy.TryGetValue(adminToyBase, out AdminToy adminToy))
151+
return adminToy;
152+
153+
return adminToyBase switch
154+
{
155+
LightSourceToy lightSourceToy => new Light(lightSourceToy),
156+
PrimitiveObjectToy primitiveObjectToy => new Primitive(primitiveObjectToy),
157+
ShootingTarget shootingTarget => new ShootingTargetToy(shootingTarget),
158+
_ => throw new System.NotImplementedException()
159+
};
160+
}
146161

147162
/// <summary>
148163
/// Spawns the toy into the game. Use <see cref="UnSpawn"/> to remove it.

0 commit comments

Comments
 (0)