mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-06-18 08:41:46 +00:00
75 lines
2.9 KiB
Java
75 lines
2.9 KiB
Java
package com.sk89q.worldedit.extension.factory.parser.pattern;
|
|
|
|
import com.boydti.fawe.object.pattern.BiomeApplyingPattern;
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
import com.sk89q.worldedit.extension.factory.parser.RichParser;
|
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
|
import com.sk89q.worldedit.extension.input.NoMatchException;
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
public class BiomePatternParser extends RichParser<Pattern> {
|
|
private final static String BIOME_PREFIX = "$";
|
|
|
|
/**
|
|
* Create a new biome pattern parser.
|
|
*
|
|
* @param worldEdit the worldedit instance.
|
|
*/
|
|
public BiomePatternParser(WorldEdit worldEdit) {
|
|
super(worldEdit, "#biome");
|
|
}
|
|
|
|
// overridden to provide $<biome> too
|
|
@Override
|
|
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
|
|
if (input.startsWith(BIOME_PREFIX)) {
|
|
String biomeId = input.substring(1);
|
|
BiomeType biomeType = BiomeTypes.get(biomeId);
|
|
if (biomeType == null) {
|
|
throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-biome", TextComponent.of(biomeId)));
|
|
}
|
|
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
|
} else {
|
|
return super.parseFromInput(input, context);
|
|
}
|
|
}
|
|
|
|
// overridden to provide $<biome> too
|
|
@Override
|
|
public Stream<String> getSuggestions(String input) {
|
|
if (input.startsWith(BIOME_PREFIX)) {
|
|
return BiomeType.REGISTRY.getSuggestions(input.substring(1)).map(biome -> BIOME_PREFIX + biome);
|
|
} else {
|
|
return super.getSuggestions(input);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected Stream<String> getSuggestions(String argumentInput, int index) {
|
|
if (index == 0) {
|
|
return BiomeType.REGISTRY.getSuggestions(argumentInput);
|
|
}
|
|
return Stream.empty();
|
|
}
|
|
|
|
@Override
|
|
protected Pattern parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
|
|
if (arguments.length != 1) {
|
|
throw new InputParseException(TranslatableComponent.of("fawe.error.invalid-arguments", TextComponent.of("#biome[<biome>]")));
|
|
}
|
|
BiomeType biomeType = BiomeTypes.get(arguments[0]);
|
|
if (biomeType == null) {
|
|
throw new NoMatchException(TranslatableComponent.of("worldedit.error.unknown-biome", TextComponent.of(arguments[0])));
|
|
}
|
|
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
|
|
}
|
|
}
|