Update to 26.1
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package io.github.skippyall.ruler.command;
|
||||
|
||||
import com.mojang.brigadier.LiteralMessage;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
@@ -12,10 +14,12 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class RuleSuggestionProvider<S> implements SuggestionProvider<S> {
|
||||
private final SimpleCommandExceptionType INVALID_RULE_PATH = new SimpleCommandExceptionType(new LiteralMessage("Invalid rule path"));
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<S> commandContext, SuggestionsBuilder suggestionsBuilder) throws CommandSyntaxException {
|
||||
return Ruler.getPlatform().runAsync(() -> {
|
||||
String start = suggestionsBuilder.getInput();
|
||||
String start = suggestionsBuilder.getRemaining();
|
||||
int last = start.lastIndexOf('.');
|
||||
|
||||
String incomplete;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.github.skippyall.ruler.rule;
|
||||
|
||||
public class InvalidRulePathException extends RuntimeException {
|
||||
public InvalidRulePathException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidRulePathException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidRulePathException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,9 @@ public class RuleUtils {
|
||||
Arrays.stream(path.split("\\.")).noneMatch(String::isEmpty);
|
||||
}
|
||||
|
||||
public static void checkValidRulePath(String path) throws InvalidRuleException {
|
||||
public static void checkValidRulePath(String path) throws InvalidRulePathException {
|
||||
if(!isValidRulePath(path)) {
|
||||
throw new InvalidRuleException("\"" + path + "\" is not a valid rule path");
|
||||
throw new InvalidRulePathException("\"" + path + "\" is not a valid rule path");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class RuleUtils {
|
||||
return path.toAbsolutePath().startsWith(getRoot());
|
||||
}
|
||||
|
||||
public static void checkDirectory(Path path) throws InvalidRuleException {
|
||||
public static void checkDirectory(Path path) throws InvalidRulePathException {
|
||||
if(!isInDirectory(path)) {
|
||||
throw new InvalidRuleException("File path \"" + path.toString() + "\" is not in the root rule directory.");
|
||||
}
|
||||
@@ -79,8 +79,15 @@ public class RuleUtils {
|
||||
public static String getRulePath(Path filePath) throws InvalidRuleException {
|
||||
checkDirectory(filePath);
|
||||
|
||||
Path relative = filePath.toAbsolutePath().relativize(getRoot());
|
||||
String withoutExtension = FileUtils.removeExtension(relative).toString();
|
||||
Path relative = getRoot().relativize(filePath.toAbsolutePath());
|
||||
String relativeString = relative.toString();
|
||||
|
||||
String withoutExtension;
|
||||
if(relativeString.endsWith(".config.json")) {
|
||||
withoutExtension = relativeString.substring(0, relativeString.length() - ".config.json".length());
|
||||
} else {
|
||||
withoutExtension = FileUtils.removeExtension(relativeString);
|
||||
}
|
||||
String path = withoutExtension.replace(FileSystems.getDefault().getSeparator(), ".");
|
||||
|
||||
checkValidRulePath(path);
|
||||
@@ -123,7 +130,7 @@ public class RuleUtils {
|
||||
if (Files.isDirectory(path)) {
|
||||
return directories;
|
||||
} else {
|
||||
return extension_to_serializer.containsKey(FileUtils.getExtension(path));
|
||||
return path.endsWith(".config.json") || extension_to_serializer.containsKey(FileUtils.getExtension(path));
|
||||
}
|
||||
})
|
||||
.map(RuleUtils::getRulePath)
|
||||
|
||||
Reference in New Issue
Block a user