Skip to content

Instantly share code, notes, and snippets.

@Jire
Created April 13, 2017 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jire/724f1aa39c84c570cfde5e06e82282da to your computer and use it in GitHub Desktop.
Save Jire/724f1aa39c84c570cfde5e06e82282da to your computer and use it in GitHub Desktop.
package ps.eden.server.plugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Jonathan on 10/18/2015.
*/
@InitializablePlugin
public final class PluginFixer {
public static Map<Path, List<String>> FILES = new HashMap<>();
public static void main(String[] args) throws IOException {
if (true) {
System.out.println("Be careful when using this. Enable it.");
return;
}
for (String l : Files.readAllLines(new File("plugin_meta.txt").toPath())) {
String input = l;
input = "src.main.java." + input;
input = input.replace(".", "/") + ".java";
Path path = null;
try {
path = new File(input).toPath();
List<String> lines = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
String line;
while ((line = br.readLine()) != null) {
lines.add(line);
}
} catch (Throwable t) {
t.printStackTrace();
continue;
}
boolean good = false;
outerloop:
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
if ((line.contains("extends") || line.contains("implements")) && line.contains("class") && line.contains("{")) {
lines.add(i, "@InitializablePlugin");
for (int j = i; j > 0; j--) {
String im = lines.get(j);
if (im.contains("import")) {
lines.add(j, "import ps.eden.server.plugin.InitializablePlugin;");
good = true;
break outerloop;
}
}
}
}
if (!good) {
System.out.println("Couldn't do " + l + ", " + input);
System.exit(9);
continue;
} else {
System.out.println("Did: " + input);
}
FILES.put(path, lines);
} catch (Throwable t) {
System.out.println("Error " + l + ", " + input);
FILES.remove(path);
t.printStackTrace();
System.exit(9);
}
}
for (Path p : FILES.keySet()) {
Files.write(p, FILES.get(p));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment