Clear static object REMOVE messages when re-adding

This commit is contained in:
Gary Tierney
2017-09-17 20:27:50 +01:00
parent 8a3decfc54
commit 169d89ffc0
2 changed files with 6 additions and 16 deletions
@@ -46,7 +46,7 @@ class ExpireObjectTask(
respawning = true respawning = true
setDelay(respawnDelay) setDelay(respawnDelay)
} else { } else {
region.removeEntity(replacement, false) region.removeEntity(replacement)
world.spawn(obj) world.spawn(obj)
stop() stop()
} }
@@ -334,23 +334,13 @@ public final class Region {
listeners.forEach(listener -> listener.execute(this, entity, type)); listeners.forEach(listener -> listener.execute(this, entity, type));
} }
/**
* Removes an {@link Entity} from this Region and notifies listeners.
*
* @param entity The Entity.
* @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
*/
public void removeEntity(Entity entity) {
removeEntity(entity, true);
}
/** /**
* Removes an {@link Entity} from this Region. * Removes an {@link Entity} from this Region.
* *
* @param entity The Entity. * @param entity The Entity.
* @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added. * @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
*/ */
public void removeEntity(Entity entity, boolean notifyListeners) { public void removeEntity(Entity entity) {
EntityType type = entity.getEntityType(); EntityType type = entity.getEntityType();
if (type.isTransient()) { if (type.isTransient()) {
throw new IllegalArgumentException("Tried to remove a transient Entity (" + entity + ") from " + throw new IllegalArgumentException("Tried to remove a transient Entity (" + entity + ") from " +
@@ -366,9 +356,7 @@ public final class Region {
throw new IllegalArgumentException("Entity (" + entity + ") belongs in (" + this + ") but does not exist."); throw new IllegalArgumentException("Entity (" + entity + ") belongs in (" + this + ") but does not exist.");
} }
if (notifyListeners) { notifyListeners(entity, EntityUpdateType.REMOVE);
notifyListeners(entity, EntityUpdateType.REMOVE);
}
} }
@Override @Override
@@ -425,7 +413,9 @@ public final class Region {
} else { // TODO should this really be possible? } else { // TODO should this really be possible?
removedObjects.get(height).remove(inverse); removedObjects.get(height).remove(inverse);
} }
} else if (update == EntityUpdateType.REMOVE && !type.isTransient()) { }
if (update == EntityUpdateType.REMOVE && !type.isTransient()) {
updates.remove(inverse); updates.remove(inverse);
} }