Search in sources :

Example 6 with Crate

use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.

the class CSGO method startCSGO.

private static void startCSGO(final Player player, final Inventory inv, Crate crate) {
    cc.addCrateTask(player, new BukkitRunnable() {

        int time = 1;

        int full = 0;

        int open = 0;

        @Override
        public void run() {
            if (full <= 50) {
                // When Spinning
                moveItems(inv, player, crate);
                setGlass(inv);
                player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
            }
            open++;
            if (open >= 5) {
                player.openInventory(inv);
                open = 0;
            }
            full++;
            if (full > 51) {
                if (slowSpin().contains(time)) {
                    // When Slowing Down
                    moveItems(inv, player, crate);
                    setGlass(inv);
                    player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                }
                time++;
                if (time == 60) {
                    // When done
                    player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                    cc.endCrate(player);
                    Prize prize = crate.getPrize(inv.getItem(13));
                    if (prize != null) {
                        cc.givePrize(player, prize);
                        if (prize.useFireworks()) {
                            Methods.fireWork(player.getLocation().add(0, 1, 0));
                        }
                        CrazyManager.getJavaPlugin().getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, crate.getName(), prize));
                    } else {
                        player.sendMessage(Methods.getPrefix("&cNo prize was found, please report this issue if you think this is an error."));
                    }
                    cc.removePlayerFromOpeningList(player);
                    cancel();
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            if (player.getOpenInventory().getTopInventory().equals(inv)) {
                                player.closeInventory();
                            }
                        }
                    }.runTaskLater(CrazyManager.getJavaPlugin(), 40);
                } else if (time > 60) {
                    // Added this due reports of the prizes spamming when low tps.
                    cancel();
                }
            }
        }
    }.runTaskTimer(CrazyManager.getJavaPlugin(), 1, 1));
}
Also used : PlayerPrizeEvent(com.badbones69.crazycrates.api.events.PlayerPrizeEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Prize(com.badbones69.crazycrates.api.objects.Prize)

Example 7 with Crate

use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.

the class Cosmic method pickTier.

private static Tier pickTier(Player player) {
    Crate crate = cc.getOpeningCrate(player);
    if (crate.getTiers() != null && !crate.getTiers().isEmpty()) {
        for (int stopLoop = 0; stopLoop <= 100; stopLoop++) {
            for (Tier tier : crate.getTiers()) {
                int chance = tier.getChance();
                int num = new Random().nextInt(tier.getMaxRange());
                if (num >= 1 && num <= chance) {
                    return tier;
                }
            }
        }
    }
    return null;
}
Also used : Random(java.util.Random) Tier(com.badbones69.crazycrates.api.objects.Tier) Crate(com.badbones69.crazycrates.api.objects.Crate)

Example 8 with Crate

use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.

the class Wonder method startWonder.

public static void startWonder(final Player player, Crate crate, KeyType keyType, boolean checkHand) {
    if (!cc.takeKeys(1, player, crate, keyType, checkHand)) {
        Methods.failedToTakeKey(player, crate);
        cc.removePlayerFromOpeningList(player);
        return;
    }
    final Inventory inv = CrazyManager.getJavaPlugin().getServer().createInventory(null, 45, crate.getCrateInventoryName());
    final ArrayList<String> slots = new ArrayList<>();
    for (int i = 0; i < 45; i++) {
        Prize prize = crate.pickPrize(player);
        slots.add(i + "");
        inv.setItem(i, prize.getDisplayItem());
    }
    player.openInventory(inv);
    cc.addCrateTask(player, new BukkitRunnable() {

        int fulltime = 0;

        int timer = 0;

        int slot1 = 0;

        int slot2 = 44;

        ArrayList<Integer> Slots = new ArrayList<>();

        Prize prize = null;

        @Override
        public void run() {
            if (timer >= 2 && fulltime <= 65) {
                slots.remove(slot1 + "");
                slots.remove(slot2 + "");
                Slots.add(slot1);
                Slots.add(slot2);
                inv.setItem(slot1, new ItemBuilder().setMaterial(Material.BLACK_STAINED_GLASS_PANE).setName(" ").build());
                inv.setItem(slot2, new ItemBuilder().setMaterial(Material.BLACK_STAINED_GLASS_PANE).setName(" ").build());
                for (String slot : slots) {
                    prize = crate.pickPrize(player);
                    inv.setItem(Integer.parseInt(slot), prize.getDisplayItem());
                }
                slot1++;
                slot2--;
            }
            if (fulltime > 67) {
                ItemStack item = Methods.getRandomPaneColor().setName(" ").build();
                for (int slot : Slots) {
                    inv.setItem(slot, item);
                }
            }
            player.openInventory(inv);
            if (fulltime > 100) {
                cc.endCrate(player);
                player.closeInventory();
                cc.givePrize(player, prize);
                if (prize.useFireworks()) {
                    Methods.fireWork(player.getLocation().add(0, 1, 0));
                }
                CrazyManager.getJavaPlugin().getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, crate.getName(), prize));
                cc.removePlayerFromOpeningList(player);
                return;
            }
            fulltime++;
            timer++;
            if (timer > 2) {
                timer = 0;
            }
        }
    }.runTaskTimer(CrazyManager.getJavaPlugin(), 0, 2));
}
Also used : PlayerPrizeEvent(com.badbones69.crazycrates.api.events.PlayerPrizeEvent) ItemBuilder(com.badbones69.crazycrates.api.objects.ItemBuilder) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) Prize(com.badbones69.crazycrates.api.objects.Prize)

