Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds skript list command #6439

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -64,27 +65,29 @@ public class SkriptCommand implements CommandExecutor {
private static final String CONFIG_NODE = "skript command";
private static final ArgsMessage m_reloading = new ArgsMessage(CONFIG_NODE + ".reload.reloading");

// TODO /skript scripts show/list - lists all enabled and/or disabled scripts in the scripts folder and/or subfolders (maybe add a pattern [using * and **])
// TODO document this command on the website
private static final CommandHelp SKRIPT_COMMAND_HELP = new CommandHelp("<gray>/<gold>skript", SkriptColor.LIGHT_CYAN, CONFIG_NODE + ".help")
.add(new CommandHelp("reload", SkriptColor.DARK_CYAN)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_CYAN)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_CYAN)
.add("check")
.add("changes")
.add("download")
).add("info"
).add("help");
.add(new CommandHelp("reload", SkriptColor.DARK_RED)
.add("all")
.add("config")
.add("aliases")
.add("scripts")
.add("<script>")
).add(new CommandHelp("enable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("disable", SkriptColor.DARK_RED)
.add("all")
.add("<script>")
).add(new CommandHelp("update", SkriptColor.DARK_RED)
.add("check")
.add("changes")
.add("download")
)
.add("list")
.add("show")
.add("info")
.add("help");

static {
// Add command to generate documentation
Expand Down Expand Up @@ -449,6 +452,22 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
})
);
} else if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("show")) {
info(sender, "list.enabled.header");
ScriptLoader.getLoadedScripts().stream()
.map(script -> script.getConfig().getFileName())
.forEach(name -> info(sender, "list.enabled.element", name));
info(sender, "list.disabled.header");
ScriptLoader.getDisabledScripts().stream()
.flatMap(file -> {
if (file.isDirectory()) {
return Arrays.stream(file.listFiles());
}
return Arrays.stream(new File[]{file});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Arrays.stream(new File[]{file});
return Stream.of(file);

might need import

})
.map(File::getPath)
.map(path -> path.substring(Skript.getInstance().getScriptsFolder().getPath().length() + 1))
.forEach(path -> info(sender, "list.disabled.element", path));
} else if (args[0].equalsIgnoreCase("help")) {
SKRIPT_COMMAND_HELP.showHelp(sender);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
options.add("enable");
options.add("disable");
options.add("update");
options.add("list");
options.add("show");
options.add("info");
if (Documentation.getDocsTemplateDirectory().exists())
options.add("gen-docs");
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/lang/english.lang
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ skript command:
check: Checks for a new version
changes: Lists all changes since the current version
download: Download the newest version
list: Lists all enabled and disabled scripts
info: Prints a message with links to Skript's aliases and documentation
gen-docs: Generates documentation using docs/templates in plugin folder
test: Used for running internal Skript tests
Expand Down Expand Up @@ -113,6 +114,13 @@ skript command:
# invalid version: No changelog for the version <gold>%s<red> available
title: <bold><cyan>%s<reset> (%s)
next page: <grey>page %s of %s. Type <gold>/skript update changes %s<gray> for the next page (hint: use the up arrow key)
list:
enabled:
header: <white>Enabled scripts:
element: <lime green> %s
disabled:
header: <white>Disabled scripts:
element: <light red> %s
info:
aliases: Skript's aliases can be found here: <aqua>https://github.com/SkriptLang/skript-aliases
documentation: Skript's documentation can be found here: <aqua>https://docs.skriptlang.org/
Expand Down
Loading