Another selective merge

This commit is contained in:
matt 2019-03-28 15:02:37 -04:00
parent acc8eb0a99
commit 699783ba72
14 changed files with 260 additions and 626 deletions

View File

@ -6,63 +6,60 @@ import com.boydti.fawe.object.FaweQueue;
import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.FaweMaskManager;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.cui.CUI; import com.boydti.fawe.util.cui.CUI;
import com.boydti.fawe.util.gui.FormBuilder;
import com.boydti.fawe.util.image.ImageViewer; import com.boydti.fawe.util.image.ImageViewer;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
public interface IFawe { public interface IFawe {
public void debug(final String s); void debug(final String s);
public File getDirectory(); File getDirectory();
public void setupCommand(final String label, final FaweCommand cmd); void setupCommand(final String label, final FaweCommand cmd);
public FawePlayer wrap(final Object obj); FawePlayer wrap(final Object obj);
public void setupVault(); void setupVault();
public TaskManager getTaskManager(); TaskManager getTaskManager();
public FaweQueue getNewQueue(World world, boolean fast); FaweQueue getNewQueue(World world, boolean fast);
public FaweQueue getNewQueue(String world, boolean fast); FaweQueue getNewQueue(String world, boolean fast);
public String getWorldName(World world); String getWorldName(World world);
public Collection<FaweMaskManager> getMaskManagers(); Collection<FaweMaskManager> getMaskManagers();
public void startMetrics(); void startMetrics();
default CUI getCUI(FawePlayer player) { return null; } default CUI getCUI(FawePlayer player) { return null; }
default ImageViewer getImageViewer(FawePlayer player) { return null; } default ImageViewer getImageViewer(FawePlayer player) { return null; }
public default void registerPacketListener() {} default void registerPacketListener() {}
default int getPlayerCount() { default int getPlayerCount() {
return Fawe.get().getCachedPlayers().size(); return Fawe.get().getCachedPlayers().size();
} }
public String getPlatformVersion(); String getPlatformVersion();
public boolean isOnlineMode(); boolean isOnlineMode();
public String getPlatform(); String getPlatform();
public UUID getUUID(String name); UUID getUUID(String name);
public String getName(UUID uuid); String getName(UUID uuid);
public Object getBlocksHubApi(); Object getBlocksHubApi();
public default String getDebugInfo() { default String getDebugInfo() {
return ""; return "";
} }
public default FormBuilder getFormBuilder() {
return null;
}
} }

View File

@ -55,7 +55,7 @@ public class Message {
return text(caption.format(args)); return text(caption.format(args));
} }
public Message text(Object text) { public Message text(java.io.Serializable text) {
Fawe.get().getChatManager().text(this, BBC.color(Objects.toString(text))); Fawe.get().getChatManager().text(this, BBC.color(Objects.toString(text)));
return this; return this;
} }

View File

