mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 03:25:13 +01:00
Reuse code
This commit is contained in:
parent
c5504379e4
commit
046ab7dd38
@ -92,13 +92,10 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
// Spawn the NPC
|
||||
Spawned spawned = getTrait(Spawned.class);
|
||||
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
|
||||
try {
|
||||
spawned.load(root.getRelative("traits.spawned"));
|
||||
spawnLocation.load(root.getRelative("traits.location"));
|
||||
loadTrait(spawned, root.getRelative("traits.spawned"));
|
||||
loadTrait(spawnLocation, root.getRelative("traits.location"));
|
||||
if (spawned.shouldSpawn() && spawnLocation.getLocation() != null)
|
||||
spawn(spawnLocation.getLocation());
|
||||
} catch (NPCLoadException e) {
|
||||
}
|
||||
|
||||
metadata.loadFrom(root.getRelative("metadata"));
|
||||
// Load traits
|
||||
@ -126,6 +123,13 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
addTrait(trait);
|
||||
}
|
||||
loadTrait(trait, traitKey);
|
||||
}
|
||||
|
||||
navigator.load(root.getRelative("navigator"));
|
||||
}
|
||||
|
||||
private void loadTrait(Trait trait, DataKey traitKey) {
|
||||
try {
|
||||
trait.load(traitKey);
|
||||
PersistenceLoader.load(trait, traitKey);
|
||||
@ -134,9 +138,6 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
}
|
||||
}
|
||||
|
||||
navigator.load(root.getRelative("navigator"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTrait(Class<? extends Trait> clazz) {
|
||||
Trait present = traits.get(clazz);
|
||||
|
Loading…
Reference in New Issue
Block a user