3.0.0.0 R2 - master branch

+ Added base code to create a boss entity
+ Added some targetting classes
+ Added a bunch of interfaces which will do different things towards the boss entity.
This commit is contained in:
AMinecraftDev 2017-05-31 23:04:55 +08:00
parent ce698e209b
commit 24079c208e
14 changed files with 521 additions and 9 deletions

View File

@ -1,9 +0,0 @@
package net.aminecraftdev.custombosses.handlers;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class EntityHandler {
}

View File

@ -0,0 +1,129 @@
package net.aminecraftdev.custombosses.handlers.builders;
import net.aminecraftdev.custombosses.innerapi.reflection.ReflectionUtils;
import org.bukkit.Location;
import org.bukkit.entity.*;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class EntityHandler extends ReflectionUtils {
public final LivingEntity getBaseEntity(String type, Location location) {
LivingEntity livingEntity = null;
EntityType entityType = null;
if(type.equalsIgnoreCase("WITHER_SKELETON")) livingEntity = getWitherSkeleton(location);
else if(type.equalsIgnoreCase("ELDER_GUARDIAN")) livingEntity = getElderGuardian(location);
else if(type.equalsIgnoreCase("KILLER_BUNNY")) livingEntity = getKillerBunny(location);
else if(type.equalsIgnoreCase("ZOMBIE")) livingEntity = getZombie(location);
else if(type.equalsIgnoreCase("BABY_ZOMBIE")) livingEntity = getBabyZombie(location);
else if(type.equalsIgnoreCase("PIG_ZOMBIE")) livingEntity = getPigZombie(location);
else if(type.equalsIgnoreCase("BABY_PIG_ZOMBIE")) livingEntity = getBabyPigZombie(location);
else if(type.contains(":")) {
String[] split = type.split(":");
if(split[0].equalsIgnoreCase("SLIME")) {
livingEntity = getSlime(location, Integer.valueOf(split[1]));
} else if(split[0].equalsIgnoreCase("MAGMA_CUBE")) {
livingEntity = getMagmaCube(location, Integer.valueOf(split[1]));
} else {
if(EntityType.valueOf(type).equals(null)) {
/* ADD A DEBUG MESSAGE HERE */
return null;
}
}
} else {
if(EntityType.valueOf(type).equals(null)) {
/* ADD A DEBUG MESSAGE HERE */
return null;
}
entityType = EntityType.valueOf(type);
}
if(livingEntity == null) {
if(entityType == EntityType.SLIME) getSlime(location, 10);
else if(entityType == EntityType.MAGMA_CUBE) getSlime(location, 10);
else {
livingEntity = (LivingEntity) location.getWorld().spawn(location, entityType.getEntityClass());
}
}
return livingEntity;
}
private LivingEntity getWitherSkeleton(Location location) {
if(getAPIVersion().startsWith("v1_11_R")) {
return (LivingEntity) location.getWorld().spawn(location, EntityType.WITHER_SKELETON.getEntityClass());
} else {
Skeleton skeleton = (Skeleton) location.getWorld().spawn(location, EntityType.SKELETON.getEntityClass());
skeleton.setSkeletonType(Skeleton.SkeletonType.WITHER);
return skeleton;
}
}
private LivingEntity getElderGuardian(Location location) {
if(getAPIVersion().startsWith("v1_11_R")) {
return (LivingEntity) location.getWorld().spawn(location, EntityType.ELDER_GUARDIAN.getEntityClass());
} else {
Guardian guardian = (Guardian) location.getWorld().spawn(location, EntityType.GUARDIAN.getEntityClass());
guardian.setElder(true);
return guardian;
}
}
private LivingEntity getKillerBunny(Location location) {
Rabbit rabbit = (Rabbit) location.getWorld().spawn(location, EntityType.RABBIT.getEntityClass());
rabbit.setRabbitType(Rabbit.Type.THE_KILLER_BUNNY);
return rabbit;
}
private LivingEntity getBabyZombie(Location location) {
Zombie zombie = (Zombie) location.getWorld().spawn(location, EntityType.ZOMBIE.getEntityClass());
zombie.setBaby(true);
return zombie;
}
private LivingEntity getZombie(Location location) {
Zombie zombie = (Zombie) location.getWorld().spawn(location, EntityType.ZOMBIE.getEntityClass());
zombie.setBaby(false);
return zombie;
}
private LivingEntity getBabyPigZombie(Location location) {
PigZombie pigZombie = (PigZombie) location.getWorld().spawn(location, EntityType.PIG_ZOMBIE.getEntityClass());
pigZombie.setBaby(true);
return pigZombie;
}
private LivingEntity getPigZombie(Location location) {
PigZombie pigZombie = (PigZombie) location.getWorld().spawn(location, EntityType.PIG_ZOMBIE.getEntityClass());
pigZombie.setBaby(false);
return pigZombie;
}
private LivingEntity getSlime(Location location, int size) {
Slime slime = (Slime) location.getWorld().spawn(location, EntityType.SLIME.getEntityClass());
slime.setSize(size);
return slime;
}
private LivingEntity getMagmaCube(Location location, int size) {
MagmaCube magmaCube = (MagmaCube) location.getWorld().spawn(location, EntityType.MAGMA_CUBE.getEntityClass());
magmaCube.setSize(size);
return magmaCube;
}
}

