use of org.spongepowered.api.data.property.item.EquipmentProperty in project LanternServer by LanternPowered.
the class EquipmentItemFilter method of.
/**
* Constructs a {@link ItemFilter} for the provided
* {@link EquipmentSlotType} property.
*
* @param equipmentSlotType The equipment slot type property
* @return The equipment item filter
*/
static EquipmentItemFilter of(EquipmentSlotType equipmentSlotType) {
checkNotNull(equipmentSlotType, "equipmentSlotType");
final EquipmentType slotEquipmentType = equipmentSlotType.getValue();
checkNotNull(slotEquipmentType, "value");
final Property.Operator operator = equipmentSlotType.getOperator();
checkArgument(operator == Property.Operator.EQUAL || operator == Property.Operator.NOTEQUAL, "Only the operators EQUAL and NOTEQUAL are supported, %s is not.", operator);
return new EquipmentItemFilter() {
@Override
public boolean isValid(EquipmentType equipmentType) {
final boolean result = ((LanternEquipmentType) slotEquipmentType).isChild(equipmentType);
return (operator == Property.Operator.EQUAL) == result;
}
private boolean isValid(Optional<EquipmentProperty> optEquipmentProperty) {
return optEquipmentProperty.map(property -> {
final EquipmentType equipmentType = property.getValue();
final boolean result = ((LanternEquipmentType) slotEquipmentType).isChild(equipmentType);
return (operator == Property.Operator.EQUAL) == result;
}).orElse(false);
}
@Override
public boolean isValid(ItemStack stack) {
return isValid(stack.getProperty(EquipmentProperty.class));
}
@Override
public boolean isValid(ItemStackSnapshot stack) {
return isValid(stack.getProperty(EquipmentProperty.class));
}
@Override
public boolean isValid(ItemType type) {
return isValid(type.getDefaultProperty(EquipmentProperty.class));
}
};
}
Aggregations