Search in sources :

Example 1 with PlayerPrizeEvent

use of com.badbones69.crazycrates.api.events.PlayerPrizeEvent 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 2 with PlayerPrizeEvent

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

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

use of com.badbones69.crazycrates.api.events.PlayerPrizeEvent 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)

Example 5 with PlayerPrizeEvent

use of com.badbones69.crazycrates.api.events.PlayerPrizeEvent in project Crazy-Crates by Crazy-Crew.

the class CrateOnTheGo method onCrateOpen.

@EventHandler
public void onCrateOpen(PlayerInteractEvent e) {
    Player player = e.getPlayer();
    if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
        ItemStack item = cc.getNMSSupport().getItemInMainHand(player);
        if (item == null || item.getType() == Material.AIR)
            return;
        for (Crate crate : cc.getCrates()) {
            if (crate.getCrateType() == CrateType.CRATE_ON_THE_GO && Methods.isSimilar(item, crate)) {
                e.setCancelled(true);
                cc.addPlayerToOpeningList(player, crate);
                Methods.removeItem(item, player);
                Prize prize = crate.pickPrize(player);
                cc.givePrize(player, prize);
                CrazyManager.getJavaPlugin().getServer().getPluginManager().callEvent(new PlayerPrizeEvent(player, crate, cc.getOpeningCrate(player).getName(), prize));
                if (prize.useFireworks()) {
                    Methods.fireWork(player.getLocation().add(0, 1, 0));
                }
                cc.removePlayerFromOpeningList(player);
            }
        }
    }
}
Also used : PlayerPrizeEvent(com.badbones69.crazycrates.api.events.PlayerPrizeEvent) Player(org.bukkit.entity.Player) Crate(com.badbones69.crazycrates.api.objects.Crate) ItemStack(org.bukkit.inventory.ItemStack) Prize(com.badbones69.crazycrates.api.objects.Prize) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PlayerPrizeEvent (com.badbones69.crazycrates.api.events.PlayerPrizeEvent)7 Prize (com.badbones69.crazycrates.api.objects.Prize)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 ItemStack (org.bukkit.inventory.ItemStack)5 Inventory (org.bukkit.inventory.Inventory)4 Crate (com.badbones69.crazycrates.api.objects.Crate)3 ArrayList (java.util.ArrayList)3 Player (org.bukkit.entity.Player)3 EventHandler (org.bukkit.event.EventHandler)3 ItemBuilder (com.badbones69.crazycrates.api.objects.ItemBuilder)2 KeyType (com.badbones69.crazycrates.api.enums.KeyType)1 PlayerReceiveKeyEvent (com.badbones69.crazycrates.api.events.PlayerReceiveKeyEvent)1 CosmicCrateManager (com.badbones69.crazycrates.api.managers.CosmicCrateManager)1 Tier (com.badbones69.crazycrates.api.objects.Tier)1 NBTItem (de.tr7zw.changeme.nbtapi.NBTItem)1 HashMap (java.util.HashMap)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1