PlasmaVNGaming

Untitled

Mar 11th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.HashSet;
  3. import java.util.Set;
  4.  
  5. public class MCSourceCopy {
  6.  
  7. private static File file(String path) {
  8. return new File(path);
  9. }
  10.  
  11. public static void main(String[] args) {
  12. final String classFilePath = "C:\\Users\\nghik\\OneDrive\\Máy tính\\New folder (2)\\class.txt";
  13. Set<String> list = readList(file(classFilePath));
  14.  
  15. System.out.println("List result:");
  16. for (String clazz : list) {
  17. System.out.println(clazz);
  18. }
  19. System.out.println();
  20.  
  21. final String sourceFolderPath = "D:\\Workspace\\Code\\Tuinity\\Paper\\src\\main\\java";
  22. final String directionFolderPath = "C:\\Users\\nghik\\OneDrive\\Máy tính\\New folder (2)";
  23.  
  24. System.out.println("Copying...");
  25. copyFolder(file(sourceFolderPath)
  26. , file(directionFolderPath)
  27. , list);
  28. System.out.println("Done.");
  29. }
  30.  
  31. private static final String NMS = "v1_16_R3";
  32.  
  33. public static void copyFolder(File source, File to, Set<String> classList) {
  34. for (String clazz : classList) {
  35. copy(new File(source, clazz), new File(to, replace(clazz)));
  36. }
  37. }
  38.  
  39. private static Set<String> readList(File listFile) {
  40. Set<String> list = new HashSet<>();
  41. try (BufferedReader reader = new BufferedReader(new FileReader(listFile))) {
  42.  
  43. String line;
  44. while ((line = reader.readLine()) != null) {
  45.  
  46. list.add(line.replace(".", "\\")
  47. .replace("\\java", ".java"));
  48.  
  49. }
  50.  
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. return list;
  55. }
  56.  
  57. private static void copy(File source, File to) {
  58. if (!source.exists()) {
  59. System.out.println("Cannot find " + source.getPath());
  60. return;
  61. }
  62.  
  63. File toFolder = to.getParentFile();
  64. if (!toFolder.exists()) {
  65. toFolder.mkdirs();
  66. System.out.println("Created folder " + toFolder);
  67. }
  68.  
  69. try (BufferedWriter writer = new BufferedWriter(new FileWriter(to));
  70. BufferedReader reader = new BufferedReader(new FileReader(source))) {
  71.  
  72. String line;
  73. while ((line = reader.readLine()) != null) {
  74.  
  75. writer.write(replace(line));
  76. writer.newLine();
  77.  
  78. }
  79.  
  80. } catch (IOException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84.  
  85. private static String replace(String str) {
  86. return str
  87. .replace("net\\minecraft\\server", "net\\minecraft\\server\\" + NMS)
  88. .replace("org\\bukkit\\craftbukkit", "org\\bukkit\\craftbukkit\\" + NMS)
  89. .replace("net.minecraft.server", "net.minecraft.server." + NMS)
  90. .replace("org.bukkit.craftbukkit", "org.bukkit.craftbukkit." + NMS);
  91. }
  92.  
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment