forked from Impostor/Impostor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
namespace Impostor.Api.Events | ||
using Impostor.Api.Net; | ||
|
||
namespace Impostor.Api.Events | ||
{ | ||
public interface IGamePlayerJoinedEvent : IGameEvent | ||
{ | ||
IClientPlayer Player { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
namespace Impostor.Api.Events | ||
using Impostor.Api.Net; | ||
|
||
namespace Impostor.Api.Events | ||
{ | ||
public interface IGamePlayerLeftEvent : IGameEvent | ||
{ | ||
IClientPlayer Player { get; } | ||
|
||
bool IsBan { get; } | ||
} | ||
} |
30 changes: 15 additions & 15 deletions
30
src/Impostor.Plugins.Example/Handlers/GameEventListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
using System; | ||
using Impostor.Api.Events; | ||
using Impostor.Api.Events; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Impostor.Plugins.Example.Handlers | ||
{ | ||
public class GameEventListener : IEventListener | ||
{ | ||
[EventListener(EventPriority.Monitor)] | ||
public void OnGame(IGameEvent e) | ||
private readonly ILogger<GameEventListener> _logger; | ||
|
||
public GameEventListener(ILogger<GameEventListener> logger) | ||
{ | ||
Console.WriteLine(e.GetType().Name + " triggered"); | ||
_logger = logger; | ||
} | ||
|
||
[EventListener] | ||
public void OnGameCreated(IGameCreatedEvent e) | ||
{ | ||
Console.WriteLine("Game > created"); | ||
_logger.LogInformation("Game {code} > created", e.Game.Code); | ||
} | ||
|
||
[EventListener] | ||
public void OnGameStarting(IGameStartingEvent e) | ||
{ | ||
Console.WriteLine("Game > starting"); | ||
_logger.LogInformation("Game {code} > starting", e.Game.Code); | ||
} | ||
|
||
[EventListener] | ||
public void OnGameStarted(IGameStartedEvent e) | ||
{ | ||
Console.WriteLine("Game > started"); | ||
_logger.LogInformation("Game {code} > started", e.Game.Code); | ||
|
||
foreach (var player in e.Game.Players) | ||
{ | ||
var info = player.Character.PlayerInfo; | ||
var info = player.Character!.PlayerInfo; | ||
|
||
Console.WriteLine($"- {info.PlayerName} {info.IsImpostor}"); | ||
_logger.LogInformation("- {player} is {role}", info.PlayerName, info.IsImpostor ? "an impostor" : "a crewmate"); | ||
} | ||
} | ||
|
||
[EventListener] | ||
public void OnGameEnded(IGameEndedEvent e) | ||
{ | ||
Console.WriteLine("Game > ended"); | ||
Console.WriteLine("- Reason: " + e.GameOverReason); | ||
_logger.LogInformation("Game {code} > ended because {reason}", e.Game.Code, e.GameOverReason); | ||
} | ||
|
||
[EventListener] | ||
public void OnGameDestroyed(IGameDestroyedEvent e) | ||
{ | ||
Console.WriteLine("Game > destroyed"); | ||
_logger.LogInformation("Game {code} > destroyed", e.Game.Code); | ||
} | ||
|
||
[EventListener] | ||
public void OnPlayerJoined(IGamePlayerJoinedEvent e) | ||
{ | ||
Console.WriteLine("Player joined a game."); | ||
_logger.LogInformation("Game {code} > {player} joined", e.Game.Code, e.Player.Client.Name); | ||
} | ||
|
||
[EventListener] | ||
public void OnPlayerLeftGame(IGamePlayerLeftEvent e) | ||
{ | ||
Console.WriteLine("Player left a game."); | ||
_logger.LogInformation("Game {code} > {player} left", e.Game.Code, e.Player.Client.Name); | ||
} | ||
} | ||
} |
15 changes: 11 additions & 4 deletions
15
src/Impostor.Plugins.Example/Handlers/MeetingEventListener.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
using System; | ||
using Impostor.Api.Events; | ||
using Impostor.Api.Events; | ||
using Impostor.Api.Events.Meeting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Impostor.Plugins.Example.Handlers | ||
{ | ||
public class MeetingEventListener : IEventListener | ||
{ | ||
private readonly ILogger<MeetingEventListener> _logger; | ||
|
||
public MeetingEventListener(ILogger<MeetingEventListener> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[EventListener] | ||
public void OnMeetingStarted(IMeetingStartedEvent e) | ||
{ | ||
Console.WriteLine("Meeting > started"); | ||
_logger.LogInformation("Meeting > started"); | ||
} | ||
|
||
[EventListener] | ||
public void OnMeetingEnded(IMeetingEndedEvent e) | ||
{ | ||
Console.WriteLine("Meeting > ended"); | ||
_logger.LogInformation("Meeting > ended"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters