github.com/df-mc/dragonfly@v0.9.13/server/player/provider.go (about) 1 package player 2 3 import ( 4 "errors" 5 "github.com/df-mc/dragonfly/server/world" 6 "github.com/google/uuid" 7 "io" 8 ) 9 10 // Provider represents a value that may provide data to a Player value. It usually does the reading and 11 // writing of the player data so that the Player may use it. 12 type Provider interface { 13 // Save is called when the player leaves the server. The Data of the player is passed. 14 Save(uuid uuid.UUID, data Data) error 15 // Load is called when the player joins and passes the UUID of the player. 16 // It expects to the player data, and an error that is nil if the player data could be found. If non-nil, the player 17 // will use default values, and you can use an empty Data struct. 18 Load(uuid uuid.UUID, world func(world.Dimension) *world.World) (Data, error) 19 // Closer is used on server close when the server calls Provider.Close() and is used to safely close the Provider. 20 io.Closer 21 } 22 23 // Compile time check to make sure NopProvider implements Provider. 24 var _ Provider = (*NopProvider)(nil) 25 26 // NopProvider is a player data provider that won't store any data and instead always return default values 27 type NopProvider struct{} 28 29 func (NopProvider) Save(uuid.UUID, Data) error { return nil } 30 func (NopProvider) Load(uuid.UUID, func(world.Dimension) *world.World) (Data, error) { 31 return Data{}, errors.New("") 32 } 33 func (NopProvider) Close() error { return nil }