Selective upstream merge

Signed-off-by: MattBDev <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
MattBDev
2019-06-04 11:48:30 -04:00
parent c73fc28847
commit 6c94cca15e
75 changed files with 1039 additions and 1182 deletions

View File

@ -64,9 +64,11 @@ public enum Direction {
;
private final Vector3 direction;
private final BlockVector3 blockVector;
private final int flags, left, right;
private final int flags;
private final int left;
private final int right;
private final BlockVector3 blockPoint;
private static HashMap<String, Direction> map = new HashMap<>();
static {
@ -77,15 +79,15 @@ public enum Direction {
}
Direction(Vector3 vector, int flags, int left, int right) {
this.blockPoint = vector.toBlockPoint();
this.direction = vector.normalize();
this.blockVector = BlockVector3.at(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ()));
this.flags = flags;
this.left = left;
this.right = right;
}
public static Direction get(CharSequence sequence) {
return map.get(sequence);
return map.get((String)sequence);
}
public Direction getLeft() {
@ -96,30 +98,6 @@ public enum Direction {
return right != -1 ? values()[right] : null;
}
public double getX() {
return direction.getX();
}
public double getY() {
return direction.getY();
}
public double getZ() {
return direction.getZ();
}
public int getBlockX() {
return blockVector.getBlockX();
}
public int getBlockY() {
return blockVector.getBlockY();
}
public int getBlockZ() {
return blockVector.getBlockZ();
}
/**
* Return true if the direction is of a cardinal direction (north, west
* east, and south).
@ -177,7 +155,7 @@ public enum Direction {
* @return the vector
*/
public BlockVector3 toBlockVector() {
return direction.toBlockPoint();
return blockPoint;
}
/**
@ -332,3 +310,4 @@ public enum Direction {
}
}

View File

@ -20,10 +20,15 @@
package com.sk89q.worldedit.util;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.mask.ExistingBlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
/**
* This class uses an inefficient method to figure out what block a player
* is looking towards.
@ -33,7 +38,8 @@ import com.sk89q.worldedit.world.World;
*/
public class TargetBlock {
private World world;
private final World world;
private int maxDistance;
private double checkDistance, curDistance;
private BlockVector3 targetPos = BlockVector3.ZERO;
@ -41,6 +47,11 @@ public class TargetBlock {
private BlockVector3 prevPos = BlockVector3.ZERO;
private Vector3 offset = Vector3.ZERO;
// the mask which dictates when to stop a trace - defaults to stopping at non-air blocks
private Mask stopMask;
// the mask which dictates when to stop a solid block trace - default to BlockMaterial#isMovementBlocker
private Mask solidMask;
/**
* Constructor requiring a player, uses default values
*
@ -48,7 +59,10 @@ public class TargetBlock {
*/
public TargetBlock(Player player) {
this.world = player.getWorld();
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), 300, 1.65, 0.2);
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(),
300, 1.65, 0.2);
this.stopMask = new ExistingBlockMask(world);
this.solidMask = new SolidBlockMask(world);
}
/**
@ -60,7 +74,37 @@ public class TargetBlock {
*/
public TargetBlock(Player player, int maxDistance, double checkDistance) {
this.world = player.getWorld();
this.setValues(player.getLocation(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance);
this.stopMask = new ExistingBlockMask(world);
this.solidMask = new SolidBlockMask(world);
}
/**
* Set the mask used for determine where to stop traces.
* Setting to null will restore the default.
*
* @param stopMask the mask used to stop traces
*/
public void setStopMask(@Nullable Mask stopMask) {
if (stopMask == null) {
this.stopMask = new ExistingBlockMask(world);
} else {
this.stopMask = stopMask;
}
}
/**
* Set the mask used for determine where to stop solid block traces.
* Setting to null will restore the default.
*
* @param solidMask the mask used to stop solid block traces
*/
public void setSolidMask(@Nullable Mask solidMask) {
if (solidMask == null) {
this.solidMask = new SolidBlockMask(world);
} else {
this.solidMask = solidMask;
}
}
/**
@ -78,7 +122,7 @@ public class TargetBlock {
this.checkDistance = checkDistance;
this.curDistance = 0;
xRotation = (xRotation + 90) % 360;
yRotation = yRotation * -1;
yRotation *= -1;
double h = (checkDistance * Math.cos(Math.toRadians(yRotation)));
@ -101,15 +145,15 @@ public class TargetBlock {
boolean searchForLastBlock = true;
Location lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) {
if (stopMask.test(targetPos)) {
break;
} else {
if (searchForLastBlock) {
lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
searchForLastBlock = false;
}
}
} else {
break;
}
}
Location currentBlock = getCurrentBlock();
@ -123,7 +167,8 @@ public class TargetBlock {
* @return Block
*/
public Location getTargetBlock() {
while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ;
//noinspection StatementWithEmptyBody
while (getNextBlock() != null && !stopMask.test(targetPos)) ;
return getCurrentBlock();
}
@ -134,7 +179,8 @@ public class TargetBlock {
* @return Block
*/
public Location getSolidTargetBlock() {
while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ;
//noinspection StatementWithEmptyBody
while (getNextBlock() != null && !solidMask.test(targetPos)) ;
return getCurrentBlock();
}
@ -149,8 +195,8 @@ public class TargetBlock {
curDistance += checkDistance;
targetPosDouble = offset.add(targetPosDouble.getX(),
targetPosDouble.getY(),
targetPosDouble.getZ());
targetPosDouble.getY(),
targetPosDouble.getZ());
targetPos = targetPosDouble.toBlockPoint();
} while (curDistance <= maxDistance
&& targetPos.getBlockX() == prevPos.getBlockX()
@ -188,12 +234,17 @@ public class TargetBlock {
public Location getAnyTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
Location current = getCurrentBlock();
if (current != null)
return current.setDirection(current.toVector().subtract(getPreviousBlock().toVector()));
else
return new Location(world, targetPos.toVector3(), Float.NaN, Float.NaN);
}
public Location getTargetBlockFace() {
getAnyTargetBlock();
return getCurrentBlock().setDirection(getCurrentBlock().subtract(getPreviousBlock()));
getTargetBlock();
if (getCurrentBlock() == null) return null;
return getCurrentBlock().setDirection(getCurrentBlock().toVector().subtract(getPreviousBlock().toVector()));
}
}

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
@ -30,6 +31,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@ -64,8 +66,8 @@ public class TreeGenerator {
}
},
JUNGLE("Jungle tree", "jungle"),
SMALL_JUNGLE("Small jungle tree", "shortjungle", "smalljungle"),
SHORT_JUNGLE("Short jungle tree") {
SMALL_JUNGLE("Small jungle tree", "smalljungle"),
SHORT_JUNGLE("Short jungle tree", "shortjungle") {
@Override
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
return SMALL_JUNGLE.generate(editSession, pos);
@ -113,22 +115,22 @@ public class TreeGenerator {
private static final Set<String> primaryAliases = Sets.newHashSet();
private final String name;
private final String[] lookupKeys;
public final ImmutableList<String> lookupKeys;
static {
for (TreeType type : EnumSet.allOf(TreeType.class)) {
for (String key : type.lookupKeys) {
lookup.put(key, type);
}
if (type.lookupKeys.length > 0) {
primaryAliases.add(type.lookupKeys[0]);
if (type.lookupKeys.size() > 0) {
primaryAliases.add(type.lookupKeys.get(0));
}
}
}
TreeType(String name, String... lookupKeys) {
this.name = name;
this.lookupKeys = lookupKeys;
this.lookupKeys = ImmutableList.copyOf(lookupKeys);
}
public static Set<String> getAliases() {
@ -160,7 +162,7 @@ public class TreeGenerator {
*/
@Nullable
public static TreeType lookup(String name) {
return lookup.get(name.toLowerCase());
return lookup.get(name.toLowerCase(Locale.ROOT));
}
}
@ -179,8 +181,8 @@ public class TreeGenerator {
int trunkHeight = (int) Math.floor(Math.random() * 2) + 3;
int height = (int) Math.floor(Math.random() * 5) + 8;
BlockStateHolder logBlock = BlockTypes.OAK_LOG.getDefaultState();
BlockStateHolder leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
BlockState logBlock = BlockTypes.OAK_LOG.getDefaultState();
BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
// Create trunk
for (int i = 0; i < trunkHeight; ++i) {

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Function;
import java.util.Locale;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
@ -60,7 +61,7 @@ public class LevenshteinDistance implements Function<String, Integer> {
checkNotNull(baseString);
this.caseSensitive = caseSensitive;
this.replacePattern = replacePattern;
baseString = caseSensitive ? baseString : baseString.toLowerCase();
baseString = caseSensitive ? baseString : baseString.toLowerCase(Locale.ROOT);
baseString = replacePattern != null ? replacePattern.matcher(baseString).replaceAll("") : baseString;
this.baseString = baseString;
}
@ -79,7 +80,7 @@ public class LevenshteinDistance implements Function<String, Integer> {
if (caseSensitive) {
return distance(baseString, input);
} else {
return distance(baseString, input.toLowerCase());
return distance(baseString, input.toLowerCase(Locale.ROOT));
}
}
@ -189,5 +190,5 @@ public class LevenshteinDistance implements Function<String, Integer> {
// actually has the most recent cost counts
return p[n];
}
}

View File

@ -19,9 +19,15 @@
package com.sk89q.worldedit.util.logging;
import javax.annotation.Nullable;
import java.io.UnsupportedEncodingException;
import java.util.logging.*;
import java.util.logging.Filter;
import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.util.logging.StreamHandler;
import javax.annotation.Nullable;
/**
* A {@link StreamHandler} delegate that allows for the swap and disable of

View File

@ -39,7 +39,7 @@ public class EngineHubPaste implements Paster {
return Pasters.getExecutor().submit(new PasteTask(content));
}
private final class PasteTask implements Callable<URL> {
private static final class PasteTask implements Callable<URL> {
private final String content;
private PasteTask(String content) {
@ -50,7 +50,7 @@ public class EngineHubPaste implements Paster {
public URL call() throws IOException, InterruptedException {
HttpRequest.Form form = HttpRequest.Form.create();
form.add("content", content);
form.add("from", "worldguard");
form.add("from", "enginehub");
URL url = HttpRequest.url("http://paste.enginehub.org/paste");
String result = HttpRequest.post(url)

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.util.report;
public interface Report {
String getTitle();
}