diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index c1752319..eb7723e8 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -1,6 +1,6 @@ package carpet; -import carpet.script.utils.ScriptDownloader; +import carpet.script.utils.AppStoreManager; import carpet.settings.ParsedRule; import carpet.settings.Rule; import carpet.settings.SettingsManager; @@ -464,7 +464,7 @@ public class CarpetSettings "using //contents/" }, category = SCARPET, - validate= ScriptDownloader.ScarpetAppStoreValidator.class + validate= AppStoreManager.ScarpetAppStoreValidator.class ) public static String scriptsAppStore = "gnembon/scarpet/contents/programs"; diff --git a/src/main/java/carpet/commands/ScriptCommand.java b/src/main/java/carpet/commands/ScriptCommand.java index 69461c77..288f487c 100644 --- a/src/main/java/carpet/commands/ScriptCommand.java +++ b/src/main/java/carpet/commands/ScriptCommand.java @@ -3,7 +3,7 @@ package carpet.commands; import carpet.CarpetServer; import carpet.CarpetSettings; import carpet.script.CarpetScriptServer; -import carpet.script.utils.ScriptDownloader; +import carpet.script.utils.AppStoreManager; import carpet.script.CarpetEventServer; import carpet.script.CarpetExpression; import carpet.script.CarpetScriptHost; @@ -110,7 +110,7 @@ public class ScriptCommand } /** - * A method to suggest the available scarpet scripts based off of the current player input and {@link ScriptDownloader#localScarpetRepoStructure} + * A method to suggest the available scarpet scripts based off of the current player input and {@link AppStoreManager#localScarpetRepoStructure} * variable. */ private static CompletableFuture suggestDownloadableApps( @@ -119,9 +119,9 @@ public class ScriptCommand ) throws CommandSyntaxException { try { String previous = suggestionsBuilder.getRemaining(); - List suggestions = ScriptDownloader.suggestionsFromPath(previous); + List suggestions = AppStoreManager.suggestionsFromPath(previous); CarpetScriptServer.LOG.error(String.join(":", suggestions)); - ScriptDownloader.suggestionsFromPath(previous).forEach(suggestionsBuilder::suggest); + AppStoreManager.suggestionsFromPath(previous).forEach(suggestionsBuilder::suggest); return suggestionsBuilder.buildFuture(); } catch (IOException e) @@ -328,8 +328,8 @@ public class ScriptCommand )?1:0)))); LiteralArgumentBuilder d = literal("download").requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)). - then(literal("global").then(argument("path", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestDownloadableApps).executes(cc->ScriptDownloader.downloadScript(cc, StringArgumentType.getString(cc,"path"), true)))). - then(literal("local").then(argument("path", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestDownloadableApps).executes(cc->ScriptDownloader.downloadScript(cc, StringArgumentType.getString(cc,"path"), false)))); + then(literal("global").then(argument("path", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestDownloadableApps).executes(cc-> AppStoreManager.downloadScript(cc, StringArgumentType.getString(cc,"path"), true)))). + then(literal("local").then(argument("path", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestDownloadableApps).executes(cc-> AppStoreManager.downloadScript(cc, StringArgumentType.getString(cc,"path"), false)))); dispatcher.register(literal("script"). requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)). diff --git a/src/main/java/carpet/script/utils/ScriptDownloader.java b/src/main/java/carpet/script/utils/AppStoreManager.java similarity index 93% rename from src/main/java/carpet/script/utils/ScriptDownloader.java rename to src/main/java/carpet/script/utils/AppStoreManager.java index 0ac6775e..dc14e996 100644 --- a/src/main/java/carpet/script/utils/ScriptDownloader.java +++ b/src/main/java/carpet/script/utils/AppStoreManager.java @@ -1,6 +1,5 @@ package carpet.script.utils; -import carpet.script.CarpetScriptServer; import carpet.settings.ParsedRule; import carpet.settings.Validator; import carpet.utils.Messenger; @@ -40,7 +39,7 @@ import java.util.stream.Collectors; /** * A class used to save scarpet app store scripts to disk */ -public class ScriptDownloader +public class AppStoreManager { /** A local copy of the scarpet repo's file structure, to avoid multiple queries to github.com while typing out the * {@code /script download} command and getting the suggestions. @@ -124,18 +123,15 @@ public class ScriptDownloader if (scarpetRepoLink == null) throw new IOException("Accessing scarpet app repo is disabled"); String queryPath = scarpetRepoLink + getPath(); - CarpetScriptServer.LOG.error("Fetching: "+queryPath); String response; try { URL appURL = new URL(queryPath); - response = ScriptDownloader.getStringFromStream(appURL.openStream()); + response = AppStoreManager.getStringFromStream(appURL.openStream()); } catch (IOException e) { - CarpetScriptServer.LOG.error("Problems fetching: "+e); - sealed = true; - return; + throw new IOException("Problems fetching "+queryPath+": "+e); } JsonArray files = new JsonParser().parse(response).getAsJsonArray(); for(JsonElement je : files) @@ -152,7 +148,6 @@ public class ScriptDownloader children.put(name, scriptFile(this, name, value)); } } - CarpetScriptServer.LOG.error("nodes for "+ getPath()+" are "+children.values().stream().map(PathNode::pathElement).collect(Collectors.joining(","))); sealed = true; } @@ -173,12 +168,10 @@ public class ScriptDownloader { if (isLeaf()) { - CarpetScriptServer.LOG.error("suggestions for leaf :"+name); return Collections.singletonList(getPath()); } fillChildren(); String prefix = getPath(); - CarpetScriptServer.LOG.error("suggestions for node :"+name); return children.values().stream().map(s -> prefix+s.pathElement().replaceAll("/$", "")).collect(Collectors.toList()); } @@ -219,7 +212,7 @@ public class ScriptDownloader - /** A simple shorthand for calling the {@link ScriptDownloader#getScriptCode} and {@link ScriptDownloader#saveScriptToFile} + /** A simple shorthand for calling the {@link AppStoreManager#getScriptCode} and {@link AppStoreManager#saveScriptToFile} * methods to avoid repeating code and so it makes more sense what it's exactly doing. * * @param path The user-inputted path to the script