mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
JSON Cleaner in util & Decree tag & beatify DecreeCMD
This commit is contained in:
parent
1134cd7788
commit
ce36bcc951
@ -73,7 +73,6 @@ public class CommandIrisStudioBeautify extends MortarCommand {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int clean(VolmitSender s, File clean) {
|
private int clean(VolmitSender s, File clean) {
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (clean.isDirectory()) {
|
if (clean.isDirectory()) {
|
||||||
@ -131,6 +130,7 @@ public class CommandIrisStudioBeautify extends MortarCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getArgsUsage() {
|
protected String getArgsUsage() {
|
||||||
return "[project]";
|
return "[project]";
|
||||||
|
@ -24,6 +24,14 @@ import com.volmit.iris.util.decree.DecreeExecutor;
|
|||||||
import com.volmit.iris.util.decree.annotations.Decree;
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
import com.volmit.iris.util.decree.annotations.Param;
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
|
import com.volmit.iris.util.io.IO;
|
||||||
|
import com.volmit.iris.util.json.JSONCleaner;
|
||||||
|
import com.volmit.iris.util.json.JSONObject;
|
||||||
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
@Decree(name = "studio", aliases = {"std", "s"}, description = "Studio Commands", studio = true)
|
||||||
public class DecIrisStudio implements DecreeExecutor
|
public class DecIrisStudio implements DecreeExecutor
|
||||||
@ -35,7 +43,7 @@ public class DecIrisStudio implements DecreeExecutor
|
|||||||
@Param(name = "seed", defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s")
|
@Param(name = "seed", defaultValue = "1337", description = "The seed to generate the studio with", aliases = "s")
|
||||||
long seed)
|
long seed)
|
||||||
{
|
{
|
||||||
sender().sendMessage(C.GREEN + "Opening studio for the " + dimension.getName() + " pack (seed: " + seed + ")");
|
sender().sendMessage(C.GREEN + "Opening studio for the \"" + dimension.getName() + "\" pack (seed: " + seed + ")");
|
||||||
Iris.proj.open(sender(), seed, dimension.getLoadKey());
|
Iris.proj.open(sender(), seed, dimension.getLoadKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,4 +58,30 @@ public class DecIrisStudio implements DecreeExecutor
|
|||||||
Iris.proj.close();
|
Iris.proj.close();
|
||||||
sender().sendMessage(C.GREEN + "Project Closed.");
|
sender().sendMessage(C.GREEN + "Project Closed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Get the version of a pack", aliases = {"v", "ver"})
|
||||||
|
public void version(
|
||||||
|
@Param(name = "dimension", defaultValue = "overworld", description = "The dimension get the version of", aliases = "dim")
|
||||||
|
IrisDimension dimension
|
||||||
|
)
|
||||||
|
{
|
||||||
|
sender().sendMessage(C.GREEN + "The \"" + dimension.getName() + "\" pack has version: " + dimension.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Beatify a pack", aliases = {"beauty", "prettify"})
|
||||||
|
public void beautify(
|
||||||
|
@Param(name = "dimension", defaultValue = "overworld", description = "The to-beautify dimension", aliases = "dim")
|
||||||
|
IrisDimension dimension
|
||||||
|
)
|
||||||
|
{
|
||||||
|
File folder = dimension.getLoadFile();
|
||||||
|
sender().sendMessage("Cleaned " + Form.f(JSONCleaner.clean(sender(), folder)) + " JSON Files");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Beatify a pack - must be in studio!", aliases = {"beauty", "prettify"})
|
||||||
|
public void beautify()
|
||||||
|
{
|
||||||
|
File folder = Iris.proj.getActiveProject().getPath();
|
||||||
|
sender().sendMessage("Cleaned " + Form.f(JSONCleaner.clean(sender(), folder)) + " JSON Files");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
@Override
|
@Override
|
||||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
J.aBukkit(() -> {
|
J.aBukkit(() -> {
|
||||||
if(!call(new VolmitSender(sender), args))
|
if(!call(new VolmitSender(sender, Iris.instance.getTag()), args))
|
||||||
{
|
{
|
||||||
sender.sendMessage(C.RED + "Unknown Iris Command");
|
sender.sendMessage(C.RED + "Unknown Iris Command");
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ public class VirtualDecreeCommand {
|
|||||||
if(isStudio() && !IrisSettings.get().isStudio())
|
if(isStudio() && !IrisSettings.get().isStudio())
|
||||||
{
|
{
|
||||||
sender.sendMessage(C.RED + "To use Iris Studio Commands, please enable studio in Iris/settings.json (settings auto-reload)");
|
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(", "));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user