mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 03:59:06 +00:00
JSON Cleaner in util & Decree tag & beatify DecreeCMD
This commit is contained in:
@@ -53,7 +53,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
||||
@Override
|
||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
J.aBukkit(() -> {
|
||||
if(!call(new VolmitSender(sender), args))
|
||||
if(!call(new VolmitSender(sender, Iris.instance.getTag()), args))
|
||||
{
|
||||
sender.sendMessage(C.RED + "Unknown Iris Command");
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ public class VirtualDecreeCommand {
|
||||
if(isStudio() && !IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)");
|
||||
return false;
|
||||
return true; // Must still return true because command exists but is not enabled
|
||||
}
|
||||
|
||||
Iris.debug("@ " + getPath() + " with " + args.toString(", "));
|
||||
|
||||
66
src/main/java/com/volmit/iris/util/json/JSONCleaner.java
Normal file
66
src/main/java/com/volmit/iris/util/json/JSONCleaner.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.volmit.iris.util.json;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JSONCleaner {
|
||||
public static int clean(VolmitSender s, File clean) {
|
||||
int c = 0;
|
||||
if (clean.isDirectory()) {
|
||||
for (File i : clean.listFiles()) {
|
||||
c += clean(s, i);
|
||||
}
|
||||
} else if (clean.getName().endsWith(".json")) {
|
||||
try {
|
||||
clean(clean);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to beautify " + clean.getAbsolutePath() + " You may have errors in your json!");
|
||||
}
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public static void clean(File clean) throws IOException {
|
||||
JSONObject obj = new JSONObject(IO.readAll(clean));
|
||||
fixBlocks(obj, clean);
|
||||
|
||||
IO.writeAll(clean, obj.toString(4));
|
||||
}
|
||||
|
||||
public static void fixBlocks(JSONObject obj, File f) {
|
||||
for (String i : obj.keySet()) {
|
||||
Object o = obj.get(i);
|
||||
|
||||
if (i.equals("block") && o instanceof String && !o.toString().trim().isEmpty() && !o.toString().contains(":")) {
|
||||
obj.put(i, "minecraft:" + o);
|
||||
Iris.debug("Updated Block Key: " + o + " to " + obj.getString(i) + " in " + f.getPath());
|
||||
}
|
||||
|
||||
if (o instanceof JSONObject) {
|
||||
fixBlocks((JSONObject) o, f);
|
||||
} else if (o instanceof JSONArray) {
|
||||
fixBlocks((JSONArray) o, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixBlocks(JSONArray obj, File f) {
|
||||
for (int i = 0; i < obj.length(); i++) {
|
||||
Object o = obj.get(i);
|
||||
|
||||
if (o instanceof JSONObject) {
|
||||
fixBlocks((JSONObject) o, f);
|
||||
} else if (o instanceof JSONArray) {
|
||||
fixBlocks((JSONArray) o, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user