added /script remove app command
This commit is contained in:
1 parent
f2e759130a
commit
328ded0537
3 files changed
+41
-2
No files matched your search
@@ -176,3 +176,9 @@ Downloaded apps will be placed in the world's scripts folder automatically. Loca
|
|||||||
with a global carpet setting of `/carpet scriptsAppStore`. Apps, if required, will also download all the resources they need
|
with a global carpet setting of `/carpet scriptsAppStore`. Apps, if required, will also download all the resources they need
|
||||||
to run it. Consecutive downloads of the same app will re-download its content and its resources, but will not remove anything
|
to run it. Consecutive downloads of the same app will re-download its content and its resources, but will not remove anything
|
||||||
that has been removed or renamed.
|
that has been removed or renamed.
|
||||||
|
|
||||||
|
# `/script remove` command
|
||||||
|
|
||||||
|
command allow to stop and remove apps installed in the worlds scripts folder. The app is unloaded and app 'sc' file is moved
|
||||||
|
to the `/scripts/trash`. Removed apps can only be restored by manually moving it back from the trash folder,
|
||||||
|
or by redownloading from the appstore.
|
||||||
@@ -110,7 +110,7 @@ public class ScriptCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A method to suggest the available scarpet scripts based off of the current player input and {@link AppStoreManager#localScarpetRepoStructure}
|
* A method to suggest the available scarpet scripts based off of the current player input and {@link AppStoreManager#appStoreRoot}
|
||||||
* variable.
|
* variable.
|
||||||
*/
|
*/
|
||||||
private static CompletableFuture<Suggestions> suggestDownloadableApps(
|
private static CompletableFuture<Suggestions> suggestDownloadableApps(
|
||||||
@@ -329,10 +329,18 @@ public class ScriptCommand
|
|||||||
then(argument("path", StringArgumentType.greedyString()).
|
then(argument("path", StringArgumentType.greedyString()).
|
||||||
suggests(ScriptCommand::suggestDownloadableApps).
|
suggests(ScriptCommand::suggestDownloadableApps).
|
||||||
executes(cc-> AppStoreManager.downloadScript(cc.getSource(), StringArgumentType.getString(cc,"path"))));
|
executes(cc-> AppStoreManager.downloadScript(cc.getSource(), StringArgumentType.getString(cc,"path"))));
|
||||||
|
LiteralArgumentBuilder<ServerCommandSource> r = literal("remove").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
|
||||||
|
then(argument("app", StringArgumentType.word()).
|
||||||
|
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.unloadableModules,bb)).
|
||||||
|
executes((cc) ->
|
||||||
|
{
|
||||||
|
boolean success =CarpetServer.scriptServer.uninstallApp(cc.getSource(), StringArgumentType.getString(cc, "app"));
|
||||||
|
return success?1:0;
|
||||||
|
}));
|
||||||
|
|
||||||
dispatcher.register(literal("script").
|
dispatcher.register(literal("script").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
||||||
then(b).then(u).then(o).then(l).then(s).then(c).then(h).then(i).then(e).then(t).then(a).then(f).then(q).then(d));
|
then(b).then(u).then(o).then(l).then(s).then(c).then(h).then(i).then(e).then(t).then(a).then(f).then(q).then(d).then(r));
|
||||||
dispatcher.register(literal("script").
|
dispatcher.register(literal("script").
|
||||||
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
|
||||||
then(literal("in").
|
then(literal("in").
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.io.IOException;
|
|||||||
import java.nio.file.FileVisitOption;
|
import java.nio.file.FileVisitOption;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -347,6 +348,30 @@ public class CarpetScriptServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean uninstallApp(ServerCommandSource source, String name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
name = name.toLowerCase(Locale.ROOT);
|
||||||
|
Path folder = server.getSavePath(WorldSavePath.ROOT).resolve("scripts/trash");
|
||||||
|
if (!Files.exists(folder)) Files.createDirectories(folder);
|
||||||
|
if (!Files.exists(folder.getParent().resolve(name+".sc")))
|
||||||
|
{
|
||||||
|
Messenger.m(source, "App doesn't exist in the world scripts folder, so can only be unloaded");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
removeScriptHost(source, name, false, false);
|
||||||
|
Files.move(folder.getParent().resolve(name+".sc"), folder.resolve(name+".sc"), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
Messenger.m(source, "gi Removed "+name+" app");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (IOException exc)
|
||||||
|
{
|
||||||
|
Messenger.m(source, "rb Failed to uninstall the app");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean runEventCall(ServerCommandSource sender, String hostname, String optionalTarget, FunctionValue udf, List<Value> argv)
|
public boolean runEventCall(ServerCommandSource sender, String hostname, String optionalTarget, FunctionValue udf, List<Value> argv)
|
||||||
{
|
{
|
||||||
CarpetScriptHost host = globalHost;
|
CarpetScriptHost host = globalHost;
|
||||||
|
|||||||
Reference in new issue
Block a user