Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.13 KB | None | 0 0
  1. private UUID owner;
  2. private MinionType minionType;
  3. private Location location;
  4. private World world;
  5. private int health;
  6. private int max_health;
  7. private int hunger;
  8. private UUID entityID;
  9. private ArmorStand minion;
  10.  
  11. public Minion(UUID owner, MinionType type, Location location, int health, int hunger, int max_health){
  12. setWorld(location.getWorld());
  13. setOwner(owner);
  14. setMinionType(type);
  15. setLocation(location);
  16. setHealth(health);
  17. setHunger(hunger);
  18. setMaxHealth(max_health);
  19.  
  20. load();
  21.  
  22. CloudBlock.getInstance().getMinionManager().activeMinions.put(Bukkit.getPlayer(owner), this);
  23.  
  24. this.runTaskTimer(CloudBlock.getInstance(), 0L, 2L);
  25. }
  26.  
  27. /**
  28. * ================================================================================================
  29. * GET & SET MINION LOCATION (+ other location methods)
  30. * ================================================================================================
  31. */
  32.  
  33. private boolean canSpawn(Location location){
  34. if(location.add(0, 1, 0).getBlock().isEmpty()){
  35. return true;
  36. }
  37. return false;
  38. }
  39.  
  40. public Location getLocation(){
  41. return location;
  42. }
  43.  
  44. public void setLocation(Location location){
  45. this.location = location;
  46. }
  47.  
  48. public void setWorld(World world){
  49. this.world = world;
  50. }
  51.  
  52. public World getWorld(){
  53. return world;
  54. }
  55.  
  56. /**
  57. * ================================================================================================
  58. * GET & SET MINION OWNER
  59. * ================================================================================================
  60. */
  61.  
  62. //get & set owner of the minion.
  63. public UUID getOwner(){ return owner; }
  64.  
  65. public void setOwner(UUID uuid){ owner = uuid; }
  66.  
  67. /**
  68. * ================================================================================================
  69. * GET & SET MINION TYPE
  70. * ================================================================================================
  71. */
  72.  
  73. //get the minion type
  74. public MinionType getMinionType(){
  75. return minionType;
  76. }
  77.  
  78. public void setMinionType(MinionType minionType){
  79. this.minionType = minionType;
  80. }
  81.  
  82. /**
  83. * ================================================================================================
  84. * HEALTH & HUNGER
  85. * ================================================================================================
  86. */
  87.  
  88. //set and get health and hunger
  89. public int getHealth(){
  90. return health;
  91. }
  92.  
  93. public void setHealth(int health){
  94. this.health = health;
  95. }
  96.  
  97.  
  98. public void heal(int heal){
  99. health += heal;
  100. }
  101.  
  102. public void heal(){
  103. health = max_health;
  104. }
  105.  
  106. public void hurt(int amount){
  107. health -= amount;
  108. if(health <= 0){
  109. destroy();
  110. }
  111. }
  112.  
  113. public void setHunger(int hunger){
  114. this.hunger = hunger;
  115. }
  116.  
  117. public void setMaxHealth(int health){
  118. this.max_health = health;
  119. }
  120.  
  121. /**
  122. * ================================================================================================
  123. * LOAD & DESTROY
  124. * ================================================================================================
  125. */
  126.  
  127. public void load(){
  128. minion = getWorld().spawn(location, ArmorStand.class);
  129. minion.setSmall(true);
  130. minion.setGravity(false);
  131. minion.setVisible(true);
  132. minion.setCustomName(Bukkit.getPlayer(owner).getName() + "'s Mining Minion [" + getHealth() + "]");
  133. minion.setCustomNameVisible(true);
  134. minion.setArms(true);
  135. minion.setBasePlate(false);
  136.  
  137. switch (minionType)
  138. {
  139. case MINING_MINION:
  140.  
  141. /**
  142. * ==================================================================
  143. * Item Stack data for mining minion
  144. * ==================================================================
  145. */
  146.  
  147. //=====================================================================
  148. // Helmet
  149. ItemStack healmet = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
  150.  
  151. SkullMeta healmetMeta = (SkullMeta) healmet.getItemMeta();
  152.  
  153. healmetMeta.setOwner(Bukkit.getPlayer(owner).getName()); //Change this username to skin of minion when we find one.
  154.  
  155. healmet.setItemMeta(healmetMeta);
  156.  
  157. //=====================================================================
  158.  
  159. //=====================================================================
  160. // Chestplate
  161.  
  162. ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
  163.  
  164. LeatherArmorMeta chestplateMeta = (LeatherArmorMeta) chestplate.getItemMeta();
  165.  
  166. chestplateMeta.setColor(Color.YELLOW);
  167.  
  168. chestplate.setItemMeta(chestplateMeta);
  169.  
  170. //=====================================================================
  171.  
  172.  
  173. //=====================================================================
  174. //Leggings
  175.  
  176. ItemStack leggings = new ItemStack(Material.LEATHER_LEGGINGS);
  177.  
  178. LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) leggings.getItemMeta();
  179.  
  180. leggingsMeta.setColor(Color.YELLOW);
  181.  
  182. leggings.setItemMeta(leggingsMeta);
  183.  
  184. //=====================================================================
  185.  
  186. //=====================================================================
  187. //Boots
  188.  
  189. ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
  190.  
  191. LeatherArmorMeta bootsMeta = (LeatherArmorMeta) boots.getItemMeta();
  192.  
  193. bootsMeta.setColor(Color.YELLOW);
  194.  
  195. boots.setItemMeta(bootsMeta);
  196.  
  197. //=====================================================================
  198.  
  199. //=====================================================================
  200. //Diamond Pick In Hand
  201.  
  202. ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE);
  203.  
  204. //=====================================================================
  205.  
  206. //Set the minions gear
  207. minion.setHelmet(healmet);
  208. minion.setChestplate(chestplate);
  209. minion.setLeggings(leggings);
  210. minion.setBoots(boots);
  211. minion.setItemInHand(pick);
  212. }
  213. entityID = minion.getUniqueId();
  214. }
  215.  
  216. public void destroy(){
  217. for(Entity entity : world.getEntities()){
  218. if(entity.getUniqueId().equals(entityID)){
  219. entity.remove();
  220. }
  221. }
  222. }
  223.  
  224.  
  225. /**
  226. * ================================================================================================
  227. * ANIMATION
  228. * ================================================================================================
  229. */
  230.  
  231. private double armPos = -0.1;
  232.  
  233. private boolean down = false;
  234.  
  235.  
  236. public void run(){
  237. if(minion == null || !minion.isValid()){
  238. cancel();
  239. return;
  240. }
  241.  
  242. minion.setRightArmPose(new EulerAngle(-Math.abs(armPos), 0, 0));
  243.  
  244. if(down){
  245. armPos -= 0.2;
  246. if(armPos <= 0.6){
  247. down = false;
  248. }
  249. }else {
  250. armPos += 0.2;
  251. if(armPos >= 2){
  252. down = true;
  253. }
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement