package re.imc.geysermodelengine.model; import com.comphenix.protocol.wrappers.EnumWrappers; import com.google.common.collect.Sets; import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ModeledEntity; import lombok.Getter; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import re.imc.geysermodelengine.GeyserModelEngine; import re.imc.geysermodelengine.packet.entity.PacketEntity; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @Getter public class ModelEntity { public static Map> ENTITIES = new ConcurrentHashMap<>(); public static Map MODEL_ENTITIES = new ConcurrentHashMap<>(); private PacketEntity entity; private final Set viewers = Sets.newConcurrentHashSet(); private final ModeledEntity modeledEntity; private final ActiveModel activeModel; private EntityTask task; private ModelEntity(ModeledEntity modeledEntity, ActiveModel model) { this.modeledEntity = modeledEntity; this.activeModel = model; this.entity = spawnEntity(); runEntityTask(); } public void teleportToModel() { Location location = modeledEntity.getBase().getLocation(); entity.teleport(location); } public static ModelEntity create(ModeledEntity entity, ActiveModel model) { ModelEntity modelEntity = new ModelEntity(entity, model); int id = entity.getBase().getEntityId(); Map map = ENTITIES.computeIfAbsent(id, k -> new HashMap<>()); for (Map.Entry entry : map.entrySet()) { if (entry.getKey() != model && entry.getKey().getBlueprint().getName().equals(model.getBlueprint().getName())) { return null; } } map.put(model, modelEntity); return modelEntity; } public PacketEntity spawnEntity() { entity = new PacketEntity(GeyserModelEngine.getInstance().getModelEntityType(), viewers, modeledEntity.getBase().getLocation()); return entity; } public void runEntityTask() { task = new EntityTask(this); task.run(GeyserModelEngine.getInstance()); } }