mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 19:36:41 +00:00
Re-implement richer mask and transform parsing (#1223)
Co-authored-by: dordsor21 <dordsor21@gmail.com> Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.fastasyncworldedit.core.configuration.Caption;
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
@ -70,6 +71,17 @@ public abstract class AbstractFactory<E> {
|
||||
return Collections.unmodifiableList(parsers);
|
||||
}
|
||||
|
||||
//FAWE start - javadoc
|
||||
|
||||
/**
|
||||
* Parse a string and context to each {@link InputParser} added to this factory. If no result found, throws {@link InputParseException}
|
||||
*
|
||||
* @param input input string
|
||||
* @param context input context
|
||||
* @return parsed result
|
||||
* @throws InputParseException if no result found
|
||||
*/
|
||||
//FAWE end
|
||||
public E parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
E match;
|
||||
|
||||
@ -101,4 +113,19 @@ public abstract class AbstractFactory<E> {
|
||||
parsers.add(parsers.size() - 1, inputParser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test all parsers to see if alias is contained by one of them
|
||||
*
|
||||
* @param alias alias to test
|
||||
* @return if a parser contains the alias
|
||||
*/
|
||||
public boolean containsAlias(String alias) {
|
||||
return parsers.stream().anyMatch(p -> {
|
||||
if (!(p instanceof AliasedParser)) {
|
||||
return false;
|
||||
}
|
||||
return ((AliasedParser) p).getMatchedAliases().contains(alias);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,11 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.fastasyncworldedit.core.extension.factory.parser.AliasedParser;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -32,19 +32,14 @@ import java.util.stream.Stream;
|
||||
*
|
||||
* @param <E> the element
|
||||
*/
|
||||
public abstract class SimpleInputParser<E> extends InputParser<E> {
|
||||
//FAWE start - AliasedParser interface, rather than method being here
|
||||
public abstract class SimpleInputParser<E> extends InputParser<E> implements AliasedParser {
|
||||
//FAWE end
|
||||
|
||||
protected SimpleInputParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
/**
|
||||
* The strings this parser matches.
|
||||
*
|
||||
* @return the matching aliases
|
||||
*/
|
||||
public abstract List<String> getMatchedAliases();
|
||||
|
||||
@Override
|
||||
public E parseFromInput(String input, ParserContext context) throws InputParseException {
|
||||
if (!getMatchedAliases().contains(input)) {
|
||||
|
Reference in New Issue
Block a user