Skip to content

Commit

Permalink
fix: fix events might be turned off if trying to call Remove multiple…
Browse files Browse the repository at this point in the history
… times (#8)
  • Loading branch information
duydang2311 authored and Doxoh committed Mar 26, 2024
1 parent 9bea34e commit a4bbf89
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions api/AltV.Net.Shared/Events/HashSetEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ public HashSetEventHandler()
public void Add(TEvent value)
{
if (value == null) return;
if (type != null) core.EventStateManager.AddHandler(type.Value);
events.Add(value);
if (events.Add(value))
{
if (type != null) core.EventStateManager.AddHandler(type.Value);
}
}

public void Remove(TEvent value)
{
if (value == null) return;
if (type != null) core.EventStateManager.RemoveHandler(type.Value);
events.Remove(value);
if (events.Remove(value))
{
if (type != null) core.EventStateManager.RemoveHandler(type.Value);
}
}

public HashSet<TEvent> GetEvents() => events;
Expand Down

0 comments on commit a4bbf89

Please sign in to comment.