Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.redefocus.vender;
- import com.redefocus.*;
- import org.bukkit.inventory.meta.*;
- import java.util.*;
- import org.bukkit.entity.*;
- import org.bukkit.*;
- import org.bukkit.inventory.*;
- public class CaptchaGui
- {
- private final Integer[] SLOTS_POSSIVEIS;
- private HashMap<String, Integer> captchahash;
- private List<ItemStack> itens;
- public CaptchaGui(final Main plugin) {
- this.SLOTS_POSSIVEIS = new Integer[] { 10, 12, 14, 16 };
- this.captchahash = new HashMap<String, Integer>();
- this.carregarItens();
- }
- private void carregarItens() {
- this.itens = new ArrayList<ItemStack>();
- final ItemStack arco = this.Item(Material.BOW, 0, "§aArco", Arrays.asList("§7Clique para selecionar"));
- final ItemStack peixe = this.Item(Material.COOKED_FISH, 0, "§aPeixe", Arrays.asList("§7Clique para selecionar"));
- final ItemStack beacon = this.Item(Material.ANVIL, 0, "§aAnvil", Arrays.asList("§7Clique para selecionar"));
- final ItemStack ender = this.Item(Material.STICK, 0, "§aGraveto", Arrays.asList("§7Clique para selecionar"));
- this.itens.add(arco);
- this.itens.add(peixe);
- this.itens.add(beacon);
- this.itens.add(ender);
- }
- public ItemStack Item(final Material i, final int data, final String string, final List<String> lore) {
- final ItemStack item = new ItemStack(i, 1, (short)data);
- final ItemMeta meta = item.getItemMeta();
- meta.setDisplayName(string.replace("&", "§"));
- if (lore != null) {
- final List<String> lores = new ArrayList<String>();
- for (final String lor : lore) {
- lores.add(lor.replace("&", "§"));
- }
- meta.setLore((List)lores);
- }
- meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_ATTRIBUTES });
- meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_ENCHANTS });
- meta.addItemFlags(new ItemFlag[] { ItemFlag.HIDE_POTION_EFFECTS });
- item.setItemMeta(meta);
- return item;
- }
- public boolean inCaptcha(final String p) {
- return this.captchahash.containsKey(p);
- }
- public void remove(final String p) {
- this.captchahash.remove(p);
- }
- public int getSlot() {
- final Random r = new Random();
- final int aleatorio = r.nextInt(4);
- return this.SLOTS_POSSIVEIS[aleatorio];
- }
- public ItemStack getItem() {
- final Random r = new Random();
- final int aleatorio = r.nextInt(4);
- return this.itens.get(aleatorio);
- }
- public String getNome(final ItemStack item) {
- return item.getItemMeta().getDisplayName().replace("§a", "");
- }
- public void abrirCaptcha(final Player p) {
- final int numero = this.getSlot();
- this.captchahash.put(p.getName(), numero);
- final ItemStack item = this.getItem();
- final Inventory inv = this.criarInventario(numero, item);
- p.openInventory(inv);
- }
- public HashMap<String, Integer> isCaptcha() {
- return this.captchahash;
- }
- public Inventory criarInventario(final int slotCorreto, final ItemStack item) {
- final Inventory inv = Bukkit.createInventory((InventoryHolder)null, 27, "Clique no " + this.getNome(item) + ".");
- inv.setItem(slotCorreto, item);
- final List<ItemStack> itens = new ArrayList<ItemStack>();
- final List<Integer> slots = new ArrayList<Integer>();
- for (final ItemStack itemNovo : this.itens) {
- if (itemNovo.getType() == item.getType()) {
- continue;
- }
- itens.add(itemNovo);
- }
- Integer[] slots_POSSIVEIS;
- for (int length = (slots_POSSIVEIS = this.SLOTS_POSSIVEIS).length, j = 0; j < length; ++j) {
- final Integer slot = slots_POSSIVEIS[j];
- if (slot != slotCorreto) {
- slots.add(slot);
- }
- }
- for (int i = 0; i < slots.size(); ++i) {
- inv.setItem((int)slots.get(i), (ItemStack)itens.get(i));
- }
- return inv;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement