better global scripts pathing
This commit is contained in:
1 parent
e7671bd022
commit
199efb19a9
2 files changed
+52
-40
No files matched your search
@@ -159,7 +159,7 @@ public class CarpetScriptServer extends ScriptServer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Module globalModule = Carpet.fetchGlobalModule(name, allowLibraries);
|
Module globalModule = fetchGlobalModule(server, name, allowLibraries);
|
||||||
if (globalModule != null)
|
if (globalModule != null)
|
||||||
{
|
{
|
||||||
return globalModule;
|
return globalModule;
|
||||||
@@ -179,6 +179,53 @@ public class CarpetScriptServer extends ScriptServer
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nullable Module fetchGlobalModule(MinecraftServer server, String name, boolean allowLibraries) throws IOException
|
||||||
|
{
|
||||||
|
Path globalFolder = Carpet.fetchGlobalPath(server);
|
||||||
|
if (globalFolder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!Files.exists(globalFolder))
|
||||||
|
{
|
||||||
|
Files.createDirectories(globalFolder);
|
||||||
|
}
|
||||||
|
try (Stream<Path> folderWalker = Files.walk(globalFolder))
|
||||||
|
{
|
||||||
|
Optional<Path> scriptPath = folderWalker
|
||||||
|
.filter(script -> script.getFileName().toString().equalsIgnoreCase(name + ".sc") ||
|
||||||
|
(allowLibraries && script.getFileName().toString().equalsIgnoreCase(name + ".scl")))
|
||||||
|
.findFirst();
|
||||||
|
if (scriptPath.isPresent())
|
||||||
|
{
|
||||||
|
return Module.fromPath(scriptPath.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGlobalModules(final MinecraftServer server, final List<String> moduleNames, boolean includeBuiltIns) throws IOException
|
||||||
|
{
|
||||||
|
if (!includeBuiltIns)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Path globalScripts = Carpet.fetchGlobalPath(server);
|
||||||
|
if (globalScripts == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!Files.exists(globalScripts))
|
||||||
|
{
|
||||||
|
Files.createDirectories(globalScripts);
|
||||||
|
}
|
||||||
|
try (Stream<Path> folderWalker = Files.walk(globalScripts, FileVisitOption.FOLLOW_LINKS))
|
||||||
|
{
|
||||||
|
folderWalker
|
||||||
|
.filter(f -> f.toString().endsWith(".sc"))
|
||||||
|
.forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Module getRuleModule(String name)
|
public Module getRuleModule(String name)
|
||||||
{
|
{
|
||||||
for (Module moduleData : ruleModuleData)
|
for (Module moduleData : ruleModuleData)
|
||||||
@@ -218,7 +265,7 @@ public class CarpetScriptServer extends ScriptServer
|
|||||||
.forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
|
.forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Carpet.addGlobalModules(moduleNames, includeBuiltIns);
|
addGlobalModules(server, moduleNames, includeBuiltIns);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
|
|||||||
+3
-38
@@ -147,49 +147,14 @@ public class Carpet
|
|||||||
return CarpetSettings.superSecretSetting;
|
return CarpetSettings.superSecretSetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
public static @Nullable Path fetchGlobalPath(MinecraftServer server) {
|
||||||
public static Module fetchGlobalModule(String name, boolean allowLibraries) throws IOException
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||||
{
|
|
||||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
|
|
||||||
{
|
|
||||||
Path globalFolder = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
|
Path globalFolder = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
|
||||||
if (!Files.exists(globalFolder))
|
return globalFolder;
|
||||||
{
|
|
||||||
Files.createDirectories(globalFolder);
|
|
||||||
}
|
|
||||||
try (Stream<Path> folderWalker = Files.walk(globalFolder))
|
|
||||||
{
|
|
||||||
Optional<Path> scriptPath = folderWalker
|
|
||||||
.filter(script -> script.getFileName().toString().equalsIgnoreCase(name + ".sc") ||
|
|
||||||
(allowLibraries && script.getFileName().toString().equalsIgnoreCase(name + ".scl")))
|
|
||||||
.findFirst();
|
|
||||||
if (scriptPath.isPresent())
|
|
||||||
{
|
|
||||||
return Module.fromPath(scriptPath.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addGlobalModules(final List<String> moduleNames, boolean includeBuiltIns) throws IOException
|
|
||||||
{
|
|
||||||
if (includeBuiltIns && (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT))
|
|
||||||
{
|
|
||||||
Path globalScripts = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
|
|
||||||
if (!Files.exists(globalScripts))
|
|
||||||
{
|
|
||||||
Files.createDirectories(globalScripts);
|
|
||||||
}
|
|
||||||
try (Stream<Path> folderWalker = Files.walk(globalScripts, FileVisitOption.FOLLOW_LINKS))
|
|
||||||
{
|
|
||||||
folderWalker
|
|
||||||
.filter(f -> f.toString().endsWith(".sc"))
|
|
||||||
.forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void assertRequirementMet(CarpetScriptHost host, String requiredModId, String stringPredicate)
|
public static void assertRequirementMet(CarpetScriptHost host, String requiredModId, String stringPredicate)
|
||||||
{
|
{
|
||||||
VersionPredicate predicate;
|
VersionPredicate predicate;
|
||||||
|
|||||||
Reference in new issue
Block a user