use of org.spongepowered.api.block.entity.Banner in project SpongeCommon by SpongePowered.
the class MapTest method addWorldBanner.
private CommandResult addWorldBanner(final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final ItemStack heldMap = player.itemInHand(HandTypes.MAIN_HAND);
if (heldMap.type() != ItemTypes.FILLED_MAP.get()) {
throw new CommandException(Component.text("You must hold a map in your hand"));
}
final MapInfo mapInfo = heldMap.require(Keys.MAP_INFO);
final RayTraceResult<LocatableBlock> hit = RayTrace.block().sourcePosition(player).direction(player).world(player.serverLocation().world()).continueWhileBlock(RayTrace.onlyAir()).limit(100).select(a -> a.location().blockEntity().filter(entity -> entity instanceof Banner).isPresent()).execute().orElseThrow(() -> new CommandException(Component.text("You must look at a banner")));
mapInfo.addBannerDecoration(hit.selectedObject().serverLocation());
return CommandResult.success();
}
Aggregations