add createPlayer

This commit is contained in:
Tofaa 2024-02-23 13:54:47 +04:00
parent a6070ef5cc
commit 549f897013
2 changed files with 19 additions and 0 deletions

View file

@ -36,6 +36,8 @@ public interface EntityLibAPI<T> {
@NotNull WrapperPlayer spawnPlayer(UserProfile profile, Location location); @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 <T extends WrapperEntity> T spawnEntity(@NotNull Class<T> wrapperClass, @NotNull EntityType entityType, @NotNull Location location);
@NotNull WrapperEntity spawnEntity(@NotNull EntityType entityType, @NotNull Location location); @NotNull WrapperEntity spawnEntity(@NotNull EntityType entityType, @NotNull Location location);

View file

@ -94,6 +94,23 @@ public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> {
return player; 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 @Override
public <T1 extends WrapperEntity> @NotNull T1 spawnEntity(@NotNull T1 entity, @NotNull Location location) { public <T1 extends WrapperEntity> @NotNull T1 spawnEntity(@NotNull T1 entity, @NotNull Location location) {
entity.spawn(location); entity.spawn(location);