This commit is contained in:
Jesse Boyd
2019-08-07 01:32:05 +10:00
190 changed files with 162 additions and 20609 deletions

View File

@ -115,8 +115,8 @@ public class AnvilCommands {
@CommandPermissions("worldedit.anvil.replaceall")
public void replaceAll(Player player, String folder,
@Arg(name = "from", desc = "String", def = "")
String from,
String to,
String fromPattern,
String toPattern,
@Switch(name = 'd', desc = "Disable wildcard data matching")
boolean useData) throws WorldEditException {
// final FaweBlockMatcher matchFrom; TODO NOT IMPLEMENTED

View File

@ -240,14 +240,14 @@ public class CFICommands {
desc = "Set the floor and main block"
)
@CommandPermissions("worldedit.anvil.cfi")
public void column(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
public void column(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
if (image != null) {
gen.setColumn(load(image), pattern, !disableWhiteOnly);
gen.setColumn(load(image), patternArg, !disableWhiteOnly);
} else if (mask != null) {
gen.setColumn(mask, pattern);
gen.setColumn(mask, patternArg);
} else {
gen.setColumn(pattern);
gen.setColumn(patternArg);
}
fp.sendMessage("Set column!");
assertSettings(fp).resetComponent();
@ -259,21 +259,21 @@ public class CFICommands {
desc = "Set the floor (default: grass)"
)
@CommandPermissions("worldedit.anvil.cfi")
public void floorCmd(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
floor(fp, pattern, image, mask, disableWhiteOnly);
public void floorCmd(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
floor(fp, patternArg, image, mask, disableWhiteOnly);
fp.sendMessage("Set floor!");
assertSettings(fp).resetComponent();
component(fp);
}
private void floor(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) {
private void floor(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly) {
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
if (image != null) {
gen.setFloor(load(image), pattern, !disableWhiteOnly);
gen.setFloor(load(image), patternArg, !disableWhiteOnly);
} else if (mask != null) {
gen.setFloor(mask, pattern);
gen.setFloor(mask, patternArg);
} else {
gen.setFloor(pattern);
gen.setFloor(patternArg);
}
}
@ -282,21 +282,21 @@ public class CFICommands {
desc = "Set the main block (default: stone)"
)
@CommandPermissions("worldedit.anvil.cfi")
public void mainCmd(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
main(fp, pattern, image, mask, disableWhiteOnly);
public void mainCmd(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
main(fp, patternArg, image, mask, disableWhiteOnly);
fp.sendMessage("Set main!");
assertSettings(fp).resetComponent();
component(fp);
}
public void main(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
public void main(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
if (image != null) {
gen.setMain(load(image), pattern, !disableWhiteOnly);
gen.setMain(load(image), patternArg, !disableWhiteOnly);
} else if (mask != null) {
gen.setMain(mask, pattern);
gen.setMain(mask, patternArg);
} else {
gen.setMain(pattern);
gen.setMain(patternArg);
}
}
@ -308,14 +308,14 @@ public class CFICommands {
"e.g. Tallgrass"
)
@CommandPermissions("worldedit.anvil.cfi")
public void overlay(FawePlayer fp, Pattern pattern, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
public void overlay(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
if (image != null) {
gen.setOverlay(load(image), pattern, !disableWhiteOnly);
gen.setOverlay(load(image), patternArg, !disableWhiteOnly);
} else if (mask != null) {
gen.setOverlay(mask, pattern);
gen.setOverlay(mask, patternArg);
} else {
gen.setOverlay(pattern);
gen.setOverlay(patternArg);
}
fp.sendMessage("Set overlay!");
component(fp);
@ -530,14 +530,14 @@ public class CFICommands {
" - If a mask is used, the biome will be set anywhere the mask applies"
)
@CommandPermissions("worldedit.anvil.cfi")
public void biome(FawePlayer fp, BiomeType biome, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
public void biome(FawePlayer fp, @Arg(name = "biome", desc = "Biome type") BiomeType biomeType, @Arg(def = "", desc = "image url or filename") ProvideBindings.ImageUri image, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name = 'w', desc = "TODO") boolean disableWhiteOnly){
HeightMapMCAGenerator gen = assertSettings(fp).getGenerator();
if (image != null) {
gen.setBiome(load(image), biome, !disableWhiteOnly);
gen.setBiome(load(image), biomeType, !disableWhiteOnly);
} else if (mask != null) {
gen.setBiome(mask, biome);
gen.setBiome(mask, biomeType);
} else {
gen.setBiome(biome);
gen.setBiome(biomeType);
}
fp.toWorldEditPlayer().print(TextComponent.of("Set biome!"));
assertSettings(fp).resetComponent();
@ -561,8 +561,8 @@ public class CFICommands {
descFooter = "Use a specific pattern and settings to generate ore"
)
@CommandPermissions("worldedit.anvil.cfi")
public void ore(FawePlayer fp, Mask mask, Pattern pattern, int size, int frequency, int rariry, int minY, int maxY) throws WorldEditException {
assertSettings(fp).getGenerator().addOre(mask, pattern, size, frequency, rariry, minY, maxY);
public void ore(FawePlayer fp, Mask mask, @Arg(name = "pattern", desc = "Pattern") Pattern patternArg, int size, int frequency, int rariry, int minY, int maxY) throws WorldEditException {
assertSettings(fp).getGenerator().addOre(mask, patternArg, size, frequency, rariry, minY, maxY);
fp.toWorldEditPlayer().print(TextComponent.of("Added ore!"));
populate(fp);
}
@ -630,8 +630,8 @@ public class CFICommands {
" - A value of 0 is the default and will not modify the height"
)
@CommandPermissions("worldedit.anvil.cfi")
public void worldthickness(FawePlayer fp, int height) throws WorldEditException {
assertSettings(fp).getGenerator().setWorldThickness(height);
public void worldthickness(FawePlayer fp, @Arg(name = "height", desc = "brush height") int heightArg) throws WorldEditException {
assertSettings(fp).getGenerator().setWorldThickness(heightArg);
fp.toWorldEditPlayer().print(TextComponent.of("Set world thickness!"));
component(fp);
}
@ -643,8 +643,8 @@ public class CFICommands {
" - A value of 0 is the default and will only set the top block"
)
@CommandPermissions("worldedit.anvil.cfi")
public void floorthickness(FawePlayer fp, int height) throws WorldEditException {
assertSettings(fp).getGenerator().setFloorThickness(height);
public void floorthickness(FawePlayer fp, @Arg(name = "height", desc = "brush height") int heightArg) throws WorldEditException {
assertSettings(fp).getGenerator().setFloorThickness(heightArg);
fp.toWorldEditPlayer().print(TextComponent.of("Set floor thickness!"));
component(fp);
}
@ -685,8 +685,8 @@ public class CFICommands {
" - By default water is disabled (with a value of 0)"
)
@CommandPermissions("worldedit.anvil.cfi")
public void waterheight(FawePlayer fp, int height) throws WorldEditException {
assertSettings(fp).getGenerator().setWaterHeight(height);
public void waterheight(FawePlayer fp, @Arg(name = "height", desc = "brush height") int heightArg) throws WorldEditException {
assertSettings(fp).getGenerator().setWaterHeight(heightArg);
fp.toWorldEditPlayer().print(TextComponent.of("Set water height!"));
component(fp);
}
@ -890,16 +890,16 @@ public class CFICommands {
desc = "Select a pattern"
)
@CommandPermissions("worldedit.anvil.cfi")
public void pattern(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern", def = "") Pattern pattern, InjectedValueAccess context)throws CommandException {
public void pattern(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern", def = "") Pattern patternArg, InjectedValueAccess context)throws CommandException {
CFISettings settings = assertSettings(fp);
String[] split = getArguments(context).split(" ");
int index = 2;
settings.pattern = pattern;
settings.patternArg = pattern == null ? null : split[index++];
settings.pattern = patternArg;
settings.patternArg = patternArg == null ? null : split[index++];
StringBuilder cmd = new StringBuilder("/cfi pattern ");
if (pattern != null) {
if (patternArg != null) {
settings.getCategory().accept(fp);
} else {
String s = cmd + " stone";

View File

@ -4,13 +4,33 @@ import com.boydti.fawe.util.StringMan;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.registry.InputParser;
import java.util.*;
public abstract class FaweParser<T> extends InputParser<T> {
protected FaweParser(WorldEdit worldEdit) {
private final PlatformCommandManager platform;
private final Class<T> type;
protected FaweParser(WorldEdit worldEdit, PlatformCommandManager commandManager, Class<T> type) {
super(worldEdit);
this.platform = commandManager;
this.type = type;
}
public PlatformCommandManager getPlatform() {
return platform;
}
public Class<T> getType() {
return type;
}
public Collection<T> parse(String input, Actor actor) {
return getPlatform().parse(getType(), "pattern " + input, actor);
}
public T catchSuggestion(String currentInput, String nextInput, ParserContext context) throws InputParseException {

View File

@ -1,6 +1,5 @@
package com.boydti.fawe.object.brush;
import com.boydti.fawe.jnbt.anvil.generator.SchemGen;
import com.boydti.fawe.util.MaskTraverser;
import com.boydti.fawe.util.MathMan;
import com.sk89q.worldedit.EditSession;
@ -30,7 +29,6 @@ public class PopulateSchem implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
new MaskTraverser(mask).reset(editSession);
SchemGen gen = new SchemGen(mask, editSession, clipboards, randomRotate);
int size1 = MathMan.roundInt(size);
CuboidRegion cuboid = new CuboidRegion(editSession.getWorld(), position.subtract(size1, size1, size1), position.add(size1, size1, size1));
try {

View File

@ -2,8 +2,6 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.brush.visualization.cfi.HeightMapMCAGenerator;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.history.UndoContext;
@ -23,10 +21,9 @@ public class CFIChange implements Change {
}
private HeightMapMCAGenerator getQueue(UndoContext context) {
ExtentTraverser found = new ExtentTraverser(context.getExtent()).find(HasIQueueExtent.class);
ExtentTraverser<HeightMapMCAGenerator> found = new ExtentTraverser<>(context.getExtent()).find(HeightMapMCAGenerator.class);
if (found != null) {
IQueueExtent queue = ((HasIQueueExtent) found.get()).getQueue();
if (queue instanceof HeightMapMCAGenerator) return (HeightMapMCAGenerator) queue;
return found.get();
}
Fawe.debug("FAWE does not support: " + context.getExtent() + " for " + getClass() + " (bug Empire92)");
return null;

View File

@ -1,71 +0,0 @@
package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockTypes;
public class MutableChunkChange implements Change {
private final boolean checkEmpty;
public FaweChunk from;
public FaweChunk to;
public MutableChunkChange(FaweChunk from, FaweChunk to, boolean checkEmpty) {
this.from = from;
this.to = to;
this.checkEmpty = checkEmpty;
}
@Override
public void undo(UndoContext context) throws WorldEditException {
create(context, true);
}
@Override
public void redo(UndoContext context) throws WorldEditException {
create(context, false);
}
private IQueueExtent queue;
private boolean checkedQueue;
public void create(UndoContext context, boolean undo) {
if (queue != null) {
perform(queue, undo);
}
if (!checkedQueue) {
checkedQueue = true;
Extent extent = context.getExtent();
ExtentTraverser found = new ExtentTraverser(extent).find(HasIQueueExtent.class);
if (found != null) {
perform(queue = ((HasIQueueExtent) found.get()).getQueue(), undo);
} else {
Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
}
}
}
public void perform(IQueueExtent queue, boolean undo) {
if (undo) {
if (checkEmpty) {
int[][] previousIds = from.getCombinedIdArrays();
int[][] nextIds = to.getCombinedIdArrays();
for (int i = 0; i < previousIds.length; i++) {
if (previousIds[i] == null && nextIds[i] != null) {
from.fillCuboid(0, 15, i << 4, (i << 4) + 15, 0, 15, BlockTypes.AIR.getInternalId());
}
}
}
queue.setChunk(from);
} else {
queue.setChunk(to);
}
}
}

View File

@ -2,18 +2,20 @@ package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.object.extent.FastWorldEditExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.boydti.fawe.util.MathMan;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -47,54 +49,28 @@ public class MutableEntityChange implements Change {
}
public void delete(UndoContext context) {
Extent extent = context.getExtent();
ExtentTraverser<FastWorldEditExtent> find = new ExtentTraverser(extent).find(FastWorldEditExtent.class);
if (find != null) {
FastWorldEditExtent fwee = find.get();
Map<String, Tag> map = tag.getValue();
long most;
long least;
if (map.containsKey("UUIDMost")) {
most = ((LongTag) map.get("UUIDMost")).getValue();
least = ((LongTag) map.get("UUIDLeast")).getValue();
} else if (map.containsKey("PersistentIDMSB")) {
most = ((LongTag) map.get("PersistentIDMSB")).getValue();
least = ((LongTag) map.get("PersistentIDLSB")).getValue();
} else {
Fawe.debug("Skipping entity without uuid.");
return;
}
List<DoubleTag> pos = (List<DoubleTag>) map.get("Pos").getValue();
int x = MathMan.roundInt(pos.get(0).getValue());
int y = MathMan.roundInt(pos.get(1).getValue());
int z = MathMan.roundInt(pos.get(2).getValue());
UUID uuid = new UUID(most, least);
fwee.getQueue().removeEntity(x, y, z, uuid);
Map<String, Tag> map = tag.getValue();
long most;
long least;
if (map.containsKey("UUIDMost")) {
most = ((LongTag) map.get("UUIDMost")).getValue();
least = ((LongTag) map.get("UUIDLeast")).getValue();
} else if (map.containsKey("PersistentIDMSB")) {
most = ((LongTag) map.get("PersistentIDMSB")).getValue();
least = ((LongTag) map.get("PersistentIDLSB")).getValue();
} else {
Fawe.debug("FAWE doesn't support: " + context + " for " + getClass() + " (bug Empire92)");
Fawe.debug("Skipping entity without uuid.");
return;
}
List<DoubleTag> pos = (List<DoubleTag>) map.get("Pos").getValue();
int x = MathMan.roundInt(pos.get(0).getValue());
int y = MathMan.roundInt(pos.get(1).getValue());
int z = MathMan.roundInt(pos.get(2).getValue());
UUID uuid = new UUID(most, least);
context.getExtent().removeEntity(x, y, z, uuid);
}
private IQueueExtent queue;
private boolean checkedQueue;
public void create(UndoContext context) {
if (queue != null) {
perform(queue);
}
if (!checkedQueue) {
checkedQueue = true;
Extent extent = context.getExtent();
ExtentTraverser found = new ExtentTraverser(extent).find(HasIQueueExtent.class);
if (found != null) {
perform(queue = ((HasIQueueExtent) found.get()).getQueue());
} else {
Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
}
}
}
public void perform(IQueueExtent queue) {
Map<String, Tag> map = tag.getValue();
Tag posTag = map.get("Pos");
if (posTag == null) {
@ -105,6 +81,15 @@ public class MutableEntityChange implements Change {
int x = MathMan.roundInt(pos.get(0).getValue());
int y = MathMan.roundInt(pos.get(1).getValue());
int z = MathMan.roundInt(pos.get(2).getValue());
queue.setEntity(x, y, z, tag);
Extent extent = context.getExtent();
Location location = new Location(extent, x, y, z, 0, 0);
String id = tag.getString("id");
EntityType type = EntityTypes.parse(id);
BaseEntity entity = new BaseEntity(type, tag);
context.getExtent().createEntity(location, entity);
}
public void perform(IQueueExtent queue) {
}
}

View File

@ -1,18 +1,11 @@
package com.boydti.fawe.object.change;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.util.ExtentTraverser;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
public class MutableFullBlockChange implements Change {
@ -41,45 +34,26 @@ public class MutableFullBlockChange implements Change {
create(context);
}
private IQueueExtent queue;
private boolean checkedQueue;
public void create(UndoContext context) {
if (queue != null) {
perform(queue);
}
if (!checkedQueue) {
checkedQueue = true;
Extent extent = context.getExtent();
ExtentTraverser found = new ExtentTraverser(extent).find(HasIQueueExtent.class);
if (found != null) {
perform(queue = ((HasIQueueExtent) found.get()).getQueue());
} else {
Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
}
}
}
public void perform(IQueueExtent queue) {
BlockType idFrom = BlockTypes.getFromStateId(from);
BlockState fromState = BlockState.getFromOrdinal(from);
if (blockBag != null) {
BlockType idTo = BlockTypes.getFromStateId(to);
if (idFrom != idTo) {
BlockState toState = BlockState.getFromOrdinal(to);
if (fromState != toState) {
if (allowFetch && from != 0) {
try {
blockBag.fetchPlacedBlock(BlockState.getFromInternalId(from));
blockBag.fetchPlacedBlock(fromState);
} catch (BlockBagException e) {
return;
}
}
if (allowStore && to != 0) {
try {
blockBag.storeDroppedBlock(BlockState.getFromInternalId(to));
blockBag.storeDroppedBlock(toState);
} catch (BlockBagException ignored) {
}
}
}
}
queue.setBlock(x, y, z, from);
context.getExtent().setBlock(x, y, z, fromState);
}
}

View File

@ -36,30 +36,10 @@ public class MutableTileChange implements Change {
}
}
private IQueueExtent queue;
private boolean checkedQueue;
public void create(UndoContext context) {
if (queue != null) {
perform(queue);
}
if (!checkedQueue) {
checkedQueue = true;
Extent extent = context.getExtent();
ExtentTraverser found = new ExtentTraverser(extent).find(HasIQueueExtent.class);
if (found != null) {
perform(queue = ((HasIQueueExtent) found.get()).getQueue());
} else {
Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
}
}
}
public void perform(IQueueExtent queue) {
Map<String, Tag> map = tag.getValue();
int x = ((IntTag) map.get("x")).getValue();
int y = ((IntTag) map.get("y")).getValue();
int z = ((IntTag) map.get("z")).getValue();
queue.setTile(x, y, z, tag);
int x = tag.getInt("x");
int y = tag.getInt("y");
int z = tag.getInt("z");
context.getExtent().setTile(x, y, z, tag);
}
}

View File

@ -1,122 +0,0 @@
package com.boydti.fawe.object.changeset;
import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.change.MutableChunkChange;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import java.util.ArrayList;
import java.util.Iterator;
public class CPUOptimizedChangeSet extends FaweChangeSet {
public CPUOptimizedChangeSet(World world) {
super(world);
}
private ArrayList<Change> changes = new ArrayList<>();
public void addChangeTask(IQueueExtent queue) {
queue.setChangeTask(new RunnableVal2<FaweChunk, FaweChunk>() {
@Override
public void run(final FaweChunk previous, final FaweChunk next) {
int[][] previousIds = previous.getCombinedIdArrays();
int[][] nextIds = next.getCombinedIdArrays();
boolean checkEmpty = false;
for (int i = 0; i < nextIds.length; i++) {
int[] nextArray = nextIds[i];
if (nextArray != null) {
int[] previousArray = previousIds[i];
if (previousArray == null) {
checkEmpty = true;
continue;
}
for (int k = 0; k < nextArray.length; k++) {
int combinedNext = nextArray[k];
if (combinedNext == 0) {
int combinedPrevious = previousArray[k];
if (combinedPrevious == 0) {
previousArray[k] = 1;
}
} else {
previousArray[k] = 0;
}
}
}
}
changes.add(new MutableChunkChange(previous, next, checkEmpty));
}
});
}
@Override
public void add(int x, int y, int z, int combinedFrom, int combinedTo) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public void addBiomeChange(int x, int z, BiomeType from, BiomeType to) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public void addTileCreate(CompoundTag tag) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public void addTileRemove(CompoundTag tag) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public void addEntityRemove(CompoundTag tag) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public void addEntityCreate(CompoundTag tag) {
throw new UnsupportedOperationException("Invalid mode");
}
@Override
public Iterator<Change> getIterator(BlockBag blockBag, int mode, boolean redo) {
return getIterator(redo);
}
@Override
public Iterator<Change> getIterator(boolean redo) {
return changes.iterator();
}
@Override
public boolean isEmpty() {
if (changes.isEmpty()) {
close();
return changes.isEmpty();
} else {
return false;
}
}
@Override
public int size() {
return changes.size() * 65536; // num chunks * 65536 (guess of 65536 changes per chunk)
}
@Override
public boolean isRecordingChanges() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setRecordChanges(boolean recordChanges) {
// TODO Auto-generated method stub
}
}

View File

@ -1,71 +0,0 @@
package com.boydti.fawe.object.changeset;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.HasIQueueExtent;
import com.boydti.fawe.object.RegionWrapper;
import com.boydti.fawe.util.ExtentTraverser;
import com.boydti.fawe.util.MainUtil;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.history.UndoContext;
import com.sk89q.worldedit.history.change.Change;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
public class MutableAnvilChange implements Change {
private Path source;
private Path destDir;
public void setSource(Path source) {
this.source = source;
}
private IQueueExtent queue;
private boolean checkedQueue;
@Override
public void undo(UndoContext context) throws WorldEditException {
if (queue != null) {
perform(queue);
}
if (!checkedQueue) {
checkedQueue = true;
Extent extent = context.getExtent();
ExtentTraverser found = new ExtentTraverser(extent).find(HasIQueueExtent.class);
if (found != null) {
queue = ((HasIQueueExtent) found.get()).getQueue();
destDir = queue.getSaveFolder().toPath();
perform(queue);
} else {
Fawe.debug("FAWE does not support: " + extent + " for " + getClass() + " (bug Empire92)");
}
}
}
public void perform(IQueueExtent queue) {
Path dest = destDir.resolve(source.getFileName());
try {
Files.move(source, dest, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException ignore) {
int[] coords = MainUtil.regionNameToCoords(source.toString());
queue.setMCA(coords[0], coords[1], RegionWrapper.GLOBAL(), new Runnable() {
@Override
public void run() {
try {
Files.move(source, dest, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}, false, true);
}
}
@Override
public void redo(UndoContext context) throws WorldEditException {
throw new UnsupportedOperationException("Redo not supported");
}
}

View File

@ -3,15 +3,15 @@ package com.boydti.fawe.object.progress;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.beta.IQueueExtent;
import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager;
import java.util.function.BiConsumer;
/**
* The default progress tracker uses titles
*/
public class DefaultProgressTracker extends RunnableVal2<IQueueExtent.ProgressType, Integer> {
public class DefaultProgressTracker implements BiConsumer<DefaultProgressTracker.ProgressType, Integer> {
private final FawePlayer player;
private final long start;
@ -54,8 +54,14 @@ public class DefaultProgressTracker extends RunnableVal2<IQueueExtent.ProgressTy
// If the task is finished
private boolean done = false;
public enum ProgressType {
DISPATCH,
QUEUE,
DONE
}
@Override
public void run(IQueueExtent.ProgressType type, Integer amount) {
public void accept(ProgressType type, Integer amount) {
switch (type) {
case DISPATCH:
amountDispatch++;

View File

@ -52,7 +52,7 @@ public class CompoundTag extends Tag {
}
@Override
public Map<String, Tag> getValue() {
public final Map<String, Tag> getValue() {
return value;
}

View File

@ -167,6 +167,12 @@ public class EditSession extends AbstractDelegateExtent implements SimpleWorld,
private static final Logger log = LoggerFactory.getLogger(EditSession.class);
//TODO
@Override
public String getId() {
return null;
}
/**
* Used by {@link EditSession#setBlock(BlockVector3, BlockStateHolder, Stage)} to
* determine which {@link Extent}s should be bypassed.

View File

@ -497,17 +497,17 @@ public class BrushCommands {
desc = "Scatter a schematic on a surface"
)
@CommandPermissions("worldedit.brush.populateschematic")
public BrushSettings scatterSchemBrush(Player player, LocalSession session, Mask mask, String clipboard, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name = 'r', desc = "Apply random rotation") boolean rotate, InjectedValueAccess context) throws WorldEditException {
public BrushSettings scatterSchemBrush(Player player, LocalSession session, Mask mask, @Arg(name = "clipboard", desc = "Clipboard uri") String clipboardStr, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name = 'r', desc = "Apply random rotation") boolean rotate, InjectedValueAccess context) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
try {
MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboard, null, true);
MultiClipboardHolder clipboards = ClipboardFormats.loadAllFromInput(player, clipboardStr, null, true);
if (clipboards == null) {
BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard);
BBC.SCHEMATIC_NOT_FOUND.send(player, clipboardStr);
return null;
}
List<ClipboardHolder> holders = clipboards.getHolders();
if (holders == null) {
BBC.SCHEMATIC_NOT_FOUND.send(player, clipboard);
BBC.SCHEMATIC_NOT_FOUND.send(player, clipboardStr);
return null;
}

View File

@ -140,13 +140,8 @@ public class BrushOptionsCommands {
int page) throws WorldEditException {
String baseCmd = "/brush loadbrush";
File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
// new RunnableVal2<Message, String[]>() {
// @Override
// public void run(Message msg, String[] info) {
//
// }
// });
// TODO NOT IMPLEMENTED
// UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
}
@Command(
@ -275,14 +270,14 @@ public class BrushOptionsCommands {
desc = "Set the targeting mask"
)
@CommandPermissions("worldedit.brush.targetmask")
public void targetMask(Player player, EditSession editSession, LocalSession session, Mask mask) throws WorldEditException {
public void targetMask(Player player, EditSession editSession, LocalSession session, @Arg(desc = "The destination mask", def = "") Mask maskArg) throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
if (tool == null) {
BBC.BRUSH_NONE.send(player);
return;
}
tool.setTraceMask(mask);
BBC.BRUSH_TARGET_MASK_SET.send(player, mask.toString());
tool.setTraceMask(maskArg);
BBC.BRUSH_TARGET_MASK_SET.send(player, maskArg.toString());
}
@Command(
@ -342,7 +337,7 @@ public class BrushOptionsCommands {
@Switch(name = 'h', desc = "TODO")
boolean offHand,
@Arg(desc = "The destination mask", def = "")
Mask mask,
Mask maskArg,
Arguments arguments)
throws WorldEditException {
BrushTool tool = session.getBrushTool(player, false);
@ -350,7 +345,7 @@ public class BrushOptionsCommands {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (mask == null) {
if (maskArg == null) {
BBC.BRUSH_MASK_DISABLED.send(player);
tool.setMask(null);
return;
@ -359,7 +354,7 @@ public class BrushOptionsCommands {
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
System.out.println(lastArg + " TODO check this is not the whole command");
settings.addSetting(BrushSettings.SettingType.MASK, lastArg);
settings.setMask(mask);
settings.setMask(maskArg);
tool.update();
BBC.BRUSH_MASK.send(player);
}
@ -373,7 +368,7 @@ public class BrushOptionsCommands {
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
public void smask(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The destination mask", def = "")
Mask mask,
Mask maskArg,
@Switch(name = 'h', desc = "TODO")
boolean offHand,
Arguments arguments) throws WorldEditException {
@ -382,7 +377,7 @@ public class BrushOptionsCommands {
player.print(BBC.BRUSH_NONE.s());
return;
}
if (mask == null) {
if (maskArg == null) {
BBC.BRUSH_SOURCE_MASK_DISABLED.send(player);
tool.setSourceMask(null);
return;
@ -390,7 +385,7 @@ public class BrushOptionsCommands {
BrushSettings settings = offHand ? tool.getOffHand() : tool.getContext();
String lastArg = Iterables.getLast(CommandArgParser.spaceSplit(arguments.get())).getSubstring();
settings.addSetting(BrushSettings.SettingType.SOURCE_MASK, lastArg);
settings.setSourceMask(mask);
settings.setSourceMask(maskArg);
tool.update();
BBC.BRUSH_SOURCE_MASK.send(player);
}

View File

@ -94,7 +94,7 @@ public class ScriptingCommands {
@Arg(desc = "Filename of the CraftScript to load")
String filename,
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
List<String> args) throws WorldEditException {
List<String> commandStr) throws WorldEditException {
if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
BBC.SCRIPTING_NO_PERM.send(player);
return;
@ -105,7 +105,7 @@ public class ScriptingCommands {
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), args.stream())
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), commandStr.stream())
.toArray(String[]::new));
}
@ -117,7 +117,7 @@ public class ScriptingCommands {
@Logging(ALL)
public void executeLast(Player player, LocalSession session,
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
List<String> args) throws WorldEditException {
List<String> commandStr) throws WorldEditException {
String lastScript = session.getLastScript();
@ -134,7 +134,7 @@ public class ScriptingCommands {
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), args.stream())
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), commandStr.stream())
.toArray(String[]::new));
}
}

View File

@ -176,9 +176,9 @@ public class UtilityCommands {
)
@CommandPermissions("fawe.cancel")
@CommandQueued(false)
public void cancel(FawePlayer player) {
int cancelled = player.cancel(false);
BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled);
public void cancel(FawePlayer fp) {
int cancelled = fp.cancel(false);
BBC.WORLDEDIT_CANCEL_COUNT.send(fp, cancelled);
}
@Command(
@ -361,15 +361,15 @@ public class UtilityCommands {
@CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT)
public int removeAbove(Player player, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The apothem of the square to remove from", def = "1")
int size,
@Range(min=1) @Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
int sizeOpt,
@Arg(desc = "The maximum height above you to remove from", def = "")
Integer height) throws WorldEditException {
size = Math.max(1, size);
we.checkMaxRadius(size);
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
World world = player.getWorld();
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
int affected = editSession.removeAbove(session.getPlacementPosition(player), size, height);
int affected = editSession.removeAbove(session.getPlacementPosition(player), sizeOpt, height);
BBC.VISITOR_BLOCK.send(player, affected);
return affected;
}
@ -382,16 +382,16 @@ public class UtilityCommands {
@CommandPermissions("worldedit.removebelow")
@Logging(PLACEMENT)
public int removeBelow(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The apothem of the square to remove from", def = "1")
int size,
@Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
int sizeOpt,
@Arg(desc = "The maximum height below you to remove from", def = "")
Integer height) throws WorldEditException {
size = Math.max(1, size);
we.checkMaxRadius(size);
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
World world = player.getWorld();
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
int affected = editSession.removeBelow(session.getPlacementPosition(player), size, height);
int affected = editSession.removeBelow(session.getPlacementPosition(player), sizeOpt, height);
BBC.VISITOR_BLOCK.send(player, affected);
return affected;
}

View File

@ -630,8 +630,8 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
return false;
}
public void queueVisualization(FawePlayer player) {
Fawe.get().getVisualQueue().queue(player);
public void queueVisualization(FawePlayer fp) {
Fawe.get().getVisualQueue().queue(fp);
}
@Deprecated

View File

@ -14,30 +14,18 @@ import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.command.ActorAuthorizer;
import com.sk89q.worldedit.internal.command.WorldEditBinding;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.util.command.Dispatcher;
import com.sk89q.worldedit.util.command.SimpleDispatcher;
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class DefaultTransformParser extends FaweParser<ResettableExtent> {
private final Pattern INTERSECTION_PATTERN = Pattern.compile("[&|;]+(?![^\\[]*\\])");
private final Dispatcher dispatcher;
public DefaultTransformParser(WorldEdit worldEdit) {
super(worldEdit);
this.dispatcher = new SimpleDispatcher();
this.register(new TransformCommands());
}
@Override
public Dispatcher getDispatcher() {
return dispatcher;
}
public void register(Object clazz) {
ParametricBuilder builder = new ParametricBuilder();

View File

@ -164,7 +164,7 @@ public class ProvideBindings extends Bindings {
*
* @param context the context
* @param direction the direction annotation
* @return a pattern
* @return a BlockVector3
* @throws ParameterException on error
* @throws UnknownDirectionException on an unknown direction
*/
@ -181,7 +181,7 @@ public class ProvideBindings extends Bindings {
* Gets an {@link TreeType} from a {@link ArgumentStack}.
*
* @param context the context
* @return a pattern
* @return a TreeType
* @throws ParameterException on error
* @throws WorldEditException on error
*/
@ -204,7 +204,7 @@ public class ProvideBindings extends Bindings {
* Gets an {@link BiomeType} from a {@link ArgumentStack}.
*
* @param context the context
* @return a pattern
* @return a BiomeType
* @throws ParameterException on error
* @throws WorldEditException on error
*/

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.extent;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
@ -51,7 +52,9 @@ public interface OutputExtent {
* @param block block to set
* @return true if the block was successfully set (return value may not be accurate)
* @throws WorldEditException thrown on an error
* @deprecated Use {@link #setBlock(int, int, int, BlockStateHolder)}
*/
@Deprecated
default <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
return setBlock(position.getX(), position.getY(), position.getZ(), block);
}
@ -60,6 +63,8 @@ public interface OutputExtent {
return setBlock(MutableBlockVector3.get(x, y, z), block);
}
boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException;
/**
* Set the biome.
*

View File

@ -25,8 +25,6 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
import javax.annotation.Nullable;
/**
* A mask that tests whether given positions are contained within a region.
*/

View File

@ -1,72 +0,0 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.MultiUserPlatform;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.util.command.CommandCompleter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* Provides the names of connected users as suggestions.
*/
public class UserCommandCompleter implements CommandCompleter {
private final PlatformManager platformManager;
/**
* Create a new instance.
*
* @param platformManager the platform manager
*/
public UserCommandCompleter(PlatformManager platformManager) {
checkNotNull(platformManager);
this.platformManager = platformManager;
}
@Override
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
Platform platform = platformManager.queryCapability(Capability.USER_COMMANDS);
if (platform instanceof MultiUserPlatform) {
List<String> suggestions = new ArrayList<>();
Collection<Actor> users = ((MultiUserPlatform) platform).getConnectedUsers();
for (Actor user : users) {
if (user.getName().toLowerCase().startsWith(arguments.toLowerCase().trim())) {
suggestions.add(user.getName());
}
}
return suggestions;
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,102 +0,0 @@
package com.sk89q.worldedit.scripting;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.command.FaweParser;
import com.boydti.fawe.config.Settings;
import com.boydti.fawe.util.MainUtil;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.BrushCommands;
import com.sk89q.worldedit.extension.factory.parser.mask.DefaultMaskParser;
import com.sk89q.worldedit.extension.factory.parser.pattern.DefaultPatternParser;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.util.command.ProcessedCallable;
import com.sk89q.worldedit.util.command.parametric.FunctionParametricCallable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class CommandScriptLoader {
private final NashornCraftScriptEngine engine;
private final String loader;
public CommandScriptLoader() throws IOException {
this.engine = new NashornCraftScriptEngine();
try (InputStream inputStream = WorldEdit.class.getResourceAsStream("/cs_adv.js")) {
this.loader = CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
}
}
/**
* Load all file commands
* @throws Throwable
*/
public void load() throws Throwable {
File commands = MainUtil.getFile(Fawe.imp().getDirectory(), Settings.IMP.PATHS.COMMANDS);
if (commands.exists()) {
for (File file : commands.listFiles()) add(new String[0], file);
}
}
private void add(String[] aliases, File file) throws Throwable {
if (file.isDirectory()) {
if (aliases.length == 0) {
String[] newAliases = new String[] {file.getName()};
for (File newFile : file.listFiles()) {
add(newAliases, newFile);
}
} else {
Fawe.debug("Ignoring nested directory: " + file);
}
} else {
String name = file.getName();
if (name.endsWith(".js")) {
Fawe.debug("Loading script: " + name);
List<FunctionParametricCallable> cmds = getCommands(file, Collections.emptyMap());
if (aliases.length == 1) {
FaweParser parser = null;
switch (aliases[0]) {
case "brush":
if (!cmds.isEmpty()) {
BrushCommands processor = new BrushCommands(WorldEdit.getInstance());
for (FunctionParametricCallable cmd : cmds) {
ProcessedCallable processed = new ProcessedCallable(cmd, processor);
PlatformCommandManager.getInstance().registration.register(aliases, cmd.getCommand(), processed);
}
}
return;
case "patterns":
parser = FaweAPI.getParser(DefaultPatternParser.class);
break;
case "masks":
parser = FaweAPI.getParser(DefaultMaskParser.class);
break;
}
if (parser != null) {
for (FunctionParametricCallable cmd : cmds) {
parser.getDispatcher().registerCommand(cmd, cmd.getCommand().aliases());
}
return;
}
}
for (FunctionParametricCallable cmd : cmds) {
PlatformCommandManager.getInstance().registerSubCommands(name);registerCommand(aliases, cmd.getCommand(), cmd);
}
}
}
}
private List<FunctionParametricCallable> getCommands(File file, Map<String, Object> vars) throws Throwable {
String script = new String(Files.readAllBytes(file.toPath())) + loader;
return (List) engine.evaluate(script, file.getPath(), vars);
}
}