Advertisement
Guest User

Pião do Baú

a guest
Dec 18th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. public class BoxScroller implements Runnable{
  2.  
  3. private Player p;
  4. private int[] slots_roda = {4, 13, 22, 31, 40};
  5. private boolean end = false;
  6. private Inventory gui;
  7. private int index = 0;
  8. private int max = 0;
  9. private Caixa caixa = null;
  10.  
  11. public BoxScroller(Player p, Caixa caixa, Inventory inv) {
  12. this.p = p;
  13. this.caixa = caixa;
  14. setGui(inv);
  15. }
  16. private void setGui(Inventory inv) {
  17. this.gui = inv;
  18. loadGui();
  19. }
  20. @SuppressWarnings("deprecation")
  21. private void loadGui(){
  22.  
  23. //gui = Bukkit.createInventory(null, 5*9, "Sorteando...");
  24.  
  25. gui.setItem(0, getVidro(6));
  26. gui.setItem(1, getVidro(5));
  27. gui.setItem(2, getVidro(7));
  28. gui.setItem(3, getVidro(10));
  29. gui.setItem(5, getVidro(15));
  30. gui.setItem(6, getVidro(14));
  31. gui.setItem(7, getVidro(0));
  32. gui.setItem(8, getVidro(1));
  33. gui.setItem(9, getVidro(8));
  34. gui.setItem(10, getVidro(4));
  35. gui.setItem(11, getVidro(6));
  36. gui.setItem(12, getVidro(7));
  37. gui.setItem(14, getVidro(3));
  38. gui.setItem(15, getVidro(2));
  39. gui.setItem(16, getVidro(9));
  40. gui.setItem(17, getVidro(8));
  41. gui.setItem(18, getVidro(12));
  42. gui.setItem(19, getVidro(14));
  43. gui.setItem(20, getVidro(15));
  44. gui.setItem(24, getVidro(7));
  45. gui.setItem(25, getVidro(6));
  46. gui.setItem(26, getVidro(2));
  47. gui.setItem(27, getVidro(1));
  48. gui.setItem(28, getVidro(6));
  49. gui.setItem(29, getVidro(5));
  50. gui.setItem(30, getVidro(4));
  51. gui.setItem(31, getVidro(3));
  52. gui.setItem(33, getVidro(9));
  53. gui.setItem(34, getVidro(7));
  54. gui.setItem(35, getVidro(8));
  55. gui.setItem(36, getVidro(2));
  56. gui.setItem(37, getVidro(10));
  57. gui.setItem(38, getVidro(12));
  58. gui.setItem(39, getVidro(10));
  59. gui.setItem(40, getVidro(5));
  60. gui.setItem(41, getVidro(2));
  61. gui.setItem(42, getVidro(11));
  62. gui.setItem(43, getVidro(12));
  63. gui.setItem(44, getVidro(9));
  64. gui.setItem(32, getVidro(4));
  65.  
  66. ItemStack item1 = new ItemStack(351, 1, (short)8);
  67. ItemMeta meta1 = item1.getItemMeta();
  68. meta1.setDisplayName("§a---->");
  69. item1.setItemMeta(meta1);
  70.  
  71. ItemStack item2 = new ItemStack(351, 1, (short)8);
  72. ItemMeta meta2 = item2.getItemMeta();
  73. meta2.setDisplayName("§a<----");
  74. item2.setItemMeta(meta2);
  75.  
  76. gui.setItem(21, Main.addGlow(item1));
  77. gui.setItem(23, Main.addGlow(item2));
  78. }
  79. @SuppressWarnings("deprecation")
  80. private ItemStack getVidro(int data){
  81. ItemStack item = new ItemStack(Material.getMaterial(160), 1, (short)data);
  82. ItemMeta meta = item.getItemMeta();
  83. meta.setDisplayName("§c");
  84. item.setItemMeta(meta);
  85. return item;
  86. }
  87.  
  88. public Caixa getBox(){
  89. return this.caixa;
  90. }
  91. public int getMax(){
  92. return this.max;
  93. }
  94. public int getIndex(){
  95. return this.index;
  96. }
  97. public boolean isEnd(){
  98. return this.end;
  99. }
  100. public void setEnd(boolean end){
  101. this.end = end;
  102. }
  103. public Inventory getGui(){
  104. return this.gui;
  105. }
  106.  
  107. @Override
  108. public void run() {
  109. max = 80;
  110. int atual = 0;
  111. int start = 100;
  112. while (!end){
  113. if (p == null){
  114. end = true;
  115. Main.getCache().remove(p);
  116. }
  117. index++;
  118. atual++;
  119. if (start > 0){
  120. rodar();
  121. sleep(100);
  122. start = start - 25;
  123. p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 10, 2);
  124. } else {
  125. if (atual >= max){
  126. rodar();
  127. p.playSound(p.getLocation(), Sound.LEVEL_UP, 10, 2);
  128. sleep(1300);
  129. Main.getCache().remove(p);
  130. p.closeInventory();
  131. ItemStack i = gui.getItem(22);
  132.  
  133. FileConfiguration c = Main.getInstance().getConfig();
  134.  
  135. String path = caixa.getHashPath().get(i);
  136.  
  137. boolean give = c.getBoolean(path + ".give");
  138. String categoria = c.getString(path + ".categoria");
  139. boolean clear = c.getBoolean(path + ".clear_item");
  140.  
  141. if (give) {
  142.  
  143. ItemStack toGive = i.clone();
  144. if (clear) {
  145. ItemMeta meta = toGive.getItemMeta();
  146. meta.setDisplayName(null);
  147. meta.setLore(null);
  148. toGive.setItemMeta(meta);
  149. }
  150.  
  151. p.getInventory().addItem(toGive);
  152.  
  153. }
  154.  
  155. if (Main.getCIL().getCmds(c, path).contains("-|-")) {
  156. for (String cmd : Main.getCIL().getCmds(c, path).split("-|-")) {
  157. if (!cmd.equalsIgnoreCase("")) {
  158. //System.out.println(cmd);
  159. Main.getCmds().add(cmd.replace("@player", p.getName()));
  160. }
  161. }
  162. }
  163.  
  164. if (categoria.equalsIgnoreCase("raro")) {
  165. Bukkit.broadcastMessage("§e[Caixas] §f" + p.getName() + "§e ganhou um item §5§lRARO§e na caixa §r" + getDisplay());
  166. }
  167. Main.getFireworkQueue().add(p);
  168. end = true;
  169. Main.getR_h().add(p);
  170. } else {
  171. rodar();
  172. sleep(95);
  173. p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 10, 2);
  174. }
  175. }
  176. }
  177. }
  178. public String getDisplay() {
  179. if (caixa.getType() == BoxType.ADVANCED) {
  180. return "§bAvançada";
  181. }
  182. if (caixa.getType() == BoxType.BASIC) {
  183. return "§eBásica";
  184. }
  185. if (caixa.getType() == BoxType.ULTRA) {
  186. return "§4Ultra";
  187. }
  188. return "";
  189. }
  190. private void sleep(int s){
  191. try {
  192. Thread.sleep(s);
  193. } catch (InterruptedException e) {
  194. // TODO Auto-generated catch block
  195. e.printStackTrace();
  196. }
  197. }
  198. private void rodar(){
  199.  
  200. gui.setItem(slots_roda[4], gui.getItem(slots_roda[3]));
  201. gui.setItem(slots_roda[3], gui.getItem(slots_roda[2]));
  202. gui.setItem(slots_roda[2], gui.getItem(slots_roda[1]));
  203. gui.setItem(slots_roda[1], gui.getItem(slots_roda[0]));
  204. gui.setItem(slots_roda[0], getRandom());
  205. }
  206. private ItemStack getRandom() {
  207. Random r = new Random();
  208. int index = r.nextInt(caixa.getContents().split(",").length);
  209. //System.out.println(caixa.getContents().split(",")[index]);
  210. if (caixa.getType() == BoxType.ADVANCED) {
  211. return caixa.getHashChance().get("Advanced." + caixa.getContents().split(",")[index]);
  212. }
  213. if (caixa.getType() == BoxType.BASIC) {
  214. return caixa.getHashChance().get("Basica." + caixa.getContents().split(",")[index]);
  215. }
  216. if (caixa.getType() == BoxType.ULTRA) {
  217. return caixa.getHashChance().get("Ultra." + caixa.getContents().split(",")[index]);
  218. }
  219. return null;
  220. }
  221.  
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement