use of com.badbones69.crazycrates.api.enums.KeyType 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())));
}
}
}
use of com.badbones69.crazycrates.api.enums.KeyType in project Crazy-Crates by Crazy-Crew.
the class GUIMenu method onInvClick.
@EventHandler
public void onInvClick(InventoryClickEvent e) {
Player player = (Player) e.getWhoClicked();
Inventory inv = e.getInventory();
FileConfiguration config = Files.CONFIG.getFile();
if (inv != null) {
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU && crate.isCrateMenu(e.getView())) {
return;
}
}
if (e.getView().getTitle().equals(Methods.sanitizeColor(config.getString("Settings.InventoryName")))) {
e.setCancelled(true);
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
NBTItem nbtItem = new NBTItem(item);
if (nbtItem.hasNBTData() && nbtItem.hasKey("CrazyCrates-Crate")) {
Crate crate = cc.getCrateFromName(nbtItem.getString("CrazyCrates-Crate"));
if (crate != null) {
if (e.getAction() == InventoryAction.PICKUP_HALF) {
// Right-clicked the item
if (crate.isPreviewEnabled()) {
player.closeInventory();
Preview.setPlayerInMenu(player, true);
Preview.openNewPreview(player, crate);
} else {
player.sendMessage(Messages.PREVIEW_DISABLED.getMessage());
}
return;
}
if (cc.isInOpeningList(player)) {
player.sendMessage(Messages.CRATE_ALREADY_OPENED.getMessage());
return;
}
boolean hasKey = false;
KeyType keyType = KeyType.VIRTUAL_KEY;
if (cc.getVirtualKeys(player, crate) >= 1) {
hasKey = true;
} else {
if (Files.CONFIG.getFile().getBoolean("Settings.Virtual-Accepts-Physical-Keys") && cc.hasPhysicalKey(player, crate, false)) {
hasKey = true;
keyType = KeyType.PHYSICAL_KEY;
}
}
if (!hasKey) {
if (config.contains("Settings.Need-Key-Sound")) {
Sound sound = Sound.valueOf(config.getString("Settings.Need-Key-Sound"));
if (sound != null) {
player.playSound(player.getLocation(), sound, 1f, 1f);
}
}
player.sendMessage(Messages.NO_VIRTUAL_KEY.getMessage());
return;
}
for (String world : getDisabledWorlds()) {
if (world.equalsIgnoreCase(player.getWorld().getName())) {
player.sendMessage(Messages.WORLD_DISABLED.getMessage("%World%", player.getWorld().getName()));
return;
}
}
if (Methods.isInventoryFull(player)) {
player.sendMessage(Messages.INVENTORY_FULL.getMessage());
return;
}
cc.openCrate(player, crate, keyType, player.getLocation(), true, false);
}
}
}
}
}
}
}
use of com.badbones69.crazycrates.api.enums.KeyType 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));
}
use of com.badbones69.crazycrates.api.enums.KeyType 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.enums.KeyType 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