removed MojangApiBuilder
parent
c3a7118dee
commit
87c126289e
|
@ -1,5 +1,7 @@
|
|||
package amidst;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import amidst.documentation.AmidstThread;
|
||||
import amidst.documentation.CalledOnlyBy;
|
||||
import amidst.documentation.NotThreadSafe;
|
||||
|
@ -17,8 +19,9 @@ import amidst.gui.main.viewer.ViewerFacade;
|
|||
import amidst.gui.main.viewer.Zoom;
|
||||
import amidst.gui.profileselect.ProfileSelectWindow;
|
||||
import amidst.mojangapi.MojangApi;
|
||||
import amidst.mojangapi.MojangApiBuilder;
|
||||
import amidst.mojangapi.file.DotMinecraftDirectoryNotFoundException;
|
||||
import amidst.mojangapi.file.LauncherProfile;
|
||||
import amidst.mojangapi.file.MinecraftInstallation;
|
||||
import amidst.mojangapi.file.PlayerInformationCache;
|
||||
import amidst.mojangapi.file.PlayerInformationProvider;
|
||||
import amidst.mojangapi.minecraftinterface.local.LocalMinecraftInterfaceCreationException;
|
||||
|
@ -34,6 +37,8 @@ public class PerApplicationInjector {
|
|||
private final AmidstSettings settings;
|
||||
private final PlayerInformationProvider playerInformationProvider;
|
||||
private final SeedHistoryLogger seedHistoryLogger;
|
||||
private final MinecraftInstallation minecraftInstallation;
|
||||
private final Optional<LauncherProfile> preferredLauncherProfile;
|
||||
private final WorldBuilder worldBuilder;
|
||||
private final MojangApi mojangApi;
|
||||
private final BiomeProfileDirectory biomeProfileDirectory;
|
||||
|
@ -52,8 +57,12 @@ public class PerApplicationInjector {
|
|||
this.settings = settings;
|
||||
this.playerInformationProvider = new PlayerInformationCache();
|
||||
this.seedHistoryLogger = SeedHistoryLogger.from(parameters.seedHistoryFile);
|
||||
this.minecraftInstallation = MinecraftInstallation
|
||||
.newLocalMinecraftInstallation(parameters.dotMinecraftDirectory);
|
||||
this.preferredLauncherProfile = minecraftInstallation
|
||||
.tryReadLauncherProfile(parameters.minecraftJarFile, parameters.minecraftJsonFile);
|
||||
this.worldBuilder = new WorldBuilder(playerInformationProvider, seedHistoryLogger);
|
||||
this.mojangApi = new MojangApiBuilder(worldBuilder, parameters).construct();
|
||||
this.mojangApi = MojangApi.from(minecraftInstallation, preferredLauncherProfile, worldBuilder);
|
||||
this.biomeProfileDirectory = BiomeProfileDirectory.create(parameters.biomeProfilesDirectory);
|
||||
this.threadMaster = new ThreadMaster();
|
||||
this.layerBuilder = new LayerBuilder();
|
||||
|
|
|
@ -22,15 +22,24 @@ import amidst.parsing.FormatException;
|
|||
|
||||
@ThreadSafe
|
||||
public class MojangApi {
|
||||
private final WorldBuilder worldBuilder;
|
||||
public static MojangApi from(
|
||||
MinecraftInstallation minecraftInstallation,
|
||||
Optional<LauncherProfile> preferredLauncherProfile,
|
||||
WorldBuilder worldBuilder) throws LocalMinecraftInterfaceCreationException {
|
||||
MojangApi result = new MojangApi(minecraftInstallation, worldBuilder);
|
||||
result.setLauncherProfile(preferredLauncherProfile.orElse(null));
|
||||
return result;
|
||||
}
|
||||
|
||||
private final MinecraftInstallation minecraftInstallation;
|
||||
private final WorldBuilder worldBuilder;
|
||||
|
||||
private volatile MinecraftInterface minecraftInterface;
|
||||
private volatile LauncherProfile launcherProfile;
|
||||
|
||||
public MojangApi(WorldBuilder worldBuilder, MinecraftInstallation minecraftInstallation) {
|
||||
this.worldBuilder = worldBuilder;
|
||||
public MojangApi(MinecraftInstallation minecraftInstallation, WorldBuilder worldBuilder) {
|
||||
this.minecraftInstallation = minecraftInstallation;
|
||||
this.worldBuilder = worldBuilder;
|
||||
}
|
||||
|
||||
public MinecraftInstallation getMinecraftInstallation() {
|
||||
|
@ -60,7 +69,7 @@ public class MojangApi {
|
|||
}
|
||||
|
||||
public MojangApi createSilentPlayerlessCopy() {
|
||||
MojangApi result = new MojangApi(WorldBuilder.createSilentPlayerless(), minecraftInstallation);
|
||||
MojangApi result = new MojangApi(minecraftInstallation, WorldBuilder.createSilentPlayerless());
|
||||
try {
|
||||
result.setLauncherProfile(launcherProfile);
|
||||
} catch (LocalMinecraftInterfaceCreationException e) {
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
package amidst.mojangapi;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import amidst.CommandLineParameters;
|
||||
import amidst.documentation.Immutable;
|
||||
import amidst.documentation.NotNull;
|
||||
import amidst.mojangapi.file.DotMinecraftDirectoryNotFoundException;
|
||||
import amidst.mojangapi.file.MinecraftInstallation;
|
||||
import amidst.mojangapi.minecraftinterface.local.LocalMinecraftInterfaceCreationException;
|
||||
import amidst.mojangapi.world.WorldBuilder;
|
||||
import amidst.parsing.FormatException;
|
||||
|
||||
@Immutable
|
||||
public class MojangApiBuilder {
|
||||
private final WorldBuilder worldBuilder;
|
||||
private final CommandLineParameters parameters;
|
||||
|
||||
public MojangApiBuilder(WorldBuilder worldBuilder, CommandLineParameters parameters) {
|
||||
this.worldBuilder = worldBuilder;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MojangApi construct()
|
||||
throws DotMinecraftDirectoryNotFoundException,
|
||||
LocalMinecraftInterfaceCreationException {
|
||||
MinecraftInstallation minecraftInstallation = MinecraftInstallation
|
||||
.newLocalMinecraftInstallation(parameters.dotMinecraftDirectory);
|
||||
MojangApi result = new MojangApi(worldBuilder, minecraftInstallation);
|
||||
if (parameters.minecraftJarFile != null && parameters.minecraftJsonFile != null) {
|
||||
try {
|
||||
result.setLauncherProfile(
|
||||
minecraftInstallation.newLauncherProfile(
|
||||
new File(parameters.minecraftJarFile),
|
||||
new File(parameters.minecraftJsonFile)));
|
||||
} catch (FormatException | IOException e) {
|
||||
result.setLauncherProfile(null);
|
||||
}
|
||||
} else {
|
||||
result.setLauncherProfile(null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import amidst.documentation.Immutable;
|
||||
|
@ -92,4 +93,23 @@ public class MinecraftInstallation {
|
|||
SaveDirectory saveDirectory = saveDirectoryService.newSaveDirectory(location);
|
||||
return new SaveGame(saveDirectory, saveDirectoryService.readLevelDat(saveDirectory));
|
||||
}
|
||||
|
||||
public Optional<LauncherProfile> tryReadLauncherProfile(
|
||||
String preferredMinecraftJarFile,
|
||||
String preferredMinecraftJsonFile) {
|
||||
if (preferredMinecraftJarFile != null && preferredMinecraftJsonFile != null) {
|
||||
try {
|
||||
return Optional.of(
|
||||
newLauncherProfile(new File(preferredMinecraftJarFile), new File(preferredMinecraftJsonFile)));
|
||||
} catch (FormatException | IOException e) {
|
||||
AmidstLogger.error(
|
||||
e,
|
||||
"cannot read launcher profile. preferredMinecraftJarFile: '" + preferredMinecraftJarFile
|
||||
+ "', preferredMinecraftJsonFile: '" + "'");
|
||||
return Optional.empty();
|
||||
}
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue