mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-28 13:45:18 +01:00
Fix saving and loading bugs.
This commit is contained in:
parent
3f9218f568
commit
38e1955825
@ -18,6 +18,7 @@ import net.citizensnpcs.command.Requirements;
|
|||||||
import net.citizensnpcs.command.exception.CommandException;
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.command.exception.NoPermissionsException;
|
import net.citizensnpcs.command.exception.NoPermissionsException;
|
||||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||||
|
import net.citizensnpcs.npc.CitizensTraitManager;
|
||||||
import net.citizensnpcs.trait.CurrentLocation;
|
import net.citizensnpcs.trait.CurrentLocation;
|
||||||
import net.citizensnpcs.trait.LookClose;
|
import net.citizensnpcs.trait.LookClose;
|
||||||
import net.citizensnpcs.trait.Powered;
|
import net.citizensnpcs.trait.Powered;
|
||||||
@ -35,6 +36,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|||||||
public class NPCCommands {
|
public class NPCCommands {
|
||||||
private final CharacterManager characterManager = CitizensAPI.getCharacterManager();
|
private final CharacterManager characterManager = CitizensAPI.getCharacterManager();
|
||||||
private final CitizensNPCManager npcManager;
|
private final CitizensNPCManager npcManager;
|
||||||
|
private final CitizensTraitManager traitManager = (CitizensTraitManager) CitizensAPI.getTraitManager();
|
||||||
|
|
||||||
public NPCCommands(Citizens plugin) {
|
public NPCCommands(Citizens plugin) {
|
||||||
npcManager = plugin.getNPCManager();
|
npcManager = plugin.getNPCManager();
|
||||||
@ -116,8 +118,8 @@ public class NPCCommands {
|
|||||||
// Initialize necessary traits
|
// Initialize necessary traits
|
||||||
create.getTrait(Owner.class).setOwner(player.getName());
|
create.getTrait(Owner.class).setOwner(player.getName());
|
||||||
create.getTrait(MobType.class).setType(type.toString());
|
create.getTrait(MobType.class).setType(type.toString());
|
||||||
create.addTrait(new LookClose(create));
|
create.addTrait(traitManager.getTrait(LookClose.class, create));
|
||||||
create.addTrait(new Text(create));
|
create.addTrait(traitManager.getTrait(Text.class, create));
|
||||||
|
|
||||||
create.spawn(player.getLocation());
|
create.spawn(player.getLocation());
|
||||||
npcManager.selectNPC(player, create);
|
npcManager.selectNPC(player, create);
|
||||||
|
@ -28,8 +28,8 @@ import org.bukkit.inventory.Inventory;
|
|||||||
public abstract class CitizensNPC extends AbstractNPC {
|
public abstract class CitizensNPC extends AbstractNPC {
|
||||||
private final CitizensAI ai = new CitizensAI(this);
|
private final CitizensAI ai = new CitizensAI(this);
|
||||||
private final CitizensNPCManager manager;
|
private final CitizensNPCManager manager;
|
||||||
protected EntityLiving mcEntity;
|
|
||||||
private final CitizensTraitManager traitManager;
|
private final CitizensTraitManager traitManager;
|
||||||
|
protected EntityLiving mcEntity;
|
||||||
|
|
||||||
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
protected CitizensNPC(CitizensNPCManager manager, int id, String name) {
|
||||||
super(id, name);
|
super(id, name);
|
||||||
@ -43,6 +43,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
Bukkit.getLogger().log(Level.SEVERE, "Cannot register a null trait. Was it registered properly?");
|
Bukkit.getLogger().log(Level.SEVERE, "Cannot register a null trait. Was it registered properly?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trait instanceof Runnable) {
|
if (trait instanceof Runnable) {
|
||||||
runnables.add((Runnable) trait);
|
runnables.add((Runnable) trait);
|
||||||
if (traits.containsKey(trait.getClass()))
|
if (traits.containsKey(trait.getClass()))
|
||||||
@ -52,6 +53,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
Bukkit.getPluginManager().registerEvents((Listener) trait, null);
|
Bukkit.getPluginManager().registerEvents((Listener) trait, null);
|
||||||
// TODO: insert plugin instance somehow
|
// TODO: insert plugin instance somehow
|
||||||
}
|
}
|
||||||
|
|
||||||
traits.put(trait.getClass(), trait);
|
traits.put(trait.getClass(), trait);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +181,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
if (trait == null)
|
if (trait == null)
|
||||||
throw new NPCLoadException("No trait with the name '" + traitKey.name()
|
throw new NPCLoadException("No trait with the name '" + traitKey.name()
|
||||||
+ "' exists. Was it registered properly?");
|
+ "' exists. Was it registered properly?");
|
||||||
|
addTrait(trait);
|
||||||
try {
|
try {
|
||||||
trait.load(traitKey);
|
getTrait(trait.getClass()).load(traitKey);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Bukkit.getLogger().log(
|
Bukkit.getLogger().log(
|
||||||
Level.SEVERE,
|
Level.SEVERE,
|
||||||
@ -189,7 +192,6 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
+ ex.getMessage());
|
+ ex.getMessage());
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
addTrait(trait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spawn the NPC
|
// Spawn the NPC
|
||||||
|
Loading…
Reference in New Issue
Block a user