using OWML.Common; using QSB.Messaging; using QSB.Utility; namespace QSB.Events { public class PlayerJoinEvent : QSBEvent { public override EventType Type => EventType.PlayerJoin; public override void SetupListener() { GlobalMessenger.AddListener(EventNames.QSBPlayerJoin, Handler); } public override void CloseListener() { GlobalMessenger.RemoveListener(EventNames.QSBPlayerJoin, Handler); } private void Handler(string name) => SendEvent(CreateMessage(name)); private PlayerJoinMessage CreateMessage(string name) => new PlayerJoinMessage { AboutId = LocalPlayerId, PlayerName = name }; public override void OnReceiveRemote(PlayerJoinMessage message) { var player = PlayerRegistry.GetPlayer(message.AboutId); player.Name = message.PlayerName; var text = $"{player.Name} joined!"; DebugLog.ToAll(text, MessageType.Info); } public override void OnReceiveLocal(PlayerJoinMessage message) { var player = PlayerRegistry.GetPlayer(PlayerRegistry.LocalPlayerId); player.Name = message.PlayerName; var text = $"Connected to server as {player.Name}."; DebugLog.ToAll(text, MessageType.Info); } } }