use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.
the class SpongeCommonEventFactory method fireCreateMapEvent.
public static Optional<MapInfo> fireCreateMapEvent(final Cause cause, final Set<Value<?>> values) {
final ServerLevel defaultWorld = (ServerLevel) Sponge.server().worldManager().defaultWorld();
final MapIdTrackerBridge mapIdTrackerBridge = (MapIdTrackerBridge) defaultWorld.getDataStorage().computeIfAbsent(MapIndex::new, Constants.Map.MAP_INDEX_DATA_NAME);
final int id = mapIdTrackerBridge.bridge$getHighestMapId().orElse(-1) + 1;
final String s = Constants.Map.MAP_PREFIX + id;
final MapItemSavedData mapData = new MapItemSavedData(s);
// Set default to prevent NPEs
mapData.dimension = Level.OVERWORLD;
final MapInfo mapInfo = (MapInfo) mapData;
for (final Value<?> value : values) {
mapInfo.offer(value);
}
final CreateMapEvent event = SpongeEventFactory.createCreateMapEvent(cause, mapInfo);
SpongeCommon.post(event);
if (event.isCancelled()) {
return Optional.empty();
}
// Advance map id.
final int mcId = defaultWorld.getFreeMapId();
if (id != mcId) {
// TODO: REMOVE OR replace for Integer.MAX_VALUE
SpongeCommon.logger().warn("Map size corruption, vanilla only allows " + Integer.MAX_VALUE + "! " + "Expected next number was not equal to the true next number.");
SpongeCommon.logger().warn("Expected: " + id + ". Got: " + mcId);
SpongeCommon.logger().warn("Automatically cancelling map creation");
mapIdTrackerBridge.bridge$setHighestMapId(id - 1);
return Optional.empty();
}
defaultWorld.setMapData(mapData);
((SpongeMapStorage) Sponge.server().mapStorage()).addMapInfo(mapInfo);
return Optional.of(mapInfo);
}
use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.
the class MinecraftServerMixin_API method api$initializeSpongeFields.
@Inject(method = "<init>", at = @At("TAIL"))
public void api$initializeSpongeFields(final Thread p_i232576_1_, final RegistryAccess.RegistryHolder p_i232576_2_, final LevelStorageSource.LevelStorageAccess p_i232576_3_, final WorldData p_i232576_4_, final PackRepository p_i232576_5_, final Proxy p_i232576_6_, final DataFixer p_i232576_7_, final ServerResources p_i232576_8_, final MinecraftSessionService p_i232576_9_, final GameProfileRepository p_i232576_10_, final GameProfileCache p_i232576_11_, final ChunkProgressListenerFactory p_i232576_12_, final CallbackInfo ci) {
this.api$scheduler = new ServerScheduler();
this.api$playerDataHandler = new SpongePlayerDataManager(this);
this.api$teleportHelper = new SpongeTeleportHelper();
this.api$mapStorage = new SpongeMapStorage();
this.api$registryHolder = new RegistryHolderLogic(p_i232576_2_);
this.api$userManager = new SpongeUserManager((MinecraftServer) (Object) this);
}
use of org.spongepowered.common.map.SpongeMapStorage in project SpongeCommon by SpongePowered.
the class MapItemSavedDataMixin method impl$setMapId.
@Inject(method = "<init>", at = @At("RETURN"))
public void impl$setMapId(final String mapname, final CallbackInfo ci) {
final int underscore = mapname.lastIndexOf('_');
if (underscore != -1) {
final String id = mapname.substring(underscore + 1);
try {
this.impl$mapId = Integer.parseInt(id);
final SpongeMapStorage mapStorage = (SpongeMapStorage) Sponge.server().mapStorage();
mapStorage.addMapInfo((MapInfo) this);
this.impl$uuid = mapStorage.requestUUID(this.impl$mapId);
return;
} catch (final NumberFormatException e) {
// ignored
}
}
SpongeCommon.logger().error("Map id could not be got from map name, (" + mapname + ")");
}
Aggregations