Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-added customrole and customitem commands. #2715

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomItem/Give.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// -----------------------------------------------------------------------
// <copyright file="Give.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Commands.CustomItem
{
using System;
using System.Collections.Generic;
using System.Linq;

using CommandSystem;
using Exiled.API.Features;
using Exiled.Permissions.Extensions;
using RemoteAdmin;

using CustomItem = Exiled.CustomModules.API.Features.CustomItems.CustomItem;

/// <summary>
/// The command to give a player an item.
/// </summary>
internal sealed class Give : ICommand
{
private Give()
{
}

/// <summary>
/// Gets the <see cref="Give"/> instance.
/// </summary>
public static Give Instance { get; } = new();

/// <inheritdoc/>
public string Command { get; } = "give";

/// <inheritdoc/>
public string[] Aliases { get; } = { "g" };

/// <inheritdoc/>
public string Description { get; } = "Gives a custom item.";

/// <inheritdoc cref="SanitizeResponse" />
public bool SanitizeResponse { get; } = true;

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("customitems.give"))
{
response = "Permission Denied, required: customitems.give";
return false;
}

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

if (!CustomItem.TryGet(arguments.At(0), out CustomItem item))
{
response = $"Custom item {arguments.At(0)} not found!";
return false;
}

if (arguments.Count == 1)
{
if (sender is PlayerCommandSender playerCommandSender)
{
Player player = Player.Get(playerCommandSender.SenderId);

if (!CheckEligible(player))
{
response = "You cannot receive custom items!";
return false;
}

item?.Give(player);
response = $"{item?.Name} given to {player.Nickname} ({player.UserId})";
return true;
}

response = "Failed to provide a valid player, please follow the syntax.";
return false;
}

string identifier = string.Join(" ", arguments.Skip(1));

switch (identifier)
{
case "*":
case "all":
List<Player> eligiblePlayers = Player.List.Where(CheckEligible).ToList();
foreach (Player ply in eligiblePlayers)
item?.Give(ply);

response = $"Custom item {item?.Name} given to all players who can receive them ({eligiblePlayers.Count} players)";
return true;
default:
if (Player.Get(identifier) is not { } player)
{
response = $"Unable to find player: {identifier}.";
return false;
}

if (!CheckEligible(player))
{
response = "Player cannot receive custom items!";
return false;
}

item?.Give(player);
response = $"{item?.Name} given to {player.Nickname} ({player.UserId})";
return true;
}
}

/// <summary>
/// Checks if the player is eligible to receive custom items.
/// </summary>
private bool CheckEligible(Player player) => player.IsAlive && !player.IsCuffed && (player.Items.Count < 8);
}
}
86 changes: 86 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomItem/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// -----------------------------------------------------------------------
// <copyright file="Info.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Commands.CustomItem
{
using System;
using System.Text;

using CommandSystem;
using Exiled.API.Features.Core.Generic.Pools;
using Exiled.API.Features.Spawn;
using Exiled.Permissions.Extensions;

using CustomItem = Exiled.CustomModules.API.Features.CustomItems.CustomItem;

/// <summary>
/// The command to view info about a specific item.
/// </summary>
internal sealed class Info : ICommand
{
private Info()
{
}

/// <summary>
/// Gets the <see cref="Info"/> instance.
/// </summary>
public static Info Instance { get; } = new();

/// <inheritdoc/>
public string Command { get; } = "info";

/// <inheritdoc/>
public string[] Aliases { get; } = { "i" };

/// <inheritdoc/>
public string Description { get; } = "Gets more information about the specified custom item.";

/// <inheritdoc cref="SanitizeResponse" />
public bool SanitizeResponse { get; } = true;

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("customitems.info"))
{
response = "Permission Denied, required: customitems.info";
return false;
}

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

if (!(uint.TryParse(arguments.At(0), out uint id) && CustomItem.TryGet(id, out CustomItem item)) &&
!CustomItem.TryGet(arguments.At(0), out item))
{
response = $"{arguments.At(0)} is not a valid custom item.";
return false;
}

StringBuilder message = StringBuilderPool.Pool.Get().AppendLine();

message.Append("<color=#E6AC00>-</color> <color=#00D639>").Append(item?.Name).Append("</color> <color=#05C4EB>(").Append(item?.Id).AppendLine(")</color>")
.Append("- ").AppendLine(item?.Description)
.AppendLine(item?.ItemType.ToString())
.Append("- Spawn Limit: ").AppendLine(item?.Settings.SpawnProperties?.Limit.ToString()).AppendLine()
.Append("[Spawn Locations (").Append(item?.Settings.SpawnProperties?.DynamicSpawnPoints.Count + item?.Settings.SpawnProperties?.StaticSpawnPoints.Count).AppendLine(")]");

foreach (DynamicSpawnPoint spawnPoint in item?.Settings.SpawnProperties?.DynamicSpawnPoints!)
message.Append(spawnPoint.Name).Append(' ').Append(spawnPoint.Position).Append(" Chance: ").Append(spawnPoint.Chance).AppendLine("%");

foreach (StaticSpawnPoint spawnPoint in item.Settings.SpawnProperties.StaticSpawnPoints)
message.Append(spawnPoint.Name).Append(' ').Append(spawnPoint.Position).Append(" Chance: ").Append(spawnPoint.Chance).AppendLine("%");

response = StringBuilderPool.Pool.ToStringReturn(message);
return true;
}
}
}
52 changes: 52 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomItem/List/List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// -----------------------------------------------------------------------
// <copyright file="List.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Commands.CustomItem.List
{
using System;

using CommandSystem;

/// <summary>
/// The command to list all installed items.
/// </summary>
internal sealed class List : ParentCommand
{
private List()
{
LoadGeneratedCommands();
}

/// <summary>
/// Gets the <see cref="Info"/> instance.
/// </summary>
public static List Instance { get; } = new();

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

/// <inheritdoc/>
public override string[] Aliases { get; } = { "s", "l", "show", "sh" };

/// <inheritdoc/>
public override string Description { get; } = "Gets a list of all currently registered custom items.";

/// <inheritdoc/>
public override void LoadGeneratedCommands()
{
RegisterCommand(Registered.Instance);
RegisterCommand(Tracked.Instance);
}

/// <inheritdoc/>
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = $"Invalid subcommand! Available: registered, insideinventories";
return false;
}
}
}
76 changes: 76 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomItem/List/Registered.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -----------------------------------------------------------------------
// <copyright file="Registered.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Commands.CustomItem.List
{
using System;
using System.Linq;
using System.Text;

using CommandSystem;
using Exiled.API.Features.Core.Generic.Pools;
using Exiled.Permissions.Extensions;

using CustomItem = Exiled.CustomModules.API.Features.CustomItems.CustomItem;

/// <inheritdoc/>
internal sealed class Registered : ICommand
{
private Registered()
{
}

/// <summary>
/// Gets the command instance.
/// </summary>
public static Registered Instance { get; } = new();

/// <inheritdoc/>
public string Command { get; } = "registered";

/// <inheritdoc/>
public string[] Aliases { get; } = { "r", "reg" };

/// <inheritdoc cref="SanitizeResponse" />
public bool SanitizeResponse { get; } = true;

/// <inheritdoc/>
public string Description { get; } = "Gets a list of registered custom items.";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("customitems.list.registered"))
{
response = "Permission Denied, required: customitems.list.registered";
return false;
}

if (arguments.Count != 0)
{
response = "list registered";
return false;
}

if (!CustomItem.List.Any())
{
response = "There are no custom items currently on this server.";
return false;
}

StringBuilder message = StringBuilderPool.Pool.Get().AppendLine();

message.Append("[Registered custom items (").Append(CustomItem.List.Count()).AppendLine(")]");

foreach (CustomItem customItem in CustomItem.List.OrderBy(item => item.Id))
message.Append('[').Append(customItem.Id).Append(". ").Append(customItem.Name).Append(" (").Append(customItem.ItemType).Append(')').AppendLine("]");

response = StringBuilderPool.Pool.ToStringReturn(message);
return true;
}
}
}
Loading
Loading