Skip to content
This repository has been archived by the owner on Feb 28, 2021. It is now read-only.

Commit

Permalink
Added command handler until I actually fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
PintTheDragon committed Jul 10, 2020
1 parent 9b8b993 commit efc37cc
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 27 deletions.
13 changes: 12 additions & 1 deletion Buddy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Exiled.API.Enums;
using Exiled.API.Features;
using RemoteAdmin;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,7 +11,7 @@ class Buddy : Plugin<Config>
{
public override PluginPriority Priority => PluginPriority.Medium;

public override Version Version { get; } = new Version("1.1.6");
public override Version Version { get; } = new Version("1.1.7");

public EventHandlers EventHandlers;

Expand Down Expand Up @@ -63,6 +64,9 @@ public override void OnDisabled()
Exiled.Events.Handlers.Server.RoundStarted -= EventHandlers.OnRoundStart;
Exiled.Events.Handlers.Player.Joined -= EventHandlers.OnPlayerJoin;
Exiled.Events.Handlers.Server.RestartingRound -= EventHandlers.OnRoundRestart;
Exiled.Events.Handlers.Server.SendingConsoleCommand -= EventHandlers.OnConsoleCommand;
CommandHandler.isEnabled = false;

Log.Info("Buddy v"+Version+" (by PintTheDragon) has unloaded.");
}

Expand All @@ -83,6 +87,13 @@ public override void OnEnabled()
Exiled.Events.Handlers.Server.RoundStarted += EventHandlers.OnRoundStart;
Exiled.Events.Handlers.Player.Joined += EventHandlers.OnPlayerJoin;
Exiled.Events.Handlers.Server.RestartingRound += EventHandlers.OnRoundRestart;
Exiled.Events.Handlers.Server.SendingConsoleCommand += EventHandlers.OnConsoleCommand;

CommandHandler.isEnabled = true;
CommandHandler.Register(new BuddyCommand());
CommandHandler.Register(new BuddyAcceptCommand());
CommandHandler.Register(new UnBuddyCommand());

Log.Info("Buddy v" + Version + " (by PintTheDragon) has loaded.");
}

Expand Down
2 changes: 2 additions & 0 deletions Buddy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
<Compile Include="Buddy.cs" />
<Compile Include="BuddyAcceptCommand.cs" />
<Compile Include="BuddyCommand.cs" />
<Compile Include="CommandHandler.cs" />
<Compile Include="Config.cs" />
<Compile Include="EventHandlers.cs" />
<Compile Include="ICommandPint.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnBuddyCommand.cs" />
</ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions BuddyAcceptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@

namespace Buddy
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
class BuddyAcceptCommand : ICommand
//[CommandHandler(typeof(GameConsoleCommandHandler))]
class BuddyAcceptCommand : ICommandPint
{
public string Command => Buddy.singleton.buddyAcceptCommand;

public string[] Aliases => new string[] { };
public string[] Aliases => null;

public string Description => "A command to accept a pending buddy request.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public bool Execute(ArraySegment<string> arguments, /*ICommandSender sender*/ Player player, out string response)
{
response = "";
string[] args = arguments.ToArray();
if (sender is PlayerCommandSender p)
{
Player player = Player.Get(p.Processor._hub);
//if (sender is PlayerCommandSender p)
//{
//Player player = Player.Get(p.Processor._hub);
response = handleBuddyAcceptCommand(player, new string[] { });
return true;
}
//return true;
//}
return true;
}

Expand Down
16 changes: 8 additions & 8 deletions BuddyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

namespace Buddy
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
class BuddyCommand : ICommand
//[CommandHandler(typeof(GameConsoleCommandHandler))]
class BuddyCommand : ICommandPint
{
public string Command => Buddy.singleton.buddyCommand;

public string[] Aliases => new string[] { };
public string[] Aliases => null;

public string Description => "Allows you to pair up with another player and play on the same team.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public bool Execute(ArraySegment<string> arguments, /*ICommandSender sender*/ Player player, out string response)
{
response = "";
string[] args = arguments.ToArray();
if(sender is PlayerCommandSender p)
{
Player player = Player.Get(p.Processor._hub);
//if(sender is PlayerCommandSender p)
//{
//Player player = Player.Get(p.Processor._hub);
if (args.Length != 1)
{
response = Buddy.singleton.invalidUsage;
Expand All @@ -37,7 +37,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
Log.Error(e.ToString());
response = Buddy.singleton.errorMessage;
}
}
//}
return true;
}

Expand Down
34 changes: 34 additions & 0 deletions CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using CommandSystem;
using Exiled.Events.EventArgs;
using RemoteAdmin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Buddy
{
class CommandHandler
{
private static Dictionary<string, ICommandPint> commands = new Dictionary<string, ICommandPint>();

public static bool isEnabled = false;

public static void Register(ICommandPint cmd)
{
string commandStr = cmd.Command;
commands.Add(commandStr, cmd);
}

public static void RunCommand(SendingConsoleCommandEventArgs ev)
{
if (!isEnabled) return;
ICommandPint cmd = null;
if (!commands.TryGetValue(ev.Name, out cmd) || cmd == null) return;
string outText = ev.ReturnMessage;
cmd.Execute(new ArraySegment<string>(ev.Arguments.ToArray()), ev.Player, out outText);
ev.ReturnMessage = outText;
}
}
}
5 changes: 5 additions & 0 deletions EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,10 @@ private IEnumerator<float> doTheSCPThing()

}
}

public void OnConsoleCommand(SendingConsoleCommandEventArgs ev)
{
CommandHandler.RunCommand(ev);
}
}
}
20 changes: 20 additions & 0 deletions ICommandPint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Exiled.API.Features;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Buddy
{
interface ICommandPint
{
string Command { get; }

string[] Aliases { get; }

string Description { get; }

bool Execute(ArraySegment<string> arguments, Player sender, out string response);
}
}
18 changes: 9 additions & 9 deletions UnBuddyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@

namespace Buddy
{
[CommandHandler(typeof(GameConsoleCommandHandler))]
class UnBuddyCommand : ICommand
//[CommandHandler(typeof(GameConsoleCommandHandler))]
class UnBuddyCommand : ICommandPint
{
public string Command => Buddy.singleton.buddyUnbuddyCommand;

public string[] Aliases => new string[] { };
public string[] Aliases => null;

public string Description => "A command to remove your current buddy.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public bool Execute(ArraySegment<string> arguments, /*ICommandSender sender*/ Player player, out string response)
{
response = "";
string[] args = arguments.ToArray();
if (sender is PlayerCommandSender p)
{
Player player = Player.Get(p.Processor._hub);
//if (sender is PlayerCommandSender p)
//{
//Player player = Player.Get(p.Processor._hub);
response = handleUnBuddyCommand(player);
return true;
}
//return true;
//}
return true;
}

Expand Down

0 comments on commit efc37cc

Please sign in to comment.