-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure a game directory for every version
- Loading branch information
1 parent
38fe5cf
commit e3044d8
Showing
18 changed files
with
228 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
headlessmc-launcher/src/main/java/me/earth/headlessmc/launcher/files/LauncherConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package me.earth.headlessmc.launcher.files; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import me.earth.headlessmc.launcher.LauncherProperties; | ||
import me.earth.headlessmc.launcher.version.Version; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Manages the directories the HeadlessMc Launcher will work in. | ||
*/ | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class LauncherConfig { | ||
/** | ||
* Supplies the config to check the {@link LauncherProperties#GAME_DIR_FOR_EACH_VERSION} property from. | ||
* Also supplies {@link #getFileManager()}. | ||
*/ | ||
private ConfigService config; | ||
/** | ||
* The .minecraft directory in which we store assets, libraries and versions. | ||
*/ | ||
private FileManager mcFiles; | ||
/** | ||
* The directory in which the game will run. | ||
*/ | ||
private FileManager gameDir; | ||
|
||
/** | ||
* The directory HeadlessMc configuration files, logs and others reside in. | ||
* Usually the folder HeadlessMC where the launcher has been started. | ||
* This FileManager is usually supplied from the {@link #config}. | ||
* | ||
* @return The directory for HeadlessMc files. | ||
* @see #setFileManager(FileManager) | ||
*/ | ||
public FileManager getFileManager() { | ||
return config.getFileManager(); | ||
} | ||
|
||
/** | ||
* Sets the FileManager to use for HeadlessMc. | ||
* | ||
* @param fileManager the new file manager to use. | ||
* @see #getFileManager() | ||
*/ | ||
public void setFileManager(FileManager fileManager) { | ||
config.setFileManager(fileManager); | ||
} | ||
|
||
/** | ||
* Gets the directory to run the game in for a specific version. | ||
* Usually this is just {@link #gameDir}, but if {@link LauncherProperties#GAME_DIR_FOR_EACH_VERSION} is enabled, | ||
* a game directory for each version will be created inside {@link #gameDir}. | ||
* | ||
* @param version the version to get a game directory for. | ||
* @return a FileManager managing the game dir for this version. | ||
*/ | ||
public FileManager getGameDir(Version version) { | ||
return getGameDir(version.getName()); | ||
} | ||
|
||
/** | ||
* Gets the directory to run the game in for a specific name. | ||
* Usually this is just {@link #gameDir}, but if {@link LauncherProperties#GAME_DIR_FOR_EACH_VERSION} is enabled, | ||
* a relative directory for the given name will be created inside {@link #gameDir}. | ||
* If name is {@code null} the default game directory will be used instead. | ||
* | ||
* @param name the name to get a game directory for. | ||
* @return a FileManager managing the game dir for this version. | ||
*/ | ||
public FileManager getGameDir(@Nullable String name) { | ||
if (name != null && config.getConfig().get(LauncherProperties.GAME_DIR_FOR_EACH_VERSION, false)) { | ||
return gameDir.createRelative(name); | ||
} | ||
|
||
return gameDir; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.