Skip to content

Commit

Permalink
Better AdminToy::Get()
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Aug 1, 2024
1 parent 00f6d58 commit 7ed04d5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion EXILED/Exiled.API/Features/Toys/AdminToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,22 @@ public bool IsStatic
/// </summary>
/// <param name="adminToyBase">The <see cref="AdminToys.AdminToyBase"/> instance.</param>
/// <returns>The corresponding <see cref="AdminToy"/> instance.</returns>
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()
};
}

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

0 comments on commit 7ed04d5

Please sign in to comment.