Skip to content

Commit

Permalink
Update ResourcePackResponseStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbraemer committed Dec 28, 2023
1 parent 59b0b0e commit 30737af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 11 additions & 0 deletions pkg/edition/java/proto/packet/resourcepack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 18 additions & 5 deletions pkg/edition/java/proxy/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/edition/java/proxy/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 30737af

Please sign in to comment.