Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to download the server starter jar #25

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

public class DownloadUtils {
public static final String MANIFEST_URL = "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
public static final String SERVER_STARTER_JAR = "https://github.com/NeoForged/serverstarterjar/releases/latest/download/server.jar";

public static boolean OFFLINE_MODE = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraftforge.installer.actions.Actions;
import net.minecraftforge.installer.actions.FatInstallerAction;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.actions.ServerInstall;
import net.minecraftforge.installer.json.InstallV1;
import net.minecraftforge.installer.json.Util;
import net.minecraftforge.installer.ui.InstallerPanel;
Expand Down Expand Up @@ -84,6 +85,8 @@ public static void main(String[] args) throws IOException, URISyntaxException {
OptionSpec<File> clientInstallOption = parser.acceptsAll(Arrays.asList("installClient", "install-client"), "Install a client to the specified directory, defaulting to the MC installation directory").withOptionalArg().ofType(File.class).defaultsTo(getMCDir());
OptionSpec<File> serverInstallOption = parser.acceptsAll(Arrays.asList("installServer", "install-server"), "Install a server to the current directory").withOptionalArg().ofType(File.class).defaultsTo(new File("."));

OptionSpec<Void> serverStarterOption = parser.acceptsAll(Arrays.asList("server-starter", "server.jar", "server-jar"), "Download the server starter jar for arg-free executable launches");

OptionSpec<File> fatInstallerOption = parser.acceptsAll(Arrays.asList("fat-installer", "fat", "generate-fat"), "Generate a fat installer jar").withOptionalArg().ofType(File.class).defaultsTo(new File(installer.getParent(), installer.getName().replace(".jar", "-fat.jar")));
OptionSpec<Void> fatIncludeMC = parser.acceptsAll(Arrays.asList("fat-include-minecraft"), "Include the Minecraft client / server jar in the fat installer").availableIf(fatInstallerOption);
OptionSpec<Void> fatIncludeMCLibs = parser.acceptsAll(Arrays.asList("fat-include-minecraft-libs"), "Include the Minecraft libraries in the fat installer").availableIf(fatInstallerOption);
Expand Down Expand Up @@ -133,6 +136,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
if (optionSet.has(serverInstallOption)) {
action = Actions.SERVER;
target = optionSet.valueOf(serverInstallOption);
ServerInstall.serverStarterJar = optionSet.has(serverStarterOption);
} else if (optionSet.has(clientInstallOption)) {
action = Actions.CLIENT;
target = optionSet.valueOf(clientInstallOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public boolean run(File target, Predicate<String> optionals, File installer) thr
}
if (OPTIONS.contains(Options.INSTALLER_LIBS)) {
libraries.addAll(Arrays.asList(processors.getLibraries()));

monitor.stage("Downloading server starter jar");
writeFromUrl(out, "serverstarter.jar", DownloadUtils.SERVER_STARTER_JAR);
}

Set<String> duplicates = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

import net.minecraftforge.installer.DownloadUtils;
import net.minecraftforge.installer.SimpleInstaller;
import net.minecraftforge.installer.json.Artifact;
import net.minecraftforge.installer.json.InstallV1;
Expand All @@ -30,7 +32,9 @@
import net.minecraftforge.installer.ui.TranslatedMessage;

public class ServerInstall extends Action {
private List<Artifact> grabbed = new ArrayList<>();
public static boolean serverStarterJar;

private final List<Artifact> grabbed = new ArrayList<>();

public ServerInstall(InstallV1 profile, ProgressCallback monitor) {
super(profile, monitor, false);
Expand Down Expand Up @@ -105,9 +109,11 @@ public boolean run(File target, Predicate<String> optionals, File installer) thr
if (!processors.process(librariesDir, serverTarget, target, installer))
return false;

// TODO: Optionals
//if (!OptionalLibrary.saveModListJson(librariesDir, new File(target, "mods/mod_list.json"), VersionInfo.getOptionals(), optionals))
// return false;
if (serverStarterJar) {
monitor.downloader(DownloadUtils.SERVER_STARTER_JAR)
.localPath("serverstarter.jar")
.download(new File(target, "server.jar"));
}

return true;
}
Expand Down
37 changes: 32 additions & 5 deletions src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.minecraftforge.installer.actions.Actions;
import net.minecraftforge.installer.actions.FatInstallerAction;
import net.minecraftforge.installer.actions.ProgressCallback;
import net.minecraftforge.installer.actions.ServerInstall;
import net.minecraftforge.installer.actions.TargetValidator;
import net.minecraftforge.installer.json.InstallV1;
import net.minecraftforge.installer.json.OptionalLibrary;
Expand All @@ -63,8 +64,10 @@ public class InstallerPanel extends JPanel {
private final AtomicReference<Actions> action = new AtomicReference<>(Actions.CLIENT);
private JPanel fileEntryPanel;
private JPanel fatInstallerOptionsPanel;
private JPanel serverOptionsPanel;

private JCheckBox fatIncludeMC, fatIncludeMCLibs, fatIncludeInstallerLibs, fatOffline;
private JCheckBox serverStarterJar;

private List<OptionalListEntry> optionals = new ArrayList<>();
private Map<String, Function<ProgressCallback, Action>> actions = new HashMap<>();
Expand Down Expand Up @@ -221,10 +224,19 @@ public InstallerPanel(File targetDir, InstallV1 profile, File installer) {
this.remove(fileEntryPanel);
this.add(fatInstallerOptionsPanel);
} else {
this.add(fileEntryPanel);
if (!Arrays.asList(this.getComponents()).contains(fileEntryPanel)) {
this.add(fileEntryPanel);
}
this.remove(fatInstallerOptionsPanel);
}
});
} else if (action == Actions.SERVER) {
radioButton.addChangeListener(e -> {
if (radioButton.isSelected() != serverStarterJar.isSelected()) {
serverStarterJar.setVisible(radioButton.isSelected());
revalidate();
}
});
}
}
choicePanel.setAlignmentX(CENTER_ALIGNMENT);
Expand Down Expand Up @@ -256,6 +268,14 @@ public InstallerPanel(File targetDir, InstallV1 profile, File installer) {
infoLabel.setForeground(Color.RED);
infoLabel.setVisible(false);

serverOptionsPanel = centreAlignedPanel();
serverStarterJar = TRANSLATIONS.checkBox("installer.action.install.server.starterjar");
serverStarterJar.setMargin(new Insets(3, 0, 3, 0));
serverStarterJar.setVisible(false);
TRANSLATIONS.setTooltip(serverStarterJar, "installer.action.install.server.starterjar.tooltip");
serverOptionsPanel.add(serverStarterJar);
this.add(serverOptionsPanel);

fileEntryPanel = new JPanel();
fileEntryPanel.setLayout(new BoxLayout(fileEntryPanel, BoxLayout.Y_AXIS));
fileEntryPanel.add(infoLabel);
Expand All @@ -265,10 +285,7 @@ public InstallerPanel(File targetDir, InstallV1 profile, File installer) {
fileEntryPanel.setAlignmentY(TOP_ALIGNMENT);
this.add(fileEntryPanel);

fatInstallerOptionsPanel = new JPanel();
fatInstallerOptionsPanel.setLayout(new BoxLayout(fatInstallerOptionsPanel, BoxLayout.Y_AXIS));
fatInstallerOptionsPanel.setAlignmentX(CENTER_ALIGNMENT);
fatInstallerOptionsPanel.setAlignmentY(TOP_ALIGNMENT);
fatInstallerOptionsPanel = centreAlignedPanel();

this.fatIncludeMC = TRANSLATIONS.checkBox("installer.fat.includemc");
TRANSLATIONS.setTooltip(fatIncludeMC, "installer.fat.includemc.tooltip");
Expand Down Expand Up @@ -300,6 +317,14 @@ public InstallerPanel(File targetDir, InstallV1 profile, File installer) {
updateFilePath();
}

private JPanel centreAlignedPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setAlignmentX(CENTER_ALIGNMENT);
panel.setAlignmentY(TOP_ALIGNMENT);
return panel;
}

private void updateFilePath() {
try {
targetDir = targetDir.getCanonicalFile();
Expand Down Expand Up @@ -388,6 +413,8 @@ public void run(ProgressCallback monitor) {
FatInstallerAction.OPTIONS.add(FatInstallerAction.Options.INSTALLER_LIBS);
}
targetDir = new File(installer.getParent(), installer.getName().replace(".jar", "-fat.jar"));
} else if (action.get() == Actions.SERVER) {
ServerInstall.serverStarterJar = serverStarterJar.isSelected();
}

ProgressFrame prog = new ProgressFrame(monitor, Thread.currentThread()::interrupt, "installer.frame.installing", profile.getProfile(), profile.getVersion());
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/neoforged/installer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<entry key="installer.action.install.server.finished.withoutlibs">Successfully downloaded minecraft server and installed %s</entry>
<entry key="installer.action.install.server.finished.withlibs">Successfully downloaded minecraft server, downloaded %d libraries and installed %s</entry>

<entry key="installer.action.install.server.starterjar">Server starter jar</entry>
<entry key="installer.action.install.server.starterjar.tooltip">Generate a server.jar file that can be used to launch the server as an executable, as an alternative to the launch scripts</entry>

<entry key="installer.action.install.fat.name">Create fat installer</entry>
<entry key="installer.action.install.fat.tooltip">Create an installer that packs downloaded libs, for eventual offline use</entry>
<entry key="installer.action.install.fat.finished">Successfully created fat installer for version %s</entry>
Expand Down
Loading