Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardosnt committed Jul 21, 2016
1 parent 4cc7412 commit 9b0aaf5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Commands/CommandHome.cs
Expand Up @@ -43,9 +43,9 @@ public class CommandHome : EssCommand {
internal static SimpleCooldown Cooldown = new SimpleCooldown();

internal static PlayerDictionary<Tasks.Task> Delay = new PlayerDictionary<Tasks.Task>(
PlayerDictionaryCharacteristics.LAZY_REGISTER_HANDLERS |
PlayerDictionaryCharacteristics.REMOVE_ON_DEATH |
PlayerDictionaryCharacteristics.REMOVE_ON_DISCONNECT,
PlayerDictionaryOptions.LAZY_REGISTER_HANDLERS |
PlayerDictionaryOptions.REMOVE_ON_DEATH |
PlayerDictionaryOptions.REMOVE_ON_DISCONNECT,
task => task.Cancel()
);

Expand Down
20 changes: 10 additions & 10 deletions src/Common/Util/PlayerDictionary.cs
Expand Up @@ -31,18 +31,18 @@ namespace Essentials.Common.Util {

public class PlayerDictionary<TValue> : Dictionary<ulong, TValue> {

public PlayerDictionaryCharacteristics Characteristics { get; }
public PlayerDictionaryOptions Options { get; }
private bool _registeredEventHandlers;
private readonly Action<TValue> _removalCallback;

public PlayerDictionary() : this(PlayerDictionaryCharacteristics.REMOVE_ON_DISCONNECT, null) {}
public PlayerDictionary() : this(PlayerDictionaryOptions.REMOVE_ON_DISCONNECT, null) {}

public PlayerDictionary(PlayerDictionaryCharacteristics characteristics, Action<TValue> removalCallback) {
Characteristics = characteristics;
public PlayerDictionary(PlayerDictionaryOptions options, Action<TValue> removalCallback) {
Options = options;
_removalCallback = removalCallback;

if ((Characteristics & PlayerDictionaryCharacteristics.LAZY_REGISTER_HANDLERS) !=
PlayerDictionaryCharacteristics.LAZY_REGISTER_HANDLERS)
if ((Options & PlayerDictionaryOptions.LAZY_REGISTER_HANDLERS) !=
PlayerDictionaryOptions.LAZY_REGISTER_HANDLERS)
RegisterEventHandlers();
}

Expand All @@ -57,7 +57,7 @@ public class PlayerDictionary<TValue> : Dictionary<ulong, TValue> {
}

public new void Add(ulong key, TValue value) {
if ((Characteristics & PlayerDictionaryCharacteristics.LAZY_REGISTER_HANDLERS) != 0 && !_registeredEventHandlers)
if ((Options & PlayerDictionaryOptions.LAZY_REGISTER_HANDLERS) != 0 && !_registeredEventHandlers)
RegisterEventHandlers();
base.Add(key, value);
}
Expand All @@ -72,10 +72,10 @@ public class PlayerDictionary<TValue> : Dictionary<ulong, TValue> {
private void RegisterEventHandlers() {
_registeredEventHandlers = true;

if ((Characteristics & PlayerDictionaryCharacteristics.REMOVE_ON_DISCONNECT) != 0)
if ((Options & PlayerDictionaryOptions.REMOVE_ON_DISCONNECT) != 0)
Provider.onServerDisconnected += OnPlayerDisconnected;

if ((Characteristics & PlayerDictionaryCharacteristics.REMOVE_ON_DEATH) != 0)
if ((Options & PlayerDictionaryOptions.REMOVE_ON_DEATH) != 0)
UnturnedPlayerEvents.OnPlayerDeath += OnPlayerDeath;
}

Expand All @@ -91,7 +91,7 @@ public class PlayerDictionary<TValue> : Dictionary<ulong, TValue> {
}

[Flags]
public enum PlayerDictionaryCharacteristics {
public enum PlayerDictionaryOptions {

/// Remove when player dies.
REMOVE_ON_DEATH = 1,
Expand Down
6 changes: 3 additions & 3 deletions src/NativeModules/Warp/Commands/CommandWarp.cs
Expand Up @@ -40,9 +40,9 @@ namespace Essentials.NativeModules.Warp.Commands {
public class CommandWarp : EssCommand {

internal static PlayerDictionary<Tasks.Task> Delay = new PlayerDictionary<Tasks.Task>(
PlayerDictionaryCharacteristics.LAZY_REGISTER_HANDLERS |
PlayerDictionaryCharacteristics.REMOVE_ON_DEATH |
PlayerDictionaryCharacteristics.REMOVE_ON_DISCONNECT,
PlayerDictionaryOptions.LAZY_REGISTER_HANDLERS |
PlayerDictionaryOptions.REMOVE_ON_DEATH |
PlayerDictionaryOptions.REMOVE_ON_DISCONNECT,
task => task.Cancel()
);

Expand Down

0 comments on commit 9b0aaf5

Please sign in to comment.