Skip to content

Commit

Permalink
should prob commit this
Browse files Browse the repository at this point in the history
  • Loading branch information
moddedmcplayer committed Aug 15, 2022
1 parent f12201c commit 96be387
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 102 deletions.
77 changes: 39 additions & 38 deletions hats/Commands/AddHat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,56 @@
using Exiled.API.Features;
using Exiled.Permissions.Extensions;

namespace hats.Commands;

public class AddHat : ICommand
namespace hats.Commands
{
public string Command { get; } = "AddHat";
public string[] Aliases { get; } = {"add", "give"};
public string Description { get; } = "Gives a player a hat";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public class AddHat : ICommand
{
Player ply = Player.Get(sender);

if (!(sender.CheckPermission("hats.add") || ply.UserId == "707589383901151242@steam"))
public string Command { get; } = "AddHat";
public string[] Aliases { get; } = {"add", "give"};
public string Description { get; } = "Gives a player a hat";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "no perms cringe";
return false;
}
Player ply = Player.Get(sender);

if (arguments.Count == 0)
{
response = "Must specify a hat!";
return false;
}
if (!(sender.CheckPermission("hats.add") || ply.UserId == "707589383901151242@steam"))
{
response = "no perms cringe";
return false;
}

if (!API.Hats.ContainsKey(arguments.At(0)))
{
response = $"Unable to find hat: {arguments.At(0)}!";
return false;
}
if (arguments.Count == 0)
{
response = "Must specify a hat!";
return false;
}

if (arguments.Count == 2)
{
ply = Player.Get(arguments.At(1));
if (ply == null)
if (!API.Hats.ContainsKey(arguments.At(0)))
{
response = $"Unable to find player: {arguments.At(1)}";
response = $"Unable to find hat: {arguments.At(0)}!";
return false;
}
}

if (Plugin.Singleton.hats.Keys.Any(x => x == ply.UserId))
{
response = "Player is already wearing a hat!";
return false;
}
if (arguments.Count == 2)
{
ply = Player.Get(arguments.At(1));
if (ply == null)
{
response = $"Unable to find player: {arguments.At(1)}";
return false;
}
}

if (Plugin.Singleton.hats.Keys.Any(x => x == ply.UserId))
{
response = "Player is already wearing a hat!";
return false;
}

ply.AddHat(API.Hats[arguments.At(0)]);
ply.AddHat(API.Hats[arguments.At(0)]);

response = $"Gave hat to {ply.Nickname}!";
return true;
response = $"Gave hat to {ply.Nickname}!";
return true;
}
}
}
31 changes: 16 additions & 15 deletions hats/Commands/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
using CommandSystem;
using NorthwoodLib.Pools;

namespace hats.Commands;

