github.com/df-mc/dragonfly@v0.9.13/server/player/playerdb/effect.go (about) 1 package playerdb 2 3 import "github.com/df-mc/dragonfly/server/entity/effect" 4 5 func effectsToData(effects []effect.Effect) []jsonEffect { 6 data := make([]jsonEffect, len(effects)) 7 for key, eff := range effects { 8 id, ok := effect.ID(eff.Type()) 9 if !ok { 10 continue 11 } 12 data[key] = jsonEffect{ 13 ID: id, 14 Duration: eff.Duration(), 15 Level: eff.Level(), 16 Ambient: eff.Ambient(), 17 } 18 } 19 return data 20 } 21 22 func dataToEffects(data []jsonEffect) []effect.Effect { 23 effects := make([]effect.Effect, len(data)) 24 for i, d := range data { 25 e, ok := effect.ByID(d.ID) 26 if !ok { 27 continue 28 } 29 switch eff := e.(type) { 30 case effect.LastingType: 31 if d.Ambient { 32 effects[i] = effect.NewAmbient(eff, d.Level, d.Duration) 33 continue 34 } 35 effects[i] = effect.New(eff, d.Level, d.Duration) 36 default: 37 effects[i] = effect.NewInstant(eff, d.Level) 38 } 39 } 40 return effects 41 }