Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
Fixed ImplementConfigs and ApplyConfig methods. Made some adjustm…
Browse files Browse the repository at this point in the history
…ents to modules commands.
  • Loading branch information
NaoUnderscore committed Sep 15, 2024
1 parent 10b4975 commit 0938f9c
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 77 deletions.
34 changes: 33 additions & 1 deletion Exiled.API/Extensions/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace Exiled.API.Extensions
{
using System;
using System.Collections.Generic;
using System.Reflection;

using HarmonyLib;

using LiteNetLib.Utils;

/// <summary>
Expand Down Expand Up @@ -110,5 +110,37 @@ public static Type GetFirstNonGenericBaseType(this Type type)

return baseType;
}

/// <summary>
/// Retrieves the names and values of all properties of an object based on the specified binding flags.
/// </summary>
/// <param name="obj">The object whose properties are to be retrieved.</param>
/// <param name="bindingFlags">Optional. Specifies the binding flags to use for retrieving properties. Default is <see cref="BindingFlags.Instance"/> and <see cref="BindingFlags.Public"/>.</param>
/// <returns>A dictionary containing property names as keys and their respective values as values.</returns>
public static Dictionary<string, object> GetPropertiesWithValue(this object obj, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
{
Dictionary<string, object> propertyValues = new();

obj.GetType().GetProperties(bindingFlags)
.ForEach(property => propertyValues.Add(property.Name, property.GetValue(obj, null)));

return propertyValues;
}

/// <summary>
/// Retrieves the names and values of all fields of an object based on the specified binding flags.
/// </summary>
/// <param name="obj">The object whose fields are to be retrieved.</param>
/// <param name="bindingFlags">Optional. Specifies the binding flags to use for retrieving fields. Default is <see cref="BindingFlags.Instance"/> and <see cref="BindingFlags.Public"/>.</param>
/// <returns>A dictionary containing field names as keys and their respective values as values.</returns>
public static Dictionary<string, object> GetFieldsWithValue(this object obj, BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public)
{
Dictionary<string, object> propertyValues = new();

obj.GetType().GetFields(bindingFlags)
.ForEach(field => propertyValues.Add(field.Name, field.GetValue(obj)));

return propertyValues;
}
}
}
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/CustomEscapes/Attach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 2)
{
response = "attach [Custom Escape ID > Nickname / PlayerID / UserID / all / *]";
response = "attach <Custom Escape> [Nickname / PlayerID / UserID / all / *]";
return false;
}

if (!CustomEscape.TryGet(arguments.At(0), out CustomEscape escape) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomEscape.TryGet(id, out escape)) && escape is null)
{
response = $"Custom Escape {arguments.At(0)} not found!";
response = $"Custom escape {arguments.At(0)} not found!";
return false;
}

Expand Down
10 changes: 6 additions & 4 deletions Exiled.CustomModules/API/Commands/CustomEscapes/Detach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private Detach()
public string[] Aliases { get; } = { "d" };

/// <inheritdoc/>
public string Description { get; } = "Detach the specified custom escape from a player(s).";
public string Description { get; } = "Detaches the specified custom escape from a player(s).";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
Expand All @@ -53,13 +53,15 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 2)
{
response = "detach [Custom Escape ID > Nickname / PlayerID / UserID / all / *]";
response = "detach <Custom Escape> [Nickname / PlayerID / UserID / all / *]";
return false;
}

if (!CustomEscape.TryGet(arguments.At(0), out CustomEscape escape) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomEscape.TryGet(id, out escape)) && escape is null)
if (!CustomEscape.TryGet(arguments.At(0), out CustomEscape escape) &&
(!uint.TryParse(arguments.At(0), out uint id) ||
!CustomEscape.TryGet(id, out escape)) && escape is null)
{
response = $"Custom Escape {arguments.At(0)} not found!";
response = $"Custom escape {arguments.At(0)} not found!";
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions Exiled.CustomModules/API/Commands/CustomEscapes/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public Parent()
}

/// <inheritdoc/>
public override string Command { get; } = "escapes";
public override string Command { get; } = "customescapes";

/// <inheritdoc/>
public override string[] Aliases { get; } = { "esc" };
public override string[] Aliases { get; } = { "ce", "ces", "escapes", "esc" };

/// <inheritdoc/>
public override string Description { get; } = "Exiled Custom Escape Commands";
public override string Description { get; } = "Commands for managing custom escapes.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
Expand Down
2 changes: 1 addition & 1 deletion Exiled.CustomModules/API/Commands/CustomItem/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Parent()
public override string[] Aliases { get; } = { "ci", "cis" };

/// <inheritdoc/>
public override string Description { get; } = "Exiled Custom Item Commands";
public override string Description { get; } = "Commands for managing custom items.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
Expand Down
2 changes: 1 addition & 1 deletion Exiled.CustomModules/API/Commands/CustomRoles/Give.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 2)
{
response = "give <Custom role ID> [Nickname / PlayerID / UserID / all / *]";
response = "give <Custom Role> [Nickname / PlayerID / UserID / all / *]";
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Exiled.CustomModules/API/Commands/CustomRoles/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "info [Custom role name / Custom role ID]";
response = "info <Custom Role>";
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Exiled.CustomModules/API/Commands/CustomRoles/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Parent()
public override string[] Aliases { get; } = { "cr", "crs" };

/// <inheritdoc/>
public override string Description { get; } = "Exiled Custom Role Commands";
public override string Description { get; } = "Commands for managing custom roles.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
Expand Down
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/CustomTeams/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "info [Custom Team ID]";
response = "info <Custom Team>";
return false;
}

