mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-30 22:53:24 +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
|
// Spawn the NPC
|
||||||
Spawned spawned = getTrait(Spawned.class);
|
Spawned spawned = getTrait(Spawned.class);
|
||||||
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
|
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
|
||||||
try {
|
loadTrait(spawned, root.getRelative("traits.spawned"));
|
||||||
spawned.load(root.getRelative("traits.spawned"));
|
loadTrait(spawnLocation, root.getRelative("traits.location"));
|
||||||
spawnLocation.load(root.getRelative("traits.location"));
|
if (spawned.shouldSpawn() && spawnLocation.getLocation() != null)
|
||||||
if (spawned.shouldSpawn() && spawnLocation.getLocation() != null)
|
spawn(spawnLocation.getLocation());
|
||||||
spawn(spawnLocation.getLocation());
|
|
||||||
} catch (NPCLoadException e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata.loadFrom(root.getRelative("metadata"));
|
metadata.loadFrom(root.getRelative("metadata"));
|
||||||
// Load traits
|
// Load traits
|
||||||
@ -126,17 +123,21 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
addTrait(trait);
|
addTrait(trait);
|
||||||
}
|
}
|
||||||
try {
|
loadTrait(trait, traitKey);
|
||||||
trait.load(traitKey);
|
|
||||||
PersistenceLoader.load(trait, traitKey);
|
|
||||||
} catch (NPCLoadException ex) {
|
|
||||||
Messaging.logTr(Messages.TRAIT_LOAD_FAILED, traitKey.name(), getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
navigator.load(root.getRelative("navigator"));
|
navigator.load(root.getRelative("navigator"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadTrait(Trait trait, DataKey traitKey) {
|
||||||
|
try {
|
||||||
|
trait.load(traitKey);
|
||||||
|
PersistenceLoader.load(trait, traitKey);
|
||||||
|
} catch (NPCLoadException ex) {
|
||||||
|
Messaging.logTr(Messages.TRAIT_LOAD_FAILED, traitKey.name(), getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTrait(Class<? extends Trait> clazz) {
|
public void removeTrait(Class<? extends Trait> clazz) {
|
||||||
Trait present = traits.get(clazz);
|
Trait present = traits.get(clazz);
|
||||||
|
Loading…
Reference in New Issue
Block a user