@ -17,7 +17,6 @@ import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.parametric.ParameterData; import com.sk89q.worldedit.util.command.parametric.ParameterData;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -58,7 +57,7 @@ public class UsageMessage extends Message {
String prefix = !commandString.isEmpty() ? commandString + " " : ""; String prefix = !commandString.isEmpty() ? commandString + " " : "";
List<CommandMapping> list = new ArrayList<>(dispatcher.getCommands()); List<CommandMapping> list = new ArrayList<>(dispatcher.getCommands());
Collections.sort(list, new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN)); list.sort(new PrimaryAliasComparator(CommandManager.COMMAND_CLEAN_PATTERN));
for (CommandMapping mapping : list) { for (CommandMapping mapping : list) {
boolean perm = locals == null || mapping.getCallable().testPermission(locals); boolean perm = locals == null || mapping.getCallable().testPermission(locals);
@ -110,7 +109,6 @@ public class UsageMessage extends Message {
StringBuilder tooltip = new StringBuilder(); StringBuilder tooltip = new StringBuilder();
String command = null; String command = null;
String webpage = null;
tooltip.append("Name: " + param.getName()); tooltip.append("Name: " + param.getName());
if (param instanceof ParameterData) { if (param instanceof ParameterData) {
@ -129,23 +127,21 @@ public class UsageMessage extends Message {
if (type instanceof Class) { if (type instanceof Class) {
Link link = (Link) ((Class) type).getAnnotation(Link.class); Link link = (Link) ((Class) type).getAnnotation(Link.class);
if (link != null) { if (link != null) {
if (link.value().startsWith("http")) webpage = link.value(); command = Commands.getAlias(link.clazz(), link.value());
else command = Commands.getAlias(link.clazz(), link.value());
} }
} }
} }
tooltip.append("\nOptional: " + (param.isOptional() || param.isValueFlag())); tooltip.append("\nOptional: " + (param.isOptional() || param.isValueFlag()));
if (param.getDefaultValue() != null && param.getDefaultValue().length >= 0) { if (param.getDefaultValue() != null) {
tooltip.append("\nDefault: " + param.getDefaultValue()[0]); tooltip.append("\nDefault: " + param.getDefaultValue()[0]);
} else if (argStr.contains("=")) { } else if (argStr.contains("=")) {
tooltip.append("\nDefault: " + argStr.split("[=|\\]|>]")[1]); tooltip.append("\nDefault: " + argStr.split("[=|\\]|>]")[1]);
} }
if (command != null || webpage != null) { if (command != null) {
tooltip.append("\nClick for more info"); tooltip.append("\nClick for more info");
} }
tooltip(tooltip.toString()); tooltip(tooltip.toString());
if (command != null) command(command); if (command != null) command(command);
if (webpage != null) link(webpage);
} }
newline(); newline();

View File

@ -1,31 +0,0 @@
package com.boydti.fawe.util.gui;
import com.boydti.fawe.object.FawePlayer;
import java.net.URL;
import java.util.Map;
import java.util.function.Consumer;
import javax.annotation.Nullable;
public interface FormBuilder<T> {
FormBuilder setTitle(String text);
FormBuilder setIcon(URL icon);
FormBuilder addButton(String text, @Nullable URL image);
FormBuilder addDropdown(String text, int def, String... options);
FormBuilder addInput(String text, String placeholder, String def);
FormBuilder addLabel(String text);
FormBuilder addSlider(String text, double min, double max, int step, double def);
FormBuilder addStepSlider(String text, int def, String... options);
FormBuilder addToggle(String text, boolean def);
FormBuilder setResponder(Consumer<Map<Integer, Object>> handler);
void display(FawePlayer<T> fp);
}

View File

@ -543,7 +543,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return the world * @return the world
*/ */
public World getWorld() { public World getWorld() {
return this.world; return world;
} }
/** /**
@ -612,6 +612,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* *
* @return whether the queue is enabled * @return whether the queue is enabled
*/ */
@Deprecated
public boolean isQueueEnabled() { public boolean isQueueEnabled() {
return true; return true;
} }
@ -619,12 +620,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
/** /**
* Queue certain types of block for better reproduction of those blocks. * Queue certain types of block for better reproduction of those blocks.
*/ */
@Deprecated
public void enableQueue() { public void enableQueue() {
} }
/** /**
* Disable the queue. This will close the queue. * Disable the queue. This will close the queue.
*/ */
@Deprecated
public void disableQueue() { public void disableQueue() {
if (this.isQueueEnabled()) { if (this.isQueueEnabled()) {
this.flushQueue(); this.flushQueue();
@ -967,10 +970,25 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
} }
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
return getHighestTerrainBlock(x, z, minY, maxY, null);
}
/**
* Returns the highest solid 'terrain' block.
*
* @param x the X coordinate
* @param z the Z coordinate
* @param minY minimal height
* @param maxY maximal height
* @param filter a mask of blocks to consider, or null to consider any solid (movement-blocking) block
* @return height of highest block found or 'minY'
*/
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) {
for (int y = maxY; y >= minY; --y) { for (int y = maxY; y >= minY; --y) {
BlockVector3 pt = BlockVector3.at(x, y, z); BlockVector3 pt = BlockVector3.at(x, y, z);
BlockState block = getBlock(pt); if (filter == null
if (block.getBlockType().getMaterial().isMovementBlocker()) { ? getBlock(pt).getBlockType().getMaterial().isMovementBlocker()
: filter.test(pt)) {
return y; return y;
} }
} }
@ -1008,10 +1026,17 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
throw new RuntimeException("New enum entry added that is unhandled here"); throw new RuntimeException("New enum entry added that is unhandled here");
} }
/**
* Set a block, bypassing both history and block re-ordering.
*
* @param position the position to set the block at
* @param block the block
* @return whether the block changed
*/
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) { public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
try { try {
return this.bypassAll.setBlock(position, block); return this.bypassAll.setBlock(position, block);
} catch (final WorldEditException e) { } catch (WorldEditException e) {
throw new RuntimeException("Unexpected exception", e); throw new RuntimeException("Unexpected exception", e);
} }
} }
@ -1183,7 +1208,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return the number of changes * @return the number of changes
*/ */
public int size() { public int size() {
return this.getBlockChangeCount(); return getBlockChangeCount();
} }
public void setSize(int size) { public void setSize(int size) {
@ -1426,9 +1451,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation") public int fillXZ(final BlockVector3 origin, BaseBlock block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
public int fillXZ(final BlockVector3 origin, final BaseBlock block, final double radius, final int depth, final boolean recursive) { return fillXZ(origin, (Pattern) block, radius, depth, recursive);
return this.fillXZ(origin, (Pattern) block, radius, depth, recursive);
} }
/** /**
* Fills an area recursively in the X/Z directions. * Fills an area recursively in the X/Z directions.
@ -1441,8 +1465,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation") public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
public int fillXZ(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, final boolean recursive) {
checkNotNull(origin); checkNotNull(origin);
checkNotNull(pattern); checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0"); checkArgument(radius >= 0, "radius >= 0");
@ -1457,7 +1480,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
// Masks.negate(new ExistingBlockMask(this))); // Masks.negate(new ExistingBlockMask(this)));
// Want to replace blocks // Want to replace blocks
final BlockReplace replace = new BlockReplace(EditSession.this, pattern); BlockReplace replace = new BlockReplace(this, pattern);
// Pick how we're going to visit blocks // Pick how we're going to visit blocks
RecursiveVisitor visitor; RecursiveVisitor visitor;
@ -1524,7 +1547,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation")
public int removeNear(final BlockVector3 position, Mask mask, final int apothem) { public int removeNear(final BlockVector3 position, Mask mask, final int apothem) {
checkNotNull(position); checkNotNull(position);
checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(apothem >= 1, "apothem >= 1");
@ -1589,8 +1611,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation") public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) throws MaxChangedBlocksException {
public <B extends BlockStateHolder<B>> int setBlocks(final Region region, final B block) {
checkNotNull(region); checkNotNull(region);
checkNotNull(block); checkNotNull(block);
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData(); boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
@ -1625,8 +1646,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
@SuppressWarnings("deprecation") public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
public int setBlocks(final Region region, final Pattern pattern) {
checkNotNull(region); checkNotNull(region);
checkNotNull(pattern); checkNotNull(pattern);
if (pattern instanceof BlockPattern) { if (pattern instanceof BlockPattern) {
@ -1844,7 +1864,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
*/ */
public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(block); checkNotNull(block);
return this.overlayCuboidBlocks(region, (Pattern) (block)); return overlayCuboidBlocks(region, new BlockPattern(block));
} }
/** /**
@ -2100,8 +2120,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks changed * @return number of blocks changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makeCylinder(final BlockVector3 pos, final Pattern block, final double radius, final int height, final boolean filled) { public int makeCylinder(BlockVector3 pos, Pattern block, double radius, int height, boolean filled) throws MaxChangedBlocksException {
return this.makeCylinder(pos, block, radius, radius, height, filled); return makeCylinder(pos, block, radius, radius, height, filled);
} }
/** /**
@ -2425,18 +2445,28 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks changed * @return number of blocks changed
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int makePyramid(final BlockVector3 position, final Pattern block, int size, final boolean filled) { public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException {
final int height = size; int affected = 0;
int height = size;
for (int y = 0; y <= height; ++y) { for (int y = 0; y <= height; ++y) {
size--; size--;
for (int x = 0; x <= size; ++x) { for (int x = 0; x <= size; ++x) {
for (int z = 0; z <= size; ++z) { for (int z = 0; z <= size; ++z) {
if ((filled && (z <= size) && (x <= size)) || (z == size) || (x == size)) { if ((filled && z <= size && x <= size) || z == size || x == size) {
this.setBlock(position.add(x, y, z), block);
this.setBlock(position.add(-x, y, z), block); if (setBlock(position.add(x, y, z), block)) {
this.setBlock(position.add(x, y, -z), block); ++affected;
this.setBlock(position.add(-x, y, -z), block); }
if (setBlock(position.add(-x, y, z), block)) {
++affected;
}
if (setBlock(position.add(x, y, -z), block)) {
++affected;
}
if (setBlock(position.add(-x, y, -z), block)) {
++affected;
}
} }
} }
} }
@ -2453,60 +2483,36 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int thaw(BlockVector3 position, final double radius) public int thaw(BlockVector3 position, double radius)
throws MaxChangedBlocksException { throws MaxChangedBlocksException {
int affected = 0; int affected = 0;
double radiusSq = radius * radius; double radiusSq = radius * radius;
final int ox = position.getBlockX(); int ox = position.getBlockX();
final int oy = position.getBlockY(); int oy = position.getBlockY();
final int oz = position.getBlockZ(); int oz = position.getBlockZ();
final int ceilRadius = (int) Math.ceil(radius); BlockState air = BlockTypes.AIR.getDefaultState();
for (int x = ox - ceilRadius; x <= (ox + ceilRadius); ++x) { BlockState water = BlockTypes.WATER.getDefaultState();
int dx = x - ox; int ceilRadius = (int) Math.ceil(radius);
int dx2 = dx * dx; for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
for (int z = oz - ceilRadius; z <= (oz + ceilRadius); ++z) { for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
int dz = z - oz; if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
int dz2 = dz * dz;
if (dx2 + dz2 > radiusSq) {
continue; continue;
} }
for (int y = maxY; y >= 1; --y) { for (int y = world.getMaxY(); y >= 1; --y) {
final BlockType type = getBlockType(x, y, z); BlockVector3 pt = BlockVector3.at(x, y, z);
switch (type.getResource().toUpperCase()) { BlockType id = getBlock(pt).getBlockType();
case "ICE":
this.setBlock(x, y, z, BlockTypes.WATER.getDefaultState()); if (id == BlockTypes.ICE) {
break; if (setBlock(pt, water)) {
case "SNOW": ++affected;
this.setBlock(x, y, z, BlockTypes.AIR.getDefaultState()); }
break; } else if (id == BlockTypes.SNOW) {
case "CAVE_AIR": if (setBlock(pt, air)) {
case "VOID_AIR": ++affected;
case "AIR": }
} else if (id.getMaterial().isAir()) {
continue; continue;
default:
break;
// int ceilRadius = (int) Math.ceil(radius);
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
// continue;
// }
//
// for (int y = world.getMaxY(); y >= 1; --y) {
// BlockVector3 pt = BlockVector3.at(x, y, z);
// BlockType id = getBlock(pt).getBlockType();
//
// if (id == BlockTypes.ICE) {
// if (setBlock(pt, water)) {
// ++affected;
// }
// } else if (id == BlockTypes.SNOW) {
// if (setBlock(pt, air)) {
// ++affected;
// }
// } else if (id.getMaterial().isAir()) {
// continue;
} }
break; break;
} }
@ -2524,83 +2530,55 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
* @return number of blocks affected * @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public int simulateSnow(final BlockVector3 position, final double radius) { public int simulateSnow(BlockVector3 position, double radius) throws MaxChangedBlocksException {
int affected = 0;
double radiusSq = radius * radius;
final double radiusSq = radius * radius; int ox = position.getBlockX();
int oy = position.getBlockY();
int oz = position.getBlockZ();
final int ox = position.getBlockX(); BlockState ice = BlockTypes.ICE.getDefaultState();
final int oy = position.getBlockY(); BlockState snow = BlockTypes.SNOW.getDefaultState();
final int oz = position.getBlockZ();
final int ceilRadius = (int) Math.ceil(radius); int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= (ox + ceilRadius); ++x) { for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
int dx = x - ox; for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
int dx2 = dx * dx; if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
for (int z = oz - ceilRadius; z <= (oz + ceilRadius); ++z) {
int dz = z - oz;
int dz2 = dz * dz;
if (dx2 + dz2 > radiusSq) {
continue; continue;
} }
outer: for (int y = world.getMaxY(); y >= 1; --y) {
for (int y = maxY; y >= 1; --y) { BlockVector3 pt = BlockVector3.at(x, y, z);
BlockType type = getBlockType(x, y, z); BlockType id = getBlock(pt).getBlockType();
switch (type.getResource().toUpperCase()) { if (id.getMaterial().isAir()) {
case "AIR": continue;
case "CAVE_AIR": }
case "VOID_AIR": // Ice!
continue; if (id == BlockTypes.WATER) {
case "WATER": if (setBlock(pt, ice)) {
this.setBlock(x, y, z, BlockTypes.ICE.getDefaultState()); ++affected;
break outer; }
case "ACACIA_LEAVES": // TODO FIXME get leaves dynamically break;
case "BIRCH_LEAVES": }
case "DARK_OAK_LEAVES":
case "JUNGLE_LEAVES": // Snow should not cover these blocks
case "OAK_LEAVES": if (id.getMaterial().isTranslucent()) {
case "SPRUCE_LEAVES": // Add snow on leaves
// int ceilRadius = (int) Math.ceil(radius); if (!BlockCategories.LEAVES.contains(id)) {
// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// if ((BlockVector3.at(x, oy, z)).distanceSq(position) > radiusSq) {
// continue;
// }
//
// for (int y = world.getMaxY(); y >= 1; --y) {
// BlockVector3 pt = BlockVector3.at(x, y, z);
// BlockType id = getBlock(pt).getBlockType();
//
// if (id.getMaterial().isAir()) {
// continue;
// }
//
// // Ice!
// if (id == BlockTypes.WATER) {
// if (setBlock(pt, ice)) {
// ++affected;
// }
// break;
// }
//
// // Snow should not cover these blocks
// if (id.getMaterial().isTranslucent()) {
// // Add snow on leaves
// if (!BlockCategories.LEAVES.contains(id)) {
break; break;
default:
if (type.getMaterial().isTranslucent()) {
break outer;
} }
} }
// Too high? // Too high?
if (y == maxY) { if (y == world.getMaxY()) {
break outer; break;
} }
// add snow cover // add snow cover
this.setBlock(x, y + 1, z, BlockTypes.SNOW.getDefaultState()); if (setBlock(pt.add(0, 1, 0), snow)) {
break outer; ++affected;
}
break;
} }
} }
} }
@ -3030,22 +3008,22 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
for (int x = minX; x <= maxX; ++x) { for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) { for (int y = minY; y <= maxY; ++y) {
this.recurseHollow(region, BlockVector3.at(x, y, minZ), outside); recurseHollow(region, BlockVector3.at(x, y, minZ), outside);
this.recurseHollow(region, BlockVector3.at(x, y, maxZ), outside); recurseHollow(region, BlockVector3.at(x, y, maxZ), outside);
} }
} }
for (int y = minY; y <= maxY; ++y) { for (int y = minY; y <= maxY; ++y) {
for (int z = minZ; z <= maxZ; ++z) { for (int z = minZ; z <= maxZ; ++z) {
this.recurseHollow(region, BlockVector3.at(minX, y, z), outside); recurseHollow(region, BlockVector3.at(minX, y, z), outside);
this.recurseHollow(region, BlockVector3.at(maxX, y, z), outside); recurseHollow(region, BlockVector3.at(maxX, y, z), outside);
} }
} }
for (int z = minZ; z <= maxZ; ++z) { for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) { for (int x = minX; x <= maxX; ++x) {
this.recurseHollow(region, BlockVector3.at(x, minY, z), outside); recurseHollow(region, BlockVector3.at(x, minY, z), outside);
this.recurseHollow(region, BlockVector3.at(x, maxY, z), outside); recurseHollow(region, BlockVector3.at(x, maxY, z), outside);
} }
} }
@ -3101,44 +3079,47 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
LocalBlockVectorSet vset = new LocalBlockVectorSet(); LocalBlockVectorSet vset = new LocalBlockVectorSet();
boolean notdrawn = true; boolean notdrawn = true;
final int x1 = pos1.getBlockX(), y1 = pos1.getBlockY(), z1 = pos1.getBlockZ(); int x1 = pos1.getBlockX(), y1 = pos1.getBlockY(), z1 = pos1.getBlockZ();
final int x2 = pos2.getBlockX(), y2 = pos2.getBlockY(), z2 = pos2.getBlockZ(); int x2 = pos2.getBlockX(), y2 = pos2.getBlockY(), z2 = pos2.getBlockZ();
int tipx = x1, tipy = y1, tipz = z1; int tipx = x1, tipy = y1, tipz = z1;
final int dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1), dz = Math.abs(z2 - z1); int dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1), dz = Math.abs(z2 - z1);
if ((dx + dy + dz) == 0) { if (dx + dy + dz == 0) {
vset.add(tipx, tipy, tipz); vset.add(BlockVector3.at(tipx, tipy, tipz));
notdrawn = false; notdrawn = false;
} }
if ((Math.max(Math.max(dx, dy), dz) == dx) && notdrawn) { if (Math.max(Math.max(dx, dy), dz) == dx && notdrawn) {
for (int domstep = 0; domstep <= dx; domstep++) { for (int domstep = 0; domstep <= dx; domstep++) {
tipx = x1 + (domstep * ((x2 - x1) > 0 ? 1 : -1)); tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1);
tipy = (int) Math.round(y1 + (((domstep * ((double) dy)) / (dx)) * ((y2 - y1) > 0 ? 1 : -1))); tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + (((domstep * ((double) dz)) / (dx)) * ((z2 - z1) > 0 ? 1 : -1))); tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1));
vset.add(tipx, tipy, tipz);
vset.add(BlockVector3.at(tipx, tipy, tipz));
} }
notdrawn = false; notdrawn = false;
} }
if ((Math.max(Math.max(dx, dy), dz) == dy) && notdrawn) { if (Math.max(Math.max(dx, dy), dz) == dy && notdrawn) {
for (int domstep = 0; domstep <= dy; domstep++) { for (int domstep = 0; domstep <= dy; domstep++) {
tipy = y1 + (domstep * ((y2 - y1) > 0 ? 1 : -1)); tipy = y1 + domstep * (y2 - y1 > 0 ? 1 : -1);
tipx = (int) Math.round(x1 + (((domstep * ((double) dx)) / (dy)) * ((x2 - x1) > 0 ? 1 : -1))); tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + (((domstep * ((double) dz)) / (dy)) * ((z2 - z1) > 0 ? 1 : -1))); tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1));
vset.add(tipx, tipy, tipz); vset.add(BlockVector3.at(tipx, tipy, tipz));
} }
notdrawn = false; notdrawn = false;
} }
if ((Math.max(Math.max(dx, dy), dz) == dz) && notdrawn) { if (Math.max(Math.max(dx, dy), dz) == dz && notdrawn) {
for (int domstep = 0; domstep <= dz; domstep++) { for (int domstep = 0; domstep <= dz; domstep++) {
tipz = z1 + (domstep * ((z2 - z1) > 0 ? 1 : -1)); tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1);
tipy = (int) Math.round(y1 + (((domstep * ((double) dy)) / (dz)) * ((y2 - y1) > 0 ? 1 : -1))); tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2-y1>0 ? 1 : -1));
tipx = (int) Math.round(x1 + (((domstep * ((double) dx)) / (dz)) * ((x2 - x1) > 0 ? 1 : -1))); tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2-x1>0 ? 1 : -1));
vset.add(tipx, tipy, tipz);
vset.add(BlockVector3.at(tipx, tipy, tipz));
} }
notdrawn = false;
} }
Set<BlockVector3> newVset; Set<BlockVector3> newVset;
if (flat) { if (flat) {
@ -3283,7 +3264,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue,
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
final BlockVector3 current = queue.removeFirst(); final BlockVector3 current = queue.removeFirst();
if (this.getBlockType(current).getMaterial().isMovementBlocker()) { final BlockState block = getBlock(current);
if (block.getBlockType().getMaterial().isMovementBlocker()) {
continue; continue;
} }

View File

@ -36,8 +36,6 @@ import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.util.ImgurUtility; import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MaskTraverser; import com.boydti.fawe.util.MaskTraverser;
import com.boydti.fawe.util.gui.FormBuilder;
import com.boydti.fawe.wrappers.FakePlayer;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -393,17 +391,7 @@ public class ClipboardCommands extends MethodCommands {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) { BBC.DOWNLOAD_LINK.send(player, urlText);
FormBuilder form = Fawe.imp().getFormBuilder();
FawePlayer<Object> fp = FawePlayer.wrap(player);
if (form != null && fp != FakePlayer.getConsole().toFawePlayer()) {
form.setTitle("Download Clipboard");
form.addInput("url:", urlText, urlText);
form.display(fp);
return;
}
}
BBC.DOWNLOAD_LINK.send(player, urlText);
} }
} }
} }

View File

@ -176,7 +176,7 @@ public class SchematicCommands extends MethodCommands {
@CommandPermissions({"worldedit.schematic.remap"}) @CommandPermissions({"worldedit.schematic.remap"})
public void remap(final Player player, final LocalSession session) throws WorldEditException { public void remap(final Player player, final LocalSession session) throws WorldEditException {
ClipboardRemapper remapper; ClipboardRemapper remapper;
if (Fawe.imp().getPlatform().equalsIgnoreCase("nukkit")) { if (false) {
remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE); remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE);
} else { } else {
remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PE, ClipboardRemapper.RemapPlatform.PC); remapper = new ClipboardRemapper(ClipboardRemapper.RemapPlatform.PE, ClipboardRemapper.RemapPlatform.PC);

View File

@ -28,22 +28,17 @@ import com.boydti.fawe.config.Settings;
import com.boydti.fawe.object.DelegateConsumer; import com.boydti.fawe.object.DelegateConsumer;
import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.FaweLimit;
import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.RunnableVal;
import com.boydti.fawe.object.RunnableVal3; import com.boydti.fawe.object.RunnableVal3;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.MathMan;
import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.chat.Message; import com.boydti.fawe.util.chat.Message;
import com.boydti.fawe.util.chat.UsageMessage; import com.boydti.fawe.util.chat.UsageMessage;
import com.boydti.fawe.util.gui.FormBuilder;
import com.boydti.fawe.util.image.ImageUtil; import com.boydti.fawe.util.image.ImageUtil;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.world.block.BlockState;
import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT;
import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
@ -201,33 +196,30 @@ public class UtilityCommands extends MethodCommands {
File maxImages = new File(webSrc, "images" + File.separator + "max"); File maxImages = new File(webSrc, "images" + File.separator + "max");
final int sub = srcFolder.getAbsolutePath().length(); final int sub = srcFolder.getAbsolutePath().length();
List<String> images = new ArrayList<>(); List<String> images = new ArrayList<>();
MainUtil.iterateFiles(srcFolder, new Consumer<File>() { MainUtil.iterateFiles(srcFolder, file -> {
@Override switch (file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase()) {
public void accept(File file) { case ".png":
switch (file.getName().substring(file.getName().lastIndexOf('.')).toLowerCase()) { case ".jpeg":
case ".png": break;
case ".jpeg": default:
break; return;
default: }
return; try {
} String name = file.getAbsolutePath().substring(sub);
try { if (name.startsWith(File.separator)) name = name.replaceFirst(java.util.regex.Pattern.quote(File.separator), "");
String name = file.getAbsolutePath().substring(sub); BufferedImage img = MainUtil.readImage(file);
if (name.startsWith(File.separator)) name = name.replaceFirst(java.util.regex.Pattern.quote(File.separator), ""); BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
BufferedImage img = MainUtil.readImage(file); BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
BufferedImage minImg = ImageUtil.getScaledInstance(img, min, min, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); player.sendMessage("Writing " + name);
BufferedImage maxImg = max == -1 ? img : ImageUtil.getScaledInstance(img, max, max, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true); File minFile = new File(minImages, name);
player.sendMessage("Writing " + name); File maxFile = new File(maxImages, name);
File minFile = new File(minImages, name); minFile.getParentFile().mkdirs();
File maxFile = new File(maxImages, name); maxFile.getParentFile().mkdirs();
minFile.getParentFile().mkdirs(); ImageIO.write(minImg, "png", minFile);
maxFile.getParentFile().mkdirs(); ImageIO.write(maxImg, "png", maxFile);
ImageIO.write(minImg, "png", minFile); images.add(name);
ImageIO.write(maxImg, "png", maxFile); } catch (IOException e) {
images.add(name); throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
} }
}); });
StringBuilder config = new StringBuilder(); StringBuilder config = new StringBuilder();
@ -666,20 +658,12 @@ public class UtilityCommands extends MethodCommands {
final Expression expression = Expression.compile(input); final Expression expression = Expression.compile(input);
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Double> futureResult = executor.submit(new Callable<Double>() { Future<Double> futureResult = executor.submit((Callable<Double>) expression::evaluate);
@Override
public Double call() throws Exception {
return expression.evaluate();
}
});
Double result = Double.NaN; Double result = Double.NaN;
try { try {
result = futureResult.get(limit.MAX_EXPRESSION_MS, TimeUnit.MILLISECONDS); result = futureResult.get(limit.MAX_EXPRESSION_MS, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} catch (TimeoutException e) { } catch (TimeoutException e) {
futureResult.cancel(true); futureResult.cancel(true);
@ -780,26 +764,25 @@ public class UtilityCommands extends MethodCommands {
final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0; final int sortType = args.hasFlag('d') ? -1 : args.hasFlag('n') ? 1 : 0;
// cleanup file list // cleanup file list
Collections.sort(fileList, new Comparator<File>() { fileList.sort((f1, f2) -> {
@Override boolean dir1 = f1.isDirectory();
public int compare(File f1, File f2) { boolean dir2 = f2.isDirectory();
boolean dir1 = f1.isDirectory(); if (dir1 != dir2)
boolean dir2 = f2.isDirectory(); return dir1 ? -1 : 1;
if (dir1 != dir2) return dir1 ? -1 : 1; int res;
int res; if (sortType == 0) { // use name by default
if (sortType == 0) { // use name by default int p = f1.getParent().compareTo(f2.getParent());
int p = f1.getParent().compareTo(f2.getParent()); if (p == 0) { // same parent, compare names
if (p == 0) { // same parent, compare names res = f1.getName().compareTo(f2.getName());
res = f1.getName().compareTo(f2.getName()); } else { // different parent, sort by that
} else { // different parent, sort by that res = p;
res = p;
}
} else {
res = Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); // use date if there is a flag
if (sortType == 1) res = -res; // flip date for newest first instead of oldest first
} }
return res; } else {
res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag
if (sortType == 1)
res = -res; // flip date for newest first instead of oldest first
} }
return res;
}); });
int offset = (page - 1) * perPage; int offset = (page - 1) * perPage;
@ -891,7 +874,7 @@ public class UtilityCommands extends MethodCommands {
UUID uuid = UUID.fromString(f.getName()); UUID uuid = UUID.fromString(f.getName());
return false; return false;
} }
} catch (IllegalArgumentException exception) {} } catch (IllegalArgumentException ignored) {}
return true; return true;
}; };
@ -1031,269 +1014,6 @@ public class UtilityCommands extends MethodCommands {
help(args, we, actor, "/", null); help(args, we, actor, "/", null);
} }
@Command(
aliases = {"/gui"},
desc = "Open the GUI"
)
@Logging(PLACEMENT)
public void gui(Actor actor, FawePlayer fp, LocalSession session, CommandContext args) throws WorldEditException, CommandException {
FormBuilder gui = Fawe.imp().getFormBuilder();
if (gui == null) throw new CommandException("Only supported on Pocket Edition");
Dispatcher callable = worldEdit.getPlatformManager().getCommandManager().getDispatcher();
CommandLocals locals = args.getLocals();
String prefix = Commands.getAlias(UtilityCommands.class, "/gui");
// TODO sort commands by most used
new HelpBuilder(callable, args, prefix, Integer.MAX_VALUE) {
@Override
public void displayFailure(String message) {
gui.setTitle("Error");
gui.addLabel(message);
}
@Override
public void displayUsage(CommandCallable callable, String commandString) {
gui.setTitle(commandString);
if (callable instanceof Dispatcher) {
Dispatcher dispathcer = (Dispatcher) callable;
dispathcer.getCommands();
gui.addLabel("Dispatcher not implemented for " + commandString);
} else {
Description cmdDesc = callable.getDescription();
List<Parameter> params = cmdDesc.getParameters();
String[] suggested = new String[params.size()];
if (cmdDesc.getUsage() != null) {
String[] usageArgs = cmdDesc.getUsage().split(" ", params.size());
for (int i = 0; i < usageArgs.length; i++) {
String arg = usageArgs[i];
String[] splitSug = arg.split("=");
if (splitSug.length == 2) {
suggested[i] = splitSug[1];
}
}
}
for (int i = 0 ; i < params.size(); i++) {
String[] def = params.get(i).getDefaultValue();
if (def != null && def.length != 0) {
suggested[i] = def[0];
}
}
String help = cmdDesc.getHelp();
if (help == null || help.isEmpty()) help = cmdDesc.getDescription();
gui.addLabel(BBC.color("&2" + help + "\n"));
List<String> flags = new ArrayList<>();
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
String name = param.getName();
boolean optional = param.isValueFlag() || param.isOptional();
String[] def = param.getDefaultValue();
if (param.getFlag() != null) {
flags.add("-" + param.getFlag() + " ");
} else {
flags.add("");
}
if (param instanceof ParameterData) {
ParameterData pd = (ParameterData) param;
Type type = pd.getType();
String suggestion = suggested[i];
String color = optional ? "3" : "c";
StringBuilder label = new StringBuilder(BBC.color("&" + color + name + ": "));
// if (suggested[i] != null) label.append(" e.g. " + suggestion);
Range range = MainUtil.getOf(pd.getModifiers(), Range.class);
double min = 0;
double max = 100;
if (range != null) {
min = range.min();
max = range.max();
} else {
SuggestedRange suggestedRange = MainUtil.getOf(pd.getModifiers(), SuggestedRange.class);
if (suggestedRange != null) {
min = suggestedRange.min();
max = suggestedRange.max();
} else if (name.equalsIgnoreCase("radius") || name.equalsIgnoreCase("size")) {
max = WorldEdit.getInstance().getConfiguration().maxBrushRadius;
}
}
int step = 1;
Step stepSizeAnn = MainUtil.getOf(pd.getModifiers(), Step.class);
if (stepSizeAnn != null) {
double stepVal = stepSizeAnn.value();
step = Math.max(1, (int) stepVal);
}
/*
BaseBiome
Vector
Vector2D
*/
switch (type.getTypeName()) {
case "double":
case "java.lang.Double": {
double value = suggestion != null ? Double.parseDouble(suggestion) : min;
gui.addSlider("\n" + label.toString(), min, max, 1, value);
break;
}
case "int":
case "java.lang.Integer": {
int value = suggestion != null ? Integer.parseInt(suggestion) : (int) min;
gui.addSlider("\n" + label.toString(), min, max, 1, value);
break;
}
case "boolean":
case "java.lang.Boolean": {
boolean value = suggestion != null ? Boolean.parseBoolean(suggestion) : false;
gui.addToggle(label.toString(), value);
break;
}
case "com.sk89q.worldedit.patterns.Pattern": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
case "com.sk89q.worldedit.blocks.BaseBlock": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
case "com.sk89q.worldedit.function.mask.Mask": {
gui.addInput("\n" + label.toString(), "stone", "wood");
break;
}
default:
case "java.lang.String": {
// TODO
// clipboard
// schematic
// image
if (suggestion == null) suggestion = "";
gui.addInput("\n" + label.toString(), suggestion, suggestion);
break;
}
}
} else {
throw new UnsupportedOperationException("Unsupported callable: " + callable.getClass() + " | " + param.getClass());
}
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
int index = 0;
StringBuilder command = new StringBuilder(commandString);
for (Map.Entry<Integer, Object> arg : response.entrySet()) {
String argValue = arg.getValue().toString();
String flag = flags.get(index);
if (!flag.isEmpty()) {
if (argValue.equalsIgnoreCase("false")) continue;
if (argValue.equalsIgnoreCase("true")) argValue = "";
}
command.append(" " + flag + argValue);
index++;
}
CommandEvent event = new CommandEvent(actor, command.toString());
CommandManager.getInstance().handleCommand(event);
}
});
}
}
@Override
public void displayCategories(Map<String, Map<CommandMapping, String>> categories) {
gui.setTitle(BBC.HELP_HEADER_CATEGORIES.s());
List<String> categoryList = new ArrayList<>();
for (Map.Entry<String, Map<CommandMapping, String>> categoryEntry : categories.entrySet()) {
String category = categoryEntry.getKey();
categoryList.add(category);
Map<CommandMapping, String> commandMap = categoryEntry.getValue();
int size = commandMap.size();
String plural = size == 1 ? "command" : "commands";
gui.addButton(BBC.HELP_ITEM_ALLOWED.f(category, "(" + size + " " + plural + ")"), null);
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
if (response.isEmpty()) {
// ??
throw new IllegalArgumentException("No response for categories");
} else {
Map.Entry<Integer, Object> clicked = response.entrySet().iterator().next();
String category = categoryList.get(clicked.getKey());
String arguments = prefix + " " + category;
CommandEvent event = new CommandEvent(actor, arguments);
CommandManager.getInstance().handleCommand(event);
}
}
});
}
@Override
public void displayCommands(Map<CommandMapping, String> commandMap, String visited, int page, int pageTotal, int effectiveLength) {
gui.setTitle(BBC.HELP_HEADER_SUBCOMMANDS.s());
String baseCommand = prefix;
if (effectiveLength > 0) baseCommand += " " + args.getString(0, effectiveLength - 1);
CommandLocals locals = args.getLocals();
if (!visited.isEmpty()) {
visited = visited + " ";
}
List<String> commands = new ArrayList<>();
for (Map.Entry<CommandMapping, String> cmdEntry : commandMap.entrySet()) {
CommandMapping mapping = cmdEntry.getKey();
String subPrefix = cmdEntry.getValue();
StringBuilder helpCmd = new StringBuilder();
helpCmd.append(prefix);
helpCmd.append(" ");
helpCmd.append(subPrefix);
CommandCallable c = mapping.getCallable();
helpCmd.append(visited);
helpCmd.append(mapping.getPrimaryAlias());
String s2 = mapping.getDescription().getDescription();
if (c.testPermission(locals)) {
// gui.addLabel(s2);
gui.addButton(helpCmd.toString(), null);
commands.add(helpCmd.toString());
}
}
gui.setResponder(new Consumer<Map<Integer, Object>>() {
@Override
public void accept(Map<Integer, Object> response) {
if (response.isEmpty()) {
// ??
throw new IllegalArgumentException("No response for command list: " + prefix);
} else {
Map.Entry<Integer, Object> clicked = response.entrySet().iterator().next();
int index = clicked.getKey();
String cmd = commands.get(index);
CommandEvent event = new CommandEvent(actor, cmd);
CommandManager.getInstance().handleCommand(event);
}
}
});
}
}.run();
gui.display(fp);
}
public static void help(CommandContext args, WorldEdit we, Actor actor, String prefix, CommandCallable callable) { public static void help(CommandContext args, WorldEdit we, Actor actor, String prefix, CommandCallable callable) {
final int perPage = actor instanceof Player ? 12 : 20; // More pages for console final int perPage = actor instanceof Player ? 12 : 20; // More pages for console

View File

@ -359,7 +359,7 @@ public final class CommandManager {
return split; return split;
} }
public void handleCommandOnCurrentThread(final CommandEvent event) { public void handleCommandOnCurrentThread(CommandEvent event) {
Actor actor = platformManager.createProxyActor(event.getActor()); Actor actor = platformManager.createProxyActor(event.getActor());
final String args = event.getArguments(); final String args = event.getArguments();
final String[] split = commandDetection(args.split(" ")); final String[] split = commandDetection(args.split(" "));
@ -408,12 +408,8 @@ public final class CommandManager {
final Actor finalActor = actor; final Actor finalActor = actor;
locals.put("arguments", args); locals.put("arguments", args);
ThrowableSupplier<Throwable> task = new ThrowableSupplier<Throwable>() { ThrowableSupplier<Throwable> task =
@Override () -> dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
public Object get() throws Throwable {
return dispatcher.call(Joiner.on(" ").join(split), locals, new String[0]);
}
};
handleCommandTask(task, locals, actor, session, failedPermissions, fp); handleCommandTask(task, locals, actor, session, failedPermissions, fp);
} }
@ -517,29 +513,21 @@ public final class CommandManager {
String args = event.getArguments(); String args = event.getArguments();
CommandEvent finalEvent = new CommandEvent(actor, args); CommandEvent finalEvent = new CommandEvent(actor, args);
final FawePlayer<Object> fp = FawePlayer.wrap(actor); final FawePlayer<Object> fp = FawePlayer.wrap(actor);
TaskManager.IMP.taskNow(new Runnable() { TaskManager.IMP.taskNow(() -> {
@Override int space0 = args.indexOf(' ');
public void run() { String arg0 = space0 == -1 ? args : args.substring(0, space0);
int space0 = args.indexOf(' '); CommandMapping cmd = dispatcher.get(arg0);
String arg0 = space0 == -1 ? args : args.substring(0, space0); if (cmd != null && cmd.getCallable() instanceof AParametricCallable) {
CommandMapping cmd = dispatcher.get(arg0); Command info = ((AParametricCallable) cmd.getCallable()).getDefinition();
if (cmd != null && cmd.getCallable() instanceof AParametricCallable) { if (!info.queued()) {
Command info = ((AParametricCallable) cmd.getCallable()).getDefinition(); handleCommandOnCurrentThread(finalEvent);
if (!info.queued()) { return;
handleCommandOnCurrentThread(finalEvent);
return;
}
} }
if (!fp.runAction(new Runnable() {
@Override
public void run() {
handleCommandOnCurrentThread(finalEvent);
}
}, false, true)) {
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp);
}
finalEvent.setCancelled(true);
} }
if (!fp.runAction(() -> handleCommandOnCurrentThread(finalEvent), false, true)) {
BBC.WORLDEDIT_COMMAND_LIMIT.send(fp);
}
finalEvent.setCancelled(true);
}, Fawe.isMainThread()); }, Fawe.isMainThread());
} }
@ -548,6 +536,7 @@ public final class CommandManager {
try { try {
CommandLocals locals = new CommandLocals(); CommandLocals locals = new CommandLocals();
locals.put(Actor.class, event.getActor()); locals.put(Actor.class, event.getActor());
locals.put("arguments", event.getArguments());
event.setSuggestions(dispatcher.getSuggestions(event.getArguments(), locals)); event.setSuggestions(dispatcher.getSuggestions(event.getArguments(), locals));
} catch (CommandException e) { } catch (CommandException e) {
event.getActor().printError(e.getMessage()); event.getActor().printError(e.getMessage());
@ -568,4 +557,4 @@ public final class CommandManager {
} }
} }

