Search in sources :

Example 1 with PrepareItemCraftEvent

use of org.bukkit.event.inventory.PrepareItemCraftEvent 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 PrepareItemCraftEvent

use of org.bukkit.event.inventory.PrepareItemCraftEvent in project Slimefun4 by Slimefun.

the class TestCraftingTableListener method testPreCraftEventWithSlimefunItem.

@Test
void testPreCraftEventWithSlimefunItem() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCK_DIAMOND2", new CustomItemStack(Material.DIAMOND, "&cMock Diamond"));
    item.register(plugin);
    PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem());
    Assertions.assertNull(event.getInventory().getResult());
}
Also used : PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test)

Example 3 with PrepareItemCraftEvent

use of org.bukkit.event.inventory.PrepareItemCraftEvent in project Slimefun4 by Slimefun.

the class TestCraftingTableListener method testPreCraftEventWithoutSlimefunItems.

@Test
void testPreCraftEventWithoutSlimefunItems() {
    PrepareItemCraftEvent event = mockPreCraftingEvent(new ItemStack(Material.DIAMOND));
    Assertions.assertNotNull(event.getInventory().getResult());
}
Also used : PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Test(org.junit.jupiter.api.Test)

Example 4 with PrepareItemCraftEvent

use of org.bukkit.event.inventory.PrepareItemCraftEvent in project Slimefun4 by Slimefun.

the class TestCraftingTableListener method testPreCraftEventWithVanillaItem.

@Test
void testPreCraftEventWithVanillaItem() {
    VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.GOLD_INGOT, true);
    item.register(plugin);
    PrepareItemCraftEvent event = mockPreCraftingEvent(item.getItem());
    Assertions.assertNotNull(event.getInventory().getResult());
}
Also used : PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) VanillaItem(io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem) Test(org.junit.jupiter.api.Test)

Example 5 with PrepareItemCraftEvent

use of org.bukkit.event.inventory.PrepareItemCraftEvent in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method setItems.

protected void setItems(List<org.bukkit.inventory.ItemStack> items) {
    int index = 0;
    for (org.bukkit.inventory.ItemStack item : items) {
        this.items.set(index++, CraftItemStack.asNMSCopy(item));
    }
    // Want to update the result without having to use a real player
    if (this.resultInventory instanceof InventoryCraftResult) {
        CustomContainerWorkbench container = new CustomContainerWorkbench(manager.mockPlayer.getBukkitEntity(), bloc, this, (InventoryCraftResult) resultInventory);
        container.a(this);
        CraftingInventory crafting = (CraftingInventory) container.getBukkitView().getTopInventory();
        Bukkit.getPluginManager().callEvent(new PrepareItemCraftEvent(crafting, container.getBukkitView(), false));
    }
    display.forceUpdate();
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) PublicCraftingInventory(io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory) PrepareItemCraftEvent(org.bukkit.event.inventory.PrepareItemCraftEvent) InventoryCraftResult(net.minecraft.server.v1_11_R1.InventoryCraftResult)

Aggregations

PrepareItemCraftEvent (org.bukkit.event.inventory.PrepareItemCraftEvent)21 CraftingInventory (org.bukkit.inventory.CraftingInventory)17 PublicCraftingInventory (io.github.bananapuncher714.crafters.implementation.api.PublicCraftingInventory)16 InventoryCraftResult (net.minecraft.world.inventory.InventoryCraftResult)4 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)3 ItemStack (org.bukkit.inventory.ItemStack)3 Test (org.junit.jupiter.api.Test)3 Player (org.bukkit.entity.Player)2 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)1 VanillaItem (io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem)1 OraxenPlugin (io.th0rgal.oraxen.OraxenPlugin)1 OraxenItems (io.th0rgal.oraxen.items.OraxenItems)1 CustomRecipe (io.th0rgal.oraxen.recipes.CustomRecipe)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 InventoryCraftResult (net.minecraft.server.v1_10_R1.InventoryCraftResult)1 InventoryCraftResult (net.minecraft.server.v1_11_R1.InventoryCraftResult)1 InventoryCraftResult (net.minecraft.server.v1_12_R1.InventoryCraftResult)1 InventoryCraftResult (net.minecraft.server.v1_13_R1.InventoryCraftResult)1 InventoryCraftResult (net.minecraft.server.v1_13_R2.InventoryCraftResult)1