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));
}
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());
}
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());
}
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());
}
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();
}
Aggregations