use of com.badbones69.crazycrates.api.objects.Tier 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.Tier 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.Tier in project Crazy-Crates by Crazy-Crew.
the class CrazyManager method loadCrates.
/**
* Loads all the information the plugin needs to run.
*/
public void loadCrates() {
giveNewPlayersKeys = false;
crates.clear();
brokecrates.clear();
crateLocations.clear();
crateSchematics.clear();
nmsSupport = new NMS_Support();
quadCrateTimer = Files.CONFIG.getFile().getInt("Settings.QuadCrate.Timer") * 20;
giveVirtualKeysWhenInventoryFull = Files.CONFIG.getFile().getBoolean("Settings.Give-Virtual-Keys-When-Inventory-Full");
if (Support.HOLOGRAPHIC_DISPLAYS.isPluginLoaded()) {
hologramController = new HolographicSupport();
} else if (Support.DECENT_HOLOGRAMS.isPluginLoaded()) {
hologramController = new DecentHolograms();
}
// Removes all holograms so that they can be replaced.
if (hologramController != null) {
hologramController.removeAllHolograms();
}
if (fileManager.isLogging())
getJavaPlugin().getLogger().info("Loading all crate information...");
for (String crateName : fileManager.getAllCratesNames()) {
// if(fileManager.isLogging()) plugin.getLogger().info(fileManager.getPrefix() + "Loading " + crateName + ".yml information....");
try {
FileConfiguration file = fileManager.getFile(crateName).getFile();
CrateType crateType = CrateType.getFromName(file.getString("Crate.CrateType"));
ArrayList<Prize> prizes = new ArrayList<>();
String previewName = file.contains("Crate.Preview-Name") ? file.getString("Crate.Preview-Name") : file.getString("Crate.Name");
ArrayList<Tier> tiers = new ArrayList<>();
if (file.contains("Crate.Tiers") && file.getConfigurationSection("Crate.Tiers") != null) {
for (String tier : file.getConfigurationSection("Crate.Tiers").getKeys(false)) {
String path = "Crate.Tiers." + tier;
tiers.add(new Tier(tier, file.getString(path + ".Name"), file.getString(path + ".Color"), file.getInt(path + ".Chance"), file.getInt(path + ".MaxRange")));
}
}
if (crateType == CrateType.COSMIC && tiers.isEmpty()) {
brokecrates.add(crateName);
getJavaPlugin().getLogger().warning("No tiers were found for this cosmic crate " + crateName + ".yml file.");
continue;
}
for (String prize : file.getConfigurationSection("Crate.Prizes").getKeys(false)) {
Prize altPrize = null;
String path = "Crate.Prizes." + prize;
ArrayList<Tier> prizeTiers = new ArrayList<>();
for (String tier : file.getStringList(path + ".Tiers")) {
for (Tier loadedTier : tiers) {
if (loadedTier.getName().equalsIgnoreCase(tier)) {
prizeTiers.add(loadedTier);
}
}
}
if (file.contains(path + ".Alternative-Prize")) {
if (file.getBoolean(path + ".Alternative-Prize.Toggle")) {
altPrize = new Prize("Alternative-Prize", file.getStringList(path + ".Alternative-Prize.Messages"), file.getStringList(path + ".Alternative-Prize.Commands"), // No editor items
null, getItems(file, prize + ".Alternative-Prize"));
}
}
ArrayList<ItemStack> editorItems = new ArrayList<>();
if (file.contains(path + ".Editor-Items")) {
for (Object list : file.getList(path + ".Editor-Items")) {
editorItems.add((ItemStack) list);
}
}
prizes.add(new Prize(prize, getDisplayItem(file, prize), file.getStringList(path + ".Messages"), file.getStringList(path + ".Commands"), editorItems, getItems(file, prize), crateName, file.getInt(path + ".Chance", 100), file.getInt(path + ".MaxRange", 100), file.getBoolean(path + ".Firework"), file.getStringList(path + ".BlackListed-Permissions"), prizeTiers, altPrize));
}
int newPlayersKeys = file.getInt("Crate.StartingKeys");
if (!giveNewPlayersKeys) {
if (newPlayersKeys > 0) {
giveNewPlayersKeys = true;
}
}
crates.add(new Crate(crateName, previewName, crateType, getKey(file), prizes, file, newPlayersKeys, tiers, new CrateHologram(file.getBoolean("Crate.Hologram.Toggle"), file.getDouble("Crate.Hologram.Height", 0.0), file.getStringList("Crate.Hologram.Message"))));
} catch (Exception e) {
brokecrates.add(crateName);
getJavaPlugin().getLogger().warning("There was an error while loading the " + crateName + ".yml file.");
e.printStackTrace();
}
}
crates.add(new Crate("Menu", "Menu", CrateType.MENU, new ItemStack(Material.AIR), new ArrayList<>(), null, 0, null, null));
if (fileManager.isLogging())
getJavaPlugin().getLogger().info("All crate information has been loaded.");
if (fileManager.isLogging())
getJavaPlugin().getLogger().info("Loading all the physical crate locations.");
FileConfiguration locations = Files.LOCATIONS.getFile();
int loadedAmount = 0;
int brokeAmount = 0;
if (locations.getConfigurationSection("Locations") != null) {
for (String locationName : locations.getConfigurationSection("Locations").getKeys(false)) {
try {
String worldName = locations.getString("Locations." + locationName + ".World");
World world = getJavaPlugin().getServer().getWorld(worldName);
int x = locations.getInt("Locations." + locationName + ".X");
int y = locations.getInt("Locations." + locationName + ".Y");
int z = locations.getInt("Locations." + locationName + ".Z");
Location location = new Location(world, x, y, z);
Crate crate = getCrateFromName(locations.getString("Locations." + locationName + ".Crate"));
if (world != null && crate != null) {
crateLocations.add(new CrateLocation(locationName, crate, location));
if (hologramController != null) {
hologramController.createHologram(location.getBlock(), crate);
}
loadedAmount++;
} else {
brokeLocations.add(new BrokeLocation(locationName, crate, x, y, z, worldName));
brokeAmount++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Checking if all physical locations loaded
if (fileManager.isLogging()) {
if (loadedAmount > 0 || brokeAmount > 0) {
if (brokeAmount <= 0) {
getJavaPlugin().getLogger().info("All physical crate locations have been loaded.");
} else {
getJavaPlugin().getLogger().info("Loaded " + loadedAmount + " physical crate locations.");
getJavaPlugin().getLogger().info("Failed to load " + brokeAmount + " physical crate locations.");
}
}
}
// Loading schematic files
if (fileManager.isLogging())
getJavaPlugin().getLogger().info("Searching for schematics to load.");
String[] schems = new File(getJavaPlugin().getDataFolder() + "/schematics/").list();
for (String schematicName : schems) {
if (schematicName.endsWith(".nbt")) {
crateSchematics.add(new CrateSchematic(schematicName.replace(".nbt", ""), new File(getJavaPlugin().getDataFolder() + "/schematics/" + schematicName)));
if (fileManager.isLogging())
getJavaPlugin().getLogger().info(schematicName + " was successfully found and loaded.");
}
}
if (fileManager.isLogging())
getJavaPlugin().getLogger().info("All schematics were found and loaded.");
cleanDataFile();
Preview.loadButtons();
}
use of com.badbones69.crazycrates.api.objects.Tier in project Crazy-Crates by Crazy-Crew.
the class Cosmic method onInvClose.
@EventHandler
public void onInvClose(InventoryCloseEvent e) {
Inventory inv = e.getInventory();
Player player = (Player) e.getPlayer();
Crate crate = cc.getOpeningCrate(player);
if (cc.isInOpeningList(player)) {
if (crate.getFile() == null) {
return;
} else {
if (!crate.getFile().getString("Crate.CrateType").equalsIgnoreCase("Cosmic")) {
return;
}
}
} else {
return;
}
if (e.getView().getTitle().equals(Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName") + " - Prizes"))) {
boolean playSound = false;
for (int i : picks.get(player)) {
if (inv.getItem(i) != null) {
Tier tier = getTier(crate, inv.getItem(i));
if (tier != null) {
Prize prize = crate.pickPrize(player, tier);
for (int stop = 0; prize == null && stop <= 2000; stop++) {
prize = crate.pickPrize(player, tier);
}
cc.givePrize(player, prize);
playSound = true;
}
}
}
if (playSound) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
}
cc.removePlayerFromOpeningList(player);
cc.removePlayerKeyType(player);
if (glass.containsKey(player)) {
picks.put(player, glass.get(player));
glass.remove(player);
}
checkHands.remove(player);
}
if (cc.isInOpeningList(player) && e.getView().getTitle().equals(Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName") + " - Choose"))) {
if (!glass.containsKey(player) || glass.get(player).size() < 4) {
cc.removePlayerFromOpeningList(player);
cc.removePlayerKeyType(player);
}
if (glass.containsKey(player)) {
picks.put(player, glass.get(player));
glass.remove(player);
}
checkHands.remove(player);
}
}
Aggregations