Skip to content

Commit 1c502d8

Browse files
committed
MobList now correctly refuses entry if full, and isFull() function fixed.
1 parent 67d9643 commit 1c502d8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/java/io/luna/game/model/mob/MobList.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,15 @@ public Stream<E> stream() {
208208
* @param mob The mob to register.
209209
* @throws IllegalStateException If the list is full.
210210
* @throws IllegalArgumentException If the mob is already ACTIVE.
211+
* @return {@code true} if the mob was successfully added.
211212
*/
212-
public void add(E mob) {
213+
public boolean add(E mob) {
213214
checkArgument(mob.getState() != EntityState.ACTIVE, "Mob is already ACTIVE.");
214-
checkState(!isFull(), "MobList is full.");
215215

216-
int index = indexPool.remove();
216+
Integer index = indexPool.poll();
217+
if(index == null) {
218+
return false;
219+
}
217220
mobs[index] = mob;
218221
mob.setIndex(index);
219222
size++;
@@ -224,6 +227,7 @@ public void add(E mob) {
224227
} else if (mob.getType() == EntityType.PLAYER) {
225228
world.addPlayer(mob.asPlr());
226229
}
230+
return true;
227231
}
228232

229233
/**
@@ -278,7 +282,7 @@ public boolean contains(E mob) {
278282
* @return {@code true} if no more mobs can be inserted.
279283
*/
280284
public boolean isFull() {
281-
return size == capacity();
285+
return size == capacity() - 1;
282286
}
283287

284288
/**

0 commit comments

Comments
 (0)