Skip to content

Commit

Permalink
Fix commands not working (#275)
Browse files Browse the repository at this point in the history
* Update ChatCommandPacket.cs

* Remove old method used previously for commands
  • Loading branch information
Tides authored Aug 30, 2022
1 parent a955cb3 commit ad1bd3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
21 changes: 17 additions & 4 deletions Obsidian/Net/Packets/Play/Serverbound/ChatCommandPacket.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using Obsidian.Commands;
using Microsoft.Extensions.Logging;
using Obsidian.Commands;
using Obsidian.Commands.Framework.Entities;
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;
using System.Text;

namespace Obsidian.Net.Packets.Play.Serverbound;

//TODO USE THIS PACKET PROPERLY
public partial class ChatCommandPacket : IServerboundPacket
{
[Field(0)]
public string Command { get; private set; }

[Field(1)]
public long Timestamp { get; private set; }
public DateTimeOffset Timestamp { get; private set; }

[Field(2)]
public long Salt { get; private set; }
Expand All @@ -24,5 +26,16 @@ public partial class ChatCommandPacket : IServerboundPacket

public int Id => 0x03;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
public async ValueTask HandleAsync(Server server, Player player)
{
var context = new CommandContext($"/{this.Command}", new CommandSender(CommandIssuers.Client, player, server.Logger), player, server);
try
{
await server.CommandsHandler.ProcessCommand(context);
}
catch (Exception e)
{
server.Logger.LogError(e, e.Message);
}
}
}
29 changes: 0 additions & 29 deletions Obsidian/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,35 +402,6 @@ internal async Task HandleIncomingMessageAsync(ChatMessagePacket packet, Client
BroadcastMessage(playerChatMessagePacket);
}

//internal async Task HandleIncomingMessageAsync(string message, string format, Client source, MessageType type = MessageType.Chat)
//{
// format ??= "<{0}> {1}";

// if (message.StartsWith(CommandHandler.DefaultPrefix))
// {
// // TODO command logging
// // TODO error handling for commands
// var context = new CommandContext(message, new CommandSender(CommandIssuers.Client, source.Player, Logger), source.Player, this);
// try
// {
// await CommandsHandler.ProcessCommand(context);
// }
// catch (Exception e)
// {
// Logger.LogError(e, e.Message);
// }
// }
// else
// {
// var chat = await Events.InvokeIncomingChatMessageAsync(new IncomingChatMessageEventArgs(source.Player, message, format));

// if (!chat.Cancel)
// BroadcastMessage(string.Format(format, source.Player.Username, message), type);

// return;
// }
//}

internal async Task QueueBroadcastPacketAsync(IClientboundPacket packet)
{
foreach (Player player in Players)
Expand Down

0 comments on commit ad1bd3d

Please sign in to comment.