-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
303 additions
and
43 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
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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
|
||
namespace Hkmp.Api.Client; | ||
|
||
/// <summary> | ||
/// Abstract class for a client addon that can be toggled. Extends <see cref="ClientAddon"/>. | ||
/// </summary> | ||
public abstract class TogglableClientAddon : ClientAddon { | ||
/// <summary> | ||
/// Whether this addon is disabled, meaning network is restricted | ||
/// </summary> | ||
private bool _disabled; | ||
|
||
/// <inheritdoc cref="_disabled" /> | ||
public bool Disabled { | ||
get => _disabled; | ||
internal set { | ||
var valueChanged = _disabled != value; | ||
|
||
_disabled = value; | ||
|
||
if (!valueChanged) { | ||
return; | ||
} | ||
|
||
if (value) { | ||
try { | ||
OnDisable(); | ||
} catch (Exception e) { | ||
Logger.Error($"Exception was thrown while calling OnDisable for addon '{GetName()}':\n{e}"); | ||
} | ||
} else { | ||
try { | ||
OnEnable(); | ||
} catch (Exception e) { | ||
Logger.Error($"Exception was thrown while calling OnEnable for addon '{GetName()}':\n{e}"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Callback method for when this addon gets enabled. | ||
/// </summary> | ||
protected abstract void OnEnable(); | ||
|
||
/// <summary> | ||
/// Callback method for when this addon gets disabled. | ||
/// </summary> | ||
protected abstract void OnDisable(); | ||
} |
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
Oops, something went wrong.