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:
Pim van der Loos 2021-03-28 10:38:34 +02:00
parent aa1cd41b1e
commit 95909f2978
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8
3 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import javax.annotation.CheckReturnValue;
/** /**
* Base class for the anvil / smithing table handlers. * Base class for the anvil / smithing table handlers.
* *
@ -57,6 +59,7 @@ abstract class ArmoredElytraHandler
* cursor instead. * cursor instead.
* @return True if the item could be given to the player, otherwise false (e.g. when their inventory is full). * @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) protected boolean giveItemToPlayer(final Player player, final ItemStack item, final boolean direct)
{ {
if (direct) if (direct)

View File

@ -52,7 +52,8 @@ public class NetheriteUpgradeListener extends SmithingTableListener
SmithingInventory smithingInventory = (SmithingInventory) event.getInventory(); SmithingInventory smithingInventory = (SmithingInventory) event.getInventory();
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
giveItemToPlayer(player, smithingInventory.getItem(2), event.isShiftClick()); if (!giveItemToPlayer(player, smithingInventory.getItem(2), event.isShiftClick()))
return;
smithingInventory.clear(); smithingInventory.clear();
} }
} }

View File

@ -46,7 +46,8 @@ public class SmithingTableCraftHandler extends SmithingTableListener
final ItemStack result = smithingInventory.getItem(2); final ItemStack result = smithingInventory.getItem(2);
// This cast may look unchecked, but it was checked by isSmithingTableEvent already. // 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(); smithingInventory.clear();
} }
} }