-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathArenaRegistrationExample.cs
More file actions
52 lines (43 loc) · 1.37 KB
/
ArenaRegistrationExample.cs
File metadata and controls
52 lines (43 loc) · 1.37 KB
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
47
48
49
50
51
52
using SS.Core;
using SS.Core.ComponentCallbacks;
using SS.Core.ComponentInterfaces;
namespace Example.CallbackExamples;
/// <summary>
/// An example on how to register and unregister a callback on an arena.
/// </summary>
/// <param name="chat"></param>
public sealed class ArenaRegistrationExample(IChat chat) : IModule, IArenaAttachableModule
{
private readonly IChat _chat = chat ?? throw new ArgumentNullException(nameof(chat));
bool IModule.Load(IComponentBroker broker)
{
return true;
}
bool IModule.Unload(IComponentBroker broker)
{
return true;
}
bool IArenaAttachableModule.AttachModule(Arena arena)
{
// Register on the arena.
PlayerActionCallback.Register(arena, Callback_PlayerAction);
return true;
}
bool IArenaAttachableModule.DetachModule(Arena arena)
{
// Unregister on the arena.
PlayerActionCallback.Unregister(arena, Callback_PlayerAction);
return true;
}
private void Callback_PlayerAction(Player player, PlayerAction action, Arena? arena)
{
if (action == PlayerAction.EnterArena)
{
_chat.SendArenaMessage(arena, $"Huzzah! {player.Name} entered the arena!");
}
else if (action == PlayerAction.LeaveArena)
{
_chat.SendArenaMessage(arena, $"Poof! {player.Name} left!");
}
}
}