Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofaa2 committed Feb 23, 2024
1 parent 0ec1c82 commit 263bd05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 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 @@ -38,6 +38,8 @@ public interface EntityLibAPI<T> {

@NotNull WrapperPlayer createPlayer(UserProfile profile);

@NotNull WrapperPlayer createPlayer(UserProfile profile, int entityId);

@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 @@ -6,6 +6,7 @@
import com.github.retrooper.packetevents.protocol.potion.PotionType;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityEffect;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTeams;
import me.tofaa.entitylib.meta.EntityMeta;
import me.tofaa.entitylib.meta.types.LivingEntityMeta;
import org.jetbrains.annotations.Nullable;
Expand All @@ -16,6 +17,7 @@ public class WrapperLivingEntity extends WrapperEntity{

private final WrapperEntityEquipment equipment;


public WrapperLivingEntity(int entityId, UUID uuid, EntityType entityType, EntityMeta entityMeta) {
super(entityId, uuid, entityType, entityMeta);
this.equipment = new WrapperEntityEquipment(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ else if (meta instanceof ThrownExpBottleMeta) {

@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);
return createPlayer(profile, id);
}

@Override
public @NotNull WrapperPlayer createPlayer(UserProfile profile, int entityId) {
if (getEntity(profile.getUUID()) != null) {
throw new IllegalArgumentException("Entity with UUID " + profile.getUUID() + " already exists in this world.");
}
WrapperPlayer player = new WrapperPlayer(profile, entityId);
entities.put(player.getUuid(), player);
entitiesById.put(player.getEntityId(), player);
return player;
Expand Down

0 comments on commit 263bd05

Please sign in to comment.