From 263bd058a27a3e192c70d4f3c0c457a836c84116 Mon Sep 17 00:00:00 2001 From: Tofaa <82680183+Tofaa2@users.noreply.github.com> Date: Fri, 23 Feb 2024 19:28:26 +0400 Subject: [PATCH] fix --- .../main/java/me/tofaa/entitylib/EntityLibAPI.java | 2 ++ .../entitylib/wrapper/WrapperLivingEntity.java | 2 ++ .../entitylib/common/AbstractEntityLibAPI.java | 14 +++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java b/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java index 1acf174..d647977 100644 --- a/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java +++ b/api/src/main/java/me/tofaa/entitylib/EntityLibAPI.java @@ -38,6 +38,8 @@ public interface EntityLibAPI { @NotNull WrapperPlayer createPlayer(UserProfile profile); + @NotNull WrapperPlayer createPlayer(UserProfile profile, int entityId); + @NotNull T spawnEntity(@NotNull Class wrapperClass, @NotNull EntityType entityType, @NotNull Location location); @NotNull WrapperEntity spawnEntity(@NotNull EntityType entityType, @NotNull Location location); diff --git a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java index 26fa8e2..85e3ff5 100644 --- a/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java +++ b/api/src/main/java/me/tofaa/entitylib/wrapper/WrapperLivingEntity.java @@ -6,6 +6,7 @@ import com.github.retrooper.packetevents.protocol.player.HumanoidArm; 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; @@ -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); diff --git a/common/src/main/java/me/tofaa/entitylib/common/AbstractEntityLibAPI.java b/common/src/main/java/me/tofaa/entitylib/common/AbstractEntityLibAPI.java index 824489c..564174d 100644 --- a/common/src/main/java/me/tofaa/entitylib/common/AbstractEntityLibAPI.java +++ b/common/src/main/java/me/tofaa/entitylib/common/AbstractEntityLibAPI.java @@ -96,16 +96,20 @@ public abstract class AbstractEntityLibAPI implements EntityLibAPI { @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;