use of gg.projecteden.nexus.utils.Tasks in project Nexus by ProjectEdenGG.
the class Crate method openMultiple.
public void openMultiple(Location location, Player player, int amount) {
if (inUse)
return;
this.player = player;
MenuUtils.ConfirmationMenu.builder().title("Open " + amount + " Crates?").onConfirm(e -> {
player.closeInventory();
try {
if (inUse)
return;
inUse = true;
pickCrateLoot();
if (!canHoldItems(player))
return;
takeKey();
hideHologram();
playAnimationSound(location);
playAnimation(location).thenAccept(finalLocation -> {
try {
AtomicInteger wait = new AtomicInteger(0);
Tasks.wait(TickTime.SECOND.x(wait.getAndAdd(1)), () -> {
try {
playFinalSound(location);
playFinalParticle(finalLocation);
spawnItem(finalLocation, loot.getDisplayItem());
} catch (CrateOpeningException ex) {
if (ex.getMessage() != null)
PlayerUtils.send(player, Crates.PREFIX + ex.getMessage());
reset();
}
});
List<Integer> tasks = new ArrayList<>();
for (int i = 0; i < amount - 1; i++) {
int j = i;
tasks.add(Tasks.wait(TickTime.SECOND.x(wait.getAndAdd(1)), () -> {
try {
giveItems();
removeItem();
pickCrateLoot();
if (!canHoldItems(player)) {
tasks.forEach(Tasks::cancel);
return;
}
takeKey();
playFinalSound(location);
playFinalParticle(finalLocation);
spawnItem(finalLocation, loot.getDisplayItem());
if (j == amount - 2)
Tasks.wait(TickTime.SECOND.x(3), () -> {
giveItems();
reset();
});
} catch (CrateOpeningException ex) {
if (ex.getMessage() != null)
PlayerUtils.send(player, Crates.PREFIX + ex.getMessage());
tasks.forEach(Tasks::cancel);
reset();
}
}));
}
} catch (CrateOpeningException ex) {
if (ex.getMessage() != null)
PlayerUtils.send(player, Crates.PREFIX + ex.getMessage());
reset();
}
});
} catch (CrateOpeningException ex) {
if (ex.getMessage() != null)
PlayerUtils.send(player, Crates.PREFIX + ex.getMessage());
reset();
}
}).open(player);
}
Aggregations