Помогите Добавление предметов в сундука при открытии игроком

AguRChek_TV

Активный участник
Пользователь
Баллы
76
Имя в Minecraft
AguRChek_TV
Добавление предметов в сундука при открытии игроком
Мне нужно сделать так что бы при открытии сундука по завершению таймера внутри него в него добавляется определённый лут. я пробовал сделать так но предметы на добавляются. Помогите пожалуйста.
Код:
            if(e.getClickedBlock().getType() == Material.CHEST) {
                Block block = e.getClickedBlock();
                Chest chest = (Chest) block.getState();
                Inventory inv = chest.getInventory();
                if(chest.getCustomName().equals(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Locked")) {
                    if(dropcd != 0) {
                        p.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "not so fast. please wait");
                        e.setCancelled(true);
                        return;
                    }
                    p.sendMessage("open");
                    dropcd = 21;
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            dropcd--;
                            ItemStack cd = new ItemStack(Material.PLAYER_HEAD, dropcd);
                            SkullMeta meta = (SkullMeta) cd.getItemMeta();
                            meta.setOwner("MHF_Chest");
                            meta.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "before opening the box " + dropcd);
                            ArrayList<String> lore = new ArrayList<String>();
                            lore.add(ChatColor.WHITE + "" + ChatColor.BOLD + "This box may contain a lot of valuable Loot");
                            lore.add(ChatColor.WHITE + "" + ChatColor.BOLD + "use it correctly as long as you open the box you can be killed");
                            meta.setLore(lore);
                            cd.setItemMeta(meta);
                            chest.update(true);
                            inv.setItem(13, cd);
                            chest.update(true);
                            for(Player ps : Bukkit.getOnlinePlayers()) {
                                ps.sendMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + "" + dropcd);
                            }
                            if(dropcd == 0) {
                                String name = (ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Opened");
                                setdropchestname2(block, name);
                                chest.getBlockInventory().clear();
                                ItemStack diamond_sword = new ItemStack(Material.DIAMOND_SWORD, 1);
                                ItemStack golden_apple = new ItemStack(Material.GOLDEN_APPLE, 1);
                                ItemStack enderpearl = new ItemStack(Material.ENDER_PEARL, 2);
                                inv.addItem(diamond_sword, golden_apple, enderpearl);
                                chest.update(true);
                                p.sendMessage("end");
                                this.cancel();
                            }
                            if(p.getOpenInventory().getType() != InventoryType.CHEST) {
                                dropcd = 0;
                                p.sendMessage("clouse");
                                inv.clear();
                                chest.update(true);
                                this.cancel();
                            }
                        }
                    }.runTaskTimer(this, 0, 20);
                }
            }
 
Делаешь шедулер который каждый раз заполняет сундук рандомными итемами, в чем трабл
 
Назад
Верх