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

SkriptCommand - fix test command again #7390

Merged
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
18 changes: 15 additions & 3 deletions src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,24 @@ public static EventRegistry<LoaderEvent> eventRegistry() {

/**
* Gets a script's file from its name, if one exists.
*
* @param script The script name/path
* @return The script file, if one is found
*/
@Nullable
public static File getScriptFromName(String script) {
return getScriptFromName(script, Skript.getInstance().getScriptsFolder());
}

/**
* Gets a script's file from its name and directory, if one exists.
*
* @param script The script name/path
* @param directory The scripts (or testing scripts) directory
* @return The script file, if one is found
*/
@Nullable
public static File getScriptFromName(String script, File directory) {
if (script.endsWith("/") || script.endsWith("\\")) { // Always allow '/' and '\' regardless of OS
script = script.replace('/', File.separatorChar).replace('\\', File.separatorChar);
} else if (!StringUtils.endsWithIgnoreCase(script, ".sk")) {
Expand All @@ -1209,8 +1222,7 @@ public static File getScriptFromName(String script) {
if (script.startsWith(ScriptLoader.DISABLED_SCRIPT_PREFIX))
script = script.substring(ScriptLoader.DISABLED_SCRIPT_PREFIX_LENGTH);

File scriptsFolder = Skript.getInstance().getScriptsFolder();
File scriptFile = new File(scriptsFolder, script);
File scriptFile = new File(directory, script);
if (!scriptFile.exists()) {
scriptFile = new File(scriptFile.getParentFile(), ScriptLoader.DISABLED_SCRIPT_PREFIX + scriptFile.getName());
if (!scriptFile.exists()) {
Expand All @@ -1220,7 +1232,7 @@ public static File getScriptFromName(String script) {
try {
// Unless it's a test, check if the user is asking for a script in the scripts folder
// and not something outside Skript's domain.
if (TestMode.ENABLED || scriptFile.getCanonicalPath().startsWith(scriptsFolder.getCanonicalPath() + File.separator))
if (TestMode.ENABLED || scriptFile.getCanonicalPath().startsWith(directory.getCanonicalPath() + File.separator))
return scriptFile.getCanonicalFile();
return null;
} catch (IOException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ private static List<File> getSubFiles(File file) {

private static @Nullable File getScriptFromArgs(CommandSender sender, String[] args, File directoryFile) {
String script = StringUtils.join(args, " ", 1, args.length);
File f = ScriptLoader.getScriptFromName(script);
File f = ScriptLoader.getScriptFromName(script, directoryFile);
if (f == null) {
// Always allow '/' and '\' regardless of OS
boolean directory = script.endsWith("/") || script.endsWith("\\") || script.endsWith(File.separator);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
options.add("check");
options.add("changes");
} else if (args[0].matches("(?i)(reload|disable|enable|test)") && args.length >= 2) {
File scripts = TestMode.DEV_MODE ? TestMode.TEST_DIR.toFile() : Skript.getInstance().getScriptsFolder();
boolean useTestDirectory = args[0].equalsIgnoreCase("test") && TestMode.DEV_MODE;
File scripts = useTestDirectory ? TestMode.TEST_DIR.toFile() : Skript.getInstance().getScriptsFolder();
String scriptsPathString = scripts.toPath().toString();
int scriptsPathLength = scriptsPathString.length();

Expand Down
Loading