Files
mc/server/session/handler_npc_request.go
T
TarnaWijaya 26ed99fda6
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
up3
2026-07-09 08:33:57 +08:00

33 lines
924 B
Go

package session
import (
"fmt"
"github.com/df-mc/dragonfly/server/player/dialogue"
"github.com/df-mc/dragonfly/server/world"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// NPCRequestHandler handles the NPCRequest packet.
type NPCRequestHandler struct {
dialogue dialogue.Dialogue
entityRuntimeID uint64
}
// Handle ...
func (h *NPCRequestHandler) Handle(p packet.Packet, s *Session, tx *world.Tx, c Controllable) error {
pk := p.(*packet.NPCRequest)
if h.entityRuntimeID == 0 {
// No dialogue is currently open for this session, so there is nothing to submit or close.
return nil
}
switch pk.RequestType {
case packet.NPCRequestActionExecuteAction:
if err := h.dialogue.Submit(uint(pk.ActionType), c, tx); err != nil {
return fmt.Errorf("error submitting dialogue: %w", err)
}
case packet.NPCRequestActionExecuteClosingCommands:
h.dialogue.Close(c, tx)
}
return nil
}