mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 13:15:33 +01:00
update to latest API changes
This commit is contained in:
parent
b0947cb743
commit
d2cc9982ec
Binary file not shown.
Binary file not shown.
@ -28,6 +28,7 @@ import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensCharacterManager;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.npc.CitizensTraitManager;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -242,7 +243,7 @@ public class Citizens extends JavaPlugin {
|
||||
public void save() {
|
||||
config.save();
|
||||
for (NPC npc : npcManager)
|
||||
npc.save(saves.getKey("npc." + npc.getId()));
|
||||
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
||||
saves.save();
|
||||
}
|
||||
|
||||
@ -256,7 +257,7 @@ public class Citizens extends JavaPlugin {
|
||||
NPC npc = npcManager.createNPC(EntityType.valueOf(key.getString("traits.type").toUpperCase()), id, key
|
||||
.getString("name"), null);
|
||||
try {
|
||||
npc.load(key);
|
||||
((CitizensNPC) npc).load(key);
|
||||
} catch (NPCException ex) {
|
||||
Messaging.log(ex.getMessage());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
|
||||
public class NPCUpdater implements Runnable {
|
||||
@ -15,7 +16,7 @@ public class NPCUpdater implements Runnable {
|
||||
for (NPC npc : npcManager) {
|
||||
if (!npc.isSpawned())
|
||||
continue;
|
||||
npc.update();
|
||||
((CitizensNPC) npc).update();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,18 @@
|
||||
package net.citizensnpcs.npc;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.event.NPCDespawnEvent;
|
||||
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.AbstractNPC;
|
||||
import net.citizensnpcs.api.npc.character.Character;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.npc.ai.CitizensAI;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.StringHelper;
|
||||
@ -116,9 +123,55 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
ai.update();
|
||||
}
|
||||
|
||||
public void load(DataKey root) throws NPCLoadException {
|
||||
Character character = CitizensAPI.getCharacterManager().getCharacter(root.getString("character"));
|
||||
|
||||
// Load the character if it exists
|
||||
if (character != null) {
|
||||
character.load(root.getRelative("characters." + character.getName()));
|
||||
setCharacter(character);
|
||||
}
|
||||
|
||||
// Load traits
|
||||
for (DataKey traitKey : root.getRelative("traits").getSubKeys()) {
|
||||
Trait trait = CitizensAPI.getTraitManager().getTrait(traitKey.name(), this);
|
||||
if (trait == null)
|
||||
throw new NPCLoadException("No trait with the name '" + traitKey.name()
|
||||
+ "' exists. Was it registered properly?");
|
||||
try {
|
||||
trait.load(traitKey);
|
||||
} catch (Exception ex) {
|
||||
Bukkit.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"[Citizens] The trait '" + traitKey.name()
|
||||
+ "' failed to load properly for the NPC with the ID '" + getId() + "'. "
|
||||
+ ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
addTrait(trait);
|
||||
}
|
||||
|
||||
// Spawn the NPC
|
||||
if (getTrait(Spawned.class).shouldSpawn())
|
||||
spawn(getTrait(SpawnLocation.class).getLocation());
|
||||
}
|
||||
|
||||
public void save(DataKey root) {
|
||||
root.setString("name", getFullName());
|
||||
|
||||
// Save the character if it exists
|
||||
if (getCharacter() != null) {
|
||||
root.setString("character", getCharacter().getName());
|
||||
getCharacter().save(root.getRelative("characters." + getCharacter().getName()));
|
||||
}
|
||||
|
||||
// Save all existing traits
|
||||
for (Trait trait : getTraits())
|
||||
trait.save(root.getRelative("traits." + trait.getName()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user