View File

@ -0,0 +1,77 @@
package net.aminecraftdev.custombosses.handlers.builders;
import net.aminecraftdev.custombosses.innerapi.itemstack.ItemStackUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class EquipmentHandler {
public void applyEquipment(LivingEntity livingEntity, ConfigurationSection configurationSection) {
Map<Enchantment, Integer> mapOfEnchants = getMapOfEnchants(configurationSection);
String type = configurationSection.getString("type").toUpperCase();
if(configurationSection.getName().equalsIgnoreCase("Armor")) {
String innerType = type + "_HELMET";
livingEntity.getEquipment().setHelmet(getArmour(innerType, mapOfEnchants));
innerType = type + "_CHESTPLATE";
livingEntity.getEquipment().setChestplate(getArmour(innerType, mapOfEnchants));
innerType = type + "_LEGGINGS";
livingEntity.getEquipment().setLeggings(getArmour(innerType, mapOfEnchants));
innerType = type + "_BOOTS";
livingEntity.getEquipment().setBoots(getArmour(innerType, mapOfEnchants));
} else {
ItemStack itemStack = new ItemStack(ItemStackUtils.getType(type));
itemStack.addUnsafeEnchantments(mapOfEnchants);
livingEntity.getEquipment().setItemInHand(itemStack);
}
}
public void applySkull(LivingEntity livingEntity, ConfigurationSection configurationSection) {
String owner = configurationSection.getString("owner");
ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
skullMeta.setOwner(owner);
itemStack.setItemMeta(skullMeta);
livingEntity.getEquipment().setHelmet(itemStack);
}
private Map<Enchantment, Integer> getMapOfEnchants(ConfigurationSection configurationSection) {
Map<Enchantment, Integer> enchantmentIntegerMap = new HashMap<>();
List<String> enchantsList = configurationSection.getStringList("enchants");
for(String s : enchantsList) {
String[] spl = s.split(":");
String ench = spl[0];
int level = Integer.parseInt(spl[1]);
enchantmentIntegerMap.put(Enchantment.getByName(ench), level);
}
return enchantmentIntegerMap;
}
private ItemStack getArmour(String type, Map<Enchantment, Integer> enchantments) {
ItemStack itemStack = new ItemStack(ItemStackUtils.getType(type));
itemStack.addUnsafeEnchantments(enchantments);
return itemStack;
}
}

View File

