use of org.spongepowered.api.data.Property 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.spongepowered.api.data.Property in project Nucleus by NucleusPowered.
the class BlockInfoCommand method executeCommand.
@Override
public CommandResult executeCommand(Player player, CommandContext args) throws Exception {
BlockRay<World> bl = BlockRay.from(player).distanceLimit(10).stopFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 1)).build();
Optional<BlockRayHit<World>> ob = bl.end();
// If the last block is not air...
if (ob.isPresent() && ob.get().getLocation().getBlockType() != BlockTypes.AIR) {
BlockRayHit<World> brh = ob.get();
// get the information.
BlockState b = brh.getLocation().getBlock();
BlockType it = b.getType();
List<Text> lt = new ArrayList<>();
lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.id", it.getId(), it.getTranslation().get()));
lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.iteminfo.extendedid", b.getId()));
if (args.hasAny("e") || args.hasAny("extended")) {
Collection<Property<?, ?>> cp = b.getApplicableProperties();
if (!cp.isEmpty()) {
cp.forEach(x -> {
if (x.getValue() != null) {
DataScanner.getText(player, "command.blockinfo.property.item", x.getKey().toString(), x.getValue()).ifPresent(lt::add);
}
});
}
Collection<BlockTrait<?>> cb = b.getTraits();
if (!cb.isEmpty()) {
cb.forEach(x -> b.getTraitValue(x).ifPresent(v -> DataScanner.getText(player, "command.blockinfo.traits.item", x.getName(), v).ifPresent(lt::add)));
}
}
Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().contents(lt).padding(Text.of(TextColors.GREEN, "-")).title(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.list.header", String.valueOf(brh.getBlockX()), String.valueOf(brh.getBlockY()), String.valueOf(brh.getBlockZ()))).sendTo(player);
return CommandResult.success();
}
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.blockinfo.none"));
return CommandResult.empty();
}
Aggregations