renames
This commit is contained in:
1 parent
22abf2fab6
commit
79fb489ab7
3 files changed
+12
-19
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
package carpet;
|
package carpet;
|
||||||
|
|
||||||
import carpet.script.utils.ScriptDownloader;
|
import carpet.script.utils.AppStoreManager;
|
||||||
import carpet.settings.ParsedRule;
|
import carpet.settings.ParsedRule;
|
||||||
import carpet.settings.Rule;
|
import carpet.settings.Rule;
|
||||||
import carpet.settings.SettingsManager;
|
import carpet.settings.SettingsManager;
|
||||||
@@ -464,7 +464,7 @@ public class CarpetSettings
|
|||||||
"using <user>/<repo>/contents/<path...>"
|
"using <user>/<repo>/contents/<path...>"
|
||||||
},
|
},
|
||||||
category = SCARPET,
|
category = SCARPET,
|
||||||
validate= ScriptDownloader.ScarpetAppStoreValidator.class
|
validate= AppStoreManager.ScarpetAppStoreValidator.class
|
||||||
)
|
)
|
||||||
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
|
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package carpet.commands;
|
|||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
import carpet.CarpetSettings;
|
import carpet.CarpetSettings;
|
||||||
import carpet.script.CarpetScriptServer;
|
import carpet.script.CarpetScriptServer;
|
||||||
import carpet.script.utils.ScriptDownloader;
|
import carpet.script.utils.AppStoreManager;
|
||||||
import carpet.script.CarpetEventServer;
|
import carpet.script.CarpetEventServer;
|
||||||
import carpet.script.CarpetExpression;
|
import carpet.script.CarpetExpression;
|
||||||
import carpet.script.CarpetScriptHost;
|
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.
|
* variable.
|
||||||
*/
|
*/
|
||||||
private static CompletableFuture<Suggestions> suggestDownloadableApps(
|
private static CompletableFuture<Suggestions> suggestDownloadableApps(
|
||||||
@@ -119,9 +119,9 @@ public class ScriptCommand
|
|||||||
) throws CommandSyntaxException {
|
) throws CommandSyntaxException {
|
||||||
try {
|
try {
|
||||||
String previous = suggestionsBuilder.getRemaining();
|
String previous = suggestionsBuilder.getRemaining();
|
||||||
List<String> suggestions = ScriptDownloader.suggestionsFromPath(previous);
|
List<String> suggestions = AppStoreManager.suggestionsFromPath(previous);
|
||||||
CarpetScriptServer.LOG.error(String.join(":", suggestions));
|
CarpetScriptServer.LOG.error(String.join(":", suggestions));
|
||||||
ScriptDownloader.suggestionsFromPath(previous).forEach(suggestionsBuilder::suggest);
|
AppStoreManager.suggestionsFromPath(previous).forEach(suggestionsBuilder::suggest);
|
||||||
return suggestionsBuilder.buildFuture();
|
return suggestionsBuilder.buildFuture();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
@@ -328,8 +328,8 @@ public class ScriptCommand
|
|||||||
)?1:0))));
|
)?1:0))));
|
||||||
|
|
||||||
LiteralArgumentBuilder<ServerCommandSource> d = literal("download").requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)).
|
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("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->ScriptDownloader.downloadScript(cc, StringArgumentType.getString(cc,"path"), false))));
|
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").
|
dispatcher.register(literal("script").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
||||||
|
|||||||
+4
-11
@@ -1,6 +1,5 @@
|
|||||||
package carpet.script.utils;
|
package carpet.script.utils;
|
||||||
|
|
||||||
import carpet.script.CarpetScriptServer;
|
|
||||||
import carpet.settings.ParsedRule;
|
import carpet.settings.ParsedRule;
|
||||||
import carpet.settings.Validator;
|
import carpet.settings.Validator;
|
||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
@@ -40,7 +39,7 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* A class used to save scarpet app store scripts to disk
|
* 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
|
/** 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.
|
* {@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");
|
if (scarpetRepoLink == null) throw new IOException("Accessing scarpet app repo is disabled");
|
||||||
|
|
||||||
String queryPath = scarpetRepoLink + getPath();
|
String queryPath = scarpetRepoLink + getPath();
|
||||||
CarpetScriptServer.LOG.error("Fetching: "+queryPath);
|
|
||||||
String response;
|
String response;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL appURL = new URL(queryPath);
|
URL appURL = new URL(queryPath);
|
||||||
response = ScriptDownloader.getStringFromStream(appURL.openStream());
|
response = AppStoreManager.getStringFromStream(appURL.openStream());
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
CarpetScriptServer.LOG.error("Problems fetching: "+e);
|
throw new IOException("Problems fetching "+queryPath+": "+e);
|
||||||
sealed = true;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
JsonArray files = new JsonParser().parse(response).getAsJsonArray();
|
JsonArray files = new JsonParser().parse(response).getAsJsonArray();
|
||||||
for(JsonElement je : files)
|
for(JsonElement je : files)
|
||||||
@@ -152,7 +148,6 @@ public class ScriptDownloader
|
|||||||
children.put(name, scriptFile(this, name, value));
|
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;
|
sealed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,12 +168,10 @@ public class ScriptDownloader
|
|||||||
{
|
{
|
||||||
if (isLeaf())
|
if (isLeaf())
|
||||||
{
|
{
|
||||||
CarpetScriptServer.LOG.error("suggestions for leaf :"+name);
|
|
||||||
return Collections.singletonList(getPath());
|
return Collections.singletonList(getPath());
|
||||||
}
|
}
|
||||||
fillChildren();
|
fillChildren();
|
||||||
String prefix = getPath();
|
String prefix = getPath();
|
||||||
CarpetScriptServer.LOG.error("suggestions for node :"+name);
|
|
||||||
return children.values().stream().map(s -> prefix+s.pathElement().replaceAll("/$", "")).collect(Collectors.toList());
|
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.
|
* 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
|
* @param path The user-inputted path to the script
|
||||||
Reference in new issue
Block a user