Fix shift-click crafting recipe with result greater than 1, fixes #1235

This commit is contained in:
PikaMug 2020-06-16 03:41:49 -04:00
parent f13e07f89b
commit 6e761857bc
2 changed files with 6 additions and 11 deletions

View File

@ -62,21 +62,16 @@ public class ItemListener implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private ItemStack getCraftedItem(CraftItemEvent evt) { private ItemStack getCraftedItem(CraftItemEvent evt) {
if (evt.isShiftClick()) { if (evt.isShiftClick()) {
ItemStack result = evt.getRecipe().getResult(); ItemStack recipeResult = evt.getRecipe().getResult();
int numberOfItems = result.getAmount(); int resultAmt = recipeResult.getAmount(); // Bread = 1, Cookie = 8, etc.
int itemsChecked = 0;
int leastIngredient = 1;
for (ItemStack item : evt.getInventory().getMatrix()) { for (ItemStack item : evt.getInventory().getMatrix()) {
if (item != null && !item.getType().equals(Material.AIR)) { if (item != null && !item.getType().equals(Material.AIR)) {
if (itemsChecked == 0) { leastIngredient = Math.min(leastIngredient * resultAmt, item.getAmount() * resultAmt);
numberOfItems = item.getAmount();
} else {
numberOfItems = Math.min(numberOfItems, item.getAmount());
itemsChecked++;
} }
} }
} return new ItemStack(recipeResult.getType(), leastIngredient, recipeResult.getDurability());
return new ItemStack(result.getType(), numberOfItems, result.getDurability());
} }
return evt.getCurrentItem(); return evt.getCurrentItem();
} }

View File

@ -167,7 +167,7 @@ public class PlayerListener implements Listener {
} catch (NoSuchMethodError err) { } catch (NoSuchMethodError err) {
// Do nothing, getHand() not present pre-1.9 // Do nothing, getHand() not present pre-1.9
} }
if (e == null || e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand) if (e == null || e.equals(EquipmentSlot.HAND)) { // If the event is fired by HAND (main hand)
if (evt.hasBlock() && ItemUtil.isJournal(evt.getPlayer().getItemInHand())) { if (evt.hasBlock() && ItemUtil.isJournal(evt.getPlayer().getItemInHand())) {
if (evt.getClickedBlock().getType().name().contains("PORTAL") if (evt.getClickedBlock().getType().name().contains("PORTAL")
&& plugin.getSettings().canAllowPranks()) { && plugin.getSettings().canAllowPranks()) {