mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 19:07:40 +01:00
Add EquipmentSlot convenience methods
This commit is contained in:
parent
ad084f6684
commit
d533ea2226
@ -33,4 +33,42 @@ public enum EquipmentSlot {
|
||||
public EquipmentSlotGroup getGroup() {
|
||||
return group.get();
|
||||
}
|
||||
// Paper start
|
||||
/**
|
||||
* Checks whether this equipment slot is a hand:
|
||||
* either {@link #HAND} or {@link #OFF_HAND}
|
||||
*
|
||||
* @return whether this is a hand slot
|
||||
*/
|
||||
public boolean isHand() {
|
||||
return this == HAND || this == OFF_HAND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opposite hand
|
||||
*
|
||||
* @return the opposite hand
|
||||
* @throws IllegalArgumentException if this equipment slot is not a hand
|
||||
* @see #isHand()
|
||||
*/
|
||||
public @NotNull EquipmentSlot getOppositeHand() {
|
||||
return switch (this) {
|
||||
case HAND -> OFF_HAND;
|
||||
case OFF_HAND -> HAND;
|
||||
default -> throw new IllegalArgumentException("Unable to determine an opposite hand for equipment slot: " + name());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this equipment slot
|
||||
* is one of the armor slots:
|
||||
* {@link #HEAD}, {@link #CHEST},
|
||||
* {@link #LEGS}, {@link #FEET}, or {@link #BODY}
|
||||
*
|
||||
* @return whether this is an armor slot
|
||||
*/
|
||||
public boolean isArmor() {
|
||||
return this == HEAD || this == CHEST || this == LEGS || this == FEET || this == BODY;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user