Search in sources :

Example 1 with Banner

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();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Banner(org.spongepowered.api.block.entity.Banner) MapInfo(org.spongepowered.api.map.MapInfo) LocatableBlock(org.spongepowered.api.world.LocatableBlock) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

Banner (org.spongepowered.api.block.entity.Banner)1 CommandException (org.spongepowered.api.command.exception.CommandException)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 MapInfo (org.spongepowered.api.map.MapInfo)1 LocatableBlock (org.spongepowered.api.world.LocatableBlock)1