use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.
the class Scroll method fromArguments.
public static Scroll fromArguments(BrushTool tool, Player player, LocalSession session, Action mode, List<String> arguments, boolean message) throws InputParseException {
ParserContext parserContext = new ParserContext();
parserContext.setActor(player);
parserContext.setWorld(player.getWorld());
parserContext.setSession(session);
switch(mode) {
case CLIPBOARD:
if (arguments.size() != 2) {
if (message) {
player.print(Caption.of("fawe.error.command.syntax", "clipboard [file]"));
}
return null;
}
String filename = arguments.get(1);
try {
MultiClipboardHolder multi = ClipboardFormats.loadAllFromInput(player, filename, null, message);
if (multi == null) {
return null;
}
return (new ScrollClipboard(tool, session, multi.getHolders()));
} catch (IOException e) {
throw new RuntimeException(e);
}
case MASK:
if (arguments.size() < 2) {
if (message) {
player.print(Caption.of("fawe.error.command.syntax", "mask [mask 1] [mask 2] [mask 3]..."));
}
return null;
}
Mask[] masks = new Mask[arguments.size() - 1];
for (int i = 1; i < arguments.size(); i++) {
String arg = arguments.get(i);
masks[i - 1] = WorldEdit.getInstance().getMaskFactory().parseFromInput(arg, parserContext);
}
return (new ScrollMask(tool, masks));
case PATTERN:
if (arguments.size() < 2) {
if (message) {
player.print(Caption.of("fawe.error.command.syntax", "pattern [pattern 1] [pattern 2] [pattern 3]..."));
}
return null;
}
Pattern[] patterns = new Pattern[arguments.size() - 1];
for (int i = 1; i < arguments.size(); i++) {
String arg = arguments.get(i);
patterns[i - 1] = WorldEdit.getInstance().getPatternFactory().parseFromInput(arg, parserContext);
}
return (new ScrollPattern(tool, patterns));
case TARGET_OFFSET:
return (new ScrollTargetOffset(tool));
case RANGE:
return (new ScrollRange(tool));
case SIZE:
return (new ScrollSize(tool));
case TARGET:
return (new ScrollTarget(tool));
default:
return null;
}
}
use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateRegionManager method handleClear.
public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager) {
TaskManager.taskManager().async(() -> {
synchronized (FaweDelegateRegionManager.class) {
final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
World world = BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()));
EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
final BlockType bedrock;
final BlockType air = BlockTypes.AIR;
if (hybridPlotWorld.PLOT_BEDROCK) {
bedrock = BlockTypes.BEDROCK;
} else {
bedrock = air;
}
final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
final BiomeType biome = hybridPlotWorld.getPlotBiome();
BlockVector3 pos1 = plot.getBottomAbs().getBlockVector3();
BlockVector3 pos2 = pos1.add(BlockVector3.at(hybridPlotWorld.PLOT_WIDTH - 1, hybridPlotWorld.getMaxGenHeight(), hybridPlotWorld.PLOT_WIDTH - 1));
if (hybridPlotWorld.PLOT_BEDROCK) {
Region bedrockRegion = new CuboidRegion(pos1, pos2.withY(hybridPlotWorld.getMinGenHeight()));
editSession.setBlocks(bedrockRegion, bedrock);
}
Region fillingRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.getMinGenHeight() + 1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1));
Region floorRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT), pos2.withY(hybridPlotWorld.PLOT_HEIGHT));
Region airRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1), pos2.withY(hybridPlotWorld.getMaxGenHeight()));
editSession.setBlocks(fillingRegion, filling);
editSession.setBlocks(floorRegion, plotfloor);
editSession.setBlocks(airRegion, air);
}
if (hybridPlotWorld.PLOT_SCHEMATIC) {
// We cannot reuse the editsession
EditSession scheditsession = !Settings.Schematics.PASTE_ON_TOP ? editSession : WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
File schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schem");
if (!schematicFile.exists()) {
schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schematic");
}
BlockVector3 to = plot.getBottomAbs().getBlockVector3().withY(Settings.Schematics.PASTE_ON_TOP ? hybridPlotWorld.SCHEM_Y : hybridPlotWorld.getMinBuildHeight());
try {
Clipboard clip = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
clip.paste(scheditsession, to, true, true, true);
} catch (IOException e) {
e.printStackTrace();
}
// Be verbose in editsession flushing
scheditsession.flushQueue();
}
editSession.flushQueue();
FaweAPI.fixLighting(world, new CuboidRegion(plot.getBottomAbs().getBlockVector3(), plot.getTopAbs().getBlockVector3()), null, RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE));
if (whenDone != null) {
TaskManager.taskManager().task(whenDone);
}
}
});
return true;
}
use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.
the class BlockCategoryPatternParser method parseFromInput.
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("##")) {
return null;
}
String tag = input.substring(2).toLowerCase(Locale.ROOT);
boolean anyState = false;
if (tag.startsWith("*")) {
tag = tag.substring(1);
anyState = true;
}
BlockCategory category = BlockCategory.REGISTRY.get(tag);
if (category == null) {
throw new InputParseException(Caption.of("worldedit.error.unknown-tag", TextComponent.of(tag)));
}
RandomPattern randomPattern = new RandomPattern();
Set<BlockType> blocks = category.getAll();
if (blocks.isEmpty()) {
throw new InputParseException(Caption.of("worldedit.error.empty-tag", TextComponent.of(category.getId())));
}
if (anyState) {
blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> randomPattern.add(state, 1.0));
} else {
for (BlockType blockType : blocks) {
randomPattern.add(blockType.getDefaultState(), 1.0);
}
}
return randomPattern;
}
use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.
the class RandomPatternParser method parseFromInput.
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
RandomPattern randomPattern = new RandomPattern();
// FAWE start
List<String> patterns = StringUtil.split(input, ',', '[', ']');
// FAWE end
if (patterns.size() == 1) {
// let a 'single'-pattern parser handle it
return null;
}
for (String token : patterns) {
double chance;
Pattern innerPattern;
// Parse special percentage syntax
if (token.matches("[0-9]+(\\.[0-9]*)?%.*")) {
// FAWE start
String[] p = token.split("%", 2);
if (p.length < 2) {
throw new InputParseException(Caption.of("worldedit.error.parser.missing-random-type", TextComponent.of(input)));
} else {
chance = Double.parseDouble(p[0]);
innerPattern = worldEdit.getPatternFactory().parseFromInput(p[1], context);
}
} else {
chance = 1;
innerPattern = worldEdit.getPatternFactory().parseFromInput(token, context);
}
randomPattern.add(innerPattern, chance);
}
return randomPattern;
}
use of com.sk89q.worldedit.function.pattern.Pattern in project FastAsyncWorldEdit by IntellectualSites.
the class TypeOrStateApplyingPatternParser method parseFromInput.
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (!input.startsWith("^")) {
return null;
}
Extent extent = context.requireExtent();
input = input.substring(1);
String[] parts = input.split("\\[", 2);
String type = parts[0];
if (parts.length == 1) {
return new TypeApplyingPattern(extent, worldEdit.getBlockFactory().parseFromInput(type, context).getBlockType().getDefaultState());
} else {
// states given
if (!parts[1].endsWith("]")) {
throw new InputParseException(Caption.of("worldedit.error.parser.missing-rbracket"));
}
final String[] states = parts[1].substring(0, parts[1].length() - 1).split(",");
Map<String, String> statesToSet = new HashMap<>();
for (String state : states) {
if (state.isEmpty()) {
throw new InputParseException(Caption.of("worldedit.error.parser.empty-state"));
}
String[] propVal = state.split("=", 2);
if (propVal.length != 2) {
throw new InputParseException(Caption.of("worldedit.error.parser.missing-equals-separator"));
}
final String prop = propVal[0];
if (prop.isEmpty()) {
throw new InputParseException(Caption.of("worldedit.error.parser.empty-property"));
}
final String value = propVal[1];
if (value.isEmpty()) {
throw new InputParseException(Caption.of("worldedit.error.parser.empty-value"));
}
if (statesToSet.put(prop, value) != null) {
throw new InputParseException(Caption.of("worldedit.error.parser.duplicate-property", TextComponent.of(prop)));
}
}
if (type.isEmpty()) {
return new StateApplyingPattern(extent, statesToSet);
} else {
Extent buffer = new ExtentBuffer(extent);
Pattern typeApplier = new TypeApplyingPattern(buffer, worldEdit.getBlockFactory().parseFromInput(type, context).getBlockType().getDefaultState());
Pattern stateApplier = new StateApplyingPattern(buffer, statesToSet);
return new ExtentBufferedCompositePattern(buffer, typeApplier, stateApplier);
}
}
}
Aggregations