- Баллы
- 76
- Имя в Minecraft
- AguRChek_TV
При завершении открытия нужно поменять имя сундука при размещении сундука это работает
А после открытия нет. Помогите пожалуйста.
Код:
public static void setdropchestname1(Block block, String name) {
BlockState state = block.getState();
if(!(state instanceof Nameable)) return;
((Nameable) state).setCustomName(name);
state.update();
}
А после открытия нет. Помогите пожалуйста.
Код:
@EventHandler
public void interact(PlayerInteractEvent e) {
Player p = e.getPlayer();
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if(e.getClickedBlock().getType() == Material.CHEST) {
Block block = e.getClickedBlock();
Chest chest = (Chest) block.getState();
Inventory inv = chest.getSnapshotInventory();
if(chest.getCustomName().equals(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Locked")) {
inv.clear();
if(dropcd != 0) {
p.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "not so fast. please wait");
e.setCancelled(true);
return;
}
p.sendMessage("open");
dropcd = 11;
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 lootbox " + dropcd + " second");
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);
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);
inv.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);
}
}
}
}
public static void setdropchestname2(Block block, String name) {
BlockState state = block.getState();
if(!(state instanceof Nameable)) return;
((Nameable) state).setCustomName(name);
state.update();
}