Search in sources :

Example 16 with MapInfo

use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.

the class MapTest method listMaps.

private CommandResult listMaps(final CommandContext ctx) {
    final Collection<MapInfo> mapInfos = Sponge.server().mapStorage().allMapInfos();
    ctx.sendMessage(Identity.nil(), Component.text(mapInfos.size()));
    final List<MapInfo> list = new ArrayList<>(mapInfos);
    list.sort(Comparator.comparingInt(info -> info.toContainer().getInt(DataQuery.of("UnsafeMapId")).get()));
    for (final MapInfo mapInfo : list) {
        ctx.sendMessage(Identity.nil(), Component.text("id: " + mapInfo.toContainer().getInt(DataQuery.of("UnsafeMapId")).get() + " loc: " + mapInfo.get(Keys.MAP_LOCATION).get()));
    }
    return CommandResult.success();
}
Also used : Color(java.awt.Color) Command(org.spongepowered.api.command.Command) MapDecoration(org.spongepowered.api.map.decoration.MapDecoration) Inject(com.google.inject.Inject) Banner(org.spongepowered.api.block.entity.Banner) Supports(org.spongepowered.api.event.filter.data.Supports) ItemStack(org.spongepowered.api.item.inventory.ItemStack) DataQuery(org.spongepowered.api.data.persistence.DataQuery) MapDecorationTypes(org.spongepowered.api.map.decoration.MapDecorationTypes) CommandExecutor(org.spongepowered.api.command.CommandExecutor) ImageIO(javax.imageio.ImageIO) Vector2i(org.spongepowered.math.vector.Vector2i) Plugin(org.spongepowered.plugin.builtin.jvm.Plugin) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BlockTypes(org.spongepowered.api.block.BlockTypes) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) UUID(java.util.UUID) MapColor(org.spongepowered.api.map.color.MapColor) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) MapStorage(org.spongepowered.api.map.MapStorage) Keys(org.spongepowered.api.data.Keys) List(java.util.List) Logger(org.apache.logging.log4j.Logger) MapInfo(org.spongepowered.api.map.MapInfo) HandTypes(org.spongepowered.api.data.type.HandTypes) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) RegistryEntry(org.spongepowered.api.registry.RegistryEntry) Getter(org.spongepowered.api.event.filter.Getter) ServerWorld(org.spongepowered.api.world.server.ServerWorld) MapDecorationType(org.spongepowered.api.map.decoration.MapDecorationType) ItemTypes(org.spongepowered.api.item.ItemTypes) CompletableFuture(java.util.concurrent.CompletableFuture) DataView(org.spongepowered.api.data.persistence.DataView) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MapDecorationOrientation(org.spongepowered.api.map.decoration.orientation.MapDecorationOrientation) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) MapShade(org.spongepowered.api.map.color.MapShade) MapDecorationOrientations(org.spongepowered.api.map.decoration.orientation.MapDecorationOrientations) ResourceKey(org.spongepowered.api.ResourceKey) RayTrace(org.spongepowered.api.util.blockray.RayTrace) MapColorTypes(org.spongepowered.api.map.color.MapColorTypes) RegisterCommandEvent(org.spongepowered.api.event.lifecycle.RegisterCommandEvent) RayTraceResult(org.spongepowered.api.util.blockray.RayTraceResult) CommandResult(org.spongepowered.api.command.CommandResult) MapCanvas(org.spongepowered.api.map.MapCanvas) LoadableModule(org.spongepowered.test.LoadableModule) Identity(net.kyori.adventure.identity.Identity) IOException(java.io.IOException) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) File(java.io.File) PluginContainer(org.spongepowered.plugin.PluginContainer) Audience(net.kyori.adventure.audience.Audience) CreateMapEvent(org.spongepowered.api.event.action.CreateMapEvent) CommandContext(org.spongepowered.api.command.parameter.CommandContext) Listener(org.spongepowered.api.event.Listener) Comparator(java.util.Comparator) Collections(java.util.Collections) CommandException(org.spongepowered.api.command.exception.CommandException) MapColorType(org.spongepowered.api.map.color.MapColorType) ArrayList(java.util.ArrayList) MapInfo(org.spongepowered.api.map.MapInfo)

Example 17 with MapInfo

use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.

the class MapTest method create.

private CommandResult create(final CommandContext ctx) throws CommandException {
    final Player player = this.requirePlayer(ctx);
    final MapInfo mapInfo = Sponge.server().mapStorage().createNewMapInfo().orElseThrow(() -> new CommandException(Component.text("Map creation was cancelled!")));
    final ItemStack itemStack = ItemStack.of(ItemTypes.FILLED_MAP, 1);
    final MapCanvas canvas = MapCanvas.builder().paintAll(MapColor.of(MapColorTypes.COLOR_RED)).build();
    mapInfo.offer(Keys.MAP_CANVAS, canvas);
    mapInfo.offer(Keys.MAP_LOCKED, true);
    mapInfo.offer(Keys.MAP_LOCATION, player.position().toInt().toVector2(true));
    itemStack.offer(Keys.MAP_INFO, mapInfo);
    player.inventory().offer(itemStack);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MapCanvas(org.spongepowered.api.map.MapCanvas) MapInfo(org.spongepowered.api.map.MapInfo) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

MapInfo (org.spongepowered.api.map.MapInfo)17 Player (org.spongepowered.api.entity.living.player.Player)13 CommandException (org.spongepowered.api.command.exception.CommandException)11 ItemStack (org.spongepowered.api.item.inventory.ItemStack)11 MapCanvas (org.spongepowered.api.map.MapCanvas)4 HashSet (java.util.HashSet)3 Audience (net.kyori.adventure.audience.Audience)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 MapColor (org.spongepowered.api.map.color.MapColor)3 ServerWorld (org.spongepowered.api.world.server.ServerWorld)3 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ItemStack (net.minecraft.world.item.ItemStack)2 Nullable (org.checkerframework.checker.nullness.qual.Nullable)2 Sponge (org.spongepowered.api.Sponge)2 DataView (org.spongepowered.api.data.persistence.DataView)2 MapStorage (org.spongepowered.api.map.MapStorage)2