github.com/df-mc/dragonfly@v0.9.13/server/session/handler_container_close.go (about)

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
     6  )
     7  
     8  // ContainerCloseHandler handles the ContainerClose packet.
     9  type ContainerCloseHandler struct{}
    10  
    11  // Handle ...
    12  func (h *ContainerCloseHandler) Handle(p packet.Packet, s *Session) error {
    13  	pk := p.(*packet.ContainerClose)
    14  
    15  	s.EmptyUIInventory()
    16  	switch pk.WindowID {
    17  	case 0:
    18  		// Closing of the normal inventory.
    19  		s.writePacket(&packet.ContainerClose{WindowID: 0})
    20  		s.invOpened = false
    21  	case byte(s.openedWindowID.Load()):
    22  		s.closeCurrentContainer()
    23  	case 0xff:
    24  		// TODO: Handle closing the crafting grid.
    25  	default:
    26  		return fmt.Errorf("unexpected close request for unopened container %v", pk.WindowID)
    27  	}
    28  	return nil
    29  }