From 30737afe60138daf488b0a6dec6974d9d1a475fe Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 28 Dec 2023 10:52:52 +0100 Subject: [PATCH] Update ResourcePackResponseStatus --- pkg/edition/java/proto/packet/resourcepack.go | 11 +++++++++ pkg/edition/java/proxy/events.go | 23 +++++++++++++++---- pkg/edition/java/proxy/player.go | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/pkg/edition/java/proto/packet/resourcepack.go b/pkg/edition/java/proto/packet/resourcepack.go index 67fe08f1..b8dd06ba 100644 --- a/pkg/edition/java/proto/packet/resourcepack.go +++ b/pkg/edition/java/proto/packet/resourcepack.go @@ -116,11 +116,22 @@ type ( ResourcePackResponseStatus int ) +// Intermediate returns true if the resource pack status is intermediate, indicating that the player has +// either accepted the resource pack and is currently downloading it or has successfully +// downloaded it. +func (s ResourcePackResponseStatus) Intermediate() bool { + return s == AcceptedResourcePackResponseStatus || s == DownloadedResourcePackResponseStatus +} + const ( SuccessfulResourcePackResponseStatus ResourcePackResponseStatus = iota DeclinedResourcePackResponseStatus FailedDownloadResourcePackResponseStatus AcceptedResourcePackResponseStatus + DownloadedResourcePackResponseStatus + InvalidURLResourcePackResponseStatus + FailedToReloadResourcePackResponseStatus + DiscardedResourcePackResponseStatus ) func (r *ResourcePackResponse) Encode(c *proto.PacketContext, wr io.Writer) error { diff --git a/pkg/edition/java/proxy/events.go b/pkg/edition/java/proxy/events.go index 39000b01..d49e58b2 100644 --- a/pkg/edition/java/proxy/events.go +++ b/pkg/edition/java/proxy/events.go @@ -877,15 +877,28 @@ func (p *PlayerAvailableCommandsEvent) RootNode() *brigodier.RootCommandNode { // // -// ResourcePackResponseStatus is the status for a resource pack. +// ResourcePackResponseStatus represents the possible statuses for the resource pack. type ResourcePackResponseStatus = packet.ResourcePackResponseStatus // Possible statuses for a resource pack. + const ( - SuccessfulResourcePackResponseStatus ResourcePackResponseStatus = packet.SuccessfulResourcePackResponseStatus - DeclinedResourcePackResponseStatus ResourcePackResponseStatus = packet.DeclinedResourcePackResponseStatus - FailedDownloadResourcePackResponseStatus ResourcePackResponseStatus = packet.FailedDownloadResourcePackResponseStatus - AcceptedResourcePackResponseStatus ResourcePackResponseStatus = packet.AcceptedResourcePackResponseStatus + // SuccessfulResourcePackResponseStatus indicates the resource pack was applied successfully. + SuccessfulResourcePackResponseStatus ResourcePackResponseStatus = iota + // DeclinedResourcePackResponseStatus indicates the player declined to download the resource pack. + DeclinedResourcePackResponseStatus + // FailedDownloadResourcePackResponseStatus indicates the player could not download the resource pack. + FailedDownloadResourcePackResponseStatus + // AcceptedResourcePackResponseStatus indicates the player has accepted the resource pack and is now downloading it. + AcceptedResourcePackResponseStatus + // DownloadedResourcePackResponseStatus indicates the player has downloaded the resource pack. + DownloadedResourcePackResponseStatus + // InvalidURLResourcePackResponseStatus indicates the URL of the resource pack failed to load. + InvalidURLResourcePackResponseStatus + // FailedToReloadResourcePackResponseStatus indicates the player failed to reload the resource pack. + FailedToReloadResourcePackResponseStatus + // DiscardedResourcePackResponseStatus indicates the resource pack was discarded. + DiscardedResourcePackResponseStatus ) // PlayerResourcePackStatusEvent is fired when the status of a resource pack sent to the player by the server is diff --git a/pkg/edition/java/proxy/player.go b/pkg/edition/java/proxy/player.go index 1fdca33a..053b529e 100644 --- a/pkg/edition/java/proxy/player.go +++ b/pkg/edition/java/proxy/player.go @@ -348,7 +348,7 @@ func (p *connectedPlayer) PendingResourcePack() *ResourcePackInfo { // Processes a client response to a sent resource-pack. func (p *connectedPlayer) onResourcePackResponse(status ResourcePackResponseStatus) bool { - peek := status == AcceptedResourcePackResponseStatus + peek := status.Intermediate() p.mu.Lock() if p.outstandingResourcePacks.Len() == 0 {