use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.
the class SpongeMapStorage method allMapInfos.
@Override
public Collection<MapInfo> allMapInfos() {
final Set<MapInfo> mapInfos = new HashSet<>();
final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
final int highestId = ((MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME)).bridge$getHighestMapId().orElse(-1);
for (int i = 0; i <= highestId; i++) {
@Nullable final MapInfo mapInfo = (MapInfo) defaultWorld.getMapData(Constants.Map.MAP_PREFIX + i);
if (mapInfo == null) {
SpongeCommon.logger().warn("Missing map with id: " + i);
continue;
}
this.addMapInfo(mapInfo);
mapInfos.add(mapInfo);
}
return mapInfos;
}
use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.
the class MapTest method recenterMap.
private CommandResult recenterMap(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);
mapInfo.offer(Keys.MAP_LOCATION, player.location().blockPosition().toVector2(true));
player.sendMessage(Component.text("New center " + mapInfo.require(Keys.MAP_LOCATION)));
return CommandResult.success();
}
use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.
the class MapTest method getMapFromUUID.
private CommandResult getMapFromUUID(final Parameter.Value<UUID> uuidParameter, final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final UUID uuid = ctx.one(uuidParameter).get();
final ItemStack itemStack = ItemStack.of(ItemTypes.FILLED_MAP, 1);
final MapInfo mapInfo = Sponge.server().mapStorage().mapInfo(uuid).orElseThrow(() -> new CommandException(Component.text("UUID " + uuid + " was not a valid map uuid!")));
itemStack.offer(Keys.MAP_INFO, mapInfo);
player.inventory().offer(itemStack);
return CommandResult.success();
}
use of org.spongepowered.api.map.MapInfo in project SpongeCommon by SpongePowered.
the class MapTest method setColorAndLocked.
private CommandResult setColorAndLocked(final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final ItemStack map = player.itemInHand(HandTypes.MAIN_HAND);
if (map.type() != ItemTypes.FILLED_MAP.get()) {
throw new CommandException(Component.text("You must hold a map in your hand"));
}
// map.offer(Keys.MAP_LOCATION, new Vector2i(10000,10000));
final MapColor color = MapColor.of(MapColorTypes.TERRACOTTA_BLACK);
final MapInfo mapInfo = map.require(Keys.MAP_INFO);
mapInfo.offer(Keys.MAP_LOCKED, true);
mapInfo.offer(Keys.MAP_CANVAS, MapCanvas.builder().paintAll(color).build());
player.sendMessage(Component.text(mapInfo.require(Keys.MAP_CANVAS).color(0, 0).toContainer().toString()));
return CommandResult.success();
}
use of org.spongepowered.api.map.MapInfo 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();
}
Aggregations