Search in sources :

Example 1 with MapStorage

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

the class MapTest method testMapSerialization.

private CommandResult testMapSerialization(final CommandContext ctx) {
    MapInfo mapInfo = null;
    final Audience audience = ctx.cause().audience();
    if (audience instanceof Player) {
        final Player player = (Player) audience;
        mapInfo = player.itemInHand(HandTypes.MAIN_HAND).get(Keys.MAP_INFO).orElse(null);
    }
    final MapStorage mapStorage = Sponge.server().mapStorage();
    if (mapInfo == null) {
        mapInfo = mapStorage.allMapInfos().stream().findAny().orElse(mapStorage.createNewMapInfo().get());
    }
    final DataView mapInfoView = blankMapDecorationIds(mapInfo.toContainer());
    mapInfoView.set(DataQuery.of("MapData", "MapLocked"), true).set(DataQuery.of("UnsafeMapId"), 10);
    return CommandResult.success();
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) Player(org.spongepowered.api.entity.living.player.Player) Audience(net.kyori.adventure.audience.Audience) MapInfo(org.spongepowered.api.map.MapInfo) MapStorage(org.spongepowered.api.map.MapStorage)

Example 2 with MapStorage

use of org.spongepowered.api.map.MapStorage 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)

Aggregations

Audience (net.kyori.adventure.audience.Audience)2 DataView (org.spongepowered.api.data.persistence.DataView)2 Player (org.spongepowered.api.entity.living.player.Player)2 MapInfo (org.spongepowered.api.map.MapInfo)2 MapStorage (org.spongepowered.api.map.MapStorage)2 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 Color (java.awt.Color)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1