public ItemStack get(CraftItemEvent event) { return event.getRecipe().getResult(); } }, 0);
@EventHandler(priority=EventPriority.MONITOR) public void onCrafting(CraftItemEvent event) { if (event.isCancelled()) { return; } if (event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); String playerID = PlayerConverter.getID(player); CraftData playerData = (CraftData) dataMap.get(playerID); if (containsPlayer(playerID) && item.compare(event.getRecipe().getResult()) && checkConditions(playerID)) { playerData.subtract(event.getRecipe().getResult().getAmount()); if (playerData.isZero()) { completeObjective(playerID); } } } }
/** * Prevents crafting of EnderChest unless the player has permission * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onCraft(CraftItemEvent e) { e.setCancelled(checkEnderChest((Player)e.getWhoClicked(), e.getRecipe().getResult().getType())); }
@EventHandler public void craft(CraftItemEvent e){ if(e.getInventory() instanceof CraftingInventory){ CraftingInventory inv = (CraftingInventory) e.getInventory(); if(inv.getSize() != 4 && e.getRecipe().equals(lvl1ArmorHelmetRecipe())){ ItemStack helm = inv.getMatrix()[4];//get the middle item in the bench, which is the helmet if(helm.hasItemMeta()){//make sure the helmet has item meta if(helm.getItemMeta().getDisplayName().equals("Better Helmet")){//make sure the helmet's display name is 'Better Helmet' //you're done! It works! Do something like tell the player "you have crafted better armor" or something here. return; } } //the return; above would have been called if the crafting had succeeded. When it got called, the remainder of this method would not run (this part will not be run if the crafting has succeeded) //send the player a message to make it more realistic here. For my wizardry server I use: 'One of thee items used was incorrect, and unbalanced the energy. The death block hath been destroyed' e.setCanceled(true); e.setResult(new ItemStack(Material.AIR)); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCraftItem(CraftItemEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getWhoClicked().getWorld())) return; final HumanEntity whoClicked = event.getWhoClicked(); if (!whoClicked.hasMetadata(mcMMO.playerDataKey)) { return; } ItemStack result = event.getRecipe().getResult(); if (!ItemUtils.isMcMMOItem(result)) { return; } Player player = (Player) whoClicked; /* WORLD GUARD MAIN FLAG CHECK */ if(WorldGuardUtils.isWorldGuardLoaded()) { if(!WorldGuardManager.getInstance().hasMainFlag(player)) return; } new PlayerUpdateInventoryTask((Player) whoClicked).runTaskLater(plugin, 0); }