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();
}
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();
}
Aggregations