summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events/ModMessageReceivedEventArgs.cs
blob: 49366ec646ea1a0c2cde244f37440208d48949f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using StardewModdingAPI.Framework.Networking;

namespace StardewModdingAPI.Events
{
    /// <summary>Event arguments for an <see cref="IMultiplayerEvents.ModMessageReceived"/> event.</summary>
    public class ModMessageReceivedEventArgs : EventArgs
    {
        /*********
        ** Properties
        *********/
        /// <summary>The underlying message model.</summary>
        private readonly ModMessageModel Message;


        /*********
        ** Accessors
        *********/
        /// <summary>The unique ID of the player from whose computer the message was sent.</summary>
        public long FromPlayerID => this.Message.FromPlayerID;

        /// <summary>The unique ID of the mod which sent the message.</summary>
        public string FromModID => this.Message.FromModID;

        /// <summary>A message type which can be used to decide whether it's the one you want to handle, like <c>SetPlayerLocation</c>. This doesn't need to be globally unique, so mods should check the <see cref="FromModID"/>.</summary>
        public string Type => this.Message.Type;


        /*********
        ** Public methods
        *********/
        /// <summary>Construct an instance.</summary>
        /// <param name="message">The received message.</param>
        internal ModMessageReceivedEventArgs(ModMessageModel message)
        {
            this.Message = message;
        }

        /// <summary>Read the message data into the given model type.</summary>
        /// <typeparam name="TModel">The message model type.</typeparam>
        public TModel ReadAs<TModel>()
        {
            return this.Message.Data.ToObject<TModel>();
        }
    }
}