View File

@ -1,3 +1,21 @@
/*
* 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.function.pattern; package com.sk89q.worldedit.function.pattern;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -7,7 +25,7 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
/** /**
* @deprecated Just use BaseBlock directly * A pattern that returns the same {@link BaseBlock} each time.
*/ */
@Deprecated @Deprecated
public class BlockPattern implements Pattern { public class BlockPattern implements Pattern {

View File

@ -2,9 +2,7 @@ package com.sk89q.worldedit.util.command.parametric;
import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.BBC;
import com.boydti.fawe.util.chat.UsageMessage;
import com.sk89q.minecraft.util.commands.*; import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.command.*; import com.sk89q.worldedit.util.command.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

View File

@ -26,16 +26,9 @@ import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper; import com.sk89q.worldedit.world.registry.LegacyMapper;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.registry.state.PropertyKey;
@ -271,12 +264,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return toImmutableState().getInternalPropertiesId(); return toImmutableState().getInternalPropertiesId();
} }
@Override @Override
public Mask toMask(Extent extent) {
return new SingleBlockStateMask(extent, toImmutableState());
}
@Override
public <V> BaseBlock with(Property<V> property, V value) { public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData()); return toImmutableState().with(property, value).toBaseBlock(getNbtData());
} }

View File

@ -27,8 +27,6 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockStateMask;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
@ -225,11 +223,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
return getBlockType().withPropertyId(propertyId); return getBlockType().withPropertyId(propertyId);
} }
@Override
public Mask toMask(Extent extent) {
return new SingleBlockStateMask(extent, this);
}
@Override @Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this); return extent.setBlock(set, this);

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.world.block; package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.FawePattern; import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
@ -30,7 +28,7 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePattern { public interface BlockStateHolder<B extends BlockStateHolder<B>> extends FawePattern {
/** /**
* Get the block type * Get the block type
@ -45,7 +43,7 @@ public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePat
* @return * @return
*/ */
@Deprecated @Deprecated
T withPropertyId(int propertyId); B withPropertyId(int propertyId);
/** /**
* Get combined id (legacy uses) * Get combined id (legacy uses)
@ -72,16 +70,14 @@ public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePat
@Deprecated @Deprecated
int getInternalPropertiesId(); int getInternalPropertiesId();
Mask toMask(Extent extent);
/** /**
* Returns a BlockStateHolder with the given state and value applied. * Returns a BlockState with the given state and value applied.
* *
* @param property The state * @param property The state
* @param value The value * @param value The value
* @return The modified state, or same if could not be applied * @return The modified state, or same if could not be applied
*/ */
<V> T with(final Property<V> property, final V value); <V> B with(final Property<V> property, final V value);
/** /**
* Returns a BlockStateHolder with the given state and value applied. * Returns a BlockStateHolder with the given state and value applied.
@ -90,7 +86,7 @@ public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePat
* @param value The value * @param value The value
* @return The modified state, or same if could not be applied * @return The modified state, or same if could not be applied
*/ */
<V> T with(final PropertyKey property, final V value); <V> B with(final PropertyKey property, final V value);
/** /**
* Gets the value at the given state * Gets the value at the given state