[F] Use json instead of js to store presets
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
package org.hydev.hyritone.task;
|
package org.hydev.hyritone.task;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.hydev.hyritone.Main;
|
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -14,7 +14,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hydev.hyritone.utils.ScriptUtils.getEngine;
|
import static baritone.api.utils.Helper.mc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains preset tasks
|
* This class contains preset tasks
|
||||||
@@ -63,35 +63,32 @@ public class TaskPresets
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static void reloadPresets()
|
public static void reloadPresets()
|
||||||
{
|
{
|
||||||
Path scriptDirPath = Main.taskPresetsDir.toPath();
|
Path filePath = new File(mc.gameDir, "./Hyritone/").toPath();
|
||||||
|
Files.createDirectories(filePath);
|
||||||
|
|
||||||
presets.clear();
|
presets.clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Files.walk(scriptDirPath, FileVisitOption.FOLLOW_LINKS)
|
Files.walk(filePath, FileVisitOption.FOLLOW_LINKS)
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.forEach(path ->
|
.forEach(path ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String script = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
|
String json = FileUtils.readFileToString(path.toFile(), StandardCharsets.UTF_8);
|
||||||
TaskList list = (TaskList) getEngine().eval(script);
|
TaskList list = new Gson().fromJson(json, TaskList.class);
|
||||||
presets.put(list.name.toLowerCase(), list);
|
presets.put(list.name.toLowerCase(), list);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new UncheckedIOException(e);
|
throw new UncheckedIOException(e);
|
||||||
}
|
}
|
||||||
catch (ScriptException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (IOException | UncheckedIOException e)
|
catch (IOException | UncheckedIOException e)
|
||||||
{
|
{
|
||||||
System.err.println("Error when loading hyritone scripts.");
|
System.err.println("Error when loading hyritone json.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user