Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c632e4a
added DotMinecraftDirectoryService and moved version list logic
stefandollase May 27, 2017
a37f1e0
replaced FilenameFactory by FilenameService
stefandollase May 27, 2017
33c36b2
moved remaining version list logic to DotMinecraftDirectoryService
stefandollase May 27, 2017
34a3a48
moved DotMinecraftDirectoryService
stefandollase May 27, 2017
f2f97f4
moved library logic to new LibraryService
stefandollase May 27, 2017
3b2e580
moved logic from player json to new PlayerSkinService
stefandollase May 27, 2017
afb28dd
moved launcher profile logic to new LauncherProfileService
stefandollase May 27, 2017
80bbd6c
moved directory logic
stefandollase May 27, 2017
1e24538
renamed DotMinecraftDirectoryService to DownloadService
stefandollase May 27, 2017
cef9b7e
merged LibraryFinder into LibraryService
stefandollase May 27, 2017
24e09ee
merged LauncherProfileService and DotMinecraftDirectoryFinder to DotM…
stefandollase May 28, 2017
fd59c43
moved download logic to DownloadService
stefandollase May 28, 2017
862af90
moved classes
stefandollase May 28, 2017
51d6f44
moved domain logic out of the JsonReader
stefandollase May 28, 2017
a44ab58
merged PlayerSkinService, PlayerInformationRetriever and parts of Pla…
stefandollase May 28, 2017
a4f5e57
moved code to DotMinecraftDirectoryService
stefandollase May 28, 2017
602c251
the JsonReader now throws the more generic FormatException ...
stefandollase May 28, 2017
f1302a1
changed UpdateInformationRetriever to use the JsonReader
stefandollase May 28, 2017
f9db5a7
moved JsonReader to new package
stefandollase May 28, 2017
1721b4b
switched remaining simple Gson usages to use the JsonReader
stefandollase May 28, 2017
93bf87e
added VersionListProvider
stefandollase May 28, 2017
d7725a8
the version .json file is now required ...
stefandollase May 31, 2017
83ab995
refactored LibraryService
stefandollase May 31, 2017
213a956
refactored LevelDatNbt
stefandollase May 31, 2017
b34ae7c
removed dependency from PlayerNbt
stefandollase May 31, 2017
ff7a905
removed the -mclibs command line parameter
stefandollase May 31, 2017
4c1a9b1
introduced facade classes MinecraftInstallation, LauncherProfile and …
stefandollase May 31, 2017
cf3f7c7
introduced new facade class SaveGame
stefandollase Jun 1, 2017
bc895dc
introduced facade interface PlayerInformationProvider
stefandollase Jun 1, 2017
6c2002a
moved facade class VersionListProvider
stefandollase Jun 1, 2017
88cf1be
removed unused method
stefandollase Jun 1, 2017
eff42d1
introduced new facade classes VersionList and Version
stefandollase Jun 1, 2017
91ec058
moved facade classes
stefandollase Jun 1, 2017
afffcfe
moved class
stefandollase Jun 1, 2017
13e81f3
removed MojangApiParsingException
stefandollase Jun 1, 2017
dac5189
added method MinecraftInstallation::readInstalledVersionsAsLauncherPr…
stefandollase Jun 1, 2017
30a1364
removed VersionList from MojangApi
stefandollase Jun 1, 2017
c3a7118
removed helper methods from MojangApi
stefandollase Jun 1, 2017
87c1262
removed MojangApiBuilder
stefandollase Jun 1, 2017
7aa01fb
removed MojangApi::getMinecraftInstallation
stefandollase Jun 1, 2017
a2f8e1c
removed MinecraftInstallation from MojangApi
stefandollase Jun 1, 2017
4ae5d48
split MojangApi into LauncherProfileRunner and RunningLauncherProfile
stefandollase Jun 1, 2017
eed56c1
actually used VersionListProvider
stefandollase Jun 1, 2017
e8d41c2
added dispose mechanism to World to be able to restrict the simultane…
stefandollase Jun 2, 2017
08a09ef
removed duplicate log message
stefandollase Jun 2, 2017
d0f424f
reworked service instantiation
stefandollase Jun 2, 2017
e4868bb
converted LibraryService to ClassLoaderService
stefandollase Jun 2, 2017
437ab42
added safety checks for resolveAllLater mechanism
stefandollase Jun 2, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/main/java/amidst/Application.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package amidst;

