use of org.spongepowered.api.block.BlockType 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