Skip to content

Commit

Permalink
things
Browse files Browse the repository at this point in the history
  • Loading branch information
moddedmcplayer committed Aug 29, 2022
1 parent 628361e commit 28de4ce
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
13 changes: 12 additions & 1 deletion hats/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace hats
{
using System.Diagnostics;

public static class API
{
public static Dictionary<string, Hat> Hats { get; private set; } = new Dictionary<string, Hat>();
Expand Down Expand Up @@ -50,7 +52,16 @@ public static void ClearHats()
}
foreach (var kvp in Hats)
{
kvp.Value.DestroyInstances();
try
{
kvp.Value.DestroyInstances();
}
catch (ArgumentException e)
{
Console.WriteLine(e);
throw;
}

}
Hats.Clear();
}
Expand Down
2 changes: 1 addition & 1 deletion hats/Commands/HatDebug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

public string Command { get; } = "Debug";
public string Command { get; } = "debug";
public string[] Aliases { get; } = { };
public string Description { get; } = "Print hat debug information";
}
Expand Down
3 changes: 2 additions & 1 deletion hats/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace hats
public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;

public bool RemoveHatOnDeath { get; set; } = true;

public string CommandPrefix { get; set; } = "hatplugin";

public List<HatConfig> Hats { get; set; }= new List<HatConfig>()
Expand Down
8 changes: 8 additions & 0 deletions hats/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public void WaitingForPlayers()
_isLoaded = true;
}

public void Died(DiedEventArgs ev)
{
if(!cfg.RemoveHatOnDeath)
return;
if(ev.Target.GameObject.TryGetComponent<HatComponent>(out _))
ev.Target.RemoveHat();
}

public void OnLeave(LeftEventArgs ev)
{
if(ev.Player.GameObject.TryGetComponent<HatComponent>(out _))
Expand Down
2 changes: 1 addition & 1 deletion hats/Hat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void DestroyInstances()
List<KeyValuePair<string, HatComponent>> toRemove = new List<KeyValuePair<string, HatComponent>>();
foreach (var kvp in Plugin.Singleton.hats.Where(x => x.Value.hat == this))
{
if (kvp.Value is null || kvp.Value.gameObject == null || !kvp.Value.schem.isActiveAndEnabled)
if (kvp.Value is null || kvp.Value.schem.gameObject == null || !kvp.Value.schem.isActiveAndEnabled)
{
toRemove.Add(kvp);
continue;
Expand Down
4 changes: 3 additions & 1 deletion hats/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Plugin : Plugin<Config>
{
public override string Author { get; } = "Rowpann SCP";
public override string Name { get; } = "hats";
public override Version Version { get; } = new Version(1, 2, 0);
public override Version Version { get; } = new Version(1, 3, 0);
public override Version RequiredExiledVersion { get; } = new Version(5, 2, 0);

public static Plugin Singleton;
Expand All @@ -26,6 +26,7 @@ public override void OnEnabled()

Server.WaitingForPlayers += Handler.WaitingForPlayers;
Player.Left += Handler.OnLeave;
Player.Died += Handler.Died;

base.OnEnabled();
}
Expand All @@ -34,6 +35,7 @@ public override void OnDisabled()
{
Server.WaitingForPlayers -= Handler.WaitingForPlayers;
Player.Left -= Handler.OnLeave;
Player.Died -= Handler.Died;

Singleton = null;
Handler = null;
Expand Down

0 comments on commit 28de4ce

Please sign in to comment.