use of com.badbones69.crazycrates.api.objects.Crate 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));
}
use of com.badbones69.crazycrates.api.objects.Crate 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));
}
}
}
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate 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);
}
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class War method onInventoryClick.
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
final Player player = (Player) e.getWhoClicked();
final Inventory inv = e.getInventory();
if (inv != null && canPick.containsKey(player) && cc.isInOpeningList(player)) {
Crate crate = cc.getOpeningCrate(player);
if (crate.getCrateType() == CrateType.WAR && canPick.get(player)) {
ItemStack item = e.getCurrentItem();
if (item != null && item.getType().toString().contains(Material.GLASS_PANE.toString())) {
final int slot = e.getRawSlot();
Prize prize = crate.pickPrize(player);
inv.setItem(slot, prize.getDisplayItem());
if (cc.hasCrateTask(player)) {
cc.endCrate(player);
}
canPick.remove(player);
canClose.put(player, true);
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);
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_LAND, 1, 1);
// Sets all other non-picked prizes to show what they could have been.
cc.addCrateTask(player, new BukkitRunnable() {
@Override
public void run() {
for (int i = 0; i < 9; i++) {
if (i != slot) {
inv.setItem(i, crate.pickPrize(player).getDisplayItem());
}
}
if (cc.hasCrateTask(player)) {
cc.endCrate(player);
}
// Removing other items then the prize.
cc.addCrateTask(player, new BukkitRunnable() {
@Override
public void run() {
for (int i = 0; i < 9; i++) {
if (i != slot) {
inv.setItem(i, new ItemStack(Material.AIR));
}
}
if (cc.hasCrateTask(player)) {
cc.endCrate(player);
}
// Closing the inventory when finished.
cc.addCrateTask(player, new BukkitRunnable() {
@Override
public void run() {
if (cc.hasCrateTask(player)) {
cc.endCrate(player);
}
player.closeInventory();
}
}.runTaskLater(CrazyManager.getJavaPlugin(), 30));
}
}.runTaskLater(CrazyManager.getJavaPlugin(), 30));
}
}.runTaskLater(CrazyManager.getJavaPlugin(), 30));
}
}
}
}
use of com.badbones69.crazycrates.api.objects.Crate in project Crazy-Crates by Crazy-Crew.
the class Wheel method startWheel.
public static void startWheel(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, 54, Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName")));
for (int i = 0; i < 54; i++) {
inv.setItem(i, new ItemBuilder().setMaterial(Material.BLACK_STAINED_GLASS_PANE).setName(" ").build());
}
HashMap<Integer, ItemStack> items = new HashMap<>();
for (int i : getBorder()) {
Prize prize = crate.pickPrize(player);
inv.setItem(i, prize.getDisplayItem());
items.put(i, prize.getDisplayItem());
}
rewards.put(player, items);
player.openInventory(inv);
cc.addCrateTask(player, new BukkitRunnable() {
ArrayList<Integer> slots = getBorder();
int i = 0;
int f = 17;
int full = 0;
int timer = Methods.randomNumber(42, 68);
int slower = 0;
int open = 0;
int slow = 0;
@Override
public void run() {
if (i >= 18) {
i = 0;
}
if (f >= 18) {
f = 0;
}
if (full < timer) {
if (rewards.get(player).get(slots.get(i)).getItemMeta().hasLore()) {
inv.setItem(slots.get(i), new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName(rewards.get(player).get(slots.get(i)).getItemMeta().getDisplayName()).setLore(rewards.get(player).get(slots.get(i)).getItemMeta().getLore()).build());
} else {
inv.setItem(slots.get(i), new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName(rewards.get(player).get(slots.get(i)).getItemMeta().getDisplayName()).build());
}
inv.setItem(slots.get(f), rewards.get(player).get(slots.get(f)));
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
i++;
f++;
}
if (full >= timer) {
if (slowSpin().contains(slower)) {
if (rewards.get(player).get(slots.get(i)).getItemMeta().hasLore()) {
inv.setItem(slots.get(i), new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName(rewards.get(player).get(slots.get(i)).getItemMeta().getDisplayName()).setLore(rewards.get(player).get(slots.get(i)).getItemMeta().getLore()).build());
} else {
inv.setItem(slots.get(i), new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).setName(rewards.get(player).get(slots.get(i)).getItemMeta().getDisplayName()).build());
}
inv.setItem(slots.get(f), rewards.get(player).get(slots.get(f)));
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
i++;
f++;
}
if (full == timer + 47) {
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
}
if (full >= timer + 47) {
slow++;
if (slow >= 2) {
ItemStack item = Methods.getRandomPaneColor().setName(" ").build();
for (int slot = 0; slot < 54; slot++) {
if (!getBorder().contains(slot)) {
inv.setItem(slot, item);
}
}
slow = 0;
}
}
if (full >= (timer + 55 + 47)) {
Prize prize = null;
if (cc.isInOpeningList(player)) {
prize = crate.getPrize(rewards.get(player).get(slots.get(f)));
}
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."));
}
player.closeInventory();
cc.removePlayerFromOpeningList(player);
cc.endCrate(player);
}
slower++;
}
full++;
open++;
if (open > 5) {
player.openInventory(inv);
open = 0;
}
}
}.runTaskTimer(CrazyManager.getJavaPlugin(), 1, 1));
}
Aggregations