<commit_before>package de.craften.plugins.managedentities;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import de.craften.plugins.managedentities.behavior.Behavior;
import de.craften.plugins.managedentities.behavior.PropertyChangeAware;
import de.craften.plugins.managedentities.util.nms.NmsEntityUtil;
import org.bukkit.Location;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * The abstract base for a managed entity.
 *
 * @param <T> type of the entity
 */
public abstract class ManagedEntityBase<T extends Entity> implements ManagedEntity<T> {
    EntityManager entityManager;
    private final UUID id = UUID.randomUUID();
    private final Multimap<Class<? extends Behavior>, Behavior> behaviors = ArrayListMultimap.create();
    private final Map<String, String> properties = new HashMap<>();
    private T entity;
    private Location location;

    public ManagedEntityBase(Location location) {
        this.location = location;
    }

    @Override
    public T getEntity() {
        return entity;
    }

    @Override
    public void spawn() {
        if (entity == null) {
            entity = spawnEntity(location);

            if (entity instanceof LivingEntity) {
                NmsEntityUtil.disableAi((LivingEntity) entity);
            }

            if (entityManager != null) {
                entityManager.addMapping(entity, this);
            }
        }
    }

    @Override<commit_msg>Don't remove living entities if they are far away. Fixes #1.<commit_after>package de.craften.plugins.managedentities;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import de.craften.plugins.managedentities.behavior.Behavior;
import de.craften.plugins.managedentities.behavior.PropertyChangeAware;
import de.craften.plugins.managedentities.util.nms.NmsEntityUtil;
import org.bukkit.Location;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * The abstract base for a managed entity.
 *
 * @param <T> type of the entity
 */
public abstract class ManagedEntityBase<T extends Entity> implements ManagedEntity<T> {
    EntityManager entityManager;
    private final UUID id = UUID.randomUUID();
    private final Multimap<Class<? extends Behavior>, Behavior> behaviors = ArrayListMultimap.create();
    private final Map<String, String> properties = new HashMap<>();
    private T entity;
    private Location location;

    public ManagedEntityBase(Location location) {
        this.location = location;
    }

    @Override
    public T getEntity() {
        return entity;
    }

    @Override
    public void spawn() {
        if (entity == null) {
            entity = spawnEntity(location);

            if (entity instanceof LivingEntity) {
                NmsEntityUtil.disableAi((LivingEntity) entity);
                ((LivingEntity) entity).setRemoveWhenFarAway(false); //TODO this affects performance and should be optimized later (manual tracking of far away entities)
            }

            if (entityManager != null) {
                entityManager.addMapping(entity, this);
            }
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.09532012632787827, 'fraction_numerical': 0.0002871088142405972, 'mean_word_length': 3.2643818849449207, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7393287', 'n_tokens_mistral': 975, 'n_tokens_neox': 946, 'n_words': 244}