Search in sources :

Example 1 with Prize

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

the class CrazyManager method openCrate.

/**
 * Opens a crate for a player.
 * @param player The player that is having the crate opened for them.
 * @param crate The crate that is being used.
 * @param location The location that may be needed for some crate types.
 * @param checkHand If it just checks the players hand or if it checks their inventory.
 */
public void openCrate(Player player, Crate crate, KeyType keyType, Location location, boolean virtualCrate, boolean checkHand) {
    if (crate.getCrateType() != CrateType.MENU) {
        if (!crate.canWinPrizes(player)) {
            player.sendMessage(Messages.NO_PRIZES_FOUND.getMessage());
            removePlayerFromOpeningList(player);
            removePlayerKeyType(player);
            return;
        }
    }
    addPlayerToOpeningList(player, crate);
    boolean broadcast = crate.getFile() != null && crate.getFile().getBoolean("Crate.OpeningBroadCast");
    if (broadcast && crate.getCrateType() != CrateType.QUAD_CRATE) {
        if (crate.getFile().contains("Crate.BroadCast")) {
            if (!crate.getFile().getString("Crate.BroadCast").isEmpty()) {
                getJavaPlugin().getServer().broadcastMessage(color(crate.getFile().getString("Crate.BroadCast").replaceAll("%Prefix%", Methods.getPrefix()).replaceAll("%prefix%", Methods.getPrefix()).replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
            }
        }
        broadcast = false;
    }
    switch(crate.getCrateType()) {
        case MENU:
            GUIMenu.openGUI(player);
            break;
        case COSMIC:
            Cosmic.openCosmic(player, crate, keyType, checkHand);
            break;
        case CSGO:
            CSGO.openCSGO(player, crate, keyType, checkHand);
            break;
        case ROULETTE:
            Roulette.openRoulette(player, crate, keyType, checkHand);
            break;
        case WHEEL:
            Wheel.startWheel(player, crate, keyType, checkHand);
            break;
        case WONDER:
            Wonder.startWonder(player, crate, keyType, checkHand);
            break;
        case WAR:
            War.openWarCrate(player, crate, keyType, checkHand);
            break;
        case QUAD_CRATE:
            Location last = player.getLocation();
            last.setPitch(0F);
            QuadCrateSession session = new QuadCrateSession(player, crate, keyType, location, last, checkHand);
            broadcast = session.startCrate();
            break;
        case FIRE_CRACKER:
            if (CrateControl.inUse.containsValue(location)) {
                player.sendMessage(Messages.QUICK_CRATE_IN_USE.getMessage());
                removePlayerFromOpeningList(player);
                return;
            } else {
                if (virtualCrate) {
                    player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
                    removePlayerFromOpeningList(player);
                    return;
                } else {
                    CrateControl.inUse.put(player, location);
                    FireCracker.startFireCracker(player, crate, keyType, location);
                }
            }
            break;
        case QUICK_CRATE:
            if (CrateControl.inUse.containsValue(location)) {
                player.sendMessage(Messages.QUICK_CRATE_IN_USE.getMessage());
                removePlayerFromOpeningList(player);
                return;
            } else {
                if (virtualCrate && location.equals(player.getLocation())) {
                    player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
                    removePlayerFromOpeningList(player);
                    return;
                } else {
                    CrateControl.inUse.put(player, location);
                    QuickCrate.openCrate(player, location, crate, keyType);
                }
            }
            break;
        case CRATE_ON_THE_GO:
            if (virtualCrate) {
                player.sendMessage(Messages.CANT_BE_A_VIRTUAL_CRATE.getMessage());
                removePlayerFromOpeningList(player);
                return;
            } else {
                if (takeKeys(1, player, crate, keyType, true)) {
                    Prize prize = crate.pickPrize(player);
                    givePrize(player, prize);
                    if (prize.useFireworks()) {
                        Methods.fireWork(player.getLocation().add(0, 1, 0));
                    }
                    removePlayerFromOpeningList(player);
                } else {
                    Methods.failedToTakeKey(player, crate);
                }
            }
            break;
    }
    if (broadcast) {
        if (!crate.getFile().getString("Crate.BroadCast").isEmpty()) {
            getJavaPlugin().getServer().broadcastMessage(color(crate.getFile().getString("Crate.BroadCast").replaceAll("%Prefix%", Methods.getPrefix()).replaceAll("%prefix%", Methods.getPrefix()).replaceAll("%Player%", player.getName()).replaceAll("%player%", player.getName())));
        }
    }
}
Also used : Location(org.bukkit.Location) BrokeLocation(com.badbones69.crazycrates.api.enums.BrokeLocation)

Example 2 with Prize

use of com.badbones69.crazycrates.api.objects.Prize 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 3 with Prize

use of com.badbones69.crazycrates.api.objects.Prize 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 4 with Prize

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

the class Roulette method startRoulette.

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

        int time = 1;

        int even = 0;

        int full = 0;

        int open = 0;

        @Override
        public void run() {
            if (full <= 15) {
                inv.setItem(13, crate.pickPrize(player).getDisplayItem());
                setGlass(inv);
                player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                even++;
                if (even >= 4) {
                    even = 0;
                    inv.setItem(13, crate.pickPrize(player).getDisplayItem());
                }
            }
            open++;
            if (open >= 5) {
                player.openInventory(inv);
                open = 0;
            }
            full++;
            if (full > 16) {
                if (slowSpin().contains(time)) {
                    setGlass(inv);
                    inv.setItem(13, crate.pickPrize(player).getDisplayItem());
                    player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                }
                time++;
                if (time >= 23) {
                    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);
                    new BukkitRunnable() {

                        @Override
                        public void run() {
                            if (player.getOpenInventory().getTopInventory().equals(inv)) {
                                player.closeInventory();
                            }
                        }
                    }.runTaskLater(CrazyManager.getJavaPlugin(), 40);
                }
            }
        }
    }.runTaskTimer(CrazyManager.getJavaPlugin(), 2, 2));
}
Also used : PlayerPrizeEvent(com.badbones69.crazycrates.api.events.PlayerPrizeEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Prize(com.badbones69.crazycrates.api.objects.Prize)

Example 5 with Prize

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

the class Cosmic method onInvClick.

@EventHandler
public void onInvClick(InventoryClickEvent e) {
    final Inventory inv = e.getInventory();
    final Player player = (Player) e.getWhoClicked();
    if (inv != null) {
        final Crate crate = cc.getOpeningCrate(player);
        if (cc.isInOpeningList(player)) {
            if (!crate.getFile().getString("Crate.CrateType").equalsIgnoreCase("Cosmic"))
                return;
        } else {
            return;
        }
        final FileConfiguration file = crate.getFile();
        if (e.getView().getTitle().equals(Methods.sanitizeColor(file.getString("Crate.CrateName") + " - Shuffling"))) {
            e.setCancelled(true);
        }
        if (e.getView().getTitle().equals(Methods.sanitizeColor(file.getString("Crate.CrateName") + " - Prizes"))) {
            e.setCancelled(true);
            int slot = e.getRawSlot();
            if (inCosmic(slot)) {
                for (int i : picks.get(player)) {
                    if (slot == i) {
                        ItemStack item = e.getCurrentItem();
                        Tier tier = getTier(crate, item);
                        if (item != null && tier != null) {
                            Prize prize = crate.pickPrize(player, tier);
                            for (int stop = 0; prize == null && stop <= 2000; stop++) {
                                prize = crate.pickPrize(player, tier);
                            }
                            if (prize != null) {
                                cc.givePrize(player, prize);
                                CrazyManager.getJavaPlugin().getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, cc.getOpeningCrate(player).getName(), prize));
                                e.setCurrentItem(prize.getDisplayItem());
                                player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
                                if (prize.useFireworks()) {
                                    Methods.fireWork(player.getLocation().add(0, 1, 0));
                                }
                            }
                            return;
                        }
                    }
                }
            }
        }
        if (e.getView().getTitle().equals(Methods.sanitizeColor(file.getString("Crate.CrateName") + " - Choose"))) {
            e.setCancelled(true);
            int slot = e.getRawSlot();
            if (inCosmic(slot)) {
                ItemStack item = e.getCurrentItem();
                if (item != null) {
                    CosmicCrateManager manager = (CosmicCrateManager) crate.getManager();
                    int totalPrizes = manager.getTotalPrizes();
                    int pickedSlot = slot + 1;
                    NBTItem nbtItem = new NBTItem(item);
                    if (nbtItem.hasNBTData()) {
                        if (nbtItem.hasKey("Cosmic-Mystery-Crate")) {
                            if (!glass.containsKey(player))
                                glass.put(player, new ArrayList<>());
                            if (glass.get(player).size() < totalPrizes) {
                                e.setCurrentItem(manager.getPickedCrate().setAmount(pickedSlot).addNamePlaceholder("%Slot%", pickedSlot + "").addLorePlaceholder("%Slot%", pickedSlot + "").build());
                                glass.get(player).add(slot);
                            }
                            player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                        } else if (nbtItem.hasKey("Cosmic-Picked-Crate")) {
                            if (!glass.containsKey(player))
                                glass.put(player, new ArrayList<>());
                            e.setCurrentItem(manager.getMysteryCrate().setAmount(pickedSlot).addNamePlaceholder("%Slot%", pickedSlot + "").addLorePlaceholder("%Slot%", pickedSlot + "").build());
                            ArrayList<Integer> l = new ArrayList<>();
                            for (int i : glass.get(player)) if (i != slot)
                                l.add(i);
                            glass.put(player, l);
                            player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
                        }
                    }
                    if (glass.get(player).size() >= totalPrizes) {
                        KeyType keyType = cc.getPlayerKeyType(player);
                        if (keyType == KeyType.PHYSICAL_KEY && !cc.hasPhysicalKey(player, crate, checkHands.get(player))) {
                            player.closeInventory();
                            player.sendMessage(Messages.NO_KEY.getMessage());
                            if (cc.isInOpeningList(player)) {
                                cc.removePlayerFromOpeningList(player);
                                cc.removePlayerKeyType(player);
                            }
                            checkHands.remove(player);
                            glass.remove(player);
                            return;
                        }
                        if (cc.hasPlayerKeyType(player) && !cc.takeKeys(1, player, crate, keyType, checkHands.get(player))) {
                            Methods.failedToTakeKey(player, crate);
                            cc.removePlayerFromOpeningList(player);
                            cc.removePlayerKeyType(player);
                            checkHands.remove(player);
                            glass.remove(player);
                            return;
                        }
                        cc.addCrateTask(player, new BukkitRunnable() {

                            int time = 0;

                            @Override
                            public void run() {
                                try {
                                    startRoll(player, crate);
                                } catch (Exception e) {
                                    PlayerReceiveKeyEvent event = new PlayerReceiveKeyEvent(player, crate, PlayerReceiveKeyEvent.KeyReceiveReason.REFUND, 1);
                                    CrazyManager.getJavaPlugin().getServer().getPluginManager().callEvent(event);
                                    if (!event.isCancelled()) {
                                        cc.addKeys(1, player, crate, keyType);
                                        cc.endCrate(player);
                                        cancel();
                                        player.sendMessage(Methods.getPrefix("&cAn issue has occurred and so a key refund was given."));
                                        CrazyManager.getJavaPlugin().getServer().getLogger().warning("An issue occurred when the user " + player.getName() + " was using the " + crate.getName() + " crate and so they were issued a key refund.");
                                        e.printStackTrace();
                                    }
                                    return;
                                }
                                time++;
                                if (time == 40) {
                                    cc.endCrate(player);
                                    showRewards(player, crate);
                                    player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_PLACE, 1, 1);
                                    new BukkitRunnable() {

                                        @Override
                                        public void run() {
                                            if (player.getOpenInventory().getTopInventory().equals(inv)) {
                                                player.closeInventory();
                                            }
                                        }
                                    }.runTaskLater(CrazyManager.getJavaPlugin(), 40);
                                }
                            }
                        }.runTaskTimer(CrazyManager.getJavaPlugin(), 0, 2));
                    }
                }
            }
        }
    }
}
Also used : PlayerPrizeEvent(com.badbones69.crazycrates.api.events.PlayerPrizeEvent) Player(org.bukkit.entity.Player) KeyType(com.badbones69.crazycrates.api.enums.KeyType) Tier(com.badbones69.crazycrates.api.objects.Tier) CosmicCrateManager(com.badbones69.crazycrates.api.managers.CosmicCrateManager) Crate(com.badbones69.crazycrates.api.objects.Crate) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Prize(com.badbones69.crazycrates.api.objects.Prize) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) PlayerReceiveKeyEvent(com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent) NBTItem(de.tr7zw.changeme.nbtapi.NBTItem) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Prize (com.badbones69.crazycrates.api.objects.Prize)8 PlayerPrizeEvent (com.badbones69.crazycrates.api.events.PlayerPrizeEvent)7 ItemStack (org.bukkit.inventory.ItemStack)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 Inventory (org.bukkit.inventory.Inventory)5 Crate (com.badbones69.crazycrates.api.objects.Crate)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 ArrayList (java.util.ArrayList)3 BrokeLocation (com.badbones69.crazycrates.api.enums.BrokeLocation)2 ItemBuilder (com.badbones69.crazycrates.api.objects.ItemBuilder)2 Tier (com.badbones69.crazycrates.api.objects.Tier)2 Location (org.bukkit.Location)2 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)2 CrateType (com.badbones69.crazycrates.api.enums.CrateType)1 KeyType (com.badbones69.crazycrates.api.enums.KeyType)1 PlayerReceiveKeyEvent (com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent)1 CosmicCrateManager (com.badbones69.crazycrates.api.managers.CosmicCrateManager)1 NMS_Support (com.badbones69.crazycrates.nms.NMS_Support)1 DecentHolograms (com.badbones69.crazycrates.support.holograms.DecentHolograms)1