if ((!(uint.TryParse(arguments.At(0), out uint id) && CustomTeam.TryGet(id, out CustomTeam team)) && !CustomTeam.TryGet(arguments.At(0), out team)) || team is null)
{
response = $"{arguments.At(0)} is not a valid Custom Team.";
response = $"{arguments.At(0)} is not a valid custom team.";
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions Exiled.CustomModules/API/Commands/CustomTeams/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public Parent()
}

/// <inheritdoc/>
public override string Command { get; } = "teams";
public override string Command { get; } = "customteams";

/// <inheritdoc/>
public override string[] Aliases { get; } = { "tms" };
public override string[] Aliases { get; } = { "cts" };

/// <inheritdoc/>
public override string Description { get; } = "Exiled Custom Team Commands";
public override string Description { get; } = "Commands for managing custom teams.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
Expand Down
6 changes: 3 additions & 3 deletions Exiled.CustomModules/API/Commands/CustomTeams/Spawn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "spawn <Custom Team ID>";
response = "spawn <Custom Team>";
return false;
}

if (!CustomTeam.TryGet(arguments.At(0), out CustomTeam team) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomTeam.TryGet(id, out team)) && team is null)
{
response = $"Custom Team {arguments.At(0)} not found!";
response = $"Custom team {arguments.At(0)} not found!";
return false;
}

Expand All @@ -70,7 +70,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

team.Respawn(true);

response = $"Custom Team {team.Name} has been spawned.";
response = $"Custom team {team.Name} has been spawned.";
return true;
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/Gamemodes/End.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private End()
public string[] Aliases { get; } = { "e" };

/// <inheritdoc/>
public string Description { get; } = "End the running gamemode.";
public string Description { get; } = "Ends the running gamemode.";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
Expand All @@ -52,7 +52,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (world.GameState)
{
world.RemoveComponent(world.GameState).Destroy();
world.GameState.End(true);

response = "The gamemode has been ended.";
return true;
Expand Down
8 changes: 5 additions & 3 deletions Exiled.CustomModules/API/Commands/Gamemodes/Enqueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "Usage: enqueue <gamemode>";
response = "Usage: enqueue <Custom Gamemode>";
return false;
}

if (CustomGameMode.TryGet(arguments.At(0), out CustomGameMode gameMode) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomGameMode.TryGet(id, out gameMode)) && gameMode is null)
if (CustomGameMode.TryGet(arguments.At(0), out CustomGameMode gameMode) &&
(!uint.TryParse(arguments.At(0), out uint id) ||
!CustomGameMode.TryGet(id, out gameMode)) && gameMode is null)
{
response = $"Custom GameMode {arguments.At(0)} not found!";
response = $"Custom gamemode {arguments.At(0)} not found!";
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/Gamemodes/Info.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "info [Gamemode ID]";
response = "info <Custom Gamemode>";
return false;
}

if ((!(uint.TryParse(arguments.At(0), out uint id) && CustomGameMode.TryGet(id, out CustomGameMode gameMode)) && !CustomGameMode.TryGet(arguments.At(0), out gameMode)) || gameMode is null)
{
response = $"{arguments.At(0)} is not a valid Custom Gamemode.";
response = $"{arguments.At(0)} is not a valid custom gamemode.";
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions Exiled.CustomModules/API/Commands/Gamemodes/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public Parent()
}

/// <inheritdoc/>
public override string Command { get; } = "gamemodes";
public override string Command { get; } = "customgamemodes";

/// <inheritdoc/>
public override string[] Aliases { get; } = { "gmd", "gmds" };
public override string[] Aliases { get; } = { "gm", "cgm", "cgmds" };

/// <inheritdoc/>
public override string Description { get; } = "Exiled Gamemode Commands";
public override string Description { get; } = "Commands for managing custom gamemodes.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
Expand Down
4 changes: 2 additions & 2 deletions Exiled.CustomModules/API/Commands/Gamemodes/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

if (arguments.Count < 1)
{
response = "start [Gamemode ID]";
response = "start <Custom Gamemode>";
return false;
}

if (CustomGameMode.TryGet(arguments.At(0), out CustomGameMode gameMode) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomGameMode.TryGet(id, out gameMode)) && gameMode is null)
{
response = $"Custom GameMode {arguments.At(0)} not found!";
response = $"Custom gamemode {arguments.At(0)} not found!";
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,5 @@ public class LevelAbilitySettings : ActiveAbilitySettings
/// </summary>
[Description("The message shown when the ability reaches its maximum level.")]
public virtual TextDisplay MaxLevelReached { get; set; }


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ protected override void OnBeginPlay()

if (!Owner)
{
Log.WarnWithContext("Owner is null");
Destroy();
return;
}
Expand Down
Loading

0 comments on commit 0938f9c

Please sign in to comment.