|
|
@@ -0,0 +1,116 @@
|
|
|
+package me.lethunderhawk.custom.entity;
|
|
|
+
|
|
|
+import me.lethunderhawk.fluxapi.util.itemdesign.LoreDesigner;
|
|
|
+import org.bukkit.Location;
|
|
|
+import org.bukkit.attribute.Attribute;
|
|
|
+import org.bukkit.entity.Entity;
|
|
|
+import org.bukkit.entity.EntityType;
|
|
|
+import org.bukkit.entity.LivingEntity;
|
|
|
+import org.bukkit.inventory.EntityEquipment;
|
|
|
+import org.bukkit.inventory.ItemStack;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public enum CustomEntity {
|
|
|
+ CUSTOM_ZOMBIE("<blue>Zombie?", 15, 20, EntityType.ZOMBIE, null, null, null);
|
|
|
+
|
|
|
+ private String name;
|
|
|
+ private double maxHealth;
|
|
|
+ private double spawnChance;
|
|
|
+ private double currentHealth;
|
|
|
+ private EntityType type;
|
|
|
+ private List<LootItem> lootTable = new ArrayList<>();
|
|
|
+ private ItemStack mainHandItem;
|
|
|
+ private ItemStack[] armor;
|
|
|
+
|
|
|
+ CustomEntity(String name, double maxHealth, double spawnChance, EntityType type, List<LootItem> lootTable, ItemStack mainHandItem, ItemStack[] armor) {
|
|
|
+ this.name = name;
|
|
|
+ this.maxHealth = maxHealth;
|
|
|
+ this.spawnChance = spawnChance;
|
|
|
+ this.type = type;
|
|
|
+ this.lootTable = lootTable;
|
|
|
+ this.mainHandItem = mainHandItem;
|
|
|
+ this.armor = armor;
|
|
|
+ this.currentHealth = maxHealth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public LivingEntity writeIntoEntity(LivingEntity entity) {
|
|
|
+ if(!entity.getType().equals(type)) return entity;
|
|
|
+
|
|
|
+ entity.setCustomNameVisible(true);
|
|
|
+
|
|
|
+ if(entity.getAttribute(Attribute.MAX_HEALTH) != null){
|
|
|
+ entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(maxHealth);
|
|
|
+ entity.setHealth(maxHealth);
|
|
|
+ }
|
|
|
+ EntityUtil.writeIntoBaseName(entity, name);
|
|
|
+ entity.customName(LoreDesigner.createSingle(name));
|
|
|
+
|
|
|
+ EntityUtil.updateHealthInName(entity, maxHealth);
|
|
|
+
|
|
|
+ EntityEquipment equipment = entity.getEquipment();
|
|
|
+ if(armor != null && equipment != null){
|
|
|
+ equipment.setArmorContents(armor);
|
|
|
+ setArmorDropChance(equipment, 0f);
|
|
|
+ equipment.setItemInMainHand(mainHandItem);
|
|
|
+ equipment.setItemInMainHandDropChance(0f);
|
|
|
+ }
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setArmorDropChance(EntityEquipment equipment, double chance) {
|
|
|
+ equipment.setHelmetDropChance(0f);
|
|
|
+ equipment.setChestplateDropChance(0f);
|
|
|
+ equipment.setLeggingsDropChance(0f);
|
|
|
+ equipment.setBootsDropChance(0f);
|
|
|
+ }
|
|
|
+
|
|
|
+ public LivingEntity spawn(Location location) {
|
|
|
+ LivingEntity entity = (LivingEntity) location.getWorld().spawnEntity(location, type);
|
|
|
+ return writeIntoEntity(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getName() {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void tryDropLoot(Location loc) {
|
|
|
+ if(lootTable == null || lootTable.isEmpty()) return;
|
|
|
+ for(LootItem item : lootTable) {
|
|
|
+ item.tryDropItem(loc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCurrentHealth() {
|
|
|
+ return currentHealth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public EntityType getType() {
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<LootItem> getLootTable() {
|
|
|
+ return lootTable;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ItemStack getMainHandItem() {
|
|
|
+ return mainHandItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ItemStack[] getArmor() {
|
|
|
+ return armor;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getSpawnChance() {
|
|
|
+ return spawnChance;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getMaxHealth() {
|
|
|
+ return maxHealth;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateHealthInName(Entity entity, double newHealth) {
|
|
|
+ entity.customName(LoreDesigner.createSingle(name + " <red>" + (int) Math.round(newHealth) + "/" + (int) maxHealth + "♥"));
|
|
|
+ }
|
|
|
+}
|