Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private UUID owner;
- private MinionType minionType;
- private Location location;
- private World world;
- private int health;
- private int max_health;
- private int hunger;
- private UUID entityID;
- private ArmorStand minion;
- public Minion(UUID owner, MinionType type, Location location, int health, int hunger, int max_health){
- setWorld(location.getWorld());
- setOwner(owner);
- setMinionType(type);
- setLocation(location);
- setHealth(health);
- setHunger(hunger);
- setMaxHealth(max_health);
- load();
- CloudBlock.getInstance().getMinionManager().activeMinions.put(Bukkit.getPlayer(owner), this);
- this.runTaskTimer(CloudBlock.getInstance(), 0L, 2L);
- }
- /**
- * ================================================================================================
- * GET & SET MINION LOCATION (+ other location methods)
- * ================================================================================================
- */
- private boolean canSpawn(Location location){
- if(location.add(0, 1, 0).getBlock().isEmpty()){
- return true;
- }
- return false;
- }
- public Location getLocation(){
- return location;
- }
- public void setLocation(Location location){
- this.location = location;
- }
- public void setWorld(World world){
- this.world = world;
- }
- public World getWorld(){
- return world;
- }
- /**
- * ================================================================================================
- * GET & SET MINION OWNER
- * ================================================================================================
- */
- //get & set owner of the minion.
- public UUID getOwner(){ return owner; }
- public void setOwner(UUID uuid){ owner = uuid; }
- /**
- * ================================================================================================
- * GET & SET MINION TYPE
- * ================================================================================================
- */
- //get the minion type
- public MinionType getMinionType(){
- return minionType;
- }
- public void setMinionType(MinionType minionType){
- this.minionType = minionType;
- }
- /**
- * ================================================================================================
- * HEALTH & HUNGER
- * ================================================================================================
- */
- //set and get health and hunger
- public int getHealth(){
- return health;
- }
- public void setHealth(int health){
- this.health = health;
- }
- public void heal(int heal){
- health += heal;
- }
- public void heal(){
- health = max_health;
- }
- public void hurt(int amount){
- health -= amount;
- if(health <= 0){
- destroy();
- }
- }
- public void setHunger(int hunger){
- this.hunger = hunger;
- }
- public void setMaxHealth(int health){
- this.max_health = health;
- }
- /**
- * ================================================================================================
- * LOAD & DESTROY
- * ================================================================================================
- */
- public void load(){
- minion = getWorld().spawn(location, ArmorStand.class);
- minion.setSmall(true);
- minion.setGravity(false);
- minion.setVisible(true);
- minion.setCustomName(Bukkit.getPlayer(owner).getName() + "'s Mining Minion [" + getHealth() + "]");
- minion.setCustomNameVisible(true);
- minion.setArms(true);
- minion.setBasePlate(false);
- switch (minionType)
- {
- case MINING_MINION:
- /**
- * ==================================================================
- * Item Stack data for mining minion
- * ==================================================================
- */
- //=====================================================================
- // Helmet
- ItemStack healmet = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
- SkullMeta healmetMeta = (SkullMeta) healmet.getItemMeta();
- healmetMeta.setOwner(Bukkit.getPlayer(owner).getName()); //Change this username to skin of minion when we find one.
- healmet.setItemMeta(healmetMeta);
- //=====================================================================
- //=====================================================================
- // Chestplate
- ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
- LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) chestplate.getItemMeta();
- chestplateMeta.setColor(Color.YELLOW);
- chestplate.setItemMeta(chestplateMeta);
- //=====================================================================
- //=====================================================================
- //Leggings
- ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
- LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leggings.getItemMeta();
- leggingsMeta.setColor(Color.YELLOW);
- leggings.setItemMeta(leggingsMeta);
- //=====================================================================
- //=====================================================================
- //Boots
- ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
- LeatherArmorMeta bootsMeta = (LeatherArmorMeta) boots.getItemMeta();
- bootsMeta.setColor(Color.YELLOW);
- boots.setItemMeta(bootsMeta);
- //=====================================================================
- //=====================================================================
- //Diamond Pick In Hand
- ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE);
- //=====================================================================
- //Set the minions gear
- minion.setHelmet(healmet);
- minion.setChestplate(chestplate);
- minion.setLeggings(leggings);
- minion.setBoots(boots);
- minion.setItemInHand(pick);
- }
- entityID = minion.getUniqueId();
- }
- public void destroy(){
- for(Entity entity : world.getEntities()){
- if(entity.getUniqueId().equals(entityID)){
- entity.remove();
- }
- }
- }
- /**
- * ================================================================================================
- * ANIMATION
- * ================================================================================================
- */
- private double armPos = -0.1;
- private boolean down = false;
- public void run(){
- if(minion == null || !minion.isValid()){
- cancel();
- return;
- }
- minion.setRightArmPose(new EulerAngle(-Math.abs(armPos), 0, 0));
- if(down){
- armPos -= 0.2;
- if(armPos <= 0.6){
- down = false;
- }
- }else {
- armPos += 0.2;
- if(armPos >= 2){
- down = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement