Skip to content

Commit 3529573

Browse files
committed
doc(sdk): improved error message
1 parent 1a715bf commit 3529573

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

engine/modules/entities/src/main/java/com/codingame/gameengine/module/entities/ContainerBasedEntity.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ public void remove(Entity<?> entity) {
4747
*/
4848
public void add(Entity<?>... entities) {
4949
Stream.of(entities).forEach(entity -> {
50-
if (entity.parent != null) {
51-
throw new IllegalArgumentException();
50+
if (entity.getParent().isPresent()) {
51+
throw new IllegalArgumentException(
52+
String.format(
53+
"Cannot add entity %d to container %d: it is already in container %d",
54+
entity.getId(),
55+
getId(),
56+
entity.getParent().get().getId()
57+
)
58+
);
5259
}
5360
this.entities.add(entity);
5461
entity.parent = this;

0 commit comments

Comments
 (0)