Advertisement
Guest User

AnimationTimer (cred to dNiym)

a guest
Apr 30th, 2017
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.yhl;
  2. import java.util.HashMap;
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Material;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.inventory.Inventory;
  8. import org.bukkit.inventory.ItemStack;
  9. import org.bukkit.inventory.meta.ItemMeta;
  10.  
  11.  
  12. public class AnimationTimer implements Runnable {
  13.  
  14. HashMap<Inventory,Integer> instances = new HashMap<Inventory,Integer>();
  15. HashMap<Inventory,Integer> adding = new HashMap<Inventory,Integer>();
  16. HashMap<Player, Boolean> t = new HashMap<Player, Boolean>();
  17. double nextUpdate = 0L;
  18. int Progress = 0;
  19. int add = 1;
  20. Player p;
  21.  
  22. public void onEnable(){
  23. Miner m = Miner.getInstance();
  24.  
  25.  
  26. }
  27.  
  28. public AnimationTimer(Miner Miner) {
  29. }
  30.  
  31. public void getItem(Material item, String itemname,Inventory inv, int slot){
  32. ItemStack itemm = new ItemStack(item);
  33. ItemMeta tmeta = itemm.getItemMeta();
  34. tmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', itemname));
  35. itemm.setItemMeta(tmeta);
  36. inv.setItem(slot, itemm);
  37. }
  38.  
  39. public void setName(Player p, int slot, Inventory inv, String name){
  40.  
  41. inv.getItem(slot).getItemMeta().setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
  42.  
  43. }
  44.  
  45.  
  46.  
  47. public void setup(Player p)
  48. {
  49.  
  50. Inventory miner = Bukkit.createInventory(p, 45, ChatColor.GOLD + "" + ChatColor.BOLD + p.getName() + "'s Miner"); //add their name to it so its not able to be opened by others
  51.  
  52.  
  53.  
  54.  
  55. getItem(Material.COAL, "&4&lCOAL", miner, 31);
  56.  
  57. getItem(Material.REDSTONE_BLOCK, "&c&lOFF", miner, 29);
  58. getItem(Material.PAPER, "&cProgress: &4" + Progress + "&l%", miner, 33);
  59. miner.setItem(10, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  60. miner.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  61. miner.setItem(12, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  62. miner.setItem(13, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  63. miner.setItem(14, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  64. miner.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  65. miner.setItem(16, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  66. p.openInventory(miner);
  67. this.instances.put(miner,10);
  68.  
  69.  
  70. }
  71.  
  72.  
  73. @Override
  74. public void run() {
  75.  
  76.  
  77. HashMap<Inventory,Integer> updatedMap = new HashMap<Inventory,Integer>();
  78.  
  79. if(System.currentTimeMillis() <= this.nextUpdate)
  80. return;
  81.  
  82. double seconds = Miner.getInstance().messages.getInt("seconds");
  83.  
  84.  
  85. this.nextUpdate = System.currentTimeMillis() + (1000 * seconds);
  86.  
  87.  
  88. for(Inventory inv:instances.keySet())
  89. {
  90.  
  91. Player p = (Player) inv.getViewers().get(0);
  92. t.put(p, false);
  93. if(t.get(p) == true){
  94. int currentSlot = instances.get(inv);
  95. if(inv.getViewers().isEmpty())
  96. continue;
  97. if (currentSlot > 16) {
  98. resetBar(inv);
  99. currentSlot = 10;
  100. add = 1;
  101. }
  102.  
  103.  
  104.  
  105. inv.setItem(currentSlot, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)13)); //update the item
  106. p.updateInventory();
  107.  
  108. updatedMap.put(inv, currentSlot+1);
  109. adding.put(inv, add+1);
  110. Progress = add*14;
  111.  
  112.  
  113. ItemStack itemm = new ItemStack(Material.PAPER);
  114. ItemMeta tmeta = itemm.getItemMeta();
  115. tmeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&cProgress: &4" + Progress + "&l%"));
  116.  
  117.  
  118. inv.getItem(33).setAmount(add);
  119. setName(p, 33, inv, "&cProgress: &4" + Progress + "&l%");
  120. inv.getItem(33).setItemMeta(tmeta);
  121.  
  122.  
  123. p.updateInventory();
  124. add++;
  125. if(currentSlot == 9){
  126. add = 1;
  127. }
  128.  
  129. if(currentSlot == 16){
  130.  
  131. p.getInventory().addItem(new ItemStack(inv.getItem(31).getType()));
  132.  
  133. }
  134.  
  135.  
  136. this.instances.clear();
  137. this.instances.putAll(updatedMap);
  138. }
  139. }
  140.  
  141. }
  142.  
  143.  
  144.  
  145.  
  146. public void resetBar(Inventory miner){
  147. miner.setItem(10, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  148. miner.setItem(11, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  149. miner.setItem(12, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  150. miner.setItem(13, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  151. miner.setItem(14, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  152. miner.setItem(15, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  153. miner.setItem(16, new ItemStack(Material.STAINED_GLASS_PANE, 1, (short)14));
  154. }
  155.  
  156.  
  157. }
Advertisement
RAW Paste Data Copied
Advertisement