@ -0,0 +1,140 @@
package net.aminecraftdev.custombosses.handlers.mobs;
import net.aminecraftdev.custombosses.handlers.mobs.interfaces.IDamageHandler;
import net.aminecraftdev.custombosses.handlers.mobs.interfaces.IKillHandler;
import net.aminecraftdev.custombosses.handlers.mobs.interfaces.IMobHandler;
import net.aminecraftdev.custombosses.handlers.mobs.interfaces.ISpawnHandler;
import net.aminecraftdev.custombosses.innerapi.message.MessageUtils;
import net.aminecraftdev.custombosses.managers.BossManager;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.UUID;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class BossEntity implements IMobHandler, ISpawnHandler, IDamageHandler, IKillHandler {
private boolean hasSkills, hasTaunts, hasCommands, hasMessages, isAutoBoss;
private ConfigurationSection configurationSection;
private LivingEntity livingEntity;
private BossManager bossManager;
private boolean isBossSpawned;
private double maxHealth;
private UUID uuid;
//private Set<Skill> skills = new HashSet<>();
//private List<String> taunts = new ArrayList<>();
public BossEntity(ConfigurationSection configurationSection, BossManager bossManager, boolean isAutoBoss) {
this.hasSkills = this.configurationSection.contains("Skills");
this.hasTaunts = this.configurationSection.contains("Taunts");
this.hasCommands = this.configurationSection.contains("Commands");
this.hasMessages = this.configurationSection.contains("Messages");
this.configurationSection = configurationSection;
this.bossManager = bossManager;
this.isBossSpawned = false;
this.isAutoBoss = isAutoBoss;
}
@Override
public ConfigurationSection getConfigurationSection() {
return configurationSection;
}
@Override
public double getMaxHealth() {
return maxHealth;
}
@Override
public double getCurrentHealth() {
return livingEntity.getHealth();
}
@Override
public UUID getUniqueId() {
return uuid;
}
@Override
public boolean isAutoBoss() {
return isAutoBoss;
}
@Override
public void spawn(Location location) {
spawnBoss(location);
spawnMessage(location);
}
@Override
public void spawnBoss(Location location) {
if(this.isBossSpawned) {
/* ADD DEBUG MESSAGE HERE */
return;
}
ConfigurationSection bossConfigurationSection = configurationSection.getConfigurationSection("Boss");
String type = bossConfigurationSection.getString("type");
String targetType = bossConfigurationSection.getString("targetType");
String name = bossConfigurationSection.contains("name")? bossConfigurationSection.getString("name") : "";
double health = bossConfigurationSection.getDouble("health");
this.livingEntity = this.bossManager.getEntityHandler().getBaseEntity(type, location);
this.livingEntity.setCustomName(MessageUtils.translateString(name));
this.livingEntity.setCustomNameVisible(true);
this.livingEntity.setMaxHealth(health);
this.livingEntity.setHealth(health);
this.livingEntity.setRemoveWhenFarAway(false);
this.livingEntity.setCanPickupItems(false);
if(bossConfigurationSection.contains("Armor")) this.bossManager.getEquipmentHandler().applyEquipment(this.livingEntity, bossConfigurationSection.getConfigurationSection("Armor"));
if(bossConfigurationSection.contains("Weapon")) this.bossManager.getEquipmentHandler().applyEquipment(this.livingEntity, bossConfigurationSection.getConfigurationSection("Weapon"));
if(bossConfigurationSection.contains("Head")) this.bossManager.getEquipmentHandler().applySkull(this.livingEntity, bossConfigurationSection.getConfigurationSection("Head"));
if(bossConfigurationSection.contains("Potions")) this.bossManager.applyPotionEffects(this.livingEntity, bossConfigurationSection.getConfigurationSection("Potions"));
this.maxHealth = health;
this.livingEntity.getEquipment().setHelmetDropChance(0.0F);
this.livingEntity.getEquipment().setChestplateDropChance(0.0F);
this.livingEntity.getEquipment().setLeggingsDropChance(0.0F);
this.livingEntity.getEquipment().setBootsDropChance(0.0F);
/* HANDLE TARGET SYSTEM HERE */
this.uuid = this.livingEntity.getUniqueId();
}
@Override
public void spawnMessage(Location location) {
if(!hasMessages) return;
if(!configurationSection.contains("Messages.onSpawn")) return;
}
@Override
public void onDamage(Player damager, int damage) {
}
@Override
public void kill(Location location) {
}
@Override
public void killBoss(Location location) {
}
@Override
public void killMessage(Location location) {
}
}

View File

@ -0,0 +1,9 @@
package net.aminecraftdev.custombosses.handlers.mobs;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class MinionEntity {
}

View File

@ -0,0 +1,14 @@
package net.aminecraftdev.custombosses.handlers.mobs.interfaces;
import org.bukkit.entity.Player;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface IDamageHandler {
void onDamage(Player damager, int damage);
}

View File

@ -0,0 +1,16 @@
package net.aminecraftdev.custombosses.handlers.mobs.interfaces;
import org.bukkit.Location;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface IKillHandler {
void killBoss(Location location);
void killMessage(Location location);
}

View File

@ -0,0 +1,29 @@
package net.aminecraftdev.custombosses.handlers.mobs.interfaces;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import java.util.UUID;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface IMobHandler {
ConfigurationSection getConfigurationSection();
double getMaxHealth();
double getCurrentHealth();
UUID getUniqueId();
boolean isAutoBoss();
void spawn(Location location);
void kill(Location location);
}

View File

@ -0,0 +1,16 @@
package net.aminecraftdev.custombosses.handlers.mobs.interfaces;
import org.bukkit.Location;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface ISpawnHandler {
void spawnBoss(Location location);
void spawnMessage(Location location);
}

View File

@ -1,9 +1,55 @@
package net.aminecraftdev.custombosses.managers;
import net.aminecraftdev.custombosses.handlers.builders.EntityHandler;
import net.aminecraftdev.custombosses.handlers.builders.EquipmentHandler;
import net.aminecraftdev.custombosses.handlers.mobs.BossEntity;
import net.aminecraftdev.custombosses.handlers.mobs.MinionEntity;
import net.aminecraftdev.custombosses.innerapi.PotionUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import java.util.HashSet;
import java.util.Set;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class BossManager {
private static final Set<BossEntity> BOSSES = new HashSet<>();
private static final Set<MinionEntity> MINIONS = new HashSet<>();
private EntityHandler entityHandler;
private EquipmentHandler equipmentHandler;
public BossManager() {
this.entityHandler = new EntityHandler();
this.equipmentHandler = new EquipmentHandler();
}
public EntityHandler getEntityHandler() {
return entityHandler;
}
public EquipmentHandler getEquipmentHandler() {
return equipmentHandler;
}
public void applyPotionEffects(LivingEntity livingEntity, ConfigurationSection configurationSection) {
for(String s : configurationSection.getKeys(false)) {
PotionEffect potionEffect = PotionUtils.getPotionEffect(configurationSection.getConfigurationSection(s));
if(potionEffect == null) continue;
livingEntity.addPotionEffect(potionEffect);
}
}
}

View File

@ -0,0 +1,9 @@
package net.aminecraftdev.custombosses.target;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public interface ITarget {
}

View File

@ -0,0 +1,18 @@
package net.aminecraftdev.custombosses.target;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public enum TargetTypes {
VANILLA(),
DAMAGE(),
INTERVAL();
TargetTypes() {
}
}

View File

@ -0,0 +1,9 @@
package net.aminecraftdev.custombosses.target.types;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class TargetDamage {
}

View File

@ -0,0 +1,9 @@
package net.aminecraftdev.custombosses.target.types;
/**
* @author AMinecraftDev
* @version 1.0.0
* @since 31-May-17
*/
public class TargetInterval {
}