本文整理匯總了Java中org.bukkit.event.inventory.PrepareItemCraftEvent.isRepair方法的典型用法代碼示例。如果您正苦於以下問題:Java PrepareItemCraftEvent.isRepair方法的具體用法?Java PrepareItemCraftEvent.isRepair怎麽用?Java PrepareItemCraftEvent.isRepair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.event.inventory.PrepareItemCraftEvent
的用法示例。
在下文中一共展示了PrepareItemCraftEvent.isRepair方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onPrepareCrowbarCraft
import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPrepareCrowbarCraft(PrepareItemCraftEvent event) {
CraftingInventory inventory = event.getInventory();
if (event.isRepair() && event.getRecipe().getResult().getType() == Crowbar.CROWBAR_TYPE) {
int endFrameUses = 0;
int spawnerUses = 0;
boolean changed = false;
ItemStack[] matrix = inventory.getMatrix();
for (ItemStack ingredient : matrix) {
Optional<Crowbar> crowbarOptional = Crowbar.fromStack(ingredient);
if (crowbarOptional.isPresent()) {
Crowbar crowbar = crowbarOptional.get();
spawnerUses += crowbar.getSpawnerUses();
endFrameUses += crowbar.getEndFrameUses();
changed = true;
}
}
// Finally update the result.
if (changed) {
inventory.setResult(new Crowbar(spawnerUses, endFrameUses).getItemIfPresent());
}
}
}
示例2: prepareCraft
import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler public void prepareCraft(final PrepareItemCraftEvent event) {
Recipe recipe = event.getRecipe();
if (event.isRepair() || recipe instanceof MerchantRecipe || recipe instanceof FurnaceRecipe) {
return;
}
if (recipe.getResult() != null) {
return;
}
CraftingInventory inventory = event.getInventory();
ItemStack[] matrix = inventory.getMatrix();
PlayerheadItemStack skull = null;
int gold = 0, skulls = 0;
for (ItemStack item : matrix) {
if (item.getType() == Material.SKULL_ITEM) {
if (item instanceof PlayerheadItemStack && ((SkullMeta) item.getItemMeta()).hasOwner()) {
++skulls;
skull = (PlayerheadItemStack) item;
}
} else if (item.getType() == Material.GOLD_INGOT) {
++gold;
}
}
if (skull == null || gold != 7 || skulls != 1) {
return;
}
skull.setGolden(true);
inventory.setResult(skull);
}
示例3: CraftTool
import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler
public void CraftTool(PrepareItemCraftEvent event)
{
if (event.isRepair()) return;
List<ItemStack> items = new ArrayList<ItemStack>();
boolean success = false;
for(ItemStack a : event.getInventory().getContents()) {
if(a.getType().equals(Material.AIR)) continue;
items.add(a);
} // Get an easier to handle list.
if (items.size() != 3) return;
if(items.contains(ToolRegistry.getVeinMinerCoupon())){
for (ItemStack i : items){
if(ToolRegistry.veinMinerAllowedTools.contains(i.getType())) {
ItemMeta iMeta = i.getItemMeta();
List<String> lore = new ArrayList<String>();
lore.add(ToolRegistry.VEIN_TAG);
iMeta.setLore(lore);
i.setItemMeta(iMeta);
event.getInventory().setResult(i);
success = true;
}
}
}else{
return;
}
if (success == false) {
event.getInventory().setResult(null);
}
}
示例4: onPrepareItemCraft
import org.bukkit.event.inventory.PrepareItemCraftEvent; //導入方法依賴的package包/類
@EventHandler
public void onPrepareItemCraft(PrepareItemCraftEvent event)
{
ItemStack[] items = event.getInventory().getMatrix();
for(ItemStack itemStack : items)
{
if(!NBTHelper.getName(itemStack).equals("null"))
{
EnhancedItem item = EnhancedItemUtil.getItem(itemStack);
if(item != null)
{
if(event.isRepair() && !Boolean.parseBoolean(item.getProperty("canRepair")))
{
event.getInventory().setResult(new ItemStack(Material.AIR));
}
else if(event.isRepair() && Boolean.parseBoolean(item.getProperty("canRepair")))
{
ItemStack result = event.getRecipe().getResult();
ItemStack newStack = EnhancedItemUtil.createItem(item, result);
event.getInventory().setResult(newStack);
}
}
}
}
if(EnhancedItemUtil.getItem(event.getInventory().getResult()) != null)
{
event.getInventory().setResult(new ItemStack(Material.AIR));
}
for(Recipe recipe : EnhancedItems.getInstance().getRecipes())
{
if(RecipeUtil.matches(items, recipe))
{
if(RecipeUtil.matchesExact(items, recipe))
{
event.getInventory().setResult(EnhancedItemUtil.createItem(recipe.getOutput(), null));
break;
}
else
{
event.getInventory().setResult(new ItemStack(Material.AIR));
continue;
}
}
}
}