Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1.  
  2. package lotrta.common.loading.util;
  3.  
  4. import java.io.BufferedReader;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.Map.Entry;
  8.  
  9. import cpw.mods.fml.common.FMLCommonHandler;
  10. import cpw.mods.fml.common.FMLLog;
  11. import cpw.mods.fml.common.ModContainer;
  12.  
  13. public class StringBanks {
  14.  
  15. public static Map<String, String[]> loadStringBank(Object mod, String folderPath, String extension) {
  16. Map<String, String[]> stringBanks = new HashMap<String, String[]>();
  17.  
  18. ModContainer modContainer = FMLCommonHandler.instance().findContainerFor(mod);
  19. if(modContainer == null) throw new IllegalArgumentException("The object " + mod.toString() + " can't be indentified as a mod.");
  20.  
  21. String path = "assets/" + modContainer.getModId() + "/" + folderPath;
  22. Map<String, BufferedReader> readers = ResourceHelper.getNamedReaders(mod, path, extension);
  23.  
  24. for(Entry<String, BufferedReader> entry : readers.entrySet()) {
  25. String name = entry.getKey();
  26. BufferedReader reader = entry.getValue();
  27.  
  28. String[] lines = reader.lines().toArray(String[]::new);
  29.  
  30. if (lines.length == 0) {
  31. FMLLog.severe("String bank " + name + " from " + modContainer.getModId() + " is empty!");
  32. continue;
  33. }
  34.  
  35. stringBanks.put(name, lines);
  36. }
  37.  
  38. if(stringBanks.isEmpty()) FMLLog.severe("Found no string bank in " + path + " from " + modContainer.getModId());
  39. else FMLLog.severe("Loaded " + stringBanks.size() + " banks in " + path + " from " + modContainer.getModId());
  40.  
  41. return stringBanks;
  42. }
  43.  
  44. public static void loadSpeechBanks(Object mod) {
  45. Map<String, String[]> speechBanks = StringBanks.loadStringBank(mod, "speech", "txt");
  46.  
  47. LOTRTAReflection.addSpeechBanks(speechBanks);
  48. }
  49.  
  50. public static void loadNameBanks(Object mod) {
  51. Map<String, String[]> nameBanks = StringBanks.loadStringBank(mod, "names", "txt");
  52.  
  53. LOTRTAReflection.addNameBanks(nameBanks);
  54. }
  55.  
  56. public static Map<String, String[]> getLoreBanks(Object mod) {
  57. return StringBanks.loadStringBank(mod, "lore", "txt");
  58. }
  59.  
  60. public static Map<String, String[]> getStructureScans(Object mod) {
  61. return StringBanks.loadStringBank(mod, "strscan", "strscan");
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement