mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-01 03:20:47 +00:00
65 lines
2 KiB
C#
65 lines
2 KiB
C#
namespace Minecraft.Server.FourKit.Inventory.Meta;
|
|
|
|
/// <summary>
|
|
/// Represents the metadata of an <see cref="ItemStack"/>, including display name and lore.
|
|
/// </summary>
|
|
public class ItemMeta
|
|
{
|
|
private string? _displayName;
|
|
private List<string>? _lore;
|
|
|
|
/// <summary>
|
|
/// Checks for existence of a display name.
|
|
/// </summary>
|
|
/// <returns>true if this has a display name.</returns>
|
|
public bool hasDisplayName() => _displayName != null;
|
|
|
|
/// <summary>
|
|
/// Gets the display name that is set.
|
|
/// Plugins should check that hasDisplayName() returns true before calling this method.
|
|
/// </summary>
|
|
/// <returns>The display name that is set.</returns>
|
|
public string getDisplayName() => _displayName ?? string.Empty;
|
|
|
|
/// <summary>
|
|
/// Sets the display name.
|
|
/// </summary>
|
|
/// <param name="name">The name to set.</param>
|
|
public void setDisplayName(string? name) => _displayName = name;
|
|
|
|
/// <summary>
|
|
/// Checks for existence of lore.
|
|
/// </summary>
|
|
/// <returns>true if this has lore.</returns>
|
|
public bool hasLore() => _lore != null && _lore.Count > 0;
|
|
|
|
/// <summary>
|
|
/// Gets the lore that is set.
|
|
/// Plugins should check if hasLore() returns true before calling this method.
|
|
/// </summary>
|
|
/// <returns>A list of lore that is set.</returns>
|
|
public List<string> getLore() => _lore != null ? new List<string>(_lore) : new List<string>();
|
|
|
|
/// <summary>
|
|
/// Sets the lore for this item. Removes lore when given null.
|
|
/// </summary>
|
|
/// <param name="lore">The lore that will be set.</param>
|
|
public void setLore(List<string>? lore)
|
|
{
|
|
_lore = lore != null ? new List<string>(lore) : null;
|
|
}
|
|
|
|
public ItemMeta clone()
|
|
{
|
|
var copy = new ItemMeta();
|
|
copy._displayName = _displayName;
|
|
copy._lore = _lore != null ? new List<string>(_lore) : null;
|
|
return copy;
|
|
}
|
|
|
|
internal bool isEmpty()
|
|
{
|
|
return _displayName == null && (_lore == null || _lore.Count == 0);
|
|
}
|
|
}
|