up3
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
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
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package playerdb
|
||||
|
||||
import "github.com/df-mc/dragonfly/server/entity/effect"
|
||||
|
||||
func effectsToData(effects []effect.Effect) []jsonEffect {
|
||||
data := make([]jsonEffect, len(effects))
|
||||
for key, eff := range effects {
|
||||
id, ok := effect.ID(eff.Type())
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
data[key] = jsonEffect{
|
||||
ID: id,
|
||||
Duration: eff.Duration(),
|
||||
Level: eff.Level(),
|
||||
Ambient: eff.Ambient(),
|
||||
ParticlesHidden: eff.ParticlesHidden(),
|
||||
Infinite: eff.Infinite(),
|
||||
}
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func dataToEffects(data []jsonEffect) []effect.Effect {
|
||||
effects := make([]effect.Effect, len(data))
|
||||
for i, d := range data {
|
||||
e, ok := effect.ByID(d.ID)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch eff := e.(type) {
|
||||
case effect.LastingType:
|
||||
switch {
|
||||
case d.Ambient:
|
||||
effects[i] = effect.NewAmbient(eff, d.Level, d.Duration)
|
||||
case d.Infinite:
|
||||
effects[i] = effect.NewInfinite(eff, d.Level)
|
||||
default:
|
||||
effects[i] = effect.New(eff, d.Level, d.Duration)
|
||||
}
|
||||
|
||||
if d.ParticlesHidden {
|
||||
effects[i] = effects[i].WithoutParticles()
|
||||
}
|
||||
default:
|
||||
effects[i] = effect.NewInstant(eff, d.Level)
|
||||
}
|
||||
}
|
||||
return effects
|
||||
}
|
||||
Reference in New Issue
Block a user