use of org.lanternpowered.server.inventory.equipment.LanternEquipmentType 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));
}
};
}
use of org.lanternpowered.server.inventory.equipment.LanternEquipmentType in project LanternServer by LanternPowered.
the class EquipmentTypeRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
register(new LanternEquipmentType("minecraft", "all", type -> true));
register(new LanternEquipmentType("minecraft", "equipped", type -> type instanceof LanternHeldEquipmentType || type instanceof LanternWornEquipmentType));
register(new LanternHeldEquipmentType("minecraft", "held", type -> type instanceof LanternHeldEquipmentType));
register(new LanternHeldEquipmentType("minecraft", "main_hand"));
register(new LanternHeldEquipmentType("minecraft", "off_hand"));
register(new LanternWornEquipmentType("minecraft", "worn", type -> type instanceof LanternWornEquipmentType));
register(new LanternWornEquipmentType("minecraft", "boots"));
register(new LanternWornEquipmentType("minecraft", "chestplate"));
register(new LanternWornEquipmentType("minecraft", "headwear"));
register(new LanternWornEquipmentType("minecraft", "leggings"));
}
Aggregations