Skip to content
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
27 changes: 27 additions & 0 deletions EXILED/Exiled.API/Enums/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// -----------------------------------------------------------------------
// <copyright file="MessageType.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features;

/// <summary>
/// List of <see cref="Message"/> types.
/// </summary>
public enum MessageType
{
/// <summary>
/// Broadcast.
/// </summary>
Broadcast,

/// <summary>
/// Hint.
/// </summary>
Hint,
}
}
72 changes: 72 additions & 0 deletions EXILED/Exiled.API/Features/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// -----------------------------------------------------------------------
// <copyright file="Message.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features
{
using System.ComponentModel;

using Exiled.API.Enums;

/// <summary>
/// A useful class for saving type-selective message configurations.
/// </summary>
public class Message
{
/// <summary>
/// Initializes a new instance of the <see cref="Message"/> class.
/// </summary>
public Message()
: this(string.Empty)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="Message"/> class.
/// </summary>
/// <param name="content">The content of the message.</param>
/// <param name="duration">The duration of the message, in seconds.</param>
/// <param name="show">Whether the message should be shown.</param>
/// <param name="type">The type of the message.</param>
public Message(string content, ushort duration = 10, bool show = true, MessageType type = MessageType.Broadcast)
{
Content = content;
Duration = duration;
Show = show;
Type = type;
}

/// <summary>
/// Gets or sets the message content.
/// </summary>
[Description("The message content")]
public string Content { get; set; }

/// <summary>
/// Gets or sets the message duration.
/// </summary>
[Description("The message duration")]
public ushort Duration { get; set; }

/// <summary>
/// Gets or sets the message type.
/// </summary>
[Description("The message type")]
public MessageType Type { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the message should be shown.
/// </summary>
[Description("Indicates whether the message should be shown")]
public bool Show { get; set; }

/// <summary>
/// Returns the Message in a human-readable format.
/// </summary>
/// <returns>A string containing Message-related data.</returns>
public override string ToString() => $"({Content}) {Duration} {Type}";
}
}
30 changes: 30 additions & 0 deletions EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3049,6 +3049,36 @@ public void ShowHint(Hint hint)
ShowHint(hint.Content, hint.Duration);
}

/// <summary>
/// Messages the given <see cref="Features.Message"/> to the player.
/// </summary>
/// <param name="message">The <see cref="Features.Message"/> to be messaged.</param>
/// <param name="shouldClearPrevious">Clears all player's messages before sending the new one.</param>
public void Message(Message message, bool shouldClearPrevious = false)
{
if (message.Show)
Message(message.Duration, message.Content, message.Type, shouldClearPrevious);
}

/// <summary>
/// Shows a message to the player.
/// </summary>
/// <param name="duration">The message duration.</param>
/// <param name="message">The message to be messaged.</param>
/// <param name="type">The message type.</param>
/// <param name="shouldClearPrevious">Clears all player's messages before sending the new one.</param>
public void Message(ushort duration, string message, MessageType type = MessageType.Broadcast, bool shouldClearPrevious = false)
{
if (type == MessageType.Broadcast)
{
Broadcast(duration, message, shouldClearPrevious: shouldClearPrevious);
}
else
{
ShowHint(message, duration);
}
}

/// <summary>
/// Sends a HitMarker to the player.
/// </summary>
Expand Down