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

Fix server only jars. #968

Merged
merged 2 commits into from
Nov 6, 2023
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 @@ -28,7 +28,7 @@
import java.nio.file.Path;
import java.util.Objects;

public abstract sealed class MinecraftJar permits MinecraftJar.Merged, MinecraftJar.Common, MinecraftJar.ServerOnly, MinecraftJar.ClientOnly {
public abstract sealed class MinecraftJar permits MinecraftJar.Client, MinecraftJar.ClientOnly, MinecraftJar.Common, MinecraftJar.Merged, MinecraftJar.Server {
private final Path path;
private final boolean merged, client, server;
private final String name;
Expand Down Expand Up @@ -68,8 +68,10 @@ public String getName() {
public abstract MinecraftJar forPath(Path path);

public static final class Merged extends MinecraftJar {
public static final String NAME = "merged";

public Merged(Path path) {
super(path, true, true, true, "merged");
super(path, true, true, true, NAME);
}

@Override
Expand All @@ -79,8 +81,10 @@ public MinecraftJar forPath(Path path) {
}

public static final class Common extends MinecraftJar {
public static final String NAME = "common";

public Common(Path path) {
super(path, false, false, true, "common");
super(path, false, false, true, NAME);
}

@Override
Expand All @@ -89,20 +93,39 @@ public MinecraftJar forPath(Path path) {
}
}

public static final class ServerOnly extends MinecraftJar {
public ServerOnly(Path path) {
super(path, false, false, true, "serverOnly");
public static final class Server extends MinecraftJar {
public static final String NAME = "server";

public Server(Path path) {
super(path, false, false, true, NAME);
}

@Override
public MinecraftJar forPath(Path path) {
return new Server(path);
}
}

// Un-split client jar
public static final class Client extends MinecraftJar {
public static final String NAME = "client";

public Client(Path path) {
super(path, false, true, false, NAME);
}

@Override
public MinecraftJar forPath(Path path) {
return new ServerOnly(path);
return new Client(path);
}
}

// Split client jar
public static final class ClientOnly extends MinecraftJar {
public static final String NAME = "clientOnly";

public ClientOnly(Path path) {
super(path, false, true, false, "clientOnly");
super(path, false, true, false, NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ public static final class Split extends MinecraftSourceSets {
@Override
public void applyDependencies(BiConsumer<String, String> consumer, List<String> targets) {
Preconditions.checkArgument(targets.size() == 2);
Preconditions.checkArgument(targets.contains("common"));
Preconditions.checkArgument(targets.contains("clientOnly"));
Preconditions.checkArgument(targets.contains(MinecraftJar.Common.NAME));
Preconditions.checkArgument(targets.contains(MinecraftJar.ClientOnly.NAME));

consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), "common");
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), "clientOnly");
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), "common");
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), "clientOnly");
consumer.accept(MINECRAFT_COMMON_NAMED.runtime(), MinecraftJar.Common.NAME);
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.runtime(), MinecraftJar.ClientOnly.NAME);
consumer.accept(MINECRAFT_COMMON_NAMED.compile(), MinecraftJar.Common.NAME);
consumer.accept(MINECRAFT_CLIENT_ONLY_NAMED.compile(), MinecraftJar.ClientOnly.NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@
import java.util.function.Function;

public enum SingleJarEnvType {
CLIENT(MinecraftJar.ClientOnly::new),
SERVER(MinecraftJar.ServerOnly::new);
CLIENT(MinecraftJar.Client::new, MinecraftJar.Client.NAME),
SERVER(MinecraftJar.Server::new, MinecraftJar.Server.NAME);

private final Function<Path, MinecraftJar> jarFunction;
private final String name;

SingleJarEnvType(Function<Path, MinecraftJar> jarFunction) {
SingleJarEnvType(Function<Path, MinecraftJar> jarFunction, String name) {
this.jarFunction = jarFunction;
this.name = name;
}

public Function<Path, MinecraftJar> getJar() {
return jarFunction;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ProviderImpl extends MappedMinecraftProvider {
}

interface Merged extends ProviderImpl {
String MERGED = "merged";
String MERGED = MinecraftJar.Merged.NAME;

default MinecraftJar getMergedJar() {
return new MinecraftJar.Merged(getJar(MERGED));
Expand All @@ -55,8 +55,8 @@ default List<MinecraftJar> getMinecraftJars() {
}

interface Split extends ProviderImpl {
String COMMON = "common";
String CLIENT_ONLY = "clientOnly";
String COMMON = MinecraftJar.Common.NAME;
String CLIENT_ONLY = MinecraftJar.ClientOnly.NAME;

default MinecraftJar getCommonJar() {
return new MinecraftJar.Common(getJar(COMMON));
Expand All @@ -76,7 +76,7 @@ interface SingleJar extends ProviderImpl {
SingleJarEnvType env();

default String envName() {
return "%sOnly".formatted(env());
return env().getName();
}

default MinecraftJar getEnvOnlyJar() {
Expand Down