This commit is contained in:
Tofaa 2024-02-23 19:28:26 +04:00
parent 0ec1c828a5
commit 263bd058a2
3 changed files with 13 additions and 5 deletions

View file

@ -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);

View file

@ -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);

View file

@ -96,16 +96,20 @@ public abstract class AbstractEntityLibAPI<P, T> implements EntityLibAPI<T> {
@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;