use of io.th0rgal.oraxen.recipes.CustomRecipe in project oraxen by oraxen.
the class RecipesEventsManager method onCrafted.
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
public void onCrafted(PrepareItemCraftEvent event) {
Recipe recipe = event.getRecipe();
Player player = (Player) event.getView().getPlayer();
if (hasPermission(player, CustomRecipe.fromRecipe(recipe)))
return;
ItemStack result = event.getInventory().getResult();
if (result == null)
return;
boolean containsOraxenItem = false;
if (!containsOraxenItem)
if (Arrays.stream(event.getInventory().getMatrix()).anyMatch(ingredient -> OraxenItems.exists(OraxenItems.getIdByItem(ingredient)))) {
containsOraxenItem = true;
}
if (!containsOraxenItem || recipe == null)
return;
CustomRecipe current = new CustomRecipe(null, recipe.getResult(), Arrays.asList(event.getInventory().getMatrix()));
for (CustomRecipe whitelistedRecipe : whitelistedCraftRecipes) {
if (whitelistedRecipe.equals(current))
return;
}
event.getInventory().setResult(new ItemStack(Material.AIR));
}
use of io.th0rgal.oraxen.recipes.CustomRecipe in project oraxen by oraxen.
the class RecipesView method create.
public ChestGui create(final int page, final List<CustomRecipe> filteredRecipes) {
final ChestGui gui = new ChestGui(6, menuTexture);
final CustomRecipe currentRecipe = filteredRecipes.get(page);
// Check if last page
final boolean lastPage = filteredRecipes.size() - 1 == page;
final StaticPane pane = new StaticPane(9, 6);
pane.addItem(new GuiItem(new ItemBuilder(currentRecipe.getResult()).build()), 4, 0);
for (int i = 0; i < currentRecipe.getIngredients().size(); i++) {
final ItemStack itemStack = currentRecipe.getIngredients().get(i);
if (itemStack != null && itemStack.getType() != Material.AIR)
pane.addItem(new GuiItem(itemStack), 3 + i % 3, 2 + i / 3);
}
// Close RecipeShowcase inventory button
pane.addItem(new GuiItem((OraxenItems.getItemById("exit_icon") == null ? new ItemBuilder(Material.BARRIER) : OraxenItems.getItemById("exit_icon")).setDisplayName(Message.EXIT_MENU.toSerializedString()).build(), (event -> event.getWhoClicked().closeInventory())), 4, 5);
// Previous Page button
if (page > 0)
pane.addItem(new GuiItem((OraxenItems.getItemById("arrow_previous_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_previous_icon")).setAmount(page).setDisplayName(ChatColor.YELLOW + "Open page " + page).build(), event -> create(page - 1, filteredRecipes).show(event.getWhoClicked())), 1, 3);
// Next page button
if (!lastPage)
pane.addItem(new GuiItem((OraxenItems.getItemById("arrow_next_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_next_icon")).setAmount(page + 2).setDisplayName(ChatColor.YELLOW + "Open page " + (page + 2)).build(), event -> create(page + 1, filteredRecipes).show(event.getWhoClicked())), 7, 3);
gui.addPane(pane);
gui.setOnGlobalClick(event -> event.setCancelled(true));
return gui;
}
Aggregations