Skip to content

Commit 179af5a

Browse files
committed
v0.2
1 parent 231b55b commit 179af5a

File tree

8 files changed

+58
-33
lines changed

8 files changed

+58
-33
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public enum EnumMode {
99

1010
help("Displays command usage", null),
11-
decompile("Start decompiling Minecraft", new TaskInfoDecompile(), new String[] {"debug", "ignore", "patch", "side", "client", "server"}),
11+
decompile("Start decompiling Minecraft", new TaskInfoDecompile(), new String[] {"debug", "ignore", "indention", "patch", "side", "client", "server"}),
1212
recompile("Recompile Minecraft sources", new TaskInfoRecompile(), new String[] {"debug", "side", "client", "server"}),
1313
reobfuscate("Reobfuscate Minecraft classes", new TaskInfoReobfuscate(), new String[] {"debug", "side", "client", "server"}),
1414
updatemd5("Update md5 hash tables used for reobfuscation", new TaskInfoUpdateMD5(), new String[] {"debug", "side", "client", "server"}),
@@ -44,6 +44,7 @@ public static String getParamDesc(String param) {
4444
}
4545

4646
static {
47+
paramDescs.put("indention", "Indention character used for sources");
4748
paramDescs.put("ignore", "List of packages to ignore");
4849
paramDescs.put("debug", "Show exception stack trace");
4950
paramDescs.put("patch", "Apply patches");

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class MCP {
1515

16-
public static final String VERSION = "v0.1";
16+
public static final String VERSION = "v0.2";
1717
public static EnumMode mode = null;
1818
public static EnumMode helpCommand = null;
1919
public static MCPLogger logger;
@@ -43,7 +43,7 @@ private static void attemptToDeleteUpdateJar() {
4343
}
4444

4545
public static void main(String[] args) throws Exception {
46-
SelfCommandPrompt.runWithCMD(SelfCommandPrompt.suggestAppId(), "RetroMCP " + VERSION, args);
46+
SelfCommandPrompt.runWithCMD(SelfCommandPrompt.suggestAppId(), "RetroMCP " + VERSION, args, false, false);
4747
attemptToDeleteUpdateJar();
4848
AnsiConsole.systemInstall();
4949
logger = new MCPLogger();
@@ -93,27 +93,17 @@ public static void main(String[] args) throws Exception {
9393
start();
9494
} else if (mode == EnumMode.help) {
9595
if(helpCommand == null) {
96-
List<String[]> commands = new ArrayList<>();
9796
for (EnumMode mode : EnumMode.values()) {
98-
commands.add(new String[]{mode.name(), mode.desc});
97+
logger.println(new Ansi()
98+
.fgBrightMagenta().a(" - " + String.format("%-12s", mode.name())).fgDefault()
99+
.fgGreen().a(" ").a(mode.desc).fgDefault());
99100
}
100-
101-
for (String[] command : commands) {
102-
for (int i2 = 0; i2 < command.length; i2++) {
103-
if (i2 == 0)
104-
logger.print(new Ansi().fgBrightMagenta().a(" - " + String.format("%-12s", command[i2])).fgDefault());
105-
else
106-
logger.print(new Ansi().fgGreen().a(" ").a(command[i2]).fgDefault());
107-
}
108-
109-
logger.newLine();
110-
}
111101
}
112102
else {
113103
logger.println(new Ansi().fgBrightMagenta().a(" - " + String.format("%-12s", helpCommand.name())).fgDefault().fgGreen().a(" ").a(helpCommand.desc).fgDefault());
114104
if(helpCommand.params.length > 0) logger.println("Optional parameters:");
115105
for(String param : helpCommand.params) {
116-
logger.println(new Ansi().a(" ").fgCyan().a(String.format("%-7s", param)).a(" - ").fgBrightYellow().a(EnumMode.getParamDesc(param)).fgDefault());
106+
logger.println(new Ansi().a(" ").fgCyan().a(String.format("%-10s", param)).a(" - ").fgBrightYellow().a(EnumMode.getParamDesc(param)).fgDefault());
117107
}
118108
}
119109
} else if (mode != EnumMode.exit) {
@@ -136,7 +126,7 @@ private static void setParams(Map<String, Object> parsedArgs, EnumMode mode) {
136126
String name = arg.getKey();
137127
if(value == null) {
138128
switch (name) {
139-
case "client":
129+
case "client":
140130
case "server":
141131
config.setParameter(name, true);
142132
break;
@@ -243,6 +233,7 @@ private static void processMultitasks(TaskInfo task) throws Exception {
243233
working = working || thread.isAlive();
244234
}
245235
}
236+
logger.printProgressBars(threads);
246237
for(SideThread thread : threads) {
247238
if (thread.exception != null) {
248239
ex = thread.exception;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.Path;
88
import java.nio.file.Paths;
99

10+
import org.fusesource.jansi.Ansi;
1011
import org.json.JSONObject;
1112
import org.mcphackers.mcp.MCP;
1213
import org.mcphackers.mcp.MCPConfig;
@@ -32,18 +33,19 @@ public void doTask() throws Exception {
3233
String latestVersion = releaseJson.getString("tag_name");
3334
String notes = releaseJson.getString("body");
3435
if(!latestVersion.equals(MCP.VERSION)) {
35-
MCP.logger.info("New version found: " + latestVersion);
36-
MCP.logger.info(notes);
36+
MCP.logger.info(new Ansi().a("New version found: ").fgBrightYellow().a(latestVersion).fgDefault().toString());
37+
MCP.logger.info(new Ansi().fgRgb(255,255,255).a("=========================").newline().a(notes).newline().a("=========================").fgDefault().toString());
3738
for(Object obj : releaseJson.getJSONArray("assets")) {
3839
if(obj instanceof JSONObject) {
3940
JSONObject assetObj = (JSONObject)obj;
4041
if(!assetObj.getString("name").endsWith(".jar")) {
4142
continue;
4243
}
4344
FileUtil.downloadFile(new URL(assetObj.getString("browser_download_url")), Paths.get(MCPConfig.UPDATE_JAR));
45+
break;
4446
}
4547
}
46-
MCP.logger.info("Press ENTER key to continue");
48+
MCP.logger.print("Press ENTER key to continue");
4749
MCP.input.nextLine();
4850
Path jarPath = Paths.get(MCP.class
4951
.getProtectionDomain()

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public TaskRun(int side, TaskInfo info) {
2121

2222
@Override
2323
public void doTask() throws Exception {
24+
if(side == SERVER && !VersionsParser.hasServer()) {
25+
throw new Exception("Server isn't available for this version!");
26+
}
2427
String java = Util.getJava();
2528
String natives = FileUtil.absolutePathString(MCPConfig.NATIVES);
2629
List<String> cpList = new LinkedList<String>();
@@ -60,7 +63,7 @@ else if (side == CLIENT) {
6063
"-Dorg.lwjgl.librarypath=" + natives,
6164
"-Dnet.java.games.input.librarypath=" + natives,
6265
"-cp", cp,
63-
side == SERVER ? "net.minecraft.server.MinecraftServer" : "Start"
66+
side == SERVER ? (VersionsParser.getServerVersion().startsWith("c") ? "com.mojang.minecraft.server.MinecraftServer" : "net.minecraft.server.MinecraftServer") : "Start"
6467
}));
6568
for(int i = 1; i < MCP.config.runArgs.length; i++) {
6669
String arg = MCP.config.runArgs[i];

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ public void doTask() throws Exception {
7272
VersionsParser.setCurrentVersion(chosenVersion);
7373

7474
long startTime = System.currentTimeMillis();
75-
MCP.logger.info(" Downloading mappings");
76-
FileUtil.downloadFile(VersionsParser.downloadVersion(), Paths.get(MCPConfig.CONF, "conf.zip"));
77-
FileUtil.unzip(Paths.get(MCPConfig.CONF, "conf.zip"), Paths.get(MCPConfig.CONF), true);
75+
if(Files.notExists(Paths.get("versions.json"))) {
76+
MCP.logger.info(" Downloading mappings");
77+
FileUtil.downloadFile(VersionsParser.downloadVersion(), Paths.get(MCPConfig.CONF, "conf.zip"));
78+
FileUtil.unzip(Paths.get(MCPConfig.CONF, "conf.zip"), Paths.get(MCPConfig.CONF), true);
79+
}
7880

7981
MCP.logger.info(" Setting up workspace");
8082
FileUtil.deleteDirectoryIfExists(Paths.get("workspace"));
@@ -95,9 +97,17 @@ public void doTask() throws Exception {
9597
startTime = System.currentTimeMillis();
9698
MCP.logger.info(" Downloading Minecraft " + (side == CLIENT ? "client" : "server") + "...");
9799
String url = VersionsParser.getDownloadURL(side);
98-
// TODO Classic server zips
99-
Path pathOut = Paths.get(side == CLIENT ? MCPConfig.CLIENT : MCPConfig.SERVER);
100-
FileUtil.downloadFile(new URL(url), pathOut);
100+
String out = side == CLIENT ? MCPConfig.CLIENT : MCPConfig.SERVER;
101+
Path pathOut = Paths.get(out);
102+
if(url.endsWith(".jar")) {
103+
FileUtil.downloadFile(new URL(url), pathOut);
104+
}
105+
else {
106+
Path zip = Paths.get(out.replace(".jar", ".zip"));
107+
FileUtil.downloadFile(new URL(url), zip);
108+
FileUtil.copyFileFromAZip(zip, "minecraft-server.jar", pathOut);
109+
Files.deleteIfExists(zip);
110+
}
101111
MCP.logger.info(" Done in " + Util.time(System.currentTimeMillis() - startTime));
102112
}
103113
}
@@ -117,7 +127,9 @@ public void doTask() throws Exception {
117127

118128
private void setWorkspace() throws Exception {
119129
String[] projects = { "Client", "Server" };
120-
for (String project : projects) {
130+
for (int i2 = 0; i2 < projects.length; i2++) {
131+
String project = projects[i2];
132+
String startclass = VersionsParser.hasServer() && VersionsParser.getServerVersion().startsWith("c") ? "com.mojang.minecraft.server.MinecraftServer" : "net.minecraft.server.MinecraftServer";
121133
Path[] filetoRead = new Path[] {
122134
Paths.get("workspace", ".metadata", ".plugins", "org.eclipse.debug.core", ".launches", project + ".launch"),
123135
Paths.get("workspace", project, ".idea", "workspace.xml"),
@@ -126,18 +138,27 @@ private void setWorkspace() throws Exception {
126138
for(int j = 0; j < filetoRead.length; j++) {
127139
if (Files.exists(filetoRead[j])) {
128140
List<String> lines = Files.readAllLines(filetoRead[j]);
129-
String replace = "-Dhttp.proxyPort=%s";
130141
for (int i = 0; i < lines.size(); i++) {
131142
switch (j) {
132143
case 0:
144+
if (i2 == SERVER) {
145+
String[] replace = new String[] {"value=\"/Server/src/%s.java\"", "key=\"org.eclipse.jdt.launching.MAIN_TYPE\" value=\"%s\""};
146+
lines.set(i, lines.get(i).replace(replace[0], String.format(replace[0], startclass.replace(".", "/"))));
147+
lines.set(i, lines.get(i).replace(replace[1], String.format(replace[1], startclass)));
148+
}
133149
case 1:
150+
String replace = "-Dhttp.proxyPort=%s";
134151
lines.set(i, lines.get(i).replace(replace, String.format(replace, VersionsParser.getProxyPort())));
152+
if (i2 == SERVER) {
153+
String replace2 = "name=\"MAIN_CLASS_NAME\" value=\"%s\"";
154+
lines.set(i, lines.get(i).replace(replace2, String.format(replace2, startclass)));
155+
}
135156
break;
136157
case 2:
137158
lines.set(i, lines.get(i).replace("$MCP_LOC$", Paths.get(System.getProperty("user.dir")).toAbsolutePath().toString().replace("\\", "/")));
138159
break;
139160
case 3:
140-
if(!VersionsParser.hasServer() && lines.get(i).contains("path=&quot;Server&quot;")) {
161+
if(i2 == SERVER && !VersionsParser.hasServer() && lines.get(i).contains("path=&quot;Server&quot;")) {
141162
lines.remove(i);
142163
}
143164
break;

src/main/java/org/mcphackers/mcp/tasks/info/TaskInfoDownloadUpdate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class TaskInfoDownloadUpdate extends TaskInfo {
77
@Override
88
public String title() {
9-
return "Setting up";
9+
return "Updating";
1010
}
1111

1212
@Override
@@ -16,7 +16,7 @@ public String successMsg() {
1616

1717
@Override
1818
public String failMsg() {
19-
return "COULD NOT FETCH LATEST RELEASE!";
19+
return "COULD NOT UPDATE!";
2020
}
2121

2222
@Override

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public static void deleteFileInAZip(Path sourceZip, String file) throws IOExcept
5555
Files.deleteIfExists(fileInsideZipPath);
5656
}
5757
}
58+
59+
public static void copyFileFromAZip(Path sourceZip, String file, Path out) throws IOException {
60+
try(FileSystem fs = FileSystems.newFileSystem(sourceZip, null)) {
61+
Path fileInsideZipPath = fs.getPath(file);
62+
Files.copy(fileInsideZipPath, out);
63+
}
64+
}
5865

5966
public static void unzip(final Path zipFile, final Path destDir) throws IOException {
6067
unzip(zipFile, destDir, false);

src/main/resources/workspace.zip

-20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)