From 7ed04d5ec2661c83766730843fa759c370aeb0bd Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 02:39:25 +0200 Subject: [PATCH] Better AdminToy::Get() --- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 006bdc1c2..b805668fa 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -142,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.