From 1fb0e19fdce8a0a14ff0372f75ca8714816db843 Mon Sep 17 00:00:00 2001 From: Bankokwak Date: Tue, 20 May 2025 16:06:08 +0200 Subject: [PATCH 1/6] Add Capybara::Create and Text::Create In Text.cs change of Network_collisionsEnabled to CollisionsEnabled. Change to param name for Capybara.cs and Text.cs because he was speakerToy. --- EXILED/Exiled.API/Features/Toys/Capybara.cs | 37 +++++++++++++++++---- EXILED/Exiled.API/Features/Toys/Text.cs | 34 ++++++++++++++++--- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/Capybara.cs b/EXILED/Exiled.API/Features/Toys/Capybara.cs index b88dbfd9c8..6d2ecc9970 100644 --- a/EXILED/Exiled.API/Features/Toys/Capybara.cs +++ b/EXILED/Exiled.API/Features/Toys/Capybara.cs @@ -9,7 +9,9 @@ namespace Exiled.API.Features.Toys { using AdminToys; using Enums; - using Exiled.API.Interfaces; + using Interfaces; + using Mirror; + using UnityEngine; /// /// A wrapper class for . @@ -19,9 +21,9 @@ public class Capybara : AdminToy, IWrapper /// /// Initializes a new instance of the class. /// - /// The of the toy. - internal Capybara(CapybaraToy speakerToy) - : base(speakerToy, AdminToyType.Speaker) => Base = speakerToy; + /// The of the toy. + internal Capybara(CapybaraToy capybaraToy) + : base(capybaraToy, AdminToyType.Capybara) => Base = capybaraToy; /// /// Gets the prefab. @@ -34,12 +36,33 @@ internal Capybara(CapybaraToy speakerToy) public CapybaraToy Base { get; } /// - /// Gets or sets a value indicating whether the capybara can be collided with. + /// Gets or sets a value indicating whether the capybara can be collided with. Only server side. /// public bool Collidable { - get => Base.Network_collisionsEnabled; - set => Base.Network_collisionsEnabled = value; + get => Base.CollisionsEnabled; + set => Base.CollisionsEnabled = value; + } + + /// + /// Creates a new . + /// + /// The position of the . + /// The rotation of the . + /// The scale of the . + /// Whether the should be initially spawned. + /// The new . + public static Capybara Create(Vector3? posititon, Vector3? rotation, Vector3? scale, bool spawn) + { + Capybara capybara = new Capybara(Object.Instantiate(Prefab)); + capybara.Position = posititon ?? Vector3.zero; + capybara.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); + capybara.Scale = scale ?? Vector3.one; + + if (spawn) + capybara.Spawn(); + + return capybara; } } } diff --git a/EXILED/Exiled.API/Features/Toys/Text.cs b/EXILED/Exiled.API/Features/Toys/Text.cs index 7c3317cd22..fe3d828b70 100644 --- a/EXILED/Exiled.API/Features/Toys/Text.cs +++ b/EXILED/Exiled.API/Features/Toys/Text.cs @@ -5,11 +5,12 @@ // // ----------------------------------------------------------------------- +#nullable enable namespace Exiled.API.Features.Toys { using AdminToys; using Enums; - using Exiled.API.Interfaces; + using Interfaces; using UnityEngine; /// @@ -20,9 +21,9 @@ public class Text : AdminToy, IWrapper /// /// Initializes a new instance of the class. /// - /// The of the toy. - internal Text(TextToy speakerToy) - : base(speakerToy, AdminToyType.TextToy) => Base = speakerToy; + /// The of the toy. + internal Text(TextToy textToy) + : base(textToy, AdminToyType.TextToy) => Base = textToy; /// /// Gets the prefab. @@ -51,5 +52,30 @@ public Vector2 DisplaySize get => Base.Network_displaySize; set => Base.Network_displaySize = value; } + + /// + /// Creates a new . + /// + /// The text to shown . + /// The size of the . + /// The position of the . + /// The rotation of the . + /// The scale of the . + /// Whether the should be initially spawned. + /// The new . + public static Text Create(string? newText, Vector2? displaySize, Vector3? posititon, Vector3? rotation, Vector3? scale, bool spawn) + { + Text text = new Text(Object.Instantiate(Prefab)); + text.Position = posititon ?? Vector3.zero; + text.Rotation = Quaternion.Euler(rotation ?? Vector3.zero); + text.Scale = scale ?? Vector3.one; + + text.TextFormat = newText ?? string.Empty; + text.DisplaySize = displaySize ?? TextToy.DefaultDisplaySize; + + if (spawn) + text.Spawn(); + return text; + } } } From 7f95909afad1bec5933bb0cc09f2fa6911f262e2 Mon Sep 17 00:00:00 2001 From: Bankokwak <127428972+Bankokwak@users.noreply.github.com> Date: Tue, 20 May 2025 20:59:44 +0200 Subject: [PATCH 2/6] Update Text.cs Delete #nullable --- EXILED/Exiled.API/Features/Toys/Text.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/Text.cs b/EXILED/Exiled.API/Features/Toys/Text.cs index fe3d828b70..f317d8896e 100644 --- a/EXILED/Exiled.API/Features/Toys/Text.cs +++ b/EXILED/Exiled.API/Features/Toys/Text.cs @@ -5,7 +5,6 @@ // // ----------------------------------------------------------------------- -#nullable enable namespace Exiled.API.Features.Toys { using AdminToys; @@ -63,7 +62,7 @@ public Vector2 DisplaySize /// The scale of the . /// Whether the should be initially spawned. /// The new . - public static Text Create(string? newText, Vector2? displaySize, Vector3? posititon, Vector3? rotation, Vector3? scale, bool spawn) + public static Text Create(string newText, Vector2? displaySize, Vector3? posititon, Vector3? rotation, Vector3? scale, bool spawn) { Text text = new Text(Object.Instantiate(Prefab)); text.Position = posititon ?? Vector3.zero; From 905fe466321ad2dcbaf7994cfa20aac01b0e9de6 Mon Sep 17 00:00:00 2001 From: Bankokwak Date: Wed, 21 May 2025 01:31:37 +0200 Subject: [PATCH 3/6] Add AdminToy::Create --- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 42 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 4a82030c8c..0d45d8b1c2 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -7,15 +7,12 @@ namespace Exiled.API.Features.Toys { + using System; using System.Collections.Generic; - using System.Linq; - using AdminToys; - using Enums; using Exiled.API.Interfaces; using Footprinting; - using InventorySystem.Items; using Mirror; using UnityEngine; @@ -201,5 +198,42 @@ public void Destroy() BaseToAdminToy.Remove(AdminToyBase); NetworkServer.Destroy(AdminToyBase.gameObject); } + + public static AdminToy Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn) where T : AdminToyBase + { + if (AdminToy.PrefabCache.prefab == null) + { + T t = default(T); + using (Dictionary.ValueCollection.Enumerator enumerator = NetworkClient.prefabs.Values.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + if (enumerator.Current.TryGetComponent(out t)) + { + break; + } + } + } + if (t == null) + { + throw new InvalidOperationException(string.Format("No prefab in NetworkClient.prefabs has component type {0}", typeof(T))); + } + AdminToy.PrefabCache.prefab = t; + } + T t2 = UnityEngine.Object.Instantiate(AdminToy.PrefabCache.prefab); + t2.transform.position = position ?? Vector3.zero; + t2.transform.rotation = Quaternion.Euler(rotation ?? Vector3.zero); + t2.transform.localScale = scale ?? Vector3.one; + + if (spawn) + NetworkServer.Spawn(t2.gameObject); + + return Get(t2); + } + + private static class PrefabCache where T : AdminToyBase + { + public static T prefab; + } } } \ No newline at end of file From 5f657aaa5e92a849611689b126cb740c0010d1c9 Mon Sep 17 00:00:00 2001 From: Bankokwak Date: Wed, 21 May 2025 09:28:39 +0200 Subject: [PATCH 4/6] Add XML documentation. --- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 0d45d8b1c2..e76d657ae2 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -9,12 +9,12 @@ namespace Exiled.API.Features.Toys { using System; using System.Collections.Generic; + using AdminToys; using Enums; - using Exiled.API.Interfaces; using Footprinting; + using Interfaces; using Mirror; - using UnityEngine; /// @@ -199,28 +199,42 @@ public void Destroy() NetworkServer.Destroy(AdminToyBase.gameObject); } - public static AdminToy Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn) where T : AdminToyBase + /// + /// Creates a new . + /// + /// The position of the . + /// The rotation of the . + /// The scale of the . + /// Whether the should be initially spawned. + /// The specific type of to instantiate (e.g., , ). + /// The new . + /// Thrown if no prefab with a component exists in . + public virtual AdminToy Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn) + where T : AdminToyBase { - if (AdminToy.PrefabCache.prefab == null) + if (PrefabCache.Prefab == null) { T t = default(T); using (Dictionary.ValueCollection.Enumerator enumerator = NetworkClient.prefabs.Values.GetEnumerator()) { while (enumerator.MoveNext()) { - if (enumerator.Current.TryGetComponent(out t)) + if (enumerator.Current != null && enumerator.Current.TryGetComponent(out t)) { break; } } } + if (t == null) { throw new InvalidOperationException(string.Format("No prefab in NetworkClient.prefabs has component type {0}", typeof(T))); } - AdminToy.PrefabCache.prefab = t; + + PrefabCache.Prefab = t; } - T t2 = UnityEngine.Object.Instantiate(AdminToy.PrefabCache.prefab); + + T t2 = UnityEngine.Object.Instantiate(PrefabCache.Prefab); t2.transform.position = position ?? Vector3.zero; t2.transform.rotation = Quaternion.Euler(rotation ?? Vector3.zero); t2.transform.localScale = scale ?? Vector3.one; @@ -231,9 +245,10 @@ public static AdminToy Create(Vector3? position, Vector3? rotation, Vector3? return Get(t2); } - private static class PrefabCache where T : AdminToyBase + private static class PrefabCache + where T : AdminToyBase { - public static T prefab; + public static T Prefab { get; set; } } } } \ No newline at end of file From 4dda48ed67436aa172c1e172571261bb46a45018 Mon Sep 17 00:00:00 2001 From: Bankokwak Date: Wed, 21 May 2025 09:44:23 +0200 Subject: [PATCH 5/6] Change virtual to static Create methods. (Forget to change that before oupsiii) --- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index e76d657ae2..328646902f 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -209,7 +209,7 @@ public void Destroy() /// The specific type of to instantiate (e.g., , ). /// The new . /// Thrown if no prefab with a component exists in . - public virtual AdminToy Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn) + public static AdminToy Create(Vector3? position, Vector3? rotation, Vector3? scale, bool spawn) where T : AdminToyBase { if (PrefabCache.Prefab == null) From a0c542638875dc0b1ec10558f91a5eea612a0739 Mon Sep 17 00:00:00 2001 From: Bankokwak Date: Wed, 21 May 2025 09:46:48 +0200 Subject: [PATCH 6/6] Move static before method --- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 38 ++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 328646902f..014af3f309 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -180,25 +180,6 @@ public static AdminToy Get(AdminToyBase adminToyBase) public static T Get(AdminToyBase adminToyBase) where T : AdminToy => Get(adminToyBase) as T; - /// - /// Spawns the toy into the game. Use to remove it. - /// - public void Spawn() => NetworkServer.Spawn(AdminToyBase.gameObject); - - /// - /// Removes the toy from the game. Use to bring it back. - /// - public void UnSpawn() => NetworkServer.UnSpawn(AdminToyBase.gameObject); - - /// - /// Destroys the toy. - /// - public void Destroy() - { - BaseToAdminToy.Remove(AdminToyBase); - NetworkServer.Destroy(AdminToyBase.gameObject); - } - /// /// Creates a new . /// @@ -245,6 +226,25 @@ public static AdminToy Create(Vector3? position, Vector3? rotation, Vector3? return Get(t2); } + /// + /// Spawns the toy into the game. Use to remove it. + /// + public void Spawn() => NetworkServer.Spawn(AdminToyBase.gameObject); + + /// + /// Removes the toy from the game. Use to bring it back. + /// + public void UnSpawn() => NetworkServer.UnSpawn(AdminToyBase.gameObject); + + /// + /// Destroys the toy. + /// + public void Destroy() + { + BaseToAdminToy.Remove(AdminToyBase); + NetworkServer.Destroy(AdminToyBase.gameObject); + } + private static class PrefabCache where T : AdminToyBase {