Raxen/src/main/java/me/unurled/raxen/manager/entity/EntityManager.java

238 lines
7.4 KiB
Java

package me.unurled.raxen.manager.entity;
import static me.unurled.raxen.utils.Utils.debug;
import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import me.unurled.raxen.Raxen;
import me.unurled.raxen.components.entity.Attributes.Defense;
import me.unurled.raxen.components.entity.Attributes.Health;
import me.unurled.raxen.components.entity.Attributes.ItemDefense;
import me.unurled.raxen.components.entity.Attributes.ItemHealth;
import me.unurled.raxen.components.entity.Attributes.ItemLuck;
import me.unurled.raxen.components.entity.Attributes.ItemMana;
import me.unurled.raxen.components.entity.Attributes.ItemSpeed;
import me.unurled.raxen.components.entity.Attributes.ItemStrength;
import me.unurled.raxen.components.entity.Attributes.Luck;
import me.unurled.raxen.components.entity.Attributes.Mana;
import me.unurled.raxen.components.entity.Attributes.MaxHealth;
import me.unurled.raxen.components.entity.Attributes.MaxMana;
import me.unurled.raxen.components.entity.Attributes.MaxManaBuilder;
import me.unurled.raxen.components.entity.Attributes.Speed;
import me.unurled.raxen.components.entity.Attributes.Strength;
import me.unurled.raxen.components.entity.other.EntityNamespacedKey;
import me.unurled.raxen.components.entity.other.MobData;
import me.unurled.raxen.components.entity.other.MobType;
import me.unurled.raxen.components.entity.other.RaxenEntity;
import me.unurled.raxen.utils.Tags;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
public class EntityManager {
private Raxen main;
@Getter
@Setter
private List<EntityType> list = new ArrayList<>();
@Getter
private HashMap<String, MobType> mobTypes;
@Getter
private final HashMap<UUID, MobData> spawnedMob;
@Getter
private HashMap<UUID, MobData> spawnedMobsOnlyMain;
@Getter
private final HashMap<String, me.unurled.raxen.components.entity.Attributes.Attribute> attribute;
private final HashMap<String, me.unurled.raxen.components.entity.other.RaxenEntity> entities;
private final HashMap<UUID, Entity> livingEntities = new HashMap<>();
private HashMap<UUID, BukkitTask> nameTags;
public EntityManager(Raxen main) {
this.main = main;
entities = new HashMap<>();
attribute = new HashMap<>();
mobTypes = new HashMap<>();
spawnedMob = new HashMap<>();
spawnedMobsOnlyMain = new HashMap<>();
nameTags = new HashMap<>();
reload();
registerAttributes();
}
public void reload() {
Collection<MobData> collection = new ArrayList<>();
collection.addAll(spawnedMob.values());
for (MobData mobData : collection) {
// mobData.entity.die(false);
}
}
public void registerLivingEntities(World world) {
}
public void registerEntity(Entity entity) {
/* RaxenEntity raxenEntity = new RaxenEntity();
raxenEntity.register(entity);
entities.put(entity.getUniqueId(), raxenEntity); */
}
public void setNameTag(Entity entity) {
Hologram holo = Tags.createNameTag(main, entity);
if (holo == null) {
return;
}
BukkitTask run = new BukkitRunnable() {
@Override
public void run() {
DHAPI.moveHologram(holo, entity.getLocation());
}
}.runTaskAsynchronously(main);
nameTags.put(entity.getUniqueId(), run);
}
/**
* used to register entities using fileconfigs but rapidly abandoned
*
* @param file
*/
@Deprecated
public void registerEntityFromConfig(FileConfiguration file) {
debug(file.getString("id"));
World world = Bukkit.getWorld(file.getString("world"));
String name = file.getString("name");
}
public RaxenEntity getEntity(UUID uuid) {
return null;
}
public RaxenEntity getEntity(Entity entity) {
return entities.get(entity.getUniqueId());
}
/**
* register all Attributes in me.unurled.raxen.components.entity.Attributes;
*/
public void registerAttributes() {
EntityNamespacedKey key = new EntityNamespacedKey(main);
// Attributes
Defense defense = new Defense(key.defense, "DEFENSE");
attribute.put("DEFENSE", defense);
Health health = new Health(key.health, "HEALTH");
attribute.put("HEALTH", health);
ItemDefense itemDefense = new ItemDefense(key.itemDefense, "ITEM_DEFENSE");
attribute.put("ITEM_DEFENSE", itemDefense);
ItemHealth itemHealth = new ItemHealth(key.itemHealth, "ITEM_HEALTH");
attribute.put("ITEM_HEALTH", itemHealth);
ItemLuck itemLuck = new ItemLuck(key.itemLuck, "ITEM_LUCK");
attribute.put("ITEM_LUCK", itemLuck);
ItemMana itemMana = new ItemMana(key.itemMana, "ITEM_MANA");
attribute.put("ITEM_MANA", itemMana);
ItemSpeed itemSpeed = new ItemSpeed(key.itemSpeed, "ITEM_SPEED");
attribute.put("ITEM_SPEED", itemSpeed);
ItemStrength itemStrength = new ItemStrength(key.itemStrength, "ITEM_STRENGTH");
attribute.put("ITEM_STRENGTH", itemStrength);
Luck luck = new Luck(key.luck, "LUCK");
attribute.put("LUCK", luck);
Mana mana = new Mana(key.mana, "MANA");
attribute.put("MANA", mana);
MaxMana maxMana = new MaxManaBuilder()
.setNamespacekey(key.maxMana)
.setName("MAX_MANA")
.createMaxMana();
attribute.put("MAX_MANA", maxMana);
MaxHealth maxHealth = new MaxHealth(key.maxHealth, "MAX_HEALTH");
attribute.put("MAX_HEALTH", maxHealth);
Speed speed = new Speed(key.speed, "SPEED");
attribute.put("SPEED", speed);
Strength strength = new Strength(key.strength, "STRENGTH");
attribute.put("STRENGTH", strength);
}
public Defense getDefense() {
return (Defense) attribute.get("DEFENSE");
}
public Health getHealth() {
return (Health) attribute.get("HEALTH");
}
public ItemDefense getItemDefense() {
return (ItemDefense) attribute.get("ITEM_DEFENSE");
}
public ItemHealth getItemHealth() {
return (ItemHealth) attribute.get("ITEM_HEALTH");
}
public ItemLuck getItemLuck() {
return (ItemLuck) attribute.get("ITEM_LUCK");
}
public ItemMana getItemMana() {
return (ItemMana) attribute.get("ITEM_MANA");
}
public ItemSpeed getItemSpeed() {
return (ItemSpeed) attribute.get("ITEM_SPEED");
}
public ItemStrength getItemStrength() {
return (ItemStrength) attribute.get("ITEM_STRENGTH");
}
public Luck getLuck() {
return (Luck) attribute.get("LUCK");
}
public Mana getMana() {
return (Mana) attribute.get("MANA");
}
public MaxMana getMaxMana() {
return (MaxMana) attribute.get("MAX_MANA");
}
public MaxHealth getMaxHealth() {
return (MaxHealth) attribute.get("MAX_HEALTH");
}
public Speed getSpeed() {
return (Speed) attribute.get("SPEED");
}
public Strength getStrength() {
return (Strength) attribute.get("STRENGTH");
}
}