From 67983148f81b6359a2529bb7fbf6dfe1cb8134dc Mon Sep 17 00:00:00 2001
From: Nao <60253860+NaoUnderscore@users.noreply.github.com>
Date: Mon, 1 Jul 2024 18:07:38 +0200
Subject: [PATCH] Apis rework (#2660)
* `[Exiled::Core]` `Assets` and `Fragments` (#2568)
* Core's assets have been implemented:
- Added new classes and attributes for improved entity management.
- Added AssetFragment, EClass, EntityAsset, and related attributes.
- Any types implementing IAssetFragment can be used to generate a fragment or an EntityAsset.
- Began adding EProperty attributes to classes which are supposed to be used to generate fragments and assets.
* Implemented `EProperty` for Items
* ?.
* Minor changes to `EConfig`. Added an `EClass`.
Converted `Effect` class to struct.
* Added `Generator` `EClass`
* Fix hint's `EClass`
* Added more `EClass`'es
* Fixed `AssetFragment::GenerateAsset` generating assets from types which are not marked as `EClass`.
* Fixed `State` compare by ref instead of value
* Minor fixes
* All `EClass`'es
* Fix warnings
* Fix docs
* Revert CustomHealthStat.cs
* Fix build error
* fix conflict?
* fix typo
* fix removals
* fix lag & log spam
* Changes & null fix
* [Core API] Fix null & invalid cast (#2650)
---------
Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com>
* Revert "Merge remote-tracking branch 'origin/dev' into apis-rework"
This reverts commit 08e279f061c0bce1bc9601c69173d40f6d665fdf, reversing
changes made to 1b8d3a54e06dac05e24b9abc0934c45cf0c0e33d.
* Exiled9 (#2641)
* Changes
* that
---------
Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
* Moved modified code. (#2656)
---------
Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com>
Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
Co-authored-by: Alex Rouse <123724383+ALEXWARELLC@users.noreply.github.com>
---
.../API/Extensions/ItemExtensions.cs | 24 ++++++++
.../API/Extensions/PickupExtensions.cs | 24 ++++++++
.../API/Extensions/PlayerExtensions.cs | 59 +++++++++++++++++++
.../API/Features/CustomRoles/CustomRole.cs | 15 +++++
4 files changed, 122 insertions(+)
create mode 100644 Exiled.CustomModules/API/Extensions/ItemExtensions.cs
create mode 100644 Exiled.CustomModules/API/Extensions/PickupExtensions.cs
create mode 100644 Exiled.CustomModules/API/Extensions/PlayerExtensions.cs
diff --git a/Exiled.CustomModules/API/Extensions/ItemExtensions.cs b/Exiled.CustomModules/API/Extensions/ItemExtensions.cs
new file mode 100644
index 0000000000..11717265e7
--- /dev/null
+++ b/Exiled.CustomModules/API/Extensions/ItemExtensions.cs
@@ -0,0 +1,24 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.CustomModules.API.Extensions
+{
+ using Exiled.API.Features.Items;
+ using Exiled.CustomModules.API.Features.CustomItems;
+
+ ///
+ /// A set of extensions for .
+ ///
+ public static class ItemExtensions
+ {
+ ///
+ public static CustomItem Get(this Item item) => CustomItem.Get(item);
+
+ ///
+ public static bool TryGet(this Item item, out CustomItem customItem) => CustomItem.TryGet(item, out customItem);
+ }
+}
\ No newline at end of file
diff --git a/Exiled.CustomModules/API/Extensions/PickupExtensions.cs b/Exiled.CustomModules/API/Extensions/PickupExtensions.cs
new file mode 100644
index 0000000000..97ec820f1a
--- /dev/null
+++ b/Exiled.CustomModules/API/Extensions/PickupExtensions.cs
@@ -0,0 +1,24 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.CustomModules.API.Extensions
+{
+ using Exiled.API.Features.Pickups;
+ using Exiled.CustomModules.API.Features.CustomItems;
+
+ ///
+ /// A set of extensions for .
+ ///
+ public static class PickupExtensions
+ {
+ ///
+ public static CustomItem Get(this Pickup pickup) => CustomItem.Get(pickup);
+
+ ///
+ public static bool TryGet(this Pickup pickup, out CustomItem item) => CustomItem.TryGet(pickup, out item);
+ }
+}
\ No newline at end of file
diff --git a/Exiled.CustomModules/API/Extensions/PlayerExtensions.cs b/Exiled.CustomModules/API/Extensions/PlayerExtensions.cs
new file mode 100644
index 0000000000..2cbfd65878
--- /dev/null
+++ b/Exiled.CustomModules/API/Extensions/PlayerExtensions.cs
@@ -0,0 +1,59 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.CustomModules.API.Extensions
+{
+ using System;
+
+ using Exiled.API.Features;
+ using Exiled.CustomModules.API.Features;
+ using Exiled.CustomModules.API.Features.CustomItems;
+ using Exiled.CustomModules.API.Features.CustomRoles;
+
+ ///
+ /// A set of extensions for .
+ ///
+ public static class PlayerExtensions
+ {
+ ///
+ public static CustomRole Get(this Player player) => CustomRole.Get(player.Cast());
+
+ ///
+ public static bool Spawn(this Player player, CustomRole customRole, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast(), customRole, shouldKeepPosition);
+
+ ///
+ public static bool Spawn(this Player player)
+ where T : CustomRole => CustomRole.Spawn(player.Cast());
+
+ ///
+ public static bool Spawn(this Player player, string name, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast(), name, shouldKeepPosition);
+
+ ///
+ public static bool Spawn(this Player player, uint id, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast(), id, shouldKeepPosition);
+
+ ///
+ public static bool TrySpawn(this Player player, CustomRole customRole) => CustomRole.TrySpawn(player.Cast(), customRole);
+
+ ///
+ public static bool TrySpawn(this Player player, string name) => CustomRole.TrySpawn(player.Cast(), name);
+
+ ///
+ public static bool TrySpawn(this Player player, uint id) => CustomRole.TrySpawn(player.Cast(), id);
+
+ ///
+ public static bool TryGet(this Player player, out CustomRole customRole) => CustomRole.TryGet(player.Cast(), out customRole);
+
+ ///
+ public static bool TryGive(this Player player, string name, bool displayMessage = true) => CustomItem.TryGive(player, name, displayMessage);
+
+ ///
+ public static bool TryGive(this Player player, uint id, bool displayMessage = true) => CustomItem.TryGive(player, id, displayMessage);
+
+ ///
+ public static bool TryGive(this Player player, Type type, bool displayMessage) => CustomItem.TryGive(player, type, displayMessage);
+ }
+}
\ No newline at end of file
diff --git a/Exiled.CustomModules/API/Features/CustomRoles/CustomRole.cs b/Exiled.CustomModules/API/Features/CustomRoles/CustomRole.cs
index bb45df341c..2e96580794 100644
--- a/Exiled.CustomModules/API/Features/CustomRoles/CustomRole.cs
+++ b/Exiled.CustomModules/API/Features/CustomRoles/CustomRole.cs
@@ -517,6 +517,21 @@ public static bool Spawn(Pawn player, string name, bool shouldKeepPosition = fal
return true;
}
+ ///
+ /// Spawns the specified player with the custom role identified by the provided type.
+ ///
+ /// The type of custom role to be added.
+ /// The to be spawned.
+ ///
+ /// if the player was spawned with the custom role successfully; otherwise, .
+ ///
+ ///
+ /// This method add the custom role of type assigned to the specified player.
+ /// If the addition operation fails, the method returns .
+ ///
+ public static bool Spawn(Pawn player)
+ where T : CustomRole => TryGet(typeof(T), out CustomRole customRole) && customRole.Spawn(player);
+
///
/// Removes the custom role from the specified player.
///