- Баллы
- 76
- Имя в Minecraft
- AguRChek_TV
я пытаюсь сделать дропы которые будет появляться рандомно по миру.
на открытие сундука нужно 20 секунд по истечению которых сундук должен открыться.
но если сундук открывают сразу несколько игроков то название обновляется только у тога игрока кто начал открывать сундук первый. а у остальных только после повторного открытия как это исправить помогите пожалуйста.
Код:
@Override
public void onEnable() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
if(todroptime == 0) {
todroptime = 120;
Location loc = (new Location(Bukkit.getWorld("world2"), rx, Bukkit.getWorld("world2").getHighestBlockYAt(rx, rz), rz));
loc.getBlock().setType(Material.CHEST);
Chest chest = (Chest) loc.getBlock().getState();
String name = (ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Locked");
setdropchestname1(loc.getBlock(), name);
if(rloc == 1) {
rloc = 0;
Location standloc1 = (new Location(Bukkit.getWorld("world2"), rx + 0.5, Bukkit.getWorld("world2").getHighestBlockYAt(rx, rz), rz + 0.5));
ArmorStand drop = (ArmorStand) Bukkit.getWorld("world2").spawnEntity(standloc1, EntityType.ARMOR_STAND);
drop.setCustomNameVisible(true);
drop.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + "fallen lootbox");
drop.setVisible(false);
drop.setMarker(true);
File drops = new File(plugin.getDataFolder() + File.separator + "drops.yml");
FileConfiguration dropcords = YamlConfiguration.loadConfiguration(drops);
List<String> list = plugin.getConfig().getStringList("drops");
list.add("Namber" + dropnamber + "-" + rx + "," + ry + "," + rz);
try {
dropcords.save(drops);
}
catch (IOException e) {
}
}
if(rloc == 2) {
rloc = 0;
Location standloc2 = (new Location(Bukkit.getWorld("world2"), rx + 0.5, Bukkit.getWorld("world2").getHighestBlockYAt(rx, rz), rz + 0.5));
ArmorStand drop = (ArmorStand) Bukkit.getWorld("world2").spawnEntity(standloc2, EntityType.ARMOR_STAND);
drop.setCustomNameVisible(true);
drop.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + "fallen lootbox");
drop.setVisible(false);
drop.setMarker(true);
}
if(rloc == 3) {
rloc = 0;
Location standloc3 = (new Location(Bukkit.getWorld("world2"), rx + 0.5, Bukkit.getWorld("world2").getHighestBlockYAt(rx, rz), rz + 0.5));
ArmorStand drop = (ArmorStand) Bukkit.getWorld("world2").spawnEntity(standloc3, EntityType.ARMOR_STAND);
drop.setCustomNameVisible(true);
drop.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + "fallen lootbox");
drop.setVisible(false);
drop.setMarker(true);
}
if(rloc == 4) {
rloc = 0;
Location standloc4 = (new Location(Bukkit.getWorld("world2"), rx + 0.5, Bukkit.getWorld("world2").getHighestBlockYAt(rx, rz), rz + 0.5));
ArmorStand drop = (ArmorStand) Bukkit.getWorld("world2").spawnEntity(standloc4, EntityType.ARMOR_STAND);
drop.setCustomNameVisible(true);
drop.setCustomName(ChatColor.AQUA + "" + ChatColor.BOLD + "fallen lootbox");
drop.setVisible(false);
drop.setMarker(true);
}
}
todroptime--;
if(todroptime == 59) {
int random = (int) (Math.random() * 4) + 1;
if(random == 1) {
rloc = 1;
int randomx1 = (int) (Math.random() * 2500) + 1;
int randomz1 = (int) (Math.random() * 2500) + 1;
rx = randomx1;
ry = Bukkit.getWorld("world2").getHighestBlockYAt(randomx1, randomz1);
rz = randomz1;
if(Bukkit.getWorld("world2").getBlockAt(rx, ry - 1, rz).getType() != Material.WATER) {
for(Player ps : Bukkit.getOnlinePlayers()) {
ps.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
ps.sendTitle("", ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
}
return;
}
todroptime = 60;
return;
}
if(random == 2) {
rloc = 2;
int randomx2 = (int) (Math.random() * -2500) + 1;
int randomz2 = (int) (Math.random() * -2500) + 1;
rx = randomx2;
ry = Bukkit.getWorld("world2").getHighestBlockYAt(randomx2, randomz2);
rz = randomz2;
if(Bukkit.getWorld("world2").getBlockAt(rx, ry - 1, rz).getType() != Material.WATER) {
for(Player ps : Bukkit.getOnlinePlayers()) {
ps.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
ps.sendTitle("", ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
}
return;
}
todroptime = 60;
return;
}
if(random == 3) {
rloc = 3;
int randomx3 = (int) (Math.random() * -2500) + 1;
int randomz3 = (int) (Math.random() * 2500) + 1;
rx = randomx3;
ry = Bukkit.getWorld("world2").getHighestBlockYAt(randomx3, randomz3);
rz = randomz3;
if(Bukkit.getWorld("world2").getBlockAt(rx, ry - 1, rz).getType() != Material.WATER) {
for(Player ps : Bukkit.getOnlinePlayers()) {
ps.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
ps.sendTitle("", ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
}
return;
}
todroptime = 60;
return;
}
if(random == 4) {
rloc = 4;
int randomx4 = (int) (Math.random() * 2500) + 1;
int randomz4 = (int) (Math.random() * -2500) + 1;
rx = randomx4;
ry = Bukkit.getWorld("world2").getHighestBlockYAt(randomx4, randomz4);
rz = randomz4;
if(Bukkit.getWorld("world2").getBlockAt(rx, ry - 1, rz).getType() != Material.WATER) {
for(Player ps : Bukkit.getOnlinePlayers()) {
ps.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
ps.sendTitle("", ChatColor.AQUA + "" + ChatColor.BOLD + "in 10 minutes will fall air drop with loot at " + rx + " " + rz);
}
return;
}
todroptime = 60;
return;
}
}
}
}, 0, 20);
}
на открытие сундука нужно 20 секунд по истечению которых сундук должен открыться.
Код:
@EventHandler
public void interact(PlayerInteractEvent e) {
Player p = e.getPlayer();
if(e.getClickedBlock().getType() == Material.CHEST) {
Block block = e.getClickedBlock();
Chest chest = (Chest) block.getState();
Inventory inv = chest.getSnapshotInventory();
Inventory inv2 = chest.getBlockInventory();
if(chest.getCustomName().equals(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Locked")) {
p.openInventory(inv2);
BlockState state = block.getState();
inv.clear();
if(dropcd != 0) {
if(inv.getViewers() != null) {
e.setCancelled(true);
}
return;
}
p.sendMessage("open");
dropcd = 21;
new BukkitRunnable() {
@Override
public void run() {
if(p.getOpenInventory().getType() != InventoryType.CHEST) {
dropcd = 0;
this.cancel();
return;
}
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 + "while you open the box, you can be killed");
meta.setLore(lore);
cd.setItemMeta(meta);
inv.setItem(13, cd);
chest.update(true);
if(dropcd == 0) {
chest.setCustomName(ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Opened");
inv.clear();
state.update();
ItemStack golden_apple = new ItemStack(Material.GOLDEN_APPLE, 3);
inv.addItem(golden_apple);
chest.update(true);
for(HumanEntity ps : inv2.getViewers()) {
ps.closeInventory();
ps.openInventory(chest.getBlockInventory());
}
this.cancel();
return;
}
}
}.runTaskTimer(this, 0, 20);
}
}
}
}
но если сундук открывают сразу несколько игроков то название обновляется только у тога игрока кто начал открывать сундук первый. а у остальных только после повторного открытия как это исправить помогите пожалуйста.