Advertisement
tomdodd4598

Untitled

Apr 28th, 2021
894
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.68 KB | None | 0 0
  1. package crafttweaker.preprocessor;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Set;
  5.  
  6. import crafttweaker.runtime.ScriptFile;
  7.  
  8. /**
  9.  * Preprocessor can be used as follows:
  10.  * #loader loadername1 loadername2 ...
  11.  *
  12.  * Example:
  13.  * #loader contenttweaker
  14.  * This will make scripts only being loaded when the loader is specified to load
  15.  * contenttweaker scripts
  16.  *
  17.  * Example:
  18.  * #loader preinit gregtech
  19.  * This will make scripts only being loaded when the loader is specified to load
  20.  * preinit or gregtech scripts
  21.  *
  22.  * this defaults to being solely "crafttweaker" which is being called by CraftTweaker
  23.  *
  24.  * @author BloodWorkXGaming
  25.  */
  26. public class LoaderPreprocessor extends PreprocessorActionBase{
  27.     private static final String PREPROCESSOR_NAME = "loader";
  28.     private String[] loaderNames;
  29.    
  30.     public LoaderPreprocessor(String fileName, String preprocessorLine, int lineIndex) {
  31.         super(fileName, preprocessorLine, lineIndex);
  32.        
  33.         // Regex magic to split substring
  34.         String substring = preprocessorLine.substring(7).trim();
  35.         String[] arr = substring.split("\\s+");
  36.        
  37.         // Remove duplicates and empty strings
  38.         Set<String> set = new HashSet<>();
  39.         for (String s : arr) {
  40.             String trim = s.trim();
  41.             if (!trim.isEmpty()) {
  42.                 set.add(trim);
  43.             }
  44.         }
  45.         loaderNames = set.toArray(new String[set.size()]);
  46.     }
  47.    
  48.     @Override
  49.     public void executeActionOnFind(ScriptFile scriptFile) {
  50.         scriptFile.setLoaderNames(loaderNames);
  51.     }
  52.    
  53.     @Override
  54.     public String getPreprocessorName() {
  55.         return PREPROCESSOR_NAME;
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement