use of com.badbones69.crazycrates.api.objects.ItemBuilder in project Crazy-Crates by Crazy-Crew.
the class Methods method getItems.
public static HashMap<ItemStack, String> getItems(Player player) {
HashMap<ItemStack, String> items = new HashMap<>();
FileConfiguration file = cc.getOpeningCrate(player).getFile();
for (String reward : file.getConfigurationSection("Crate.Prizes").getKeys(false)) {
String id = file.getString("Crate.Prizes." + reward + ".DisplayItem");
String name = file.getString("Crate.Prizes." + reward + ".DisplayName");
int chance = file.getInt("Crate.Prizes." + reward + ".Chance");
int max = 99;
if (file.contains("Crate.Prizes." + reward + ".MaxRange")) {
max = file.getInt("Crate.Prizes." + reward + ".MaxRange") - 1;
}
try {
ItemStack item = new ItemBuilder().setMaterial(id).setName(name).build();
int num;
for (int counter = 1; counter <= 1; counter++) {
num = 1 + random.nextInt(max);
if (num >= 1 && num <= chance)
items.put(item, "Crate.Prizes." + reward);
}
} catch (Exception e) {
}
}
return items;
}
use of com.badbones69.crazycrates.api.objects.ItemBuilder in project Crazy-Crates by Crazy-Crew.
the class GUIMenu method openGUI.
public static void openGUI(Player player) {
int size = Files.CONFIG.getFile().getInt("Settings.InventorySize");
Inventory inv = CrazyManager.getJavaPlugin().getServer().createInventory(null, size, Methods.sanitizeColor(Files.CONFIG.getFile().getString("Settings.InventoryName")));
if (Files.CONFIG.getFile().contains("Settings.Filler.Toggle")) {
if (Files.CONFIG.getFile().getBoolean("Settings.Filler.Toggle")) {
String id = Files.CONFIG.getFile().getString("Settings.Filler.Item");
String name = Files.CONFIG.getFile().getString("Settings.Filler.Name");
List<String> lore = Files.CONFIG.getFile().getStringList("Settings.Filler.Lore");
ItemStack item = new ItemBuilder().setMaterial(id).setName(name).setLore(lore).build();
for (int i = 0; i < size; i++) {
inv.setItem(i, item.clone());
}
}
}
if (Files.CONFIG.getFile().contains("Settings.GUI-Customizer")) {
for (String custom : Files.CONFIG.getFile().getStringList("Settings.GUI-Customizer")) {
int slot = 0;
ItemBuilder item = new ItemBuilder();
String[] split = custom.split(", ");
for (String option : split) {
if (option.contains("Item:")) {
item.setMaterial(option.replace("Item:", ""));
}
if (option.contains("Name:")) {
option = option.replace("Name:", "");
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU) {
option = option.replaceAll("%" + crate.getName().toLowerCase() + "%", cc.getVirtualKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_physical%", cc.getPhysicalKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_total%", cc.getTotalKeys(player, crate) + "");
}
}
item.setName(option.replaceAll("%player%", player.getName()));
}
if (option.contains("Lore:")) {
option = option.replace("Lore:", "");
String[] d = option.split(",");
for (String l : d) {
for (Crate crate : cc.getCrates()) {
if (crate.getCrateType() != CrateType.MENU) {
option = option.replaceAll("%" + crate.getName().toLowerCase() + "%", cc.getVirtualKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_physical%", cc.getPhysicalKeys(player, crate) + "").replaceAll("%" + crate.getName().toLowerCase() + "_total%", cc.getTotalKeys(player, crate) + "");
}
}
item.addLore(option.replaceAll("%player%", player.getName()));
}
}
if (option.contains("Glowing:")) {
item.setGlowing(Boolean.parseBoolean(option.replace("Glowing:", "")));
}
if (option.contains("Player:")) {
item.setPlayer(option.replaceAll("%player%", player.getName()));
}
if (option.contains("Slot:")) {
slot = Integer.parseInt(option.replace("Slot:", ""));
}
if (option.contains("Unbreakable-Item")) {
item.setUnbreakable(Boolean.parseBoolean(option.replace("Unbreakable-Item:", "")));
}
if (option.contains("Hide-Item-Flags")) {
item.hideItemFlags(Boolean.parseBoolean(option.replace("Hide-Item-Flags:", "")));
}
}
if (slot > size) {
continue;
}
slot--;
inv.setItem(slot, item.build());
}
}
for (Crate crate : cc.getCrates()) {
FileConfiguration file = crate.getFile();
if (file != null) {
if (file.getBoolean("Crate.InGUI")) {
String path = "Crate.";
int slot = file.getInt(path + "Slot");
if (slot > size) {
continue;
}
slot--;
inv.setItem(slot, new ItemBuilder().setMaterial(file.getString(path + "Item")).setName(file.getString(path + "Name")).setLore(file.getStringList(path + "Lore")).setCrateName(crate.getName()).setPlayer(file.getString(path + "Player")).setGlowing(file.getBoolean(path + "Glowing")).addLorePlaceholder("%Keys%", NumberFormat.getNumberInstance().format(cc.getVirtualKeys(player, crate))).addLorePlaceholder("%Keys_Physical%", NumberFormat.getNumberInstance().format(cc.getPhysicalKeys(player, crate))).addLorePlaceholder("%Keys_Total%", NumberFormat.getNumberInstance().format(cc.getTotalKeys(player, crate))).addLorePlaceholder("%Player%", player.getName()).build());
}
}
}
player.openInventory(inv);
}
use of com.badbones69.crazycrates.api.objects.ItemBuilder 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.ItemBuilder in project Crazy-Crates by Crazy-Crew.
the class War method setRandomGlass.
private static void setRandomGlass(Player player, Inventory inv, String inventoryTitle) {
if (cc.isInOpeningList(player) && inventoryTitle.equalsIgnoreCase(Methods.sanitizeColor(cc.getOpeningCrate(player).getFile().getString(crateNameString)))) {
if (colorCodes == null) {
colorCodes = getColorCode();
}
ItemBuilder itemBuilder = Methods.getRandomPaneColor();
itemBuilder.setName("&" + colorCodes.get(itemBuilder.build()) + "&l???");
ItemStack item = itemBuilder.build();
for (int i = 0; i < 9; i++) {
inv.setItem(i, item);
}
}
}
use of com.badbones69.crazycrates.api.objects.ItemBuilder in project Crazy-Crates by Crazy-Crew.
the class War method getColorCode.
private static HashMap<ItemStack, String> getColorCode() {
HashMap<ItemStack, String> colorCodes = new HashMap<>();
colorCodes.put(new ItemBuilder().setMaterial(Material.WHITE_STAINED_GLASS_PANE).build(), "f");
colorCodes.put(new ItemBuilder().setMaterial(Material.ORANGE_STAINED_GLASS_PANE).build(), "6");
colorCodes.put(new ItemBuilder().setMaterial(Material.MAGENTA_STAINED_GLASS_PANE).build(), "d");
colorCodes.put(new ItemBuilder().setMaterial(Material.LIGHT_BLUE_STAINED_GLASS_PANE).build(), "3");
colorCodes.put(new ItemBuilder().setMaterial(Material.YELLOW_STAINED_GLASS_PANE).build(), "e");
colorCodes.put(new ItemBuilder().setMaterial(Material.LIME_STAINED_GLASS_PANE).build(), "a");
colorCodes.put(new ItemBuilder().setMaterial(Material.PINK_STAINED_GLASS_PANE).build(), "c");
colorCodes.put(new ItemBuilder().setMaterial(Material.GRAY_STAINED_GLASS_PANE).build(), "7");
colorCodes.put(new ItemBuilder().setMaterial(Material.LIGHT_GRAY_STAINED_GLASS_PANE).build(), "7");
colorCodes.put(new ItemBuilder().setMaterial(Material.CYAN_STAINED_GLASS_PANE).build(), "3");
colorCodes.put(new ItemBuilder().setMaterial(Material.PURPLE_STAINED_GLASS_PANE).build(), "5");
colorCodes.put(new ItemBuilder().setMaterial(Material.BLUE_STAINED_GLASS_PANE).build(), "9");
colorCodes.put(new ItemBuilder().setMaterial(Material.BROWN_STAINED_GLASS_PANE).build(), "6");
colorCodes.put(new ItemBuilder().setMaterial(Material.GREEN_STAINED_GLASS_PANE).build(), "2");
colorCodes.put(new ItemBuilder().setMaterial(Material.RED_STAINED_GLASS_PANE).build(), "4");
colorCodes.put(new ItemBuilder().setMaterial(Material.BLACK_STAINED_GLASS_PANE).build(), "8");
return colorCodes;
}
Aggregations