Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BoxScroller implements Runnable{
- private Player p;
- private int[] slots_roda = {4, 13, 22, 31, 40};
- private boolean end = false;
- private Inventory gui;
- private int index = 0;
- private int max = 0;
- private Caixa caixa = null;
- public BoxScroller(Player p, Caixa caixa, Inventory inv) {
- this.p = p;
- this.caixa = caixa;
- setGui(inv);
- }
- private void setGui(Inventory inv) {
- this.gui = inv;
- loadGui();
- }
- @SuppressWarnings("deprecation")
- private void loadGui(){
- //gui = Bukkit.createInventory(null, 5*9, "Sorteando...");
- gui.setItem(0, getVidro(6));
- gui.setItem(1, getVidro(5));
- gui.setItem(2, getVidro(7));
- gui.setItem(3, getVidro(10));
- gui.setItem(5, getVidro(15));
- gui.setItem(6, getVidro(14));
- gui.setItem(7, getVidro(0));
- gui.setItem(8, getVidro(1));
- gui.setItem(9, getVidro(8));
- gui.setItem(10, getVidro(4));
- gui.setItem(11, getVidro(6));
- gui.setItem(12, getVidro(7));
- gui.setItem(14, getVidro(3));
- gui.setItem(15, getVidro(2));
- gui.setItem(16, getVidro(9));
- gui.setItem(17, getVidro(8));
- gui.setItem(18, getVidro(12));
- gui.setItem(19, getVidro(14));
- gui.setItem(20, getVidro(15));
- gui.setItem(24, getVidro(7));
- gui.setItem(25, getVidro(6));
- gui.setItem(26, getVidro(2));
- gui.setItem(27, getVidro(1));
- gui.setItem(28, getVidro(6));
- gui.setItem(29, getVidro(5));
- gui.setItem(30, getVidro(4));
- gui.setItem(31, getVidro(3));
- gui.setItem(33, getVidro(9));
- gui.setItem(34, getVidro(7));
- gui.setItem(35, getVidro(8));
- gui.setItem(36, getVidro(2));
- gui.setItem(37, getVidro(10));
- gui.setItem(38, getVidro(12));
- gui.setItem(39, getVidro(10));
- gui.setItem(40, getVidro(5));
- gui.setItem(41, getVidro(2));
- gui.setItem(42, getVidro(11));
- gui.setItem(43, getVidro(12));
- gui.setItem(44, getVidro(9));
- gui.setItem(32, getVidro(4));
- ItemStack item1 = new ItemStack(351, 1, (short)8);
- ItemMeta meta1 = item1.getItemMeta();
- meta1.setDisplayName("§a---->");
- item1.setItemMeta(meta1);
- ItemStack item2 = new ItemStack(351, 1, (short)8);
- ItemMeta meta2 = item2.getItemMeta();
- meta2.setDisplayName("§a<----");
- item2.setItemMeta(meta2);
- gui.setItem(21, Main.addGlow(item1));
- gui.setItem(23, Main.addGlow(item2));
- }
- @SuppressWarnings("deprecation")
- private ItemStack getVidro(int data){
- ItemStack item = new ItemStack(Material.getMaterial(160), 1, (short)data);
- ItemMeta meta = item.getItemMeta();
- meta.setDisplayName("§c");
- item.setItemMeta(meta);
- return item;
- }
- public Caixa getBox(){
- return this.caixa;
- }
- public int getMax(){
- return this.max;
- }
- public int getIndex(){
- return this.index;
- }
- public boolean isEnd(){
- return this.end;
- }
- public void setEnd(boolean end){
- this.end = end;
- }
- public Inventory getGui(){
- return this.gui;
- }
- @Override
- public void run() {
- max = 80;
- int atual = 0;
- int start = 100;
- while (!end){
- if (p == null){
- end = true;
- Main.getCache().remove(p);
- }
- index++;
- atual++;
- if (start > 0){
- rodar();
- sleep(100);
- start = start - 25;
- p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 10, 2);
- } else {
- if (atual >= max){
- rodar();
- p.playSound(p.getLocation(), Sound.LEVEL_UP, 10, 2);
- sleep(1300);
- Main.getCache().remove(p);
- p.closeInventory();
- ItemStack i = gui.getItem(22);
- FileConfiguration c = Main.getInstance().getConfig();
- String path = caixa.getHashPath().get(i);
- boolean give = c.getBoolean(path + ".give");
- String categoria = c.getString(path + ".categoria");
- boolean clear = c.getBoolean(path + ".clear_item");
- if (give) {
- ItemStack toGive = i.clone();
- if (clear) {
- ItemMeta meta = toGive.getItemMeta();
- meta.setDisplayName(null);
- meta.setLore(null);
- toGive.setItemMeta(meta);
- }
- p.getInventory().addItem(toGive);
- }
- if (Main.getCIL().getCmds(c, path).contains("-|-")) {
- for (String cmd : Main.getCIL().getCmds(c, path).split("-|-")) {
- if (!cmd.equalsIgnoreCase("")) {
- //System.out.println(cmd);
- Main.getCmds().add(cmd.replace("@player", p.getName()));
- }
- }
- }
- if (categoria.equalsIgnoreCase("raro")) {
- Bukkit.broadcastMessage("§e[Caixas] §f" + p.getName() + "§e ganhou um item §5§lRARO§e na caixa §r" + getDisplay());
- }
- Main.getFireworkQueue().add(p);
- end = true;
- Main.getR_h().add(p);
- } else {
- rodar();
- sleep(95);
- p.playSound(p.getLocation(), Sound.CHICKEN_EGG_POP, 10, 2);
- }
- }
- }
- }
- public String getDisplay() {
- if (caixa.getType() == BoxType.ADVANCED) {
- return "§bAvançada";
- }
- if (caixa.getType() == BoxType.BASIC) {
- return "§eBásica";
- }
- if (caixa.getType() == BoxType.ULTRA) {
- return "§4Ultra";
- }
- return "";
- }
- private void sleep(int s){
- try {
- Thread.sleep(s);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- private void rodar(){
- gui.setItem(slots_roda[4], gui.getItem(slots_roda[3]));
- gui.setItem(slots_roda[3], gui.getItem(slots_roda[2]));
- gui.setItem(slots_roda[2], gui.getItem(slots_roda[1]));
- gui.setItem(slots_roda[1], gui.getItem(slots_roda[0]));
- gui.setItem(slots_roda[0], getRandom());
- }
- private ItemStack getRandom() {
- Random r = new Random();
- int index = r.nextInt(caixa.getContents().split(",").length);
- //System.out.println(caixa.getContents().split(",")[index]);
- if (caixa.getType() == BoxType.ADVANCED) {
- return caixa.getHashChance().get("Advanced." + caixa.getContents().split(",")[index]);
- }
- if (caixa.getType() == BoxType.BASIC) {
- return caixa.getHashChance().get("Basica." + caixa.getContents().split(",")[index]);
- }
- if (caixa.getType() == BoxType.ULTRA) {
- return caixa.getHashChance().get("Ultra." + caixa.getContents().split(",")[index]);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement