use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException in project Nexus by ProjectEdenGG.
the class Crate method pickCrateLoot.
public void pickCrateLoot() {
Map<CrateLoot, Double> original = new HashMap<>();
Crates.getLootByType(getCrateType()).stream().filter(CrateLoot::isActive).forEach(crateLoot -> original.put(crateLoot, crateLoot.getWeight()));
if (original.size() == 0)
throw new CrateOpeningException("&3Coming soon...");
loot = RandomUtils.getWeightedRandom(original);
}
use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException in project Nexus by ProjectEdenGG.
the class Crate method spawnItem.
public Item spawnItem(Location location, ItemStack itemStack) {
try {
Item item = location.getWorld().dropItem(location, itemStack);
item.setVelocity(new Vector(0, 0, 0));
item.setCanPlayerPickup(false);
item.setCustomNameVisible(true);
item.setCustomName(StringUtils.colorize(loot.getTitle()));
spawnedItem = item;
new CrateSpawnItemEvent(player, loot, getCrateType()).callEvent();
return item;
} catch (Exception ex) {
player.getInventory().addItem(getCrateType().getKey());
throw new CrateOpeningException("There was an error while trying to play the crate animation");
}
}
use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException 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);
}
use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException in project Nexus by ProjectEdenGG.
the class FebVoteRewardCrate method spawnItem.
@Override
public Item spawnItem(Location location, ItemStack itemStack) {
try {
Item item = location.getWorld().spawn(location, Item.class);
item.setVelocity(new Vector(0, 0, 0));
item.setItemStack(itemStack);
item.setCanPlayerPickup(false);
item.setCustomName(itemStack.getItemMeta().getDisplayName());
item.setCustomNameVisible(true);
spawnedItem = item;
new CrateSpawnItemEvent(player, loot, getCrateType()).callEvent();
return item;
} catch (Exception ex) {
player.getInventory().addItem(getCrateType().getKey());
throw new CrateOpeningException("There was an error while trying to play the crate animation");
}
}
use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException in project Nexus by ProjectEdenGG.
the class Crates method onClickWithKey.
@EventHandler
public void onClickWithKey(PlayerInteractEvent event) {
try {
if (!Utils.ActionGroup.CLICK_BLOCK.applies(event))
return;
if (event.getClickedBlock() == null)
return;
CrateType locationType = CrateType.fromLocation(event.getClickedBlock().getLocation());
if (locationType == null)
return;
event.setCancelled(true);
Location location = LocationUtils.getCenteredLocation(event.getClickedBlock().getLocation());
if (event.getHand() == null)
return;
if (!event.getHand().equals(EquipmentSlot.HAND))
return;
if (!enabled)
throw new CrateOpeningException("Crates are temporarily disabled");
if (RebootCommand.isQueued())
throw new CrateOpeningException("Server reboot is queued, cannot open crates");
CrateType keyType = CrateType.fromKey(event.getItem());
if (locationType != keyType && locationType != CrateType.ALL)
if (Crates.getLootByType(locationType).stream().filter(CrateLoot::isActive).toArray().length == 0)
throw new CrateOpeningException("&3Coming soon...");
else
locationType.previewDrops(null).open(event.getPlayer());
else if (keyType != null)
try {
if (event.getPlayer().isSneaking() && event.getItem().getAmount() > 1)
keyType.getCrateClass().openMultiple(location, event.getPlayer(), event.getItem().getAmount());
else
keyType.getCrateClass().openCrate(location, event.getPlayer());
} catch (CrateOpeningException ex) {
if (ex.getMessage() != null)
PlayerUtils.send(event.getPlayer(), Crates.PREFIX + ex.getMessage());
keyType.getCrateClass().reset();
}
} catch (NexusException ex) {
PlayerUtils.send(event.getPlayer(), ex.withPrefix(Crates.PREFIX));
}
}
Aggregations