Avoid accidentally deleting items
- Fixed not checking return value when trying to give players the result of crafting/upgrading an AE before clearing the items. Thanks, @Tanguygab for the heads-up!
This commit is contained in:
		@@ -6,6 +6,8 @@ import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.CheckReturnValue;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Base class for the anvil / smithing table handlers.
 | 
			
		||||
 *
 | 
			
		||||
@@ -57,6 +59,7 @@ abstract class ArmoredElytraHandler
 | 
			
		||||
     *               cursor instead.
 | 
			
		||||
     * @return True if the item could be given to the player, otherwise false (e.g. when their inventory is full).
 | 
			
		||||
     */
 | 
			
		||||
    @CheckReturnValue
 | 
			
		||||
    protected boolean giveItemToPlayer(final Player player, final ItemStack item, final boolean direct)
 | 
			
		||||
    {
 | 
			
		||||
        if (direct)
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,8 @@ public class NetheriteUpgradeListener extends SmithingTableListener
 | 
			
		||||
        SmithingInventory smithingInventory = (SmithingInventory) event.getInventory();
 | 
			
		||||
        Player player = (Player) event.getWhoClicked();
 | 
			
		||||
 | 
			
		||||
        giveItemToPlayer(player, smithingInventory.getItem(2), event.isShiftClick());
 | 
			
		||||
        if (!giveItemToPlayer(player, smithingInventory.getItem(2), event.isShiftClick()))
 | 
			
		||||
            return;
 | 
			
		||||
        smithingInventory.clear();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -46,7 +46,8 @@ public class SmithingTableCraftHandler extends SmithingTableListener
 | 
			
		||||
        final ItemStack result = smithingInventory.getItem(2);
 | 
			
		||||
 | 
			
		||||
        // This cast may look unchecked, but it was checked by isSmithingTableEvent already.
 | 
			
		||||
        giveItemToPlayer((Player) e.getWhoClicked(), result, e.isShiftClick());
 | 
			
		||||
        if (!giveItemToPlayer((Player) e.getWhoClicked(), result, e.isShiftClick()))
 | 
			
		||||
            return;
 | 
			
		||||
        smithingInventory.clear();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user