use of com.elmakers.mine.bukkit.magic.MagicRecipe 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 com.elmakers.mine.bukkit.magic.MagicRecipe in project MagicPlugin by elBukkit.
the class CraftingController method load.
public void load(ConfigurationSection configuration) {
recipes.clear();
recipeCount = 0;
if (!craftingEnabled) {
return;
}
Set<String> recipeKeys = configuration.getKeys(false);
for (String key : recipeKeys) {
ConfigurationSection parameters = configuration.getConfigurationSection(key);
if (!parameters.getBoolean("enabled", true))
continue;
MagicRecipe recipe = new MagicRecipe(key, controller);
if (!recipe.load(parameters)) {
controller.getLogger().warning("Failed to create crafting recipe: " + key);
continue;
}
Material outputType = recipe.getOutputType();
List<MagicRecipe> similar = recipes.get(outputType);
if (similar == null) {
similar = new ArrayList<>();
recipes.put(outputType, similar);
}
similar.add(recipe);
recipeCount++;
}
}
Aggregations