Files
fabric-carpet/src/main/java/carpet/script/bundled/BundledModule.java
T
2020-01-09 00:53:36 -04:00

40 lines
1013 B
Java

package carpet.script.bundled;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
public class BundledModule extends Module
{
private String name;
private String code;
private boolean library;
public BundledModule(String scriptName, boolean isLibrary)
{
library = isLibrary;
try
{
name = scriptName.toLowerCase(Locale.ROOT);
code = IOUtils.toString(
getClass().getClassLoader().getResourceAsStream("assets/carpet/scripts/"+name+(isLibrary?".scl":".sc")),
StandardCharsets.UTF_8
);
}
catch ( NullPointerException | IOException e)
{
name = null;
code = null;
}
}
@Override
public boolean isLibrary() { return library; }
@Override
public String getName() { return name; }
@Override
public String getCode() { return code; }
}