From 6c441d9dee563a58dba6ce8e62917f4f08242a87 Mon Sep 17 00:00:00 2001 From: edmand46 Date: Thu, 25 May 2023 11:28:18 +0300 Subject: [PATCH] feat: Entity.OnEvent now support resubscribing --- Ragon.Client/Sources/Entity/RagonEntity.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Ragon.Client/Sources/Entity/RagonEntity.cs b/Ragon.Client/Sources/Entity/RagonEntity.cs index d9671f1..8029625 100644 --- a/Ragon.Client/Sources/Entity/RagonEntity.cs +++ b/Ragon.Client/Sources/Entity/RagonEntity.cs @@ -179,8 +179,10 @@ namespace Ragon.Client if (_events.ContainsKey(eventCode)) { - RagonLog.Warn($"Event already {eventCode} subscribed"); - return; + _events.Remove(eventCode); + _localEvents.Remove(eventCode); + + RagonLog.Warn($"Event already {eventCode} subscribed, removed old one!"); } _localEvents.Add(eventCode, (player, eventData) => { callback.Invoke(player, (TEvent) eventData); }); @@ -190,7 +192,7 @@ namespace Ragon.Client callback.Invoke(player, t); }); } - + internal void Write(RagonBuffer buffer) { buffer.WriteUShort(Id);