added /script remove app command

This commit is contained in:
gnembon committed 2021-05-27 01:54:26 -03:00
1 parent f2e759130a
commit 328ded0537
3 files changed
+41 -2

No files matched your search

@@ -43,6 +43,7 @@ import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -347,6 +348,30 @@ public class CarpetScriptServer
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)
{
CarpetScriptHost host = globalHost;