Java Code Examples for org.bukkit.inventory.CraftingInventory#setResult()

The following examples show how to use org.bukkit.inventory.CraftingInventory#setResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemCraftListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onItemCraft(PrepareItemCraftEvent event) {
    try {
        final CraftingInventory inventory = event.getInventory();
        if (inventory.getResult() == null) return;

        for (ItemStack itemStack : inventory.getContents()) {
            if (Utils.getCrystals(itemStack) == 0) continue;
            inventory.setResult(null);
            return;
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 2
Source File: CraftingMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void removeDisabledRecipe(PrepareItemCraftEvent event) {
  CraftingInventory crafting = event.getInventory();
  ItemStack result = crafting.getResult();
  if (result == null) {
    return;
  }

  for (SingleMaterialMatcher disabled : disabledRecipes) {
    if (disabled.matches(result)) {
      crafting.setResult(null);
      break;
    }
  }
}
 
Example 3
Source File: CraftItemListener.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPrepare(PrepareItemCraftEvent event) {
	if (MineTinker.getPlugin().getConfig().getBoolean("ModifiersCanBeUsedForCrafting")) return;
	CraftingInventory inv = event.getInventory();
	for (ItemStack is : inv.getMatrix()) {
		if (is == null) continue;
		if (modManager.isModifierItem(is)) {
			inv.setResult(null);
			break;
		}
	}
}
 
Example 4
Source File: ConvertToolListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onCraft(PrepareItemCraftEvent event) {
	CraftingInventory inv = event.getInventory();

	boolean canConvert = false;
	World world = null;

	HumanEntity humanEntity = null;

	for (HumanEntity human : inv.getViewers()) {
		if (human.hasPermission("minetinker.tool.create")) {
			canConvert = true;
			world = human.getWorld();
			humanEntity = human;
			break;
		}
	}

	if (!canConvert) {
		return;
	}

	if (Lists.WORLDS.contains(world.getName())) {
		return;
	}

	int recipeItems = 0;
	ItemStack lastItem = null;

	for (ItemStack item : inv.getMatrix()) {
		if (item != null && item.getType() != Material.AIR) {
			recipeItems += 1;
			lastItem = item;
		}
	}

	if (recipeItems == 1) {
		if (modManager.isArmorViable(lastItem) || modManager.isToolViable(lastItem) || modManager.isWandViable(lastItem)) {
			inv.setResult(new ItemStack(Material.AIR, 1));
			return;
		}

		if (ToolType.isMaterialCompatible(lastItem.getType())) {
			inv.setResult(lastItem);
			modManager.convertItemStack(event.getInventory().getResult(), humanEntity);
			inv.getResult().setAmount(1);
		}
	}
}
 
Example 5
Source File: EventListener.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 
 * 
 * Will only be called for shaped and shapeless
 * @param event
 */


@EventHandler(priority = EventPriority.MONITOR)
public void workbenchCraft(WorkbenchCraftEvent event){
	CraftingInventory inventory = (CraftingInventory)event.getInventory();
	
	if(event.isCancelled()){
		inventory.setResult((new ItemStack(Material.AIR)));
		return;
	}
	
	inventory.setResult(event.getResult());
	inventory.setItem(0, event.getResult());
	
	ProRecipes.getPlugin().incrementRecipesCrafted(event.getRecipe().getType());
	
}