Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2021-05-21 14:14:18 -03:00
commit 74cc9a39e1
3 files changed
+12 -19

No files matched your search

+2 -2
View File
@@ -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;
@@ -465,7 +465,7 @@ public class CarpetSettings
"using <user>/<repo>/contents/<path...>"
},
category = SCARPET,
validate= ScriptDownloader.ScarpetAppStoreValidator.class
validate= AppStoreManager.ScarpetAppStoreValidator.class
)
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
@@ -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<Suggestions> suggestDownloadableApps(
@@ -119,9 +119,9 @@ public class ScriptCommand
) throws CommandSyntaxException {
try {
String previous = suggestionsBuilder.getRemaining();
List<String> suggestions = ScriptDownloader.suggestionsFromPath(previous);
List<String> 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<ServerCommandSource> 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)).
@@ -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