use of be.isach.ultracosmetics.treasurechests.TreasureChestDesign in project UltraCosmetics by iSach.
the class TreasureChestManager method tryOpenChest.
public static void tryOpenChest(Player player, Location tpTo) {
UltraCosmetics plugin = UltraCosmeticsData.get().getPlugin();
if (!plugin.areChestsAllowedInRegion(player)) {
player.closeInventory();
player.sendMessage(MessageManager.getMessage("Chest-Location.Region-Disabled"));
return;
}
UltraPlayer ultraPlayer = plugin.getPlayerManager().getUltraPlayer(player);
if (ultraPlayer.getKeys() < 1) {
player.closeInventory();
ultraPlayer.openKeyPurchaseMenu();
return;
}
Area area = new Area(player.getLocation().add(-2, 0, -2), player.getLocation().add(2, 1, 2));
if (!area.isEmptyExcept(player.getLocation().getBlock().getLocation())) {
player.sendMessage(MessageManager.getMessage("Chest-Location.Not-Enough-Space"));
return;
}
for (Entity ent : player.getNearbyEntities(5, 5, 5)) {
if (!(ent instanceof Player))
continue;
Player loopPlayer = (Player) ent;
// check Bukkit.getPlayer(UUID) in case loopPlayer is really a player NPC
if (Bukkit.getPlayer(loopPlayer.getUniqueId()) != null && plugin.getPlayerManager().getUltraPlayer(loopPlayer).getCurrentTreasureChest() != null) {
player.closeInventory();
player.sendMessage(MessageManager.getMessage("Chest-Location.Too-Close"));
return;
}
}
Block block = player.getLocation().getBlock();
if (block.getRelative(BlockFace.UP).getType() != Material.AIR || block.getRelative(BlockFace.DOWN).getType() == Material.AIR) {
player.sendMessage(MessageManager.getMessage("Gadgets.Rocket.Not-On-Ground"));
return;
}
ultraPlayer.removeKey();
String designPath = getRandomDesign();
player.closeInventory();
Location preLoc = null;
if (tpTo != null) {
preLoc = player.getLocation();
player.teleport(tpTo);
}
new TreasureChest(player.getUniqueId(), new TreasureChestDesign(designPath), preLoc);
}
Aggregations