Breaking change: add new registry param to CitizensNPC constructor

This commit is contained in:
fullwall 2013-09-11 22:27:24 +08:00
parent 50a43d6116
commit 815733c2ad
4 changed files with 14 additions and 9 deletions

View File

@ -10,6 +10,7 @@ import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.api.util.DataKey;
@ -38,8 +39,8 @@ public class CitizensNPC extends AbstractNPC {
private EntityController entityController;
private final CitizensNavigator navigator = new CitizensNavigator(this);
public CitizensNPC(int id, String name, EntityController entityController) {
super(id, name);
public CitizensNPC(int id, String name, EntityController entityController, NPCRegistry registry) {
super(id, name, registry);
Preconditions.checkNotNull(entityController);
this.entityController = entityController;
}

View File

@ -47,8 +47,9 @@ public class CitizensNPCRegistry implements NPCRegistry {
@Override
public void deregister(NPC npc) {
npcs.remove(npc.getId());
if (saves != null)
if (saves != null) {
saves.clearData(npc);
}
npc.despawn(DespawnReason.REMOVAL);
}
@ -59,10 +60,12 @@ public class CitizensNPCRegistry implements NPCRegistry {
NPC npc = itr.next();
itr.remove();
npc.despawn(DespawnReason.REMOVAL);
for (Trait t : npc.getTraits())
for (Trait t : npc.getTraits()) {
t.onRemove();
if (saves != null)
}
if (saves != null) {
saves.clearData(npc);
}
}
}
@ -78,7 +81,7 @@ public class CitizensNPCRegistry implements NPCRegistry {
}
private CitizensNPC getByType(EntityType type, int id, String name) {
return new CitizensNPC(id, name, EntityControllers.createForType(type));
return new CitizensNPC(id, name, EntityControllers.createForType(type), this);
}
@Override

View File

@ -84,8 +84,9 @@ public class BlazeController extends MobEntityController {
// this method is called by both the entities involved - cancelling
// it will not stop the NPC from moving.
super.collide(entity);
if (npc != null)
if (npc != null) {
Util.callCollisionEvent(npc, entity.getBukkitEntity());
}
}
@Override

View File

@ -112,9 +112,9 @@ public class ByIdArray<T> implements Iterable<T> {
elementData[index] = null;
--size;
++modCount;
if (index == highest)
if (index >= highest)
recalcHighest();
if (index == lowest)
if (index <= lowest)
recalcLowest();
return prev;
}