Skip to content

Instantly share code, notes, and snippets.

@kelvneo
Last active August 29, 2015 14:23
Show Gist options
  • Save kelvneo/1d12fd50498f3639f571 to your computer and use it in GitHub Desktop.
Save kelvneo/1d12fd50498f3639f571 to your computer and use it in GitHub Desktop.
Easy Decipher for Minecraft Music
package me.deathline;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import com.google.gson.stream.JsonReader;
/**
* Created by NEOPETS on 6/17/2015.
*/
public class Main {
public static void main(String[] args) {
long time = System.nanoTime();
File workingDir = new File(System.getProperty("user.dir"));
File objectsDir = new File(workingDir.getParentFile(), "objects");
System.out.println("Current Working Directory: " + workingDir.getAbsolutePath());
System.out.println("Creating music storage directory...");
File musicStorageDir = new File(workingDir, "Music-Storage");
if (!musicStorageDir.exists())
musicStorageDir.mkdir();
System.out.println("Created at: " + musicStorageDir.getAbsolutePath());
System.out.println();
File jsonFile = workingDir.listFiles()[0];
System.out.println("Starting decoding process... ");
System.out.println();
try {
JsonReader reader = new JsonReader(new FileReader(jsonFile));
reader.beginObject();
while (reader.hasNext()) {
String object = reader.nextName();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.contains("music")) {
String musicActualName = name.split("/")[name.split("/").length - 1];
System.out.println("Music Name: " + musicActualName);
reader.beginObject();
while (reader.hasNext()) {
if (reader.nextName().equalsIgnoreCase("hash")) {
String hash = reader.nextString();
System.out.println("Hash: " + hash);
String firstTwoChar = hash.substring(0, 2);
File musicDir = new File(objectsDir, firstTwoChar);
File music = new File(musicDir, hash);
File copiedVer = new File(musicStorageDir, musicActualName);
Files.copy(music.toPath(), copiedVer.toPath(), StandardCopyOption.REPLACE_EXISTING);
System.out.println("Copied to: " + copiedVer.getAbsolutePath());
}
else
reader.skipValue();
}
reader.endObject();
System.out.println("---");
} else {
reader.skipValue();
}
}
reader.endObject();
}
reader.endObject();
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
long timeTaken = System.nanoTime() - time;
System.out.println("Time taken: " + timeTaken + "ns");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment