use of gg.projecteden.nexus.features.crates.models.CrateType 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