Skip to content

Commit

Permalink
Merge pull request #58 from qwqtoday/wait-for-game-not-return-fix
Browse files Browse the repository at this point in the history
Wait for game not return fix
  • Loading branch information
psu-de authored Jun 9, 2024
2 parents a5c0ee0 + 527c94a commit 95798fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Components/MineSharp.Protocol/Exceptions/DisconnectedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MineSharp.Protocol.Exceptions;

/// <inheritdoc />
public class DisconnectedException(string message, string reason) : MineSharpHostException(message)
{
/// <summary>
/// The reason of the disconnect
/// </summary>
public string Reason { get; private set; } = reason;
}
4 changes: 4 additions & 0 deletions Components/MineSharp.Protocol/MinecraftClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ public Task SendPacket(IPacket packet, CancellationToken? cancellation = null)
public async Task Disconnect(string reason = "disconnect.quitting")
{
Logger.Info($"Disconnecting: {reason}");

if (!_gameJoinedTsc.Task.IsCompleted)
_gameJoinedTsc.SetException(new DisconnectedException($"Client has been disconnected", reason));

if (this._client is null)
throw new InvalidOperationException("MinecraftClient is not connected.");

Expand Down

0 comments on commit 95798fc

Please sign in to comment.