Search in sources :

Example 1 with CustomRecipe

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));
}
Also used : OraxenPlugin(io.th0rgal.oraxen.OraxenPlugin) CommandSender(org.bukkit.command.CommandSender) java.util(java.util) OraxenItems(io.th0rgal.oraxen.items.OraxenItems) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler) CustomRecipe(io.th0rgal.oraxen.recipes.CustomRecipe) EventPriority(org.bukkit.event.EventPriority) PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) Recipe(org.bukkit.inventory.Recipe) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) CustomRecipe(io.th0rgal.oraxen.recipes.CustomRecipe) Recipe(org.bukkit.inventory.Recipe) CustomRecipe(io.th0rgal.oraxen.recipes.CustomRecipe) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with CustomRecipe

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;
}
Also used : ChestGui(com.github.stefvanschie.inventoryframework.gui.type.ChestGui) GuiItem(com.github.stefvanschie.inventoryframework.gui.GuiItem) ItemBuilder(io.th0rgal.oraxen.items.ItemBuilder) CustomRecipe(io.th0rgal.oraxen.recipes.CustomRecipe) StaticPane(com.github.stefvanschie.inventoryframework.pane.StaticPane) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

CustomRecipe (io.th0rgal.oraxen.recipes.CustomRecipe)2 ItemStack (org.bukkit.inventory.ItemStack)2 GuiItem (com.github.stefvanschie.inventoryframework.gui.GuiItem)1 ChestGui (com.github.stefvanschie.inventoryframework.gui.type.ChestGui)1 StaticPane (com.github.stefvanschie.inventoryframework.pane.StaticPane)1 OraxenPlugin (io.th0rgal.oraxen.OraxenPlugin)1 ItemBuilder (io.th0rgal.oraxen.items.ItemBuilder)1 OraxenItems (io.th0rgal.oraxen.items.OraxenItems)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Bukkit (org.bukkit.Bukkit)1 Material (org.bukkit.Material)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 EventPriority (org.bukkit.event.EventPriority)1 Listener (org.bukkit.event.Listener)1 PrepareItemCraftEvent (org.bukkit.event.inventory.PrepareItemCraftEvent)1 Recipe (org.bukkit.inventory.Recipe)1