Skip to content

Commit

Permalink
Breaking change: add new NPCRegistry param to AbstractNPC constructor…
Browse files Browse the repository at this point in the history
… to avoid deregistering from the wrong reigstry
  • Loading branch information
fullwall committed Sep 11, 2013
1 parent 187298e commit 6d3994e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -64,8 +64,8 @@ public void process(CommandSender sender, CommandContext context, Annotation ins

EntityType type = npc.getTrait(MobType.class).getType();
if (!types.contains(type)) {
throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE,
type.getName()));
throw new RequirementMissingException(Messaging.tr(CommandMessages.REQUIREMENTS_INVALID_MOB_TYPE, type
.name().toLowerCase().replace('_', ' ')));
}
}
}
8 changes: 5 additions & 3 deletions src/main/java/net/citizensnpcs/api/npc/AbstractNPC.java
Expand Up @@ -64,18 +64,20 @@ public void setPersistent(String key, Object data) {
}
};
private String name;
private final NPCRegistry registry;
private final List<String> removedTraits = Lists.newArrayList();
private final List<Runnable> runnables = Lists.newArrayList();
private final SpeechController speechController = new SimpleSpeechController(this);
protected final Map<Class<? extends Trait>, Trait> traits = Maps.newHashMap();

protected AbstractNPC(int id, String name) {
protected AbstractNPC(int id, String name, NPCRegistry registry) {
if (name.length() > 16) {
Messaging.severe("ID", id, "created with name length greater than 16, truncating", name, "to",
name.substring(0, 15));
name = name.substring(0, 15);
}
this.id = id;
this.registry = registry;
this.name = name;
CitizensAPI.getTraitFactory().addDefaultTraits(this);
}
Expand Down Expand Up @@ -116,7 +118,7 @@ public void addTrait(Trait trait) {

@Override
public NPC clone() {
NPC copy = CitizensAPI.getNPCRegistry().createNPC(getTrait(MobType.class).getType(), getFullName());
NPC copy = registry.createNPC(getTrait(MobType.class).getType(), getFullName());
DataKey key = new MemoryDataKey();
this.save(key);
copy.load(key);
Expand Down Expand Up @@ -146,7 +148,7 @@ public void destroy() {
trait.onRemove();
}
traits.clear();
CitizensAPI.getNPCRegistry().deregister(this);
registry.deregister(this);
}

@Override
Expand Down

0 comments on commit 6d3994e

Please sign in to comment.