Search in sources :

Example 16 with ParserContext

use of com.sk89q.worldedit.extension.input.ParserContext in project PlotSquared by IntellectualSites.

the class PatternUtil method parse.

public static Pattern parse(PlotPlayer<?> plotPlayer, String input, boolean allowLegacy) {
    ParserContext context = new ParserContext();
    if (plotPlayer != null) {
        Actor actor = plotPlayer.toActor();
        context.setActor(actor);
        if (actor instanceof Player) {
            context.setWorld(((Player) actor).getWorld());
        }
        context.setSession(WorldEdit.getInstance().getSessionManager().get(actor));
        context.setRestricted(true);
    } else {
        context.setRestricted(false);
    }
    context.setPreferringWildcard(false);
    context.setTryLegacy(allowLegacy);
    try {
        return WorldEdit.getInstance().getPatternFactory().parseFromInput(input, context);
    } catch (InputParseException e) {
        throw new Command.CommandException(TranslatableCaption.of("invalid.not_valid_block"), Template.of("value", e.getMessage()));
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) InputParseException(com.sk89q.worldedit.extension.input.InputParseException) Command(com.plotsquared.core.command.Command) Actor(com.sk89q.worldedit.extension.platform.Actor) ParserContext(com.sk89q.worldedit.extension.input.ParserContext)

Aggregations

ParserContext (com.sk89q.worldedit.extension.input.ParserContext)16 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)12 Actor (com.sk89q.worldedit.extension.platform.Actor)4 Extent (com.sk89q.worldedit.extent.Extent)4 Mask (com.sk89q.worldedit.function.mask.Mask)4 World (com.sk89q.worldedit.world.World)4 Map (java.util.Map)4 Caption (com.fastasyncworldedit.core.configuration.Caption)3 WorldEdit (com.sk89q.worldedit.WorldEdit)3 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)3 Pattern (com.sk89q.worldedit.function.pattern.Pattern)3 Region (com.sk89q.worldedit.regions.Region)3 TextComponent (com.sk89q.worldedit.util.formatting.text.TextComponent)3 IOException (java.io.IOException)3 Locale (java.util.Locale)3 Stream (java.util.stream.Stream)3 StringMan (com.fastasyncworldedit.core.util.StringMan)2 BukkitPlayer (com.sk89q.worldedit.bukkit.BukkitPlayer)2 SuggestionHelper (com.sk89q.worldedit.command.util.SuggestionHelper)2 Entity (com.sk89q.worldedit.entity.Entity)2