Skip to content

Commit

Permalink
Version - make release type an object
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee committed Sep 30, 2024
1 parent 7d3a959 commit 04a9ee4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 16 deletions.
18 changes: 17 additions & 1 deletion src/main/java/com/shanebeestudios/mcdeob/McDeob.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static void main(String[] args) {
OptionParser parser = new OptionParser();
parser.accepts("help", "Shows help and exits");
parser.accepts("versions", "Prints a list of all Minecraft versions available to deobfuscate");
parser.accepts("releases", "Prints a list of all Minecraft full releases available to deobfuscate");
parser.accepts("snapshots", "Prints a list of all Minecraft snapshots available to deobfuscate");
parser.accepts("version", "Minecraft version for which we're deobfuscating")
.withRequiredArg()
.ofType(String.class);
Expand All @@ -56,7 +58,21 @@ public static void main(String[] args) {
Version.initVersions();
if (options.has("versions")) {
System.out.println("Available Minecraft versions to deobfuscate:");
for (Version version : Version.getVersions()) {
for (Version version : Version.getAllVersions()) {
System.out.println(" - " + version.getVersion() + " (" + version.getReleaseType().getName() + ")");
}
System.exit(0);
}
if (options.has("releases")) {
System.out.println("Available Minecraft full releases to deobfuscate:");
for (Version version : Version.getReleaseVersions()) {
System.out.println(" - " + version.getVersion());
}
System.exit(0);
}
if (options.has("snapshots")) {
System.out.println("Available Minecraft snapshots to deobfuscate:");
for (Version version : Version.getSnapshotVersions()) {
System.out.println(" - " + version.getVersion());
}
System.exit(0);
Expand Down
42 changes: 34 additions & 8 deletions src/main/java/com/shanebeestudios/mcdeob/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class Version {

// Static Stuff
private static final Map<String, Version> VERSION_MAP = new LinkedHashMap<>();
private static final Map<String, Version> RELEASE_MAP = new LinkedHashMap<>();
private static final Map<String, Version> SNAPSHOT_MAP = new LinkedHashMap<>();

public static void initVersions() {
JSONObject versionManifest;
Expand All @@ -25,38 +27,53 @@ public static void initVersions() {

for (Object o : versionManifest.getJSONArray("versions")) {
JSONObject versionObject = (JSONObject) o;
String version = versionObject.getString("id");
String releaseType = versionObject.getString("type");
String id = versionObject.getString("id");
String type = versionObject.getString("type");
String url = versionObject.getString("url");

VERSION_MAP.put(version, new Version(version, releaseType, url));
ReleaseType releaseType = type.equalsIgnoreCase("release") ? ReleaseType.RELEASE : ReleaseType.SNAPSHOT;
Version version = new Version(id, releaseType, url);
VERSION_MAP.put(id, version);
if (releaseType == ReleaseType.RELEASE) {
RELEASE_MAP.put(id, version);
} else {
SNAPSHOT_MAP.put(id, version);
}

// Mappings not available before 1.14.4, so we exit
if (version.equalsIgnoreCase("1.14.4")) {
if (id.equalsIgnoreCase("1.14.4")) {
break;
}
}
}

public static Collection<Version> getVersions() {
public static Collection<Version> getAllVersions() {
return VERSION_MAP.values();
}

public static Collection<Version> getReleaseVersions() {
return RELEASE_MAP.values();
}

public static Collection<Version> getSnapshotVersions() {
return SNAPSHOT_MAP.values();
}

@Nullable
public static Version getByVersion(String version) {
return VERSION_MAP.get(version);
}

// Class Stuff
private final String version;
private final String releaseType;
private final ReleaseType releaseType;
private final String url;

private Type type;
private String jarURL;
private String mapURL;

public Version(String version, String releaseType, String url) {
public Version(String version, ReleaseType releaseType, String url) {
this.version = version;
this.releaseType = releaseType;
this.url = url;
Expand All @@ -82,7 +99,7 @@ public String getVersion() {
return this.version;
}

public String getReleaseType() {
public ReleaseType getReleaseType() {
return this.releaseType;
}

Expand Down Expand Up @@ -111,4 +128,13 @@ public String getName() {
}
}

public enum ReleaseType {
RELEASE,
SNAPSHOT;

public String getName() {
return name().toLowerCase(Locale.ROOT);
}
}

}
10 changes: 3 additions & 7 deletions src/main/java/com/shanebeestudios/mcdeob/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,13 @@ private void createTypeButton() {

private void setupVersions(boolean showSnapshots) {
this.versionBox.removeAllItems();
for (Version version : Version.getVersions()) {
if (version.getReleaseType().equalsIgnoreCase("snapshot") && !showSnapshots) continue;
else if (version.getReleaseType().equalsIgnoreCase("release") && showSnapshots) continue;
this.versionBox.addItem(version.getVersion().replace("_", " "));
for (Version version : showSnapshots ? Version.getSnapshotVersions() : Version.getReleaseVersions()) {
this.versionBox.addItem(version.getVersion());
}
}

private void createVersionPopup() {
this.versionBox = new JComboBox<>();
//setupVersions(false);
this.versionBox.addItem("Initializing Versions");
this.versionBox.setSelectedIndex(0);
this.versionBox.setBackground(Color.lightGray);
Expand Down Expand Up @@ -227,11 +224,10 @@ public void componentResized(ComponentEvent e) {

class StartButtonListener implements ActionListener {

@SuppressWarnings("DataFlowIssue")
@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == startButton) {
Version version = Version.getByVersion(((String) versionBox.getSelectedItem()).replace(" ", "_"));
Version version = Version.getByVersion(((String) versionBox.getSelectedItem()));
if (!startButton.getText().equalsIgnoreCase("Start!")) return;
if (version == null) {
fail();
Expand Down

0 comments on commit 04a9ee4

Please sign in to comment.