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