Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. package com.redefocus.vender;
  2.  
  3. import com.redefocus.*;
  4. import org.bukkit.inventory.meta.*;
  5. import java.util.*;
  6. import org.bukkit.entity.*;
  7. import org.bukkit.*;
  8. import org.bukkit.inventory.*;
  9.  
  10. public class CaptchaGui
  11. {
  12. private final Integer[] SLOTS_POSSIVEIS;
  13. private HashMap<String, Integer> captchahash;
  14. private List<ItemStack> itens;
  15.  
  16. public CaptchaGui(final Main plugin) {
  17. this.SLOTS_POSSIVEIS = new Integer[] { 10, 12, 14, 16 };
  18. this.captchahash = new HashMap<String, Integer>();
  19. this.carregarItens();
  20. }
  21.  
  22. private void carregarItens() {
  23. this.itens = new ArrayList<ItemStack>();
  24. final ItemStack arco = this.Item(Material.BOW, 0, "§aArco", Arrays.asList("§7Clique para selecionar"));
  25. final ItemStack peixe = this.Item(Material.COOKED_FISH, 0, "§aPeixe", Arrays.asList("§7Clique para selecionar"));
  26. final ItemStack beacon = this.Item(Material.ANVIL, 0, "§aAnvil", Arrays.asList("§7Clique para selecionar"));
  27. final ItemStack ender = this.Item(Material.STICK, 0, "§aGraveto", Arrays.asList("§7Clique para selecionar"));
  28. this.itens.add(arco);
  29. this.itens.add(peixe);
  30. this.itens.add(beacon);
  31. this.itens.add(ender);
  32. }
  33.  
  34. public ItemStack Item(final Material i, final int data, final String string, final List<String> lore) {
  35. final ItemStack item = new ItemStack(i, 1, (short)data);
  36. final ItemMeta meta = item.getItemMeta();
  37. meta.setDisplayName(string.replace("&", "§"));
  38. if (lore != null) {
  39. final List<String> lores = new ArrayList<String>();
  40. for (final String lor : lore) {
  41. lores.add(lor.replace("&", "§"));
  42. }
  43. meta.setLore((List)lores);
  44. }
  45. meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_ATTRIBUTES });
  46. meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_ENCHANTS });
  47. meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_POTION_EFFECTS });
  48. item.setItemMeta(meta);
  49. return item;
  50. }
  51.  
  52. public boolean inCaptcha(final String p) {
  53. return this.captchahash.containsKey(p);
  54. }
  55.  
  56. public void remove(final String p) {
  57. this.captchahash.remove(p);
  58. }
  59.  
  60. public int getSlot() {
  61. final Random r = new Random();
  62. final int aleatorio = r.nextInt(4);
  63. return this.SLOTS_POSSIVEIS[aleatorio];
  64. }
  65.  
  66. public ItemStack getItem() {
  67. final Random r = new Random();
  68. final int aleatorio = r.nextInt(4);
  69. return this.itens.get(aleatorio);
  70. }
  71.  
  72. public String getNome(final ItemStack item) {
  73. return item.getItemMeta().getDisplayName().replace("§a", "");
  74. }
  75.  
  76. public void abrirCaptcha(final Player p) {
  77. final int numero = this.getSlot();
  78. this.captchahash.put(p.getName(), numero);
  79. final ItemStack item = this.getItem();
  80. final Inventory inv = this.criarInventario(numero, item);
  81. p.openInventory(inv);
  82. }
  83.  
  84. public HashMap<String, Integer> isCaptcha() {
  85. return this.captchahash;
  86. }
  87.  
  88. public Inventory criarInventario(final int slotCorreto, final ItemStack item) {
  89. final Inventory inv = Bukkit.createInventory((InventoryHolder)null, 27, "Clique no " + this.getNome(item) + ".");
  90. inv.setItem(slotCorreto, item);
  91. final List<ItemStack> itens = new ArrayList<ItemStack>();
  92. final List<Integer> slots = new ArrayList<Integer>();
  93. for (final ItemStack itemNovo : this.itens) {
  94. if (itemNovo.getType() == item.getType()) {
  95. continue;
  96. }
  97. itens.add(itemNovo);
  98. }
  99. Integer[] slots_POSSIVEIS;
  100. for (int length = (slots_POSSIVEIS = this.SLOTS_POSSIVEIS).length, j = 0; j < length; ++j) {
  101. final Integer slot = slots_POSSIVEIS[j];
  102. if (slot != slotCorreto) {
  103. slots.add(slot);
  104. }
  105. }
  106. for (int i = 0; i < slots.size(); ++i) {
  107. inv.setItem((int)slots.get(i), (ItemStack)itens.get(i));
  108. }
  109. return inv;
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement