Added callItemUpdateStateEvent(allowFood, hand) overload, getEatingHand is now @Nullable

This commit is contained in:
Arne Dalhuisen 2021-05-23 20:19:46 +02:00
parent ca96ed3420
commit e3c41a254d
1 changed files with 18 additions and 2 deletions

View File

@ -1141,7 +1141,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
*
* @return the eating hand, null if none
*/
public Hand getEatingHand() {
public @Nullable Hand getEatingHand() {
return eatingHand;
}
@ -2296,14 +2296,19 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* Used to call {@link ItemUpdateStateEvent} with the proper item
* It does check which hand to get the item to update.
*
* @param allowFood true if food should be updated, false otherwise
* @return the called {@link ItemUpdateStateEvent},
* null if there is no item to update the state
*/
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(@Nullable Hand hand) {
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(boolean allowFood, @Nullable Hand hand) {
if (hand == null)
return null;
final ItemStack updatedItem = getItemInHand(hand);
final boolean isFood = updatedItem.getMaterial().isFood();
if (isFood && !allowFood)
return null;
ItemUpdateStateEvent itemUpdateStateEvent = new ItemUpdateStateEvent(this, hand, updatedItem);
callEvent(ItemUpdateStateEvent.class, itemUpdateStateEvent);
@ -2311,6 +2316,17 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
return itemUpdateStateEvent;
}
/**
* Used to call {@link ItemUpdateStateEvent} with the proper item
* It does check which hand to get the item to update. Allows food.
*
* @return the called {@link ItemUpdateStateEvent},
* null if there is no item to update the state
*/
public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(@Nullable Hand hand) {
return callItemUpdateStateEvent(true, hand);
}
/**
* Makes the player digging a custom block, see {@link #resetTargetBlock()} to rewind.
*