import java.util.Optional;

import amidst.dependency.injection.Factory0;
import amidst.dependency.injection.Factory1;
import amidst.documentation.AmidstThread;
Expand All @@ -10,14 +12,18 @@
import amidst.gui.main.MainWindowDialogs;
import amidst.gui.main.UpdatePrompt;
import amidst.gui.profileselect.ProfileSelectWindow;
import amidst.mojangapi.MojangApi;
import amidst.mojangapi.LauncherProfileRunner;
import amidst.mojangapi.RunningLauncherProfile;
import amidst.mojangapi.file.LauncherProfile;
import amidst.mojangapi.minecraftinterface.local.LocalMinecraftInterfaceCreationException;

@NotThreadSafe
public class Application {
private final MojangApi mojangApi;
private final Optional<LauncherProfile> preferredLauncherProfile;
private final LauncherProfileRunner launcherProfileRunner;
private final Factory1<MainWindowDialogs, UpdatePrompt> noisyUpdatePromptFactory;
private final Factory0<UpdatePrompt> silentUpdatePromptFactory;
private final Factory0<MainWindow> mainWindowFactory;
private final Factory1<RunningLauncherProfile, MainWindow> mainWindowFactory;
private final Factory0<ProfileSelectWindow> profileSelectWindowFactory;
private final Factory0<LicenseWindow> licenseWindowFactory;

Expand All @@ -26,13 +32,15 @@ public class Application {

@CalledOnlyBy(AmidstThread.EDT)
public Application(
MojangApi mojangApi,
Optional<LauncherProfile> preferredLauncherProfile,
LauncherProfileRunner launcherProfileRunner,
Factory1<MainWindowDialogs, UpdatePrompt> noisyUpdatePromptFactory,
Factory0<UpdatePrompt> silentUpdatePromptFactory,
Factory0<MainWindow> mainWindowFactory,
Factory1<RunningLauncherProfile, MainWindow> mainWindowFactory,
Factory0<ProfileSelectWindow> profileSelectWindowFactory,
Factory0<LicenseWindow> licenseWindowFactory) {
this.mojangApi = mojangApi;
this.preferredLauncherProfile = preferredLauncherProfile;
this.launcherProfileRunner = launcherProfileRunner;
this.noisyUpdatePromptFactory = noisyUpdatePromptFactory;
this.silentUpdatePromptFactory = silentUpdatePromptFactory;
this.mainWindowFactory = mainWindowFactory;
Expand All @@ -41,10 +49,10 @@ public Application(
}

@CalledOnlyBy(AmidstThread.EDT)
public void run() {
public void run() throws LocalMinecraftInterfaceCreationException {
checkForUpdatesSilently();
if (mojangApi.canCreateWorld()) {
displayMainWindow();
if (preferredLauncherProfile.isPresent()) {
displayMainWindow(launcherProfileRunner.run(preferredLauncherProfile.get()));
} else {
displayProfileSelectWindow();
}
Expand All @@ -61,8 +69,8 @@ public void checkForUpdatesSilently() {
}

@CalledOnlyBy(AmidstThread.EDT)
public void displayMainWindow() {
setMainWindow(mainWindowFactory.create());
public void displayMainWindow(RunningLauncherProfile runningLauncherProfile) {
setMainWindow(mainWindowFactory.create(runningLauncherProfile));
setProfileSelectWindow(null);
}

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/amidst/CommandLineParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ public class CommandLineParameters {
@Option(name = "-mcpath", usage = "location of the '.minecraft' directory.", metaVar = "<directory>")
public volatile String dotMinecraftDirectory;

@Option(name = "-mclibs", usage = "location of the '.minecraft/libraries' directory", metaVar = "<directory>")
public volatile String minecraftLibrariesDirectory;

@Option(name = "-mcjar", usage = "location of the minecraft jar file", metaVar = "<file>", depends = { "-mcjson" })
public volatile String minecraftJarFile;

Expand Down
55 changes: 40 additions & 15 deletions src/main/java/amidst/PerApplicationInjector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package amidst;

import java.io.IOException;
import java.util.Optional;

import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
Expand All @@ -16,28 +19,34 @@
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.LauncherProfileRunner;
import amidst.mojangapi.RunningLauncherProfile;
import amidst.mojangapi.file.DotMinecraftDirectoryNotFoundException;
import amidst.mojangapi.minecraftinterface.local.LocalMinecraftInterfaceCreationException;
import amidst.mojangapi.file.LauncherProfile;
import amidst.mojangapi.file.MinecraftInstallation;
import amidst.mojangapi.file.PlayerInformationCache;
import amidst.mojangapi.file.PlayerInformationProvider;
import amidst.mojangapi.file.VersionListProvider;
import amidst.mojangapi.world.SeedHistoryLogger;
import amidst.mojangapi.world.World;
import amidst.mojangapi.world.WorldBuilder;
import amidst.mojangapi.world.player.PlayerInformationCache;
import amidst.mojangapi.world.player.PlayerInformationCacheImpl;
import amidst.parsing.FormatException;
import amidst.settings.biomeprofile.BiomeProfileDirectory;
import amidst.threading.ThreadMaster;

@NotThreadSafe
public class PerApplicationInjector {
private final AmidstMetaData metadata;
private final AmidstSettings settings;
private final PlayerInformationCache playerInformationCache;
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 LauncherProfileRunner launcherProfileRunner;
private final BiomeProfileDirectory biomeProfileDirectory;
private final ThreadMaster threadMaster;
private final VersionListProvider versionListProvider;
private final LayerBuilder layerBuilder;
private final Zoom zoom;
private final FragmentManager fragmentManager;
Expand All @@ -47,21 +56,29 @@ public class PerApplicationInjector {
@CalledOnlyBy(AmidstThread.EDT)
public PerApplicationInjector(CommandLineParameters parameters, AmidstMetaData metadata, AmidstSettings settings)
throws DotMinecraftDirectoryNotFoundException,
LocalMinecraftInterfaceCreationException {
FormatException,
IOException {
this.metadata = metadata;
this.settings = settings;
this.playerInformationCache = new PlayerInformationCacheImpl();
this.playerInformationProvider = new PlayerInformationCache();
this.seedHistoryLogger = SeedHistoryLogger.from(parameters.seedHistoryFile);
this.worldBuilder = new WorldBuilder(playerInformationCache, seedHistoryLogger);
this.mojangApi = new MojangApiBuilder(worldBuilder, parameters).construct();
this.minecraftInstallation = MinecraftInstallation
.newLocalMinecraftInstallation(parameters.dotMinecraftDirectory);
this.preferredLauncherProfile = minecraftInstallation
.tryReadLauncherProfile(parameters.minecraftJarFile, parameters.minecraftJsonFile);
this.worldBuilder = new WorldBuilder(playerInformationProvider, seedHistoryLogger);
this.launcherProfileRunner = new LauncherProfileRunner(worldBuilder);
this.biomeProfileDirectory = BiomeProfileDirectory.create(parameters.biomeProfilesDirectory);
this.threadMaster = new ThreadMaster();
this.versionListProvider = VersionListProvider
.createLocalAndStartDownloadingRemote(threadMaster.getWorkerExecutor());
this.layerBuilder = new LayerBuilder();
this.zoom = new Zoom(settings.maxZoom);
this.fragmentManager = new FragmentManager(layerBuilder.getConstructors(), layerBuilder.getNumberOfLayers());
this.biomeSelection = new BiomeSelection();
this.application = new Application(
mojangApi,
preferredLauncherProfile,
launcherProfileRunner,
this::createNoisyUpdatePrompt,
this::createSilentUpdatePrompt,
this::createMainWindow,
Expand All @@ -80,20 +97,28 @@ private UpdatePrompt createSilentUpdatePrompt() {
}

@CalledOnlyBy(AmidstThread.EDT)
private MainWindow createMainWindow() {
private MainWindow createMainWindow(RunningLauncherProfile runningLauncherProfile) {
return new PerMainWindowInjector(
application,
metadata,
settings,
mojangApi,
minecraftInstallation,
runningLauncherProfile,
biomeProfileDirectory,
this::createViewerFacade,
threadMaster).getMainWindow();
}

@CalledOnlyBy(AmidstThread.EDT)
private ProfileSelectWindow createProfileSelectWindow() {
return new ProfileSelectWindow(application, metadata, threadMaster.getWorkerExecutor(), mojangApi, settings);
return new ProfileSelectWindow(
application,
metadata,
threadMaster.getWorkerExecutor(),
versionListProvider,
minecraftInstallation,
launcherProfileRunner,
settings);
}

@CalledOnlyBy(AmidstThread.EDT)
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/amidst/gui/main/MainWindowDialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import amidst.logging.AmidstMessageBox;
import amidst.mojangapi.MojangApi;
import amidst.mojangapi.RunningLauncherProfile;
import amidst.mojangapi.world.WorldSeed;
import amidst.mojangapi.world.WorldType;
import amidst.mojangapi.world.export.WorldExporterConfiguration;
Expand All @@ -21,13 +21,13 @@
@NotThreadSafe
public class MainWindowDialogs {
private final AmidstSettings settings;
private final MojangApi mojangApi;
private final RunningLauncherProfile runningLauncherProfile;
private final JFrame frame;

@CalledOnlyBy(AmidstThread.EDT)
public MainWindowDialogs(AmidstSettings settings, MojangApi mojangApi, JFrame frame) {
public MainWindowDialogs(AmidstSettings settings, RunningLauncherProfile runningLauncherProfile, JFrame frame) {
this.settings = settings;
this.mojangApi = mojangApi;
this.runningLauncherProfile = runningLauncherProfile;
this.frame = frame;
}

Expand All @@ -52,7 +52,7 @@ public File askForSaveGame() {

@CalledOnlyBy(AmidstThread.EDT)
private JFileChooser createSaveGameFileChooser() {
JFileChooser result = new JFileChooser(mojangApi.getSaves());
JFileChooser result = new JFileChooser(runningLauncherProfile.getLauncherProfile().getSaves());
result.setFileFilter(new LevelFileFilter());
result.setAcceptAllFileFilterUsed(false);
result.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
Expand Down
33 changes: 23 additions & 10 deletions src/main/java/amidst/gui/main/PerMainWindowInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@
import amidst.gui.main.viewer.ViewerFacade;
import amidst.gui.seedsearcher.SeedSearcher;
import amidst.gui.seedsearcher.SeedSearcherWindow;
import amidst.mojangapi.MojangApi;
import amidst.mojangapi.RunningLauncherProfile;
import amidst.mojangapi.file.MinecraftInstallation;
import amidst.mojangapi.world.World;
import amidst.settings.biomeprofile.BiomeProfileDirectory;
import amidst.threading.ThreadMaster;

@NotThreadSafe
public class PerMainWindowInjector {
@CalledOnlyBy(AmidstThread.EDT)
private static String createVersionString(AmidstMetaData metadata, MojangApi mojangApi) {
return metadata.getVersion().createLongVersionString() + " - Selected Profile: " + mojangApi.getProfileName()
+ " - Minecraft Version " + mojangApi.getVersionId() + " (recognised: "
+ mojangApi.getRecognisedVersionName() + ")";
private static String createVersionString(AmidstMetaData metadata, RunningLauncherProfile runningLauncherProfile) {
return new StringBuilder()
.append(metadata.getVersion().createLongVersionString())
.append(" - Selected Profile: ")
.append(runningLauncherProfile.getLauncherProfile().getProfileName())
.append(" - Minecraft Version ")
.append(runningLauncherProfile.getLauncherProfile().getVersionId())
.append(" (recognised: ")
.append(runningLauncherProfile.getRecognisedVersion().getName())
.append(")")
.toString();
}

private final Factory2<World, Actions, ViewerFacade> viewerFacadeFactory;
Expand All @@ -50,18 +58,20 @@ public PerMainWindowInjector(
Application application,
AmidstMetaData metadata,
AmidstSettings settings,
MojangApi mojangApi,
MinecraftInstallation minecraftInstallation,
RunningLauncherProfile runningLauncherProfile,
BiomeProfileDirectory biomeProfileDirectory,
Factory2<World, Actions, ViewerFacade> viewerFacadeFactory,
ThreadMaster threadMaster) {
this.viewerFacadeFactory = viewerFacadeFactory;
this.versionString = createVersionString(metadata, mojangApi);
this.versionString = createVersionString(metadata, runningLauncherProfile);
this.frame = new JFrame();
this.contentPane = frame.getContentPane();
this.viewerFacadeReference = new AtomicReference<>();
this.dialogs = new MainWindowDialogs(settings, mojangApi, frame);
this.dialogs = new MainWindowDialogs(settings, runningLauncherProfile, frame);
this.worldSwitcher = new WorldSwitcher(
mojangApi,
minecraftInstallation,
runningLauncherProfile,
this::createViewerFacade,
threadMaster,
frame,
Expand All @@ -70,7 +80,10 @@ public PerMainWindowInjector(
dialogs,
this::getMenuBar);
if (FeatureToggles.SEED_SEARCH) {
this.seedSearcher = new SeedSearcher(dialogs, mojangApi, threadMaster.getWorkerExecutor());
this.seedSearcher = new SeedSearcher(
dialogs,
runningLauncherProfile.createSilentPlayerlessCopy(),
threadMaster.getWorkerExecutor());
this.seedSearcherWindow = new SeedSearcherWindow(metadata, dialogs, worldSwitcher, seedSearcher);
} else {
this.seedSearcher = null;
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/amidst/gui/main/UpdateInformationRetriever.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
package amidst.gui.main;

import java.io.IOException;
import java.io.Reader;

import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import amidst.documentation.Immutable;
import amidst.documentation.NotNull;
import amidst.mojangapi.file.URIUtils;
import amidst.parsing.FormatException;
import amidst.parsing.json.JsonReader;

@Immutable
public enum UpdateInformationRetriever {
;

private static final String UPDATE_INFORMATION_JSON_URL = "https://toolbox4minecraft.github.io/amidst/api/update-information.json";
private static final Gson GSON = new Gson();

@NotNull
public static UpdateInformationJson retrieve() throws IOException {
try (Reader theReader = URIUtils.newReader(UPDATE_INFORMATION_JSON_URL)) {
UpdateInformationJson result = GSON.fromJson(theReader, UpdateInformationJson.class);
if (result != null) {
return result;
} else {
throw new IOException("result was null");
}
} catch (JsonSyntaxException | JsonIOException e) {
throw new IOException(e);
}
public static UpdateInformationJson retrieve() throws FormatException, IOException {
return JsonReader.readLocation(UPDATE_INFORMATION_JSON_URL, UpdateInformationJson.class);
}
}
Loading