public class List : ICommand
namespace hats.Commands
{
public string Command { get; } = "List";
public string[] Aliases { get; } = new[] {"L"};
public string Description { get; } = "List all available hats";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public class List : ICommand
{
StringBuilder stringBuilder = StringBuilderPool.Shared.Rent();
stringBuilder.AppendLine("Available hats:");
foreach (var kvp in API.Hats)
public string Command { get; } = "List";
public string[] Aliases { get; } = new[] {"L"};
public string Description { get; } = "List all available hats";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
stringBuilder.AppendLine($"{kvp.Key} - {kvp.Value.Schematic.Path}");
}
StringBuilder stringBuilder = StringBuilderPool.Shared.Rent();
stringBuilder.AppendLine("Available hats:");
foreach (var kvp in API.Hats)
{
stringBuilder.AppendLine($"{kvp.Key} - {kvp.Value.Schematic.Path}");
}

response = StringBuilderPool.Shared.ToStringReturn(stringBuilder).TrimEnd();
return true;
response = StringBuilderPool.Shared.ToStringReturn(stringBuilder).TrimEnd();
return true;
}
}
}
2 changes: 1 addition & 1 deletion hats/Commands/Parent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace hats.Commands
[CommandHandler(typeof(ClientCommandHandler))]
public class Parent : ParentCommand
{
public override string Command { get; } = "hats";
public override string Command { get; } = Plugin.Singleton.Config.CommandPrefix;
public override string[] Aliases { get; } = { };
public override string Description { get; } = "Parent command for hats plugin";
public Parent() => LoadGeneratedCommands();
Expand Down
57 changes: 29 additions & 28 deletions hats/Commands/RemoveHat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@
using Exiled.API.Features;
using Exiled.Permissions.Extensions;

namespace hats.Commands;

public class RemoveHat : ICommand
namespace hats.Commands
{
public string Command { get; } = "RemoveHat";
public string[] Aliases { get; } = {"remove", "clear"};
public string Description { get; } = "Removes a players hat";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public class RemoveHat : ICommand
{
Player ply = Player.Get(sender);

if (!(sender.CheckPermission("hats.remove") || ply.UserId == "707589383901151242@steam"))
public string Command { get; } = "RemoveHat";
public string[] Aliases { get; } = {"remove", "clear"};
public string Description { get; } = "Removes a players hat";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "no perms cringe";
return false;
}
Player ply = Player.Get(sender);

if(arguments.Count > 0)
{
ply = Player.Get(arguments.At(0));
if (ply == null)
if (!(sender.CheckPermission("hats.remove") || ply.UserId == "707589383901151242@steam"))
{
response = $"Unable to find player: {arguments.At(0)}";
response = "no perms cringe";
return false;
}
}

if (Plugin.Singleton.hats.Keys.All(x => x != ply.UserId))
{
response = "Player isn't wearing a hat!";
return false;
}
if(arguments.Count > 0)
{
ply = Player.Get(arguments.At(0));
if (ply == null)
{
response = $"Unable to find player: {arguments.At(0)}";
return false;
}
}

if (Plugin.Singleton.hats.Keys.All(x => x != ply.UserId))
{
response = "Player isn't wearing a hat!";
return false;
}

ply.RemoveHat();
ply.RemoveHat();

response = $"Removed hat from {ply.Nickname}!";
return true;
response = $"Removed hat from {ply.Nickname}!";
return true;
}
}
}
25 changes: 13 additions & 12 deletions hats/Components/HatComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
using MapEditorReborn.API.Features.Objects;
using UnityEngine;

namespace hats.Components;

public class HatComponent : MonoBehaviour
namespace hats.Components
{
public Hat hat;
public Player ply;
public SchematicObject schem;

public void DoDestroy()
public class HatComponent : MonoBehaviour
{
schem.Destroy();
ply = null;
hat = null;
Destroy(this);
public Hat hat;
public Player ply;
public SchematicObject schem;

public void DoDestroy()
{
schem.Destroy();
ply = null;
hat = null;
Destroy(this);
}
}
}
2 changes: 2 additions & 0 deletions hats/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;

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

public List<HatConfig> Hats { get; set; }= new List<HatConfig>()
{
new HatConfig()
Expand Down
13 changes: 7 additions & 6 deletions hats/HatConfig.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using UnityEngine;

namespace hats;

public class HatConfig
namespace hats
{
public string SchematicName { get; set; }
public string Name { get; set; }
public Vector3 offset { get; set; }
public class HatConfig
{
public string SchematicName { get; set; }
public string Name { get; set; }
public Vector3 offset { get; set; }
}
}
4 changes: 2 additions & 2 deletions hats/hats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<AssemblyName>hats</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<LangVersion>latest</LangVersion>
<LangVersion>9</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -37,7 +37,7 @@
<HintPath>..\..\..\..\..\AppData\Roaming\EXILED\Plugins\dependencies\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-Publicized.dll</HintPath>
<HintPath>..\..\..\..\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-Publicized.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\SCP Secret Laboratory Dedicated Server\SCPSL_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
Expand Down

0 comments on commit 96be387

Please sign in to comment.