Search in sources :

Example 1 with TreasureChestDesign

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);
}
Also used : Entity(org.bukkit.entity.Entity) Area(be.isach.ultracosmetics.util.Area) UltraPlayer(be.isach.ultracosmetics.player.UltraPlayer) Player(org.bukkit.entity.Player) TreasureChest(be.isach.ultracosmetics.treasurechests.TreasureChest) Block(org.bukkit.block.Block) UltraCosmetics(be.isach.ultracosmetics.UltraCosmetics) UltraPlayer(be.isach.ultracosmetics.player.UltraPlayer) TreasureChestDesign(be.isach.ultracosmetics.treasurechests.TreasureChestDesign) Location(org.bukkit.Location)

Aggregations

UltraCosmetics (be.isach.ultracosmetics.UltraCosmetics)1 UltraPlayer (be.isach.ultracosmetics.player.UltraPlayer)1 TreasureChest (be.isach.ultracosmetics.treasurechests.TreasureChest)1 TreasureChestDesign (be.isach.ultracosmetics.treasurechests.TreasureChestDesign)1 Area (be.isach.ultracosmetics.util.Area)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1 Player (org.bukkit.entity.Player)1