Skip to content

Commit

Permalink
add createPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofaa2 committed Feb 23, 2024
1 parent a6070ef commit 549f897
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface EntityLibAPI<T> {

@NotNull WrapperPlayer spawnPlayer(UserProfile profile, Location location);

@NotNull WrapperPlayer createPlayer(UserProfile profile);

@NotNull <T extends WrapperEntity> T spawnEntity(@NotNull Class<T> wrapperClass, @NotNull EntityType entityType, @NotNull Location location);

@NotNull WrapperEntity spawnEntity(@NotNull EntityType entityType, @NotNull Location location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ else if (meta instanceof ThrownExpBottleMeta) {
return player;
}

@Override
public @NotNull WrapperPlayer createPlayer(UserProfile profile) {
if (getEntity(profile.getUUID()) != null) {
throw new IllegalArgumentException("Entity with UUID " + profile.getUUID() + " already exists in this world.");
}

int id = EntityLib.getPlatform().getEntityIdProvider().provide(profile.getUUID(), EntityTypes.PLAYER);
while (entitiesById.containsKey
(id)) {
id = EntityLib.getPlatform().getEntityIdProvider().provide(profile.getUUID(), EntityTypes.PLAYER);
}
WrapperPlayer player = new WrapperPlayer(profile, id);
entities.put(player.getUuid(), player);
entitiesById.put(player.getEntityId(), player);
return player;
}

@Override
public <T1 extends WrapperEntity> @NotNull T1 spawnEntity(@NotNull T1 entity, @NotNull Location location) {
entity.spawn(location);
Expand Down

0 comments on commit 549f897

Please sign in to comment.