Skip to content

Commit

Permalink
Fix server only jars. (#968)
Browse files Browse the repository at this point in the history
* Actally fix server only jars.

* Cleanup the single jar names
  • Loading branch information
modmuss50 authored Nov 6, 2023
1 parent 731f072 commit ee0e5df
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
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

0 comments on commit ee0e5df

Please sign in to comment.