Skip to content

Commit 33a6b27

Browse files
committed
Fixed setup
1 parent 71f7c05 commit 33a6b27

81 files changed

Lines changed: 57 additions & 1924 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/mcphackers/mcp/MCPConfig.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class MCPConfig {
4343
public static final String SERVER_BIN = BIN + "minecraft_server";
4444
public static final String CLIENT_REOBF = REOBF + "minecraft";
4545
public static final String SERVER_REOBF = REOBF + "minecraft_server";
46+
public static final String VERSION = CONF + "version";
4647
public static final String CLIENT_MAPPINGS = CONF + "client.tiny";
4748
public static final String SERVER_MAPPINGS = CONF + "server.tiny";
4849
public static final String EXC_CLIENT = CONF + "client.exc";
@@ -51,8 +52,6 @@ public class MCPConfig {
5152
public static final String SERVER_PATCHES = CONF + "patches_server";
5253
public static final String JAVADOC_CLIENT = CONF + "client.javadoc";
5354
public static final String JAVADOC_SERVER = CONF + "server.javadoc";
54-
public static final String PROPERTIES_CLIENT = CONF + "client.properties";
55-
public static final String PROPERTIES_SERVER = CONF + "server.properties";
5655
public static final String BUILD_ZIP_CLIENT = BUILD + "minecraft.zip";
5756
public static final String BUILD_ZIP_SERVER = BUILD + "minecraft_server.zip";
5857
public static final String BUILD_JAR_CLIENT = BUILD + "minecraft.jar";

src/main/java/org/mcphackers/mcp/tasks/TaskRecompile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public void doTask() throws Exception {
7575
int i = 0;
7676
for(Path path : assets) {
7777
if(srcPath.relativize(path).getParent() != null) {
78-
Files.createDirectories(Paths.get(binPath.toString(), srcPath.relativize(path).getParent().toString()));
78+
Files.createDirectories(binPath.resolve(srcPath.relativize(path).getParent()));
7979
}
80-
Files.copy(path, Paths.get(binPath.toString(), srcPath.relativize(path).toString()));
80+
Files.copy(path, binPath.resolve(srcPath.relativize(path)));
8181
i++;
8282
this.progress = 50 + (int)((double)i / assets.size() * 49);
8383
}

src/main/java/org/mcphackers/mcp/tasks/TaskRun.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.mcphackers.mcp.tasks.info.TaskInfo;
1111
import org.mcphackers.mcp.tools.FileUtil;
1212
import org.mcphackers.mcp.tools.Util;
13+
import org.mcphackers.mcp.tools.VersionsParser;
1314

1415
public class TaskRun extends Task {
1516
public TaskRun(int side, TaskInfo info) {
@@ -45,19 +46,20 @@ else if (side == CLIENT) {
4546

4647

4748
String cp = String.join(";", cpList);
49+
50+
String version = new String(Files.readAllBytes(Paths.get(MCPConfig.VERSION)));
4851
int exit = Util.runCommand(
4952
new String[] {
5053
java,
5154
"-Xms1024M",
5255
"-Xmx1024M",
5356
"-Djava.util.Arrays.useLegacyMergeSort=true",
5457
"-Dhttp.proxyHost=betacraft.uk",
55-
"-Dhttp.proxyPort=11702", // TODO Get proxy from properties
58+
"-Dhttp.proxyPort=" + VersionsParser.getProxyPort(version),
5659
"-Dorg.lwjgl.librarypath=" + natives,
5760
"-Dnet.java.games.input.librarypath=" + natives,
5861
"-cp", cp,
59-
//TODO Get start class from properties
60-
side == SERVER ? "net.minecraft.server.MinecraftServer" : "net.minecraft.client.Minecraft"
62+
side == SERVER ? "net.minecraft.server.MinecraftServer" : "Start"
6163
}, Paths.get(MCPConfig.JARS), true);
6264
if(exit != 0) {
6365
throw new RuntimeException("Finished with exit value " + exit);

src/main/java/org/mcphackers/mcp/tasks/TaskSetup.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.mcphackers.mcp.tasks;
22

3+
import java.io.BufferedWriter;
4+
import java.io.FileWriter;
35
import java.net.URI;
46
import java.nio.file.Files;
57
import java.nio.file.Path;
@@ -67,20 +69,34 @@ public void doTask() throws Exception {
6769
chosenVersion = MCP.input.nextLine().toLowerCase();
6870
MCP.logger.print(new Ansi().fgDefault());
6971
}
72+
73+
FileUtil.createDirectories(Paths.get(MCPConfig.CONF));
74+
try(BufferedWriter writer = new BufferedWriter(new FileWriter(MCPConfig.VERSION))) {
75+
writer.write(chosenVersion);
76+
}
77+
7078
long startTime = System.currentTimeMillis();
7179
MCP.logger.info(" Downloading mappings");
72-
FileUtil.createDirectories(Paths.get(MCPConfig.CONF));
73-
VersionsParser.downloadVersion(chosenVersion);
80+
FileUtil.downloadFile(VersionsParser.downloadVersion(chosenVersion), Paths.get(MCPConfig.CONF, "conf.zip"));
81+
FileUtil.unzip(Paths.get(MCPConfig.CONF, "conf.zip"), Paths.get(MCPConfig.CONF), true);
7482

7583
// Create Eclipse workspace
7684
MCP.logger.info(" Setting up workspace");
7785
FileUtil.deleteDirectoryIfExists(Paths.get("eclipse"));
78-
int workspaceVersion = VersionsParser.getWorkspace(chosenVersion);
79-
FileUtil.copyDirectory(Paths.get("versions", "workspace", "eclipse_" + workspaceVersion), Paths.get("eclipse"));
86+
FileUtil.copyDirectory(Paths.get("versions", "workspace", "eclipse"), Paths.get("eclipse"));
8087

8188
// Create Intellij workspace
8289
String[] projects = { "Client", "Server" };
8390
for (String project : projects) {
91+
Path launch = Paths.get("eclipse", ".metadata", ".plugins", "org.eclipse.debug.core", ".launches", project + ".launch");
92+
if (Files.exists(launch)) {
93+
List<String> lines = Files.readAllLines(launch);
94+
String replace = "-Dhttp.proxyPort=%s";
95+
for (int i = 0; i < lines.size(); i++) {
96+
lines.set(i, lines.get(i).replace(replace, String.format(replace, VersionsParser.getProxyPort(chosenVersion))));
97+
}
98+
Files.write(launch, lines);
99+
}
84100
Path imlPath = Paths.get("eclipse", project, project + ".iml");
85101
if (Files.exists(imlPath)) {
86102
List<String> lines = Files.readAllLines(imlPath);

src/main/java/org/mcphackers/mcp/tools/FileUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public static void downloadFile(URL url, Path output) throws IOException {
9797
}
9898
}
9999

100+
@Deprecated
100101
public static void downloadGitDir(URL url, Path output) throws IOException, URISyntaxException {
101102
InputStream in = url.openStream();
102103
JSONArray json = Util.parseJSONArray(in);

src/main/java/org/mcphackers/mcp/tools/VersionsParser.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
import java.io.InputStream;
55
import java.net.URI;
66
import java.net.URL;
7-
import java.nio.file.Paths;
87
import java.util.ArrayList;
98
import java.util.Iterator;
109
import java.util.List;
1110

12-
import org.json.JSONArray;
1311
import org.json.JSONException;
1412
import org.json.JSONObject;
15-
import org.mcphackers.mcp.MCPConfig;
1613

1714
public class VersionsParser {
1815

19-
private static final String jsonURL = "https://raw.githubusercontent.com/MCPHackers/Vault/main/versions.json";
20-
private static final String contentsURL = "https://api.github.com/repos/MCPHackers/Vault/contents";
16+
private static final String jsonURL = "https://mcphackers.github.io/versions/versions.json";
2117
private static Exception cause = null;
2218

2319
public static final JSONObject json = getJson();
@@ -46,9 +42,9 @@ private static JSONObject getJson() {
4642
return null;
4743
}
4844

49-
public static int getWorkspace(String chosenVersion) throws Exception {
45+
public static int getProxyPort(String chosenVersion) throws Exception {
5046
checkJson();
51-
return json.getJSONObject(chosenVersion).getInt("workspace_version");
47+
return json.getJSONObject(chosenVersion).getInt("proxy_port");
5248
}
5349

5450
public static String getServerVersion(String chosenVersion) throws Exception {
@@ -73,17 +69,11 @@ public static String getDownloadURL(String chosenVersion, int side) throws Excep
7369
return null;
7470
}
7571

76-
public static void downloadVersion(String chosenVersion) throws Exception {
77-
InputStream in = new URL(contentsURL).openStream();
78-
JSONArray json = Util.parseJSONArray(in);
79-
for(Object object : json) {
80-
if(object instanceof JSONObject) {
81-
JSONObject jsonObject = (JSONObject)object;
82-
if(jsonObject.getString("type").equals("dir") && jsonObject.getString("name").equals(chosenVersion)) {
83-
FileUtil.downloadGitDir(new URI(jsonObject.getString("url")).toURL(), Paths.get(MCPConfig.CONF));
84-
break;
85-
}
86-
}
72+
public static URL downloadVersion(String chosenVersion) throws Exception {
73+
checkJson();
74+
if(json.getJSONObject(chosenVersion).has("resources")) {
75+
return new URI("https://mcphackers.github.io/versions/" + json.getJSONObject(chosenVersion).getString("resources")).toURL();
8776
}
77+
return null;
8878
}
8979
}

test/versions/workspace/eclipse_0/.metadata/.plugins/org.eclipse.core.resources/.projects/Client/placeholder renamed to test/versions/workspace/eclipse/.metadata/.plugins/org.eclipse.core.resources/.projects/Client/placeholder

File renamed without changes.

test/versions/workspace/eclipse_0/.metadata/.plugins/org.eclipse.core.resources/.projects/Server/placeholder renamed to test/versions/workspace/eclipse/.metadata/.plugins/org.eclipse.core.resources/.projects/Server/placeholder

File renamed without changes.

test/versions/workspace/eclipse_0/.metadata/.plugins/org.eclipse.core.resources/.root/0.tree renamed to test/versions/workspace/eclipse/.metadata/.plugins/org.eclipse.core.resources/.root/0.tree

File renamed without changes.

test/versions/workspace/eclipse_0/.metadata/.plugins/org.eclipse.debug.core/.launches/Client.launch renamed to test/versions/workspace/eclipse/.metadata/.plugins/org.eclipse.debug.core/.launches/Client.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
</listAttribute>
99
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="Start"/>
1010
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Client"/>
11-
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx1024M -Xms1024M -Djava.util.Arrays.useLegacyMergeSort=true -Dhttp.proxyHost=betacraft.uk -Dhttp.proxyPort=80"/>
11+
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx1024M -Xms1024M -Djava.util.Arrays.useLegacyMergeSort=true -Dhttp.proxyHost=betacraft.uk -Dhttp.proxyPort=%s"/>
1212
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${workspace_loc:Client/jars}"/>
1313
</launchConfiguration>

0 commit comments

Comments
 (0)