use of org.bukkit.inventory.Recipe in project Denizen-For-Bukkit by DenizenScript.
the class ItemRecipeFormedScriptEvent method onRecipeFormed.
@EventHandler
public void onRecipeFormed(PrepareItemCraftEvent event) {
HumanEntity humanEntity = event.getView().getPlayer();
if (dEntity.isNPC(humanEntity)) {
return;
}
Recipe eRecipe = event.getRecipe();
if (eRecipe == null || eRecipe.getResult() == null) {
return;
}
inventory = event.getInventory();
result = new dItem(eRecipe.getResult());
recipe = new dList();
for (ItemStack itemStack : inventory.getMatrix()) {
if (itemStack != null) {
recipe.add(new dItem(itemStack).identify());
} else {
recipe.add(new dItem(Material.AIR).identify());
}
}
player = dEntity.getPlayerFrom(humanEntity);
resultChanged = false;
cancelled = false;
fire();
if (cancelled) {
inventory.setResult(null);
} else if (resultChanged) {
inventory.setResult(result.getItemStack());
}
}
use of org.bukkit.inventory.Recipe in project Glowstone by GlowstoneMC.
the class BasicCraftingTest method can_craft_wood_from_logs.
@Test
public void can_craft_wood_from_logs() {
/*
* Used to "prove" the CraftingManager's recipe system loads and properly finds a simple matching recipe for some inputs.
* Sometimes needed to rule out other issues.
*/
ItemStack[] items = new ItemStack[4];
items[0] = new ItemStack(Material.LOG, 1, (short) 0);
Recipe recipe = cm.getCraftingRecipe(items);
assertThat("Crafting manager did not get recipe", recipe, IsNull.notNullValue());
assertThat("Crafting manager got wrong material", Material.WOOD, is(recipe.getResult().getType()));
assertThat("Crafting manager got wrong amount", 4, is(recipe.getResult().getAmount()));
}
use of org.bukkit.inventory.Recipe in project MagicPlugin by elBukkit.
the class CraftingController method onPrepareCraftItem.
@EventHandler
public void onPrepareCraftItem(PrepareItemCraftEvent event) {
CraftingInventory inventory = event.getInventory();
ItemStack[] contents = inventory.getMatrix();
// Check for wands glitched into the crafting inventory
for (int i = 0; i < 9 && i < contents.length; i++) {
ItemStack item = contents[i];
if (Wand.isSpecial(item)) {
inventory.setResult(new ItemStack(Material.AIR));
return;
}
}
if (!craftingEnabled)
return;
Recipe recipe = event.getRecipe();
if (recipe == null)
return;
ItemStack result = recipe.getResult();
if (result == null)
return;
Material resultType = result.getType();
List<MagicRecipe> candidates = recipes.get(resultType);
if (candidates == null || candidates.size() == 0)
return;
for (MagicRecipe candidate : candidates) {
MagicRecipe.MatchType matchType = candidate.getMatchType(contents);
Material substitute = candidate.getSubstitute();
if (matchType != MagicRecipe.MatchType.NONE) {
for (HumanEntity human : event.getViewers()) {
if (human instanceof Player && (matchType == MagicRecipe.MatchType.PARTIAL || !hasCraftPermission((Player) human, candidate))) {
inventory.setResult(new ItemStack(Material.AIR));
return;
}
}
if (matchType == MagicRecipe.MatchType.MATCH) {
ItemStack crafted = candidate.craft();
inventory.setResult(crafted);
}
break;
} else if (substitute != null) {
inventory.setResult(new ItemStack(substitute, 1));
}
}
}
use of org.bukkit.inventory.Recipe in project CommandHelper by EngineHub.
the class BukkitMCServer method allRecipes.
@Override
public List<MCRecipe> allRecipes() {
List<MCRecipe> ret = new ArrayList<>();
for (Iterator recipes = s.recipeIterator(); recipes.hasNext(); ) {
Recipe recipe = (Recipe) recipes.next();
ret.add(BukkitConvertor.BukkitGetRecipe(recipe));
}
return ret;
}
use of org.bukkit.inventory.Recipe in project MagicPlugin by elBukkit.
the class MagicRecipe method register.
public void register(Plugin plugin) {
// I think we can only do this once..
if (FIRST_REGISTER) {
if (disableDefaultRecipe) {
Iterator<Recipe> it = plugin.getServer().recipeIterator();
while (it.hasNext()) {
Recipe defaultRecipe = it.next();
if (defaultRecipe != null && defaultRecipe.getResult().getType() == outputType && defaultRecipe.getResult().getDurability() == 0) {
plugin.getLogger().info("Disabled default crafting recipe for " + outputType);
it.remove();
}
}
}
}
// Add our custom recipe if crafting is enabled
if (recipe != null) {
if (!FIRST_REGISTER) {
List<Recipe> existing = plugin.getServer().getRecipesFor(craft());
if (existing.size() > 0) {
return;
}
}
plugin.getLogger().info("Adding crafting recipe for " + outputKey);
try {
plugin.getServer().addRecipe(recipe);
} catch (Exception ex) {
plugin.getLogger().log(Level.WARNING, "Failed to add recipe", ex);
}
}
}
Aggregations