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));
}
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;
}
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));
}
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);
}
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)));
}
}
}
Aggregations