Example 9 with Crate

use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.

the class DecentHolograms method createHologram.

public void createHologram(Block block, Crate crate) {
    CrateHologram crateHologram = crate.getHologram();
    if (!crateHologram.isEnabled())
        return;
    double height = crateHologram.getHeight();
    Hologram hologram = DHAPI.createHologram(ThreadLocalRandom.current().nextInt() + "", block.getLocation().add(.5, height, .5));
    crateHologram.getMessages().forEach(line -> DHAPI.addHologramLine(hologram, color(line)));
    holograms.put(block, hologram);
}
Also used : CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) CrateHologram(com.badbones69.crazycrates.api.objects.CrateHologram) Hologram(eu.decentsoftware.holograms.api.holograms.Hologram)

Example 10 with Crate

use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.

the class MVdWPlaceholderAPISupport method registerPlaceholders.

public static void registerPlaceholders() {
    for (final Crate crate : cc.getCrates()) {
        if (crate.getCrateType() != CrateType.MENU) {
            PlaceholderAPI.registerPlaceholder(CrazyManager.getJavaPlugin(), "crazycrates_" + crate.getName(), e -> NumberFormat.getNumberInstance().format(cc.getVirtualKeys(e.getPlayer(), crate)));
            PlaceholderAPI.registerPlaceholder(CrazyManager.getJavaPlugin(), "crazycrates_" + crate.getName() + "_physical", e -> NumberFormat.getNumberInstance().format(cc.getPhysicalKeys(e.getPlayer(), crate)));
            PlaceholderAPI.registerPlaceholder(CrazyManager.getJavaPlugin(), "crazycrates_" + crate.getName() + "_total", e -> NumberFormat.getNumberInstance().format(cc.getTotalKeys(e.getPlayer(), crate)));
        }
    }
}
Also used : Crate(com.badbones69.crazycrates.api.objects.Crate)

Aggregations

Crate (com.badbones69.crazycrates.api.objects.Crate)11 ItemStack (org.bukkit.inventory.ItemStack)10 EventHandler (org.bukkit.event.EventHandler)9 Prize (com.badbones69.crazycrates.api.objects.Prize)8 Player (org.bukkit.entity.Player)8 Inventory (org.bukkit.inventory.Inventory)8 PlayerPrizeEvent (com.badbones69.crazycrates.api.events.PlayerPrizeEvent)7 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 ArrayList (java.util.ArrayList)4 BrokeLocation (com.badbones69.crazycrates.api.enums.BrokeLocation)3 KeyType (com.badbones69.crazycrates.api.enums.KeyType)3 ItemBuilder (com.badbones69.crazycrates.api.objects.ItemBuilder)3 Tier (com.badbones69.crazycrates.api.objects.Tier)3 Location (org.bukkit.Location)3 PlayerReceiveKeyEvent (com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent)2 CosmicCrateManager (com.badbones69.crazycrates.api.managers.CosmicCrateManager)2 CrateHologram (com.badbones69.crazycrates.api.objects.CrateHologram)2 CrateLocation (com.badbones69.crazycrates.api.objects.CrateLocation)2 QuickCrate (com.badbones69.crazycrates.cratetypes.QuickCrate)2