mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-13 14:58:35 +00:00
Add and apply .editorconfig from P2 (#1195)
* Consistenty use javax annotations. - Unfortunately jetbrains annotations seem to be exposed transitively via core somewhere, but with the correct IDE settings, annotations can be defaulted to javax - Cleaning up of import order in #1195 - Must be merged before #1195 * Add and apply .editorconfig from P2 - Does not rearrange entries * Address some comments * add back some javadoc comments * Address final comments Co-authored-by: NotMyFault <mc.cache@web.de>
This commit is contained in:
@ -27,7 +27,7 @@ public class Countable<T> implements Comparable<Countable<T>> {
|
||||
/**
|
||||
* Construct the object.
|
||||
*
|
||||
* @param id the ID
|
||||
* @param id the ID
|
||||
* @param amount the count of
|
||||
*/
|
||||
public Countable(T id, int amount) {
|
||||
@ -69,4 +69,5 @@ public class Countable<T> implements Comparable<Countable<T>> {
|
||||
public int compareTo(Countable<T> other) {
|
||||
return Integer.compare(amount, other.amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ package com.sk89q.worldedit.util;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A collection of cardinal, ordinal, and secondary-ordinal directions.
|
||||
@ -192,7 +192,7 @@ public enum Direction {
|
||||
* Find the closest direction to the given direction vector.
|
||||
*
|
||||
* @param vector the vector
|
||||
* @param flags the only flags that are permitted (use bitwise math)
|
||||
* @param flags the only flags that are permitted (use bitwise math)
|
||||
* @return the closest direction, or null if no direction can be returned
|
||||
*/
|
||||
@Nullable
|
||||
@ -240,7 +240,7 @@ public enum Direction {
|
||||
* Converts a rotation index into a Direction.
|
||||
*
|
||||
* <p>
|
||||
* Rotation indexes are used in BlockStates, such as sign posts.
|
||||
* Rotation indexes are used in BlockStates, such as sign posts.
|
||||
* </p>
|
||||
*
|
||||
* @param rotation The rotation index
|
||||
@ -328,6 +328,7 @@ public enum Direction {
|
||||
* Flags to use with {@link #findClosest(Vector3, int)}.
|
||||
*/
|
||||
public static final class Flag {
|
||||
|
||||
public static int CARDINAL = 0x1;
|
||||
public static int ORDINAL = 0x2;
|
||||
public static int SECONDARY_ORDINAL = 0x4;
|
||||
@ -342,6 +343,7 @@ public enum Direction {
|
||||
|
||||
private Flag() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ public final class Enums {
|
||||
* given values, searching in an ascending manner.
|
||||
*
|
||||
* @param enumType the enum type
|
||||
* @param values the list of values
|
||||
* @param <T> the type of enum
|
||||
* @param values the list of values
|
||||
* @param <T> the type of enum
|
||||
* @return the found value or null
|
||||
*/
|
||||
@Nullable
|
||||
@ -52,4 +52,5 @@ public final class Enums {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,14 +21,15 @@ package com.sk89q.worldedit.util;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
public final class FileDialogUtil {
|
||||
|
||||
private FileDialogUtil() {
|
||||
}
|
||||
|
||||
@ -65,6 +66,7 @@ public final class FileDialogUtil {
|
||||
}
|
||||
|
||||
private static class ExtensionFilter extends FileFilter {
|
||||
|
||||
private final Set<String> exts;
|
||||
private final String desc;
|
||||
|
||||
@ -92,5 +94,7 @@ public final class FileDialogUtil {
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,4 +31,5 @@ public final class GuavaUtil {
|
||||
public static <T> T firstNonNull(@Nullable T first, @Nullable T second) {
|
||||
return first != null ? first : checkNotNull(second);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,9 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.fastasyncworldedit.core.math.Vector3Impl;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.fastasyncworldedit.core.math.Vector3Impl;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -59,9 +59,9 @@ public class Location extends Vector3Impl {
|
||||
* with a direction vector of 0, 0, 0.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z) {
|
||||
this(extent, Vector3.at(x, y, z), 0f, 90f);
|
||||
@ -71,7 +71,7 @@ public class Location extends Vector3Impl {
|
||||
* Create a new instance in the given extent with the given position
|
||||
* vector and a direction vector of 0, 0, 0.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
*/
|
||||
public Location(Extent extent, Vector3 position) {
|
||||
@ -82,10 +82,10 @@ public class Location extends Vector3Impl {
|
||||
* Create a new instance in the given extent with the given coordinates
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z, Vector3 direction) {
|
||||
@ -97,11 +97,11 @@ public class Location extends Vector3Impl {
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
* @param z the Z coordinate
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
*/
|
||||
public Location(Extent extent, double x, double y, double z, float yaw, float pitch) {
|
||||
this(extent, Vector3.at(x, y, z), yaw, pitch);
|
||||
@ -111,8 +111,8 @@ public class Location extends Vector3Impl {
|
||||
* Create a new instance in the given extent with the given position vector
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
* @param direction the direction vector
|
||||
*/
|
||||
public Location(Extent extent, Vector3 position, Vector3 direction) {
|
||||
@ -123,10 +123,10 @@ public class Location extends Vector3Impl {
|
||||
* Create a new instance in the given extent with the given position vector
|
||||
* and the given direction vector.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param extent the extent
|
||||
* @param position the position vector
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
* @param yaw the yaw, in degrees
|
||||
* @param pitch the pitch, in degrees
|
||||
*/
|
||||
public Location(Extent extent, Vector3 position, float yaw, float pitch) {
|
||||
//FAWE start
|
||||
@ -199,7 +199,7 @@ public class Location extends Vector3Impl {
|
||||
/**
|
||||
* Create a clone of this object with the given yaw and pitch.
|
||||
*
|
||||
* @param yaw the new yaw
|
||||
* @param yaw the new yaw
|
||||
* @param pitch the new pitch
|
||||
* @return the new instance
|
||||
*/
|
||||
@ -222,7 +222,8 @@ public class Location extends Vector3Impl {
|
||||
return Vector3.at(
|
||||
-xz * Math.sin(yaw),
|
||||
-Math.sin(pitch),
|
||||
xz * Math.cos(yaw));
|
||||
xz * Math.cos(yaw)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,7 +299,8 @@ public class Location extends Vector3Impl {
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
@Override public Location clampY(int min, int max) {
|
||||
@Override
|
||||
public Location clampY(int min, int max) {
|
||||
checkArgument(min <= max, "minimum cannot be greater than maximum");
|
||||
if (getY() < min) {
|
||||
return new Location(extent, getX(), min, getZ());
|
||||
@ -338,12 +340,8 @@ public class Location extends Vector3Impl {
|
||||
if (this.getY() != location.getY()) {
|
||||
return false;
|
||||
}
|
||||
if (!extent.equals(location.extent)) {
|
||||
return false;
|
||||
}
|
||||
return extent.equals(location.extent);
|
||||
//FAWE end
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,10 +49,13 @@ import java.util.Set;
|
||||
*/
|
||||
public class PropertiesConfiguration extends LocalConfiguration {
|
||||
|
||||
@Unreported private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||
@Unreported
|
||||
private static final Logger LOGGER = LogManagerCompat.getLogger();
|
||||
|
||||
@Unreported protected Properties properties;
|
||||
@Unreported protected File path;
|
||||
@Unreported
|
||||
protected Properties properties;
|
||||
@Unreported
|
||||
protected File path;
|
||||
|
||||
/**
|
||||
* Construct the object. The configuration isn't loaded yet.
|
||||
|
@ -30,6 +30,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SideEffectSet {
|
||||
|
||||
private static final SideEffectSet DEFAULT = new SideEffectSet(
|
||||
Arrays.stream(SideEffect.values()).collect(Collectors.toMap(Function.identity(), SideEffect::getDefaultValue))
|
||||
);
|
||||
@ -57,7 +58,9 @@ public class SideEffectSet {
|
||||
}
|
||||
|
||||
public SideEffectSet with(SideEffect sideEffect, SideEffect.State state) {
|
||||
Map<SideEffect, SideEffect.State> entries = this.sideEffects.isEmpty() ? Maps.newEnumMap(SideEffect.class) : new EnumMap<>(this.sideEffects);
|
||||
Map<SideEffect, SideEffect.State> entries = this.sideEffects.isEmpty()
|
||||
? Maps.newEnumMap(SideEffect.class)
|
||||
: new EnumMap<>(this.sideEffects);
|
||||
entries.put(sideEffect, state);
|
||||
return new SideEffectSet(entries);
|
||||
}
|
||||
@ -95,4 +98,5 @@ public class SideEffectSet {
|
||||
public static SideEffectSet none() {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ public class TargetBlock {
|
||||
public TargetBlock(Player player) {
|
||||
this.world = player.getWorld();
|
||||
this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(),
|
||||
300, 1.65, 0.2);
|
||||
300, 1.65, 0.2
|
||||
);
|
||||
this.stopMask = new ExistingBlockMask(world);
|
||||
this.solidMask = new SolidBlockMask(world);
|
||||
}
|
||||
@ -71,8 +72,8 @@ public class TargetBlock {
|
||||
/**
|
||||
* Constructor requiring a player, max distance and a checking distance.
|
||||
*
|
||||
* @param player Player to work with
|
||||
* @param maxDistance how far it checks for blocks
|
||||
* @param player Player to work with
|
||||
* @param maxDistance how far it checks for blocks
|
||||
* @param checkDistance how often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
public TargetBlock(Player player, int maxDistance, double checkDistance) {
|
||||
@ -84,7 +85,14 @@ public class TargetBlock {
|
||||
//FAWE start - Extend > World
|
||||
public TargetBlock(Player player, Extent extent, int maxDistance, double checkDistance) {
|
||||
this.world = player.getWorld();
|
||||
this.setValues(player.getLocation().toVector(), 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);
|
||||
}
|
||||
@ -121,14 +129,21 @@ public class TargetBlock {
|
||||
/**
|
||||
* Set the values, all constructors uses this function.
|
||||
*
|
||||
* @param loc location of the view
|
||||
* @param rotationX the X rotation
|
||||
* @param rotationY the Y rotation
|
||||
* @param maxDistance how far it checks for blocks
|
||||
* @param viewHeight where the view is positioned in y-axis
|
||||
* @param loc location of the view
|
||||
* @param rotationX the X rotation
|
||||
* @param rotationY the Y rotation
|
||||
* @param maxDistance how far it checks for blocks
|
||||
* @param viewHeight where the view is positioned in y-axis
|
||||
* @param checkDistance how often to check for blocks, the smaller the more precise
|
||||
*/
|
||||
private void setValues(Vector3 loc, double rotationX, double rotationY, int maxDistance, double viewHeight, double checkDistance) {
|
||||
private void setValues(
|
||||
Vector3 loc,
|
||||
double rotationX,
|
||||
double rotationY,
|
||||
int maxDistance,
|
||||
double viewHeight,
|
||||
double checkDistance
|
||||
) {
|
||||
this.maxDistance = maxDistance;
|
||||
this.checkDistance = checkDistance;
|
||||
this.curDistance = 0;
|
||||
@ -137,9 +152,11 @@ public class TargetBlock {
|
||||
|
||||
double h = (checkDistance * Math.cos(Math.toRadians(rotationY)));
|
||||
|
||||
offset = Vector3.at((h * Math.cos(Math.toRadians(rotationX))),
|
||||
(checkDistance * Math.sin(Math.toRadians(rotationY))),
|
||||
(h * Math.sin(Math.toRadians(rotationX))));
|
||||
offset = Vector3.at(
|
||||
(h * Math.cos(Math.toRadians(rotationX))),
|
||||
(checkDistance * Math.sin(Math.toRadians(rotationY))),
|
||||
(h * Math.sin(Math.toRadians(rotationX)))
|
||||
);
|
||||
|
||||
targetPosDouble = loc.add(0, viewHeight, 0);
|
||||
targetPos = targetPosDouble.toBlockPoint();
|
||||
@ -207,9 +224,11 @@ public class TargetBlock {
|
||||
do {
|
||||
curDistance += checkDistance;
|
||||
|
||||
targetPosDouble = offset.add(targetPosDouble.getX(),
|
||||
targetPosDouble.getY(),
|
||||
targetPosDouble.getZ());
|
||||
targetPosDouble = offset.add(
|
||||
targetPosDouble.getX(),
|
||||
targetPosDouble.getY(),
|
||||
targetPosDouble.getZ()
|
||||
);
|
||||
targetPos = targetPosDouble.toBlockPoint();
|
||||
} while (curDistance <= maxDistance
|
||||
&& targetPos.getBlockX() == prevPos.getBlockX()
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@ -35,7 +36,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Tree generator.
|
||||
@ -51,7 +51,7 @@ public final class TreeGenerator {
|
||||
RANDOM_REDWOOD("Random spruce tree", "randspruce", "randredwood", "randomredwood", "anyredwood") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { REDWOOD, TALL_REDWOOD, MEGA_REDWOOD };
|
||||
TreeType[] choices = {REDWOOD, TALL_REDWOOD, MEGA_REDWOOD};
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
},
|
||||
@ -60,7 +60,7 @@ public final class TreeGenerator {
|
||||
RANDOM_BIRCH("Random birch tree", "randbirch", "randombirch") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { BIRCH, TALL_BIRCH };
|
||||
TreeType[] choices = {BIRCH, TALL_BIRCH};
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
},
|
||||
@ -75,7 +75,7 @@ public final class TreeGenerator {
|
||||
RANDOM_JUNGLE("Random jungle tree", "randjungle", "randomjungle") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { JUNGLE, SMALL_JUNGLE };
|
||||
TreeType[] choices = {JUNGLE, SMALL_JUNGLE};
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
},
|
||||
@ -87,7 +87,7 @@ public final class TreeGenerator {
|
||||
RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") {
|
||||
@Override
|
||||
public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException {
|
||||
TreeType[] choices = { RED_MUSHROOM, BROWN_MUSHROOM, CRIMSON_FUNGUS, WARPED_FUNGUS };
|
||||
TreeType[] choices = {RED_MUSHROOM, BROWN_MUSHROOM, CRIMSON_FUNGUS, WARPED_FUNGUS};
|
||||
return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos);
|
||||
}
|
||||
},
|
||||
@ -255,13 +255,18 @@ public final class TreeGenerator {
|
||||
* Set a block (only if a previous block was not there) if {@link Math#random()}
|
||||
* returns a number less than the given probability.
|
||||
*
|
||||
* @param position the position
|
||||
* @param block the block
|
||||
* @param position the position
|
||||
* @param block the block
|
||||
* @param probability a probability between 0 and 1, inclusive
|
||||
* @return whether a block was changed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
private static <B extends BlockStateHolder<B>> boolean setChanceBlockIfAir(EditSession session, BlockVector3 position, B block, double probability)
|
||||
private static <B extends BlockStateHolder<B>> boolean setChanceBlockIfAir(
|
||||
EditSession session,
|
||||
BlockVector3 position,
|
||||
B block,
|
||||
double probability
|
||||
)
|
||||
throws MaxChangedBlocksException {
|
||||
return Math.random() <= probability && setBlockIfAir(session, position, block);
|
||||
}
|
||||
@ -270,11 +275,16 @@ public final class TreeGenerator {
|
||||
* Set a block only if there's no block already there.
|
||||
*
|
||||
* @param position the position
|
||||
* @param block the block to set
|
||||
* @param block the block to set
|
||||
* @return if block was changed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException {
|
||||
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(
|
||||
EditSession session,
|
||||
BlockVector3 position,
|
||||
B block
|
||||
) throws MaxChangedBlocksException {
|
||||
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class WeightedChoice<T> {
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param function a function that assigns a score for each choice
|
||||
* @param target the target score that the best choice should be closest to
|
||||
* @param target the target score that the best choice should be closest to
|
||||
*/
|
||||
public WeightedChoice(Function<T, ? extends Number> function, double target) {
|
||||
checkNotNull(function);
|
||||
@ -86,6 +86,7 @@ public class WeightedChoice<T> {
|
||||
* @param <T> the choice type
|
||||
*/
|
||||
public static class Choice<T> {
|
||||
|
||||
private final T object;
|
||||
private final double value;
|
||||
|
||||
@ -111,6 +112,7 @@ public class WeightedChoice<T> {
|
||||
public double getScore() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,8 +37,10 @@ import java.util.Locale;
|
||||
*/
|
||||
public class YAMLConfiguration extends LocalConfiguration {
|
||||
|
||||
@Unreported protected final YAMLProcessor config;
|
||||
@Unreported protected final Logger logger;
|
||||
@Unreported
|
||||
protected final YAMLProcessor config;
|
||||
@Unreported
|
||||
protected final Logger logger;
|
||||
|
||||
public YAMLConfiguration(YAMLProcessor config, Logger logger) {
|
||||
this.config = config;
|
||||
@ -59,18 +61,29 @@ public class YAMLConfiguration extends LocalConfiguration {
|
||||
|
||||
defaultChangeLimit = Math.max(-1, config.getInt(
|
||||
"limits.max-blocks-changed.default", defaultChangeLimit));
|
||||
maxChangeLimit = Math.max(-1,
|
||||
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
|
||||
maxChangeLimit = Math.max(
|
||||
-1,
|
||||
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit)
|
||||
);
|
||||
|
||||
defaultVerticalHeight = Math.max(1,
|
||||
config.getInt("limits.vertical-height.default", defaultVerticalHeight));
|
||||
defaultVerticalHeight = Math.max(
|
||||
1,
|
||||
config.getInt("limits.vertical-height.default", defaultVerticalHeight)
|
||||
);
|
||||
|
||||
defaultMaxPolygonalPoints = Math.max(-1,
|
||||
config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints));
|
||||
maxPolygonalPoints = Math.max(-1,
|
||||
config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints));
|
||||
defaultMaxPolygonalPoints = Math.max(
|
||||
-1,
|
||||
config.getInt("limits.max-polygonal-points.default", defaultMaxPolygonalPoints)
|
||||
);
|
||||
maxPolygonalPoints = Math.max(
|
||||
-1,
|
||||
config.getInt("limits.max-polygonal-points.maximum", maxPolygonalPoints)
|
||||
);
|
||||
|
||||
defaultMaxPolyhedronPoints = Math.max(-1, config.getInt("limits.max-polyhedron-points.default", defaultMaxPolyhedronPoints));
|
||||
defaultMaxPolyhedronPoints = Math.max(
|
||||
-1,
|
||||
config.getInt("limits.max-polyhedron-points.default", defaultMaxPolyhedronPoints)
|
||||
);
|
||||
maxPolyhedronPoints = Math.max(-1, config.getInt("limits.max-polyhedron-points.maximum", maxPolyhedronPoints));
|
||||
|
||||
maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
|
||||
@ -81,7 +94,10 @@ public class YAMLConfiguration extends LocalConfiguration {
|
||||
butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius));
|
||||
butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));
|
||||
|
||||
disallowedBlocks = new HashSet<>(config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks())));
|
||||
disallowedBlocks = new HashSet<>(config.getStringList(
|
||||
"limits.disallowed-blocks",
|
||||
Lists.newArrayList(getDefaultDisallowedBlocks())
|
||||
));
|
||||
allowedDataCycleBlocks = new HashSet<>(config.getStringList("limits.allowed-data-cycle-blocks", null));
|
||||
|
||||
registerHelp = config.getBoolean("register-help", true);
|
||||
@ -89,16 +105,22 @@ public class YAMLConfiguration extends LocalConfiguration {
|
||||
logFile = config.getString("logging.file", logFile);
|
||||
logFormat = config.getString("logging.format", logFormat);
|
||||
|
||||
superPickaxeDrop = config.getBoolean("super-pickaxe.drop-items",
|
||||
superPickaxeDrop);
|
||||
superPickaxeDrop = config.getBoolean(
|
||||
"super-pickaxe.drop-items",
|
||||
superPickaxeDrop
|
||||
);
|
||||
superPickaxeManyDrop = config.getBoolean(
|
||||
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
|
||||
|
||||
useInventory = config.getBoolean("use-inventory.enable", useInventory);
|
||||
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
|
||||
useInventoryOverride);
|
||||
useInventoryCreativeOverride = config.getBoolean("use-inventory.creative-mode-overrides",
|
||||
useInventoryCreativeOverride);
|
||||
useInventoryOverride = config.getBoolean(
|
||||
"use-inventory.allow-override",
|
||||
useInventoryOverride
|
||||
);
|
||||
useInventoryCreativeOverride = config.getBoolean(
|
||||
"use-inventory.creative-mode-overrides",
|
||||
useInventoryCreativeOverride
|
||||
);
|
||||
|
||||
navigationWand = convertLegacyItem(config.getString("navigation-wand.item", navigationWand)).toLowerCase(Locale.ROOT);
|
||||
navigationWandMaxDistance = config.getInt("navigation-wand.max-distance", navigationWandMaxDistance);
|
||||
|
@ -51,4 +51,5 @@ public class AuthorizationException extends WorldEditException {
|
||||
public AuthorizationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public interface Authorizer {
|
||||
/**
|
||||
* Tests whether permission is granted for the given context.
|
||||
*
|
||||
* @param locals locals
|
||||
* @param locals locals
|
||||
* @param permission the permission string
|
||||
* @return true if permitted
|
||||
*/
|
||||
|
@ -49,6 +49,7 @@ public interface Subject {
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
//FAWE start
|
||||
|
||||
/**
|
||||
* Add and remove permissions from a subject to show and hide certain messages.
|
||||
*
|
||||
|
@ -86,14 +86,14 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
|
||||
private static long toGroupKey(BlockVector3 location) {
|
||||
return ((location.getX() >>> 6) & BITS_20)
|
||||
| (((location.getZ() >>> 6) & BITS_20) << 20)
|
||||
| (((location.getY() >>> 8) & BITS_24) << (20 + 20));
|
||||
| (((location.getZ() >>> 6) & BITS_20) << 20)
|
||||
| (((location.getY() >>> 8) & BITS_24) << (20 + 20));
|
||||
}
|
||||
|
||||
private static int toInnerKey(BlockVector3 location) {
|
||||
return (location.getX() & BITS_6)
|
||||
| ((location.getZ() & BITS_6) << 6)
|
||||
| ((location.getY() & BITS_8) << (6 + 6));
|
||||
| ((location.getZ() & BITS_6) << 6)
|
||||
| ((location.getY() & BITS_8) << (6 + 6));
|
||||
}
|
||||
|
||||
private static final long GROUP_X = BITS_20;
|
||||
@ -165,24 +165,24 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
public V getOrDefault(Object key, V defaultValue) {
|
||||
BlockVector3 vec = (BlockVector3) key;
|
||||
return getOrEmptyMap(toGroupKey(vec))
|
||||
.getOrDefault(toInnerKey(vec), defaultValue);
|
||||
.getOrDefault(toInnerKey(vec), defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(BiConsumer<? super BlockVector3, ? super V> action) {
|
||||
maps.forEach((groupKey, m) ->
|
||||
m.forEach((innerKey, block) ->
|
||||
action.accept(reconstructLocation(groupKey, innerKey), block)
|
||||
)
|
||||
m.forEach((innerKey, block) ->
|
||||
action.accept(reconstructLocation(groupKey, innerKey), block)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replaceAll(BiFunction<? super BlockVector3, ? super V, ? extends V> function) {
|
||||
maps.forEach((groupKey, m) ->
|
||||
m.replaceAll((innerKey, block) ->
|
||||
function.apply(reconstructLocation(groupKey, innerKey), block)
|
||||
)
|
||||
m.replaceAll((innerKey, block) ->
|
||||
function.apply(reconstructLocation(groupKey, innerKey), block)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -194,14 +194,18 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
@Override
|
||||
public boolean remove(Object key, Object value) {
|
||||
BlockVector3 vec = (BlockVector3) key;
|
||||
return cleanlyModifyMap(toGroupKey(vec),
|
||||
map -> map.remove(toInnerKey(vec), value));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(vec),
|
||||
map -> map.remove(toInnerKey(vec), value)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(BlockVector3 key, V oldValue, V newValue) {
|
||||
return cleanlyModifyMap(toGroupKey(key),
|
||||
map -> map.replace(toInnerKey(key), oldValue, newValue));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(key),
|
||||
map -> map.replace(toInnerKey(key), oldValue, newValue)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -211,26 +215,34 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
|
||||
@Override
|
||||
public V computeIfAbsent(BlockVector3 key, Function<? super BlockVector3, ? extends V> mappingFunction) {
|
||||
return cleanlyModifyMap(toGroupKey(key),
|
||||
map -> map.computeIfAbsent(toInnerKey(key), ik -> mappingFunction.apply(key)));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(key),
|
||||
map -> map.computeIfAbsent(toInnerKey(key), ik -> mappingFunction.apply(key))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V computeIfPresent(BlockVector3 key, BiFunction<? super BlockVector3, ? super V, ? extends V> remappingFunction) {
|
||||
return cleanlyModifyMap(toGroupKey(key),
|
||||
map -> map.computeIfPresent(toInnerKey(key), (ik, block) -> remappingFunction.apply(key, block)));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(key),
|
||||
map -> map.computeIfPresent(toInnerKey(key), (ik, block) -> remappingFunction.apply(key, block))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V compute(BlockVector3 key, BiFunction<? super BlockVector3, ? super V, ? extends V> remappingFunction) {
|
||||
return cleanlyModifyMap(toGroupKey(key),
|
||||
map -> map.compute(toInnerKey(key), (ik, block) -> remappingFunction.apply(key, block)));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(key),
|
||||
map -> map.compute(toInnerKey(key), (ik, block) -> remappingFunction.apply(key, block))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V merge(BlockVector3 key, V value, BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
|
||||
return cleanlyModifyMap(toGroupKey(key),
|
||||
map -> map.merge(toInnerKey(key), value, remappingFunction));
|
||||
return cleanlyModifyMap(
|
||||
toGroupKey(key),
|
||||
map -> map.merge(toInnerKey(key), value, remappingFunction)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -243,7 +255,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
return new Iterator<Entry<BlockVector3, V>>() {
|
||||
|
||||
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
|
||||
= Long2ObjectMaps.fastIterator(maps);
|
||||
= Long2ObjectMaps.fastIterator(maps);
|
||||
private Long2ObjectMap.Entry<Int2ObjectMap<V>> currentPrimaryEntry;
|
||||
private ObjectIterator<Int2ObjectMap.Entry<V>> secondaryIterator;
|
||||
private boolean finished;
|
||||
@ -274,8 +286,10 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
currentPrimaryEntry = primaryIterator.next();
|
||||
secondaryIterator = Int2ObjectMaps.fastIterator(currentPrimaryEntry.getValue());
|
||||
// be paranoid
|
||||
checkState(secondaryIterator.hasNext(),
|
||||
"Should not have an empty map entry, it should have been removed!");
|
||||
checkState(
|
||||
secondaryIterator.hasNext(),
|
||||
"Should not have an empty map entry, it should have been removed!"
|
||||
);
|
||||
}
|
||||
Int2ObjectMap.Entry<V> next = secondaryIterator.next();
|
||||
return new LazyEntry(currentPrimaryEntry.getLongKey(), next.getIntKey(), next.getValue());
|
||||
@ -354,8 +368,8 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
@SuppressWarnings("unchecked")
|
||||
LazyEntry otherE = (LazyEntry) o;
|
||||
return otherE.groupKey == groupKey
|
||||
&& otherE.innerKey == innerKey
|
||||
&& Objects.equals(value, e.getValue());
|
||||
&& otherE.innerKey == innerKey
|
||||
&& Objects.equals(value, e.getValue());
|
||||
}
|
||||
return Objects.equals(getKey(), e.getKey()) && Objects.equals(value, e.getValue());
|
||||
}
|
||||
@ -369,6 +383,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
public String toString() {
|
||||
return getKey() + "=" + getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -417,7 +432,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
if (m instanceof BlockMap) {
|
||||
// optimize insertions:
|
||||
((BlockMap<V>) m).maps.forEach((groupKey, map) ->
|
||||
getOrCreateMap(groupKey).putAll(map)
|
||||
getOrCreateMap(groupKey).putAll(map)
|
||||
);
|
||||
} else {
|
||||
super.putAll(m);
|
||||
@ -445,8 +460,8 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
return maps.values().stream()
|
||||
.flatMap(m -> m.values().stream())
|
||||
.iterator();
|
||||
.flatMap(m -> m.values().stream())
|
||||
.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -477,4 +492,5 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,11 +83,13 @@ public class DoubleArrayList<A, B> implements Iterable<Map.Entry<A, B>> {
|
||||
if (reversed) {
|
||||
return new ReverseEntryIterator<>(
|
||||
listA.listIterator(listA.size()),
|
||||
listB.listIterator(listB.size()));
|
||||
listB.listIterator(listB.size())
|
||||
);
|
||||
} else {
|
||||
return new ForwardEntryIterator<>(
|
||||
listA.iterator(),
|
||||
listB.iterator());
|
||||
listB.iterator()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,6 +126,7 @@ public class DoubleArrayList<A, B> implements Iterable<Map.Entry<A, B>> {
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,12 +157,14 @@ public class DoubleArrayList<A, B> implements Iterable<Map.Entry<A, B>> {
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to masquerade as Map.Entry.
|
||||
*/
|
||||
public class Entry<C, D> implements Map.Entry<A, B> {
|
||||
|
||||
private final A key;
|
||||
private final B value;
|
||||
|
||||
@ -182,6 +187,7 @@ public class DoubleArrayList<A, B> implements Iterable<Map.Entry<A, B>> {
|
||||
public B setValue(B value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ import it.unimi.dsi.fastutil.objects.AbstractObjectSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.BiFunction;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Int-to-BaseBlock map, but with optimizations for common cases.
|
||||
@ -68,11 +68,10 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
}
|
||||
|
||||
private final Int2IntMap commonMap = new Int2IntOpenHashMap(64, 0.9f);
|
||||
private final Int2ObjectMap<BaseBlock> uncommonMap = new Int2ObjectOpenHashMap<>(1, 0.75f);
|
||||
|
||||
{
|
||||
commonMap.defaultReturnValue(BlockStateIdAccess.invalidId());
|
||||
}
|
||||
private final Int2ObjectMap<BaseBlock> uncommonMap = new Int2ObjectOpenHashMap<>(1, 0.75f);
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
@ -88,9 +87,9 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
return new ObjectIterator<Entry<BaseBlock>>() {
|
||||
|
||||
private final ObjectIterator<Int2IntMap.Entry> commonIter
|
||||
= Int2IntMaps.fastIterator(commonMap);
|
||||
= Int2IntMaps.fastIterator(commonMap);
|
||||
private final ObjectIterator<Entry<BaseBlock>> uncommonIter
|
||||
= Int2ObjectMaps.fastIterator(uncommonMap);
|
||||
= Int2ObjectMaps.fastIterator(uncommonMap);
|
||||
private boolean lastNextFromCommon = false;
|
||||
|
||||
@Override
|
||||
@ -104,7 +103,7 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
Int2IntMap.Entry e = commonIter.next();
|
||||
lastNextFromCommon = true;
|
||||
return new BasicEntry<>(
|
||||
e.getIntKey(), assumeAsBlock(e.getIntValue())
|
||||
e.getIntKey(), assumeAsBlock(e.getIntValue())
|
||||
);
|
||||
}
|
||||
if (uncommonIter.hasNext()) {
|
||||
@ -208,4 +207,5 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ import com.sk89q.worldedit.util.LocatedBlock;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -39,7 +39,7 @@ public class LocatedBlockList implements Iterable<LocatedBlock> {
|
||||
|
||||
private final BlockMap<BaseBlock> blocks = BlockMap.createForBaseBlock();
|
||||
private final PositionList order = PositionList.create(
|
||||
WorldEdit.getInstance().getConfiguration().extendedYLimit
|
||||
WorldEdit.getInstance().getConfiguration().extendedYLimit
|
||||
);
|
||||
|
||||
public LocatedBlockList() {
|
||||
@ -82,12 +82,12 @@ public class LocatedBlockList implements Iterable<LocatedBlock> {
|
||||
@Override
|
||||
public Iterator<LocatedBlock> iterator() {
|
||||
return Iterators.transform(order.iterator(), position ->
|
||||
new LocatedBlock(position, blocks.get(position)));
|
||||
new LocatedBlock(position, blocks.get(position)));
|
||||
}
|
||||
|
||||
public Iterator<LocatedBlock> reverseIterator() {
|
||||
return Iterators.transform(order.reverseIterator(), position ->
|
||||
new LocatedBlock(position, blocks.get(position)));
|
||||
new LocatedBlock(position, blocks.get(position)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,16 +55,20 @@ class LongPositionList implements PositionList {
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
return new PositionIterator(delegate.iterator(),
|
||||
LongListIterator::hasNext,
|
||||
LongListIterator::nextLong);
|
||||
return new PositionIterator(
|
||||
delegate.iterator(),
|
||||
LongListIterator::hasNext,
|
||||
LongListIterator::nextLong
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector3> reverseIterator() {
|
||||
return new PositionIterator(delegate.listIterator(size()),
|
||||
LongListIterator::hasPrevious,
|
||||
LongListIterator::previousLong);
|
||||
return new PositionIterator(
|
||||
delegate.listIterator(size()),
|
||||
LongListIterator::hasPrevious,
|
||||
LongListIterator::previousLong
|
||||
);
|
||||
}
|
||||
|
||||
private static final class PositionIterator extends AbstractIterator<BlockVector3> {
|
||||
@ -73,9 +77,11 @@ class LongPositionList implements PositionList {
|
||||
private final Predicate<LongListIterator> hasNext;
|
||||
private final ToLongFunction<LongListIterator> next;
|
||||
|
||||
private PositionIterator(LongListIterator iterator,
|
||||
Predicate<LongListIterator> hasNext,
|
||||
ToLongFunction<LongListIterator> next) {
|
||||
private PositionIterator(
|
||||
LongListIterator iterator,
|
||||
Predicate<LongListIterator> hasNext,
|
||||
ToLongFunction<LongListIterator> next
|
||||
) {
|
||||
this.iterator = iterator;
|
||||
this.hasNext = hasNext;
|
||||
this.next = next;
|
||||
@ -84,8 +90,10 @@ class LongPositionList implements PositionList {
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
return hasNext.test(iterator)
|
||||
? BlockVector3.fromLongPackedForm(next.applyAsLong(iterator))
|
||||
: endOfData();
|
||||
? BlockVector3.fromLongPackedForm(next.applyAsLong(iterator))
|
||||
: endOfData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -74,10 +74,11 @@ public class MoreStreams {
|
||||
// Not SIZED, Not SUBSIZED
|
||||
chars &= ~(Spliterator.SIZED | Spliterator.SUBSIZED);
|
||||
return StreamSupport.stream(Spliterators.spliterator(
|
||||
iter, spliterator.estimateSize(), chars
|
||||
iter, spliterator.estimateSize(), chars
|
||||
), stream.isParallel()).onClose(stream::close);
|
||||
}
|
||||
|
||||
private MoreStreams() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,9 +37,10 @@ class VectorPositionList implements PositionList {
|
||||
@Override
|
||||
public BlockVector3 get(int index) {
|
||||
return BlockVector3.at(
|
||||
delegateX.getInt(index),
|
||||
delegateY.getInt(index),
|
||||
delegateZ.getInt(index));
|
||||
delegateX.getInt(index),
|
||||
delegateY.getInt(index),
|
||||
delegateZ.getInt(index)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,9 +76,10 @@ class VectorPositionList implements PositionList {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iteratorX.nextInt(),
|
||||
iteratorY.nextInt(),
|
||||
iteratorZ.nextInt());
|
||||
iteratorX.nextInt(),
|
||||
iteratorY.nextInt(),
|
||||
iteratorZ.nextInt()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -96,10 +98,12 @@ class VectorPositionList implements PositionList {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iteratorX.previousInt(),
|
||||
iteratorY.previousInt(),
|
||||
iteratorZ.previousInt());
|
||||
iteratorX.previousInt(),
|
||||
iteratorY.previousInt(),
|
||||
iteratorZ.previousInt()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ public final class EvenMoreExecutors {
|
||||
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
|
||||
minThreads, maxThreads,
|
||||
60L, TimeUnit.SECONDS,
|
||||
new LinkedBlockingDeque<>(queueSize));
|
||||
new LinkedBlockingDeque<>(queueSize)
|
||||
);
|
||||
threadPoolExecutor.allowCoreThreadTimeOut(true);
|
||||
if (threadFormat != null) {
|
||||
threadPoolExecutor.setThreadFactory(new ThreadFactoryBuilder().setNameFormat(threadFormat).build());
|
||||
|
@ -33,11 +33,12 @@ public class LazyReference<T> {
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
|
||||
/**
|
||||
* Pre-computed reference, for setting a lazy reference field with a known value.
|
||||
*
|
||||
* @param value the value of the reference
|
||||
* @param <T> the type of the value
|
||||
* @param <T> the type of the value
|
||||
* @return the new reference
|
||||
*/
|
||||
public static <T> LazyReference<T> computed(T value) {
|
||||
@ -50,12 +51,14 @@ public class LazyReference<T> {
|
||||
// it's no longer needed.
|
||||
|
||||
private static final class RefInfo<T> {
|
||||
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Supplier<T> valueComputation;
|
||||
|
||||
private RefInfo(Supplier<T> valueComputation) {
|
||||
this.valueComputation = valueComputation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Object value;
|
||||
|
@ -53,9 +53,9 @@ class AnnotatedSubscriberFinder implements SubscriberFindingStrategy {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"Method " + method + " has @Subscribe annotation, but requires "
|
||||
+ parameterTypes.length + " arguments. Event handler methods "
|
||||
+ "must require a single argument."
|
||||
"Method " + method + " has @Subscribe annotation, but requires "
|
||||
+ parameterTypes.length + " arguments. Event handler methods "
|
||||
+ "must require a single argument."
|
||||
);
|
||||
}
|
||||
Class<?> eventType = parameterTypes[0];
|
||||
|
@ -52,7 +52,7 @@ public final class EventBus {
|
||||
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
private final SetMultimap<Class<?>, EventHandler> handlersByType =
|
||||
HashMultimap.create();
|
||||
HashMultimap.create();
|
||||
|
||||
/**
|
||||
* Strategy for finding handler methods in registered objects. Currently,
|
||||
@ -66,7 +66,7 @@ public final class EventBus {
|
||||
/**
|
||||
* Registers the given handler for the given class to receive events.
|
||||
*
|
||||
* @param clazz the event class to register
|
||||
* @param clazz the event class to register
|
||||
* @param handler the handler to register
|
||||
*/
|
||||
public void subscribe(Class<?> clazz, EventHandler handler) {
|
||||
@ -98,7 +98,7 @@ public final class EventBus {
|
||||
/**
|
||||
* Unregisters the given handler for the given class.
|
||||
*
|
||||
* @param clazz the class
|
||||
* @param clazz the class
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void unsubscribe(Class<?> clazz, EventHandler handler) {
|
||||
@ -144,7 +144,7 @@ public final class EventBus {
|
||||
/**
|
||||
* Unregisters all handler methods on a registered {@code object}.
|
||||
*
|
||||
* @param object object whose handler methods should be unregistered.
|
||||
* @param object object whose handler methods should be unregistered.
|
||||
* @throws IllegalArgumentException if the object was not previously registered.
|
||||
*/
|
||||
public void unregister(Object object) {
|
||||
@ -156,7 +156,7 @@ public final class EventBus {
|
||||
* successfully after the event has been posted to all handlers, and
|
||||
* regardless of any exceptions thrown by handlers.
|
||||
*
|
||||
* @param event event to post.
|
||||
* @param event event to post.
|
||||
*/
|
||||
public void post(Object event) {
|
||||
List<EventHandler> dispatching = new ArrayList<>();
|
||||
@ -185,8 +185,8 @@ public final class EventBus {
|
||||
/**
|
||||
* Dispatches {@code event} to the handler in {@code handler}.
|
||||
*
|
||||
* @param event event to dispatch.
|
||||
* @param handler handler that will call the handler.
|
||||
* @param event event to dispatch.
|
||||
* @param handler handler that will call the handler.
|
||||
*/
|
||||
private void dispatch(Object event, EventHandler handler) {
|
||||
try {
|
||||
|
@ -35,8 +35,8 @@ import java.util.Set;
|
||||
class HierarchyCache {
|
||||
|
||||
private final LoadingCache<Class<?>, Set<Class<?>>> cache = CacheBuilder.newBuilder()
|
||||
.weakKeys()
|
||||
.build(CacheLoader.from(this::build));
|
||||
.weakKeys()
|
||||
.build(CacheLoader.from(this::build));
|
||||
|
||||
public Set<Class<?>> get(Class<?> concreteClass) {
|
||||
return cache.getUnchecked(concreteClass);
|
||||
|
@ -35,7 +35,7 @@ public class MethodEventHandler extends EventHandler {
|
||||
* Create a new event handler.
|
||||
*
|
||||
* @param priority the priority
|
||||
* @param method the method
|
||||
* @param method the method
|
||||
*/
|
||||
public MethodEventHandler(Priority priority, Object object, Method method) {
|
||||
super(priority);
|
||||
@ -72,11 +72,7 @@ public class MethodEventHandler extends EventHandler {
|
||||
if (!method.equals(that.method)) {
|
||||
return false;
|
||||
}
|
||||
if (object != null ? !object.equals(that.object) : that.object != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return object != null ? object.equals(that.object) : that.object == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,4 +81,5 @@ public class MethodEventHandler extends EventHandler {
|
||||
result = 31 * result + method.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,12 +31,11 @@ interface SubscriberFindingStrategy {
|
||||
* Finds all suitable event handler methods in {@code source}, organizes them
|
||||
* by the type of event they handle, and wraps them in {@link EventHandler}s.
|
||||
*
|
||||
* @param source object whose handlers are desired.
|
||||
* @param source object whose handlers are desired.
|
||||
* @return EventHandler objects for each handler method, organized by event
|
||||
* type.
|
||||
*
|
||||
* @throws IllegalArgumentException if {@code source} is not appropriate for
|
||||
* this strategy (in ways that this interface does not define).
|
||||
* this strategy (in ways that this interface does not define).
|
||||
*/
|
||||
Multimap<Class<?>, EventHandler> findAllSubscribers(Object source);
|
||||
|
||||
|
@ -29,6 +29,7 @@ import org.enginehub.piston.util.TextHelper;
|
||||
import java.util.Locale;
|
||||
|
||||
public class WorldEditText {
|
||||
|
||||
private static final ConfigRenderer RENDERER = ConfigRenderer.getInstance();
|
||||
public static final ConfigHolder CONFIG_HOLDER = ConfigHolder.create();
|
||||
|
||||
@ -38,8 +39,8 @@ public class WorldEditText {
|
||||
|
||||
public static Component format(Component component, Locale locale) {
|
||||
return WorldEdit.getInstance().getTranslationManager().convertText(
|
||||
RENDERER.render(component, CONFIG_HOLDER),
|
||||
locale
|
||||
RENDERER.render(component, CONFIG_HOLDER),
|
||||
locale
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,11 @@ public class CodeFormat extends TextComponentProducer {
|
||||
*/
|
||||
public static TextComponent wrap(String... texts) {
|
||||
CodeFormat code = new CodeFormat();
|
||||
for (String text: texts) {
|
||||
for (String text : texts) {
|
||||
code.append(text);
|
||||
}
|
||||
|
||||
return code.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ public class CommandListBox extends PaginationBox {
|
||||
}
|
||||
|
||||
private class CommandEntry {
|
||||
|
||||
private final String alias;
|
||||
private final Component description;
|
||||
private final String insertion;
|
||||
@ -90,7 +91,10 @@ public class CommandListBox extends PaginationBox {
|
||||
TextComponentProducer line = new TextComponentProducer();
|
||||
if (!hideHelp) {
|
||||
line.append(SubtleFormat.wrap("? ")
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, CommandListBox.this.helpCommand + " " + insertion))
|
||||
.clickEvent(ClickEvent.of(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
CommandListBox.this.helpCommand + " " + insertion
|
||||
))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Additional Help"))));
|
||||
}
|
||||
TextComponent command = TextComponent.of(alias, TextColor.GOLD);
|
||||
@ -103,5 +107,7 @@ public class CommandListBox extends PaginationBox {
|
||||
}
|
||||
return line.append(TextComponent.of(": ")).append(description).create();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.config.ColorConfig;
|
||||
import org.enginehub.piston.util.HelpGenerator;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.internal.command.CommandUtil.getSubCommands;
|
||||
@ -43,24 +43,27 @@ public class CommandUsageBox extends TextComponentProducer {
|
||||
/**
|
||||
* Create a new usage box.
|
||||
*
|
||||
* @param commands the commands to describe
|
||||
* @param commandString the commands that were used, such as "/we" or "/brush sphere"
|
||||
* @param commands the commands to describe
|
||||
* @param commandString the commands that were used, such as "/we" or "/brush sphere"
|
||||
* @param helpRootCommand the command used to get subcommand help
|
||||
*/
|
||||
public CommandUsageBox(List<Command> commands, String commandString, String helpRootCommand) throws InvalidComponentException {
|
||||
public CommandUsageBox(List<Command> commands, String commandString, String helpRootCommand) throws
|
||||
InvalidComponentException {
|
||||
this(commands, commandString, helpRootCommand, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new usage box.
|
||||
*
|
||||
* @param commands the commands to describe
|
||||
* @param commandString the commands that were used, such as "/we" or "/brush sphere"
|
||||
* @param commands the commands to describe
|
||||
* @param commandString the commands that were used, such as "/we" or "/brush sphere"
|
||||
* @param helpRootCommand the command used to get subcommand help
|
||||
* @param parameters list of parameters to use
|
||||
* @param parameters list of parameters to use
|
||||
*/
|
||||
public CommandUsageBox(List<Command> commands, String commandString, String helpRootCommand,
|
||||
@Nullable CommandParameters parameters) throws InvalidComponentException {
|
||||
public CommandUsageBox(
|
||||
List<Command> commands, String commandString, String helpRootCommand,
|
||||
@Nullable CommandParameters parameters
|
||||
) throws InvalidComponentException {
|
||||
checkNotNull(commands);
|
||||
checkNotNull(commandString);
|
||||
checkNotNull(helpRootCommand);
|
||||
@ -69,19 +72,21 @@ public class CommandUsageBox extends TextComponentProducer {
|
||||
|
||||
private void attachCommandUsage(List<Command> commands, String commandString, String helpRootCommand) {
|
||||
TextComponentProducer boxContent = new TextComponentProducer()
|
||||
.append(HelpGenerator.create(commands).getFullHelp());
|
||||
.append(HelpGenerator.create(commands).getFullHelp());
|
||||
if (getSubCommands(Iterables.getLast(commands)).size() > 0) {
|
||||
boxContent.append(TextComponent.newline())
|
||||
.append(ColorConfig.helpText().wrap(TextComponent.builder("> ")
|
||||
.append(ColorConfig.mainText().wrap(TextComponent.builder("List Subcommands")
|
||||
.decoration(TextDecoration.ITALIC, true)
|
||||
.clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString))
|
||||
.hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command")))
|
||||
.build()))
|
||||
.build()));
|
||||
.append(ColorConfig.helpText().wrap(TextComponent.builder("> ")
|
||||
.append(ColorConfig.mainText().wrap(TextComponent.builder("List Subcommands")
|
||||
.decoration(TextDecoration.ITALIC, true)
|
||||
.clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString))
|
||||
.hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command")))
|
||||
.build()))
|
||||
.build()));
|
||||
}
|
||||
MessageBox box = new MessageBox("Help for " + commandString,
|
||||
boxContent);
|
||||
MessageBox box = new MessageBox(
|
||||
"Help for " + commandString,
|
||||
boxContent
|
||||
);
|
||||
|
||||
append(box.create());
|
||||
}
|
||||
|
@ -48,4 +48,5 @@ public class ErrorFormat extends TextComponentProducer {
|
||||
|
||||
return error.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,4 +32,5 @@ public class InvalidComponentException extends WorldEditException {
|
||||
public InvalidComponentException(Component message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class LabelFormat extends TextComponentProducer {
|
||||
* @param texts The text
|
||||
* @return The Component
|
||||
*/
|
||||
public static TextComponent wrap(String ... texts) {
|
||||
public static TextComponent wrap(String... texts) {
|
||||
LabelFormat label = new LabelFormat();
|
||||
for (String component : texts) {
|
||||
label.append(component);
|
||||
@ -48,4 +48,5 @@ public class LabelFormat extends TextComponentProducer {
|
||||
|
||||
return label.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,8 @@ public class MessageBox extends TextComponentProducer {
|
||||
|
||||
private TextComponent createBorder(int count) {
|
||||
return TextComponent.of(Strings.repeat("-", count),
|
||||
borderColor, Sets.newHashSet(TextDecoration.STRIKETHROUGH));
|
||||
borderColor, Sets.newHashSet(TextDecoration.STRIKETHROUGH)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,4 +101,5 @@ public class MessageBox extends TextComponentProducer {
|
||||
append(contents.create());
|
||||
return super.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public abstract class PaginationBox extends MessageBox {
|
||||
/**
|
||||
* Creates a Paginated component
|
||||
*
|
||||
* @param title The title
|
||||
* @param title The title
|
||||
* @param pageCommand The command to run to switch page, with %page% representing page number
|
||||
*/
|
||||
protected PaginationBox(String title, @Nullable String pageCommand) {
|
||||
@ -117,14 +117,20 @@ public abstract class PaginationBox extends MessageBox {
|
||||
TextComponentProducer navProducer = new TextComponentProducer();
|
||||
if (page > 1) {
|
||||
TextComponent prevComponent = TextComponent.of("<<< ", TextColor.GOLD)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, pageCommand.replace("%page%", String.valueOf(page - 1))))
|
||||
.clickEvent(ClickEvent.of(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
pageCommand.replace("%page%", String.valueOf(page - 1))
|
||||
))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to navigate")));
|
||||
navProducer.append(prevComponent);
|
||||
}
|
||||
navProducer.append(pageNumberComponent);
|
||||
if (page < pageCount) {
|
||||
TextComponent nextComponent = TextComponent.of(" >>>", TextColor.GOLD)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, pageCommand.replace("%page%", String.valueOf(page + 1))))
|
||||
.clickEvent(ClickEvent.of(
|
||||
ClickEvent.Action.RUN_COMMAND,
|
||||
pageCommand.replace("%page%", String.valueOf(page + 1))
|
||||
))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to navigate")));
|
||||
navProducer.append(nextComponent);
|
||||
}
|
||||
@ -140,14 +146,19 @@ public abstract class PaginationBox extends MessageBox {
|
||||
throw new IllegalStateException("Pagination components must be created with a page");
|
||||
}
|
||||
|
||||
public static <T> PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection<T> lines, Function<T, Component> adapt) {
|
||||
public static <T> PaginationBox fromStrings(
|
||||
String header,
|
||||
@Nullable String pageCommand,
|
||||
Collection<T> lines,
|
||||
Function<T, Component> adapt
|
||||
) {
|
||||
return fromComponents(header, pageCommand, Collections2.transform(lines, adapt));
|
||||
}
|
||||
|
||||
public static PaginationBox fromStrings(String header, @Nullable String pageCommand, Collection<String> lines) {
|
||||
return fromComponents(header, pageCommand, lines.stream()
|
||||
.map(TextComponent::of)
|
||||
.collect(Collectors.toList()));
|
||||
.map(TextComponent::of)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public static PaginationBox fromComponents(String header, @Nullable String pageCommand, Collection<Component> lines) {
|
||||
@ -155,6 +166,7 @@ public abstract class PaginationBox extends MessageBox {
|
||||
}
|
||||
|
||||
private static class ListPaginationBox extends PaginationBox {
|
||||
|
||||
private final List<Component> lines;
|
||||
|
||||
ListPaginationBox(String header, String pageCommand, Collection<Component> lines) {
|
||||
@ -171,10 +183,12 @@ public abstract class PaginationBox extends MessageBox {
|
||||
public int getComponentsSize() {
|
||||
return lines.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//FAWE start
|
||||
public static class MergedPaginationBox extends PaginationBox {
|
||||
|
||||
private final PaginationBox[] values;
|
||||
|
||||
public MergedPaginationBox(String header, String pageCommand, PaginationBox... values) {
|
||||
@ -212,6 +226,7 @@ public abstract class PaginationBox extends MessageBox {
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
}
|
||||
//FAWE end
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class SideEffectBox extends PaginationBox {
|
||||
|
||||
private static List<SideEffect> sideEffects;
|
||||
|
||||
private SideEffectSet sideEffectSet;
|
||||
private final SideEffectSet sideEffectSet;
|
||||
|
||||
private static List<SideEffect> getSideEffects() {
|
||||
//FAWE start
|
||||
@ -72,7 +72,9 @@ public class SideEffectBox extends PaginationBox {
|
||||
for (SideEffect.State uiState : SHOWN_VALUES) {
|
||||
builder = builder.append(TextComponent.space());
|
||||
builder = builder.append(Caption.of(uiState.getDisplayName(), uiState == state ? TextColor.WHITE : TextColor.GRAY)
|
||||
.clickEvent(ClickEvent.runCommand("//perf -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US)))
|
||||
.clickEvent(ClickEvent.runCommand("//perf -h " + effect.name().toLowerCase(Locale.US) + " " + uiState
|
||||
.name()
|
||||
.toLowerCase(Locale.US)))
|
||||
.hoverEvent(HoverEvent.showText(uiState == state
|
||||
? Caption.of("worldedit.sideeffect.box.current")
|
||||
: Caption.of("worldedit.sideeffect.box.change-to", Caption.of(uiState.getDisplayName()))
|
||||
@ -87,4 +89,5 @@ public class SideEffectBox extends PaginationBox {
|
||||
public int getComponentsSize() {
|
||||
return getSideEffects().size();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,4 +48,5 @@ public class SubtleFormat extends TextComponentProducer {
|
||||
|
||||
return subtle.create();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -80,4 +80,5 @@ public class TextComponentProducer {
|
||||
builder = TextComponent.builder().content("");
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class TextUtils {
|
||||
* Join an array of components with a joiner component.
|
||||
*
|
||||
* @param components The components to join
|
||||
* @param joiner The joiner component
|
||||
* @param joiner The joiner component
|
||||
* @return The joined component
|
||||
*/
|
||||
public static Component join(List<Component> components, Component joiner) {
|
||||
@ -57,4 +57,5 @@ public class TextUtils {
|
||||
public static Locale getLocaleByMinecraftTag(String locale) {
|
||||
return Locale.forLanguageTag(locale.replace('_', '-'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.util.function;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -42,7 +42,7 @@ public class LevenshteinDistance implements Function<String, Integer> {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param baseString the string to compare to
|
||||
* @param baseString the string to compare to
|
||||
* @param caseSensitive true to make case sensitive comparisons
|
||||
*/
|
||||
public LevenshteinDistance(String baseString, boolean caseSensitive) {
|
||||
@ -52,8 +52,8 @@ public class LevenshteinDistance implements Function<String, Integer> {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param baseString the string to compare to
|
||||
* @param caseSensitive true to make case sensitive comparisons
|
||||
* @param baseString the string to compare to
|
||||
* @param caseSensitive true to make case sensitive comparisons
|
||||
* @param replacePattern pattern to match characters to be removed in both the input and test strings (may be null)
|
||||
*/
|
||||
public LevenshteinDistance(String baseString, boolean caseSensitive, @Nullable Pattern replacePattern) {
|
||||
@ -112,8 +112,8 @@ public class LevenshteinDistance implements Function<String, Integer> {
|
||||
* distance("hello", "hallo") = 1
|
||||
* </pre>
|
||||
*
|
||||
* @param s the first String, must not be null
|
||||
* @param t the second String, must not be null
|
||||
* @param s the first String, must not be null
|
||||
* @param t the second String, must not be null
|
||||
* @return result distance
|
||||
* @throws IllegalArgumentException if either String input {@code null}
|
||||
*/
|
||||
|
@ -31,7 +31,8 @@ import java.lang.reflect.Type;
|
||||
public class BlockVectorAdapter implements JsonDeserializer<BlockVector3> {
|
||||
|
||||
@Override
|
||||
public BlockVector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
public BlockVector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
|
||||
JsonParseException {
|
||||
JsonArray jsonArray = json.getAsJsonArray();
|
||||
if (jsonArray.size() != 3) {
|
||||
throw new JsonParseException("Expected array of 3 length for BlockVector3");
|
||||
@ -43,4 +44,5 @@ public class BlockVectorAdapter implements JsonDeserializer<BlockVector3> {
|
||||
|
||||
return BlockVector3.at(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,9 @@ public final class GsonUtil {
|
||||
}
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static String stringValue(String s) {
|
||||
return gson.toJson(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,4 +46,5 @@ public class VectorAdapter implements JsonDeserializer<Vector3> {
|
||||
|
||||
return Vector3.at(x, y, z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,8 @@ public final class Closer implements Closeable {
|
||||
private final Deque<ZipFile> zipStack = new ArrayDeque<>(4);
|
||||
private Throwable thrown;
|
||||
|
||||
@VisibleForTesting Closer(Suppressor suppressor) {
|
||||
@VisibleForTesting
|
||||
Closer(Suppressor suppressor) {
|
||||
this.suppressor = checkNotNull(suppressor); // checkNotNull to satisfy null tests
|
||||
}
|
||||
|
||||
@ -139,10 +140,12 @@ public final class Closer implements Closeable {
|
||||
*
|
||||
* @return this method does not return; it always throws
|
||||
* @throws IOException when the given throwable is an IOException
|
||||
* @throws X when the given throwable is of the declared type X
|
||||
* @throws X when the given throwable is of the declared type X
|
||||
*/
|
||||
public <X extends Exception> RuntimeException rethrow(Throwable e,
|
||||
Class<X> declaredType) throws IOException, X {
|
||||
public <X extends Exception> RuntimeException rethrow(
|
||||
Throwable e,
|
||||
Class<X> declaredType
|
||||
) throws IOException, X {
|
||||
thrown = e;
|
||||
Throwables.propagateIfPossible(e, IOException.class);
|
||||
Throwables.propagateIfPossible(e, declaredType);
|
||||
@ -162,11 +165,12 @@ public final class Closer implements Closeable {
|
||||
*
|
||||
* @return this method does not return; it always throws
|
||||
* @throws IOException when the given throwable is an IOException
|
||||
* @throws X1 when the given throwable is of the declared type X1
|
||||
* @throws X2 when the given throwable is of the declared type X2
|
||||
* @throws X1 when the given throwable is of the declared type X1
|
||||
* @throws X2 when the given throwable is of the declared type X2
|
||||
*/
|
||||
public <X1 extends Exception, X2 extends Exception> RuntimeException rethrow(
|
||||
Throwable e, Class<X1> declaredType1, Class<X2> declaredType2) throws IOException, X1, X2 {
|
||||
Throwable e, Class<X1> declaredType1, Class<X2> declaredType2
|
||||
) throws IOException, X1, X2 {
|
||||
thrown = e;
|
||||
Throwables.propagateIfPossible(e, IOException.class);
|
||||
Throwables.propagateIfPossible(e, declaredType1, declaredType2);
|
||||
@ -220,19 +224,23 @@ public final class Closer implements Closeable {
|
||||
/**
|
||||
* Suppression strategy interface.
|
||||
*/
|
||||
@VisibleForTesting interface Suppressor {
|
||||
@VisibleForTesting
|
||||
interface Suppressor {
|
||||
|
||||
/**
|
||||
* Suppresses the given exception ({@code suppressed}) which was thrown when attempting to close
|
||||
* the given closeable. {@code thrown} is the exception that is actually being thrown from the
|
||||
* method. Implementations of this method should not throw under any circumstances.
|
||||
*/
|
||||
void suppress(Object closeable, Throwable thrown, Throwable suppressed);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppresses exceptions by logging them.
|
||||
*/
|
||||
@VisibleForTesting static final class LoggingSuppressor implements Suppressor {
|
||||
@VisibleForTesting
|
||||
static final class LoggingSuppressor implements Suppressor {
|
||||
|
||||
static final LoggingSuppressor INSTANCE = new LoggingSuppressor();
|
||||
|
||||
@ -241,13 +249,15 @@ public final class Closer implements Closeable {
|
||||
// log to the same place as Closeables
|
||||
LOGGER.warn("Suppressing exception thrown when closing " + closeable, suppressed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppresses exceptions by adding them to the exception that will be thrown using JDK7's
|
||||
* addSuppressed(Throwable) mechanism.
|
||||
*/
|
||||
@VisibleForTesting static final class SuppressingSuppressor implements Suppressor {
|
||||
@VisibleForTesting
|
||||
static final class SuppressingSuppressor implements Suppressor {
|
||||
|
||||
static final SuppressingSuppressor INSTANCE = new SuppressingSuppressor();
|
||||
|
||||
@ -278,5 +288,7 @@ public final class Closer implements Closeable {
|
||||
LoggingSuppressor.INSTANCE.suppress(closeable, thrown, suppressed);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -99,4 +99,5 @@ public class ForwardSeekableInputStream extends InputStream {
|
||||
throw new IOException("Failed to seek " + diff + " bytes");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,10 @@
|
||||
|
||||
package com.sk89q.worldedit.util.io;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
@ -39,7 +39,7 @@ public interface ResourceLoader {
|
||||
* The path name <b>must not</b> start with {@code /}.
|
||||
* </p>
|
||||
*
|
||||
* @param clazz The class to search relative to
|
||||
* @param clazz The class to search relative to
|
||||
* @param pathName The path name
|
||||
* @return The URL to this bundled resource
|
||||
* @throws IOException if an IO issue occurs
|
||||
@ -48,7 +48,7 @@ public interface ResourceLoader {
|
||||
default URL getResource(Class<?> clazz, String pathName) throws IOException {
|
||||
checkArgument(!pathName.startsWith("/"), "pathName must not start with /");
|
||||
String qualifiedName = clazz.getName().substring(0, clazz.getName().lastIndexOf('.'))
|
||||
.replace(".", "/") + "/" + pathName;
|
||||
.replace(".", "/") + "/" + pathName;
|
||||
return getRootResource(qualifiedName);
|
||||
}
|
||||
|
||||
@ -78,4 +78,5 @@ public interface ResourceLoader {
|
||||
* @return The path reference
|
||||
*/
|
||||
Path getLocalResource(String pathName);
|
||||
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ public class WorldEditResourceLoader implements ResourceLoader {
|
||||
public Path getLocalResource(String pathName) {
|
||||
return this.worldEdit.getWorkingDirectoryPath(pathName);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ public class ArchiveNioSupports {
|
||||
static {
|
||||
ImmutableList.Builder<ArchiveNioSupport> builder = ImmutableList.builder();
|
||||
SUPPORTS = builder.add(ZipArchiveNioSupport.getInstance())
|
||||
.addAll(ServiceLoader.load(ArchiveNioSupport.class))
|
||||
.build();
|
||||
.addAll(ServiceLoader.load(ArchiveNioSupport.class))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Optional<ArchiveDir> tryOpenAsDir(Path archive) throws IOException {
|
||||
@ -54,6 +54,7 @@ public class ArchiveNioSupports {
|
||||
|
||||
/**
|
||||
* Get an {@link ArchiveNioSupport} that combines all known instances.
|
||||
*
|
||||
* @return a combined {@link ArchiveNioSupport} instance
|
||||
*/
|
||||
public static ArchiveNioSupport combined() {
|
||||
@ -91,4 +92,5 @@ public class ArchiveNioSupports {
|
||||
|
||||
private ArchiveNioSupports() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,5 +20,6 @@
|
||||
package com.sk89q.worldedit.util.io.file;
|
||||
|
||||
public enum AttributeTarget {
|
||||
FILE, DIRECTORY
|
||||
FILE,
|
||||
DIRECTORY
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ public class FileSelectionAbortedException extends FilenameException {
|
||||
public FileSelectionAbortedException(Component msg) {
|
||||
super("", msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,4 +84,5 @@ public class MorePaths {
|
||||
|
||||
private MorePaths() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.util.io.file;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
@ -32,7 +33,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SafeFiles {
|
||||
|
||||
@ -151,7 +151,7 @@ public class SafeFiles {
|
||||
|
||||
static {
|
||||
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
|
||||
OWNER_ONLY_FILE_ATTRS = new FileAttribute<?>[] {
|
||||
OWNER_ONLY_FILE_ATTRS = new FileAttribute<?>[]{
|
||||
PosixFilePermissions.asFileAttribute(
|
||||
ImmutableSet.of(
|
||||
PosixFilePermission.OWNER_READ,
|
||||
@ -159,7 +159,7 @@ public class SafeFiles {
|
||||
)
|
||||
)
|
||||
};
|
||||
OWNER_ONLY_DIR_ATTRS = new FileAttribute<?>[] {
|
||||
OWNER_ONLY_DIR_ATTRS = new FileAttribute<?>[]{
|
||||
PosixFilePermissions.asFileAttribute(
|
||||
ImmutableSet.of(
|
||||
PosixFilePermission.OWNER_READ,
|
||||
@ -196,4 +196,5 @@ public class SafeFiles {
|
||||
|
||||
private SafeFiles() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ public final class ZipArchiveNioSupport implements ArchiveNioSupport {
|
||||
return Optional.empty();
|
||||
}
|
||||
FileSystem zipFs = FileSystems.newFileSystem(
|
||||
archive, getClass().getClassLoader()
|
||||
archive, getClass().getClassLoader()
|
||||
);
|
||||
Path root = ArchiveNioSupports.skipRootSameName(
|
||||
zipFs.getPath("/"), archive.getFileName().toString()
|
||||
.replaceFirst("\\.zip$", "")
|
||||
zipFs.getPath("/"), archive.getFileName().toString()
|
||||
.replaceFirst("\\.zip$", "")
|
||||
);
|
||||
return Optional.of(new ArchiveDir() {
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ import java.util.function.BiConsumer;
|
||||
* A {@link Lifecycled} that never invalidates.
|
||||
*/
|
||||
public final class ConstantLifecycled<T> implements Lifecycled<T> {
|
||||
|
||||
private final T value;
|
||||
|
||||
public ConstantLifecycled(T value) {
|
||||
@ -52,4 +53,5 @@ public final class ConstantLifecycled<T> implements Lifecycled<T> {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,11 +19,12 @@
|
||||
|
||||
package com.sk89q.worldedit.util.lifecycle;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
class FlatMapLifecycled<T, U> implements Lifecycled<U> {
|
||||
|
||||
private final LifecycledCallbackHandler<U> events = new LifecycledCallbackHandler<>(this);
|
||||
private Lifecycled<U> mapped;
|
||||
private Token<FlatMapLifecycled<T, U>> mappedToken;
|
||||
@ -77,4 +78,5 @@ class FlatMapLifecycled<T, U> implements Lifecycled<U> {
|
||||
public Events<U> events() {
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.util.function.Predicate;
|
||||
public interface Lifecycled<T> {
|
||||
|
||||
interface Events<T> {
|
||||
|
||||
/**
|
||||
* Add a callback for when this lifecycled is given a new value. Will be called immediately
|
||||
* if this lifecycled is currently valid.
|
||||
@ -61,7 +62,7 @@ public interface Lifecycled<T> {
|
||||
* loop.
|
||||
* </p>
|
||||
*
|
||||
* @param owner when the owner is GC'd, the callback is removed
|
||||
* @param owner when the owner is GC'd, the callback is removed
|
||||
* @param callback the callback, will be passed the lifecycled object
|
||||
*/
|
||||
<O> void onNewValue(O owner, BiConsumer<O, ? super Lifecycled<T>> callback);
|
||||
@ -76,10 +77,11 @@ public interface Lifecycled<T> {
|
||||
* loop.
|
||||
* </p>
|
||||
*
|
||||
* @param owner when the owner is GC'd, the callback is removed
|
||||
* @param owner when the owner is GC'd, the callback is removed
|
||||
* @param callback the callback, will be passed the lifecycled object
|
||||
*/
|
||||
<O> void onInvalidated(O owner, BiConsumer<O, ? super Lifecycled<T>> callback);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,7 +121,7 @@ public interface Lifecycled<T> {
|
||||
* Map the value.
|
||||
*
|
||||
* @param mapper the mapper function
|
||||
* @param <U> the new type
|
||||
* @param <U> the new type
|
||||
* @return the downstream lifecycled
|
||||
*/
|
||||
default <U> Lifecycled<U> map(Function<T, U> mapper) {
|
||||
@ -148,4 +150,5 @@ public interface Lifecycled<T> {
|
||||
default <U> Lifecycled<U> flatMap(Function<T, Lifecycled<U>> mapper) {
|
||||
return new FlatMapLifecycled<>(this, mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import java.util.function.BiConsumer;
|
||||
* Convenience class for implementing the callbacks of {@link Lifecycled}.
|
||||
*/
|
||||
public class LifecycledCallbackHandler<T> implements Lifecycled.Events<T> {
|
||||
|
||||
private final Lifecycled<T> lifecycled;
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Map<Object, BiConsumer<?, ? super Lifecycled<T>>> onInvalidatedCallbacks =
|
||||
@ -111,4 +112,5 @@ public class LifecycledCallbackHandler<T> implements Lifecycled.Events<T> {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.util.lifecycle;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
class MapLifecycled<T, U> implements Lifecycled<U> {
|
||||
|
||||
private final LifecycledCallbackHandler<U> events = new LifecycledCallbackHandler<>(this);
|
||||
private final Lifecycled<T> upstream;
|
||||
private final Function<T, U> mapper;
|
||||
@ -43,7 +44,7 @@ class MapLifecycled<T, U> implements Lifecycled<U> {
|
||||
this$.events.fireInvalidated();
|
||||
}
|
||||
});
|
||||
upstream.events().onNewValue(this, (this$, __) -> {
|
||||
upstream.events().onNewValue(this, (this$, __) -> {
|
||||
boolean fire = !this$.computable;
|
||||
this$.computable = true;
|
||||
if (fire) {
|
||||
@ -79,4 +80,5 @@ class MapLifecycled<T, U> implements Lifecycled<U> {
|
||||
public Events<U> events() {
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,15 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.util.lifecycle;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link Lifecycled} that can be directly called to {@linkplain #invalidate() invalidate} it or
|
||||
* set a {@linkplain #newValue(Object) new value}.
|
||||
*/
|
||||
public final class SimpleLifecycled<T> implements Lifecycled<T> {
|
||||
|
||||
public static <T> SimpleLifecycled<T> valid(T value) {
|
||||
return new SimpleLifecycled<>(Objects.requireNonNull(value));
|
||||
}
|
||||
@ -76,4 +77,5 @@ public final class SimpleLifecycled<T> implements Lifecycled<T> {
|
||||
public Events<T> events() {
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ package com.sk89q.worldedit.util.lifecycle;
|
||||
* @param <T> the inner object
|
||||
*/
|
||||
class Token<T> {
|
||||
|
||||
final T inner;
|
||||
|
||||
Token(T inner) {
|
||||
this.inner = inner;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.util.logging;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.Formatter;
|
||||
@ -26,7 +27,6 @@ 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
|
||||
|
@ -29,6 +29,7 @@ import java.util.logging.LogRecord;
|
||||
* A standard logging format for WorldEdit.
|
||||
*/
|
||||
public class LogFormat extends Formatter {
|
||||
|
||||
public static final String DEFAULT_FORMAT = "[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s]: %5$s%6$s%n";
|
||||
private final Date dat = new Date();
|
||||
private final String format;
|
||||
@ -72,12 +73,15 @@ public class LogFormat extends Formatter {
|
||||
pw.close();
|
||||
throwable = sw.toString();
|
||||
}
|
||||
return String.format(format,
|
||||
return String.format(
|
||||
format,
|
||||
dat,
|
||||
source,
|
||||
record.getLoggerName(),
|
||||
record.getLevel().getName(),
|
||||
message,
|
||||
throwable);
|
||||
throwable
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
public class HttpRequest implements Closeable {
|
||||
|
||||
private static final int CONNECT_TIMEOUT = 1000 * 5;
|
||||
@ -170,8 +168,8 @@ public class HttpRequest implements Closeable {
|
||||
}
|
||||
|
||||
inputStream = conn.getResponseCode() == HttpURLConnection.HTTP_OK
|
||||
? conn.getInputStream()
|
||||
: conn.getErrorStream();
|
||||
? conn.getInputStream()
|
||||
: conn.getErrorStream();
|
||||
|
||||
successful = true;
|
||||
} finally {
|
||||
@ -376,7 +374,8 @@ public class HttpRequest implements Closeable {
|
||||
URL url = new URL(existing.toString());
|
||||
URI uri = new URI(
|
||||
url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(),
|
||||
url.getPath(), url.getQuery(), url.getRef());
|
||||
url.getPath(), url.getQuery(), url.getRef()
|
||||
);
|
||||
url = uri.toURL();
|
||||
return url;
|
||||
} catch (MalformedURLException | URISyntaxException e) {
|
||||
@ -390,13 +389,13 @@ public class HttpRequest implements Closeable {
|
||||
public static final class Form {
|
||||
|
||||
private static final Joiner.MapJoiner URL_ENCODER = Joiner.on('&')
|
||||
.withKeyValueSeparator('=');
|
||||
.withKeyValueSeparator('=');
|
||||
private static final Joiner CRLF_JOINER = Joiner.on("\r\n");
|
||||
|
||||
public final Map<String, String> elements = new LinkedHashMap<>();
|
||||
|
||||
private final String formDataSeparator = "EngineHubFormData"
|
||||
+ ThreadLocalRandom.current().nextInt(10000, 99999);
|
||||
+ ThreadLocalRandom.current().nextInt(10000, 99999);
|
||||
|
||||
private Form() {
|
||||
}
|
||||
@ -423,12 +422,12 @@ public class HttpRequest implements Closeable {
|
||||
|
||||
for (Map.Entry<String, String> element : elements.entrySet()) {
|
||||
CRLF_JOINER.appendTo(
|
||||
builder,
|
||||
separatorWithDashes,
|
||||
"Content-Disposition: form-data; name=\"" + element.getKey() + "\"",
|
||||
"",
|
||||
element.getValue(),
|
||||
""
|
||||
builder,
|
||||
separatorWithDashes,
|
||||
"Content-Disposition: form-data; name=\"" + element.getKey() + "\"",
|
||||
"",
|
||||
element.getValue(),
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
@ -439,12 +438,12 @@ public class HttpRequest implements Closeable {
|
||||
|
||||
public String toUrlEncodedString() {
|
||||
return URL_ENCODER.join(
|
||||
elements.entrySet().stream()
|
||||
.map(e -> Maps.immutableEntry(
|
||||
UrlEscapers.urlFormParameterEscaper().escape(e.getKey()),
|
||||
UrlEscapers.urlFormParameterEscaper().escape(e.getValue())
|
||||
))
|
||||
.iterator()
|
||||
elements.entrySet().stream()
|
||||
.map(e -> Maps.immutableEntry(
|
||||
UrlEscapers.urlFormParameterEscaper().escape(e.getKey()),
|
||||
UrlEscapers.urlFormParameterEscaper().escape(e.getValue())
|
||||
))
|
||||
.iterator()
|
||||
);
|
||||
}
|
||||
|
||||
@ -456,12 +455,14 @@ public class HttpRequest implements Closeable {
|
||||
public static Form create() {
|
||||
return new Form();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to buffer the response in memory.
|
||||
*/
|
||||
public class BufferedResponse {
|
||||
|
||||
private final byte[] data;
|
||||
|
||||
private BufferedResponse(byte[] data) {
|
||||
@ -525,6 +526,7 @@ public class HttpRequest implements Closeable {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ public final class ActorCallbackPaste {
|
||||
* Submit data to a pastebin service and inform the sender of
|
||||
* success or failure.
|
||||
*
|
||||
* @param supervisor The supervisor instance
|
||||
* @param sender The sender
|
||||
* @param content The content
|
||||
* @param supervisor The supervisor instance
|
||||
* @param sender The sender
|
||||
* @param content The content
|
||||
* @param successMessage The message, formatted with {@link String#format(String, Object...)} on success
|
||||
* @deprecated Use the Component-based version
|
||||
*/
|
||||
@ -62,12 +62,17 @@ public final class ActorCallbackPaste {
|
||||
* Submit data to a pastebin service and inform the sender of
|
||||
* success or failure.
|
||||
*
|
||||
* @param supervisor The supervisor instance
|
||||
* @param sender The sender
|
||||
* @param content The content
|
||||
* @param supervisor The supervisor instance
|
||||
* @param sender The sender
|
||||
* @param content The content
|
||||
* @param successMessage The message builder, given the URL as an arg
|
||||
*/
|
||||
public static void pastebin(Supervisor supervisor, final Actor sender, String content, final TranslatableComponent.Builder successMessage) {
|
||||
public static void pastebin(
|
||||
Supervisor supervisor,
|
||||
final Actor sender,
|
||||
String content,
|
||||
final TranslatableComponent.Builder successMessage
|
||||
) {
|
||||
Callable<URL> task = paster.paste(content);
|
||||
|
||||
AsyncCommandBuilder.wrap(task, sender)
|
||||
|
@ -38,6 +38,7 @@ public class EngineHubPaste implements Paster {
|
||||
}
|
||||
|
||||
private static final class PasteTask implements Callable<URL> {
|
||||
|
||||
private final String content;
|
||||
|
||||
private PasteTask(String content) {
|
||||
@ -49,10 +50,10 @@ public class EngineHubPaste implements Paster {
|
||||
URL initialUrl = HttpRequest.url("https://paste.enginehub.org/signed_paste");
|
||||
|
||||
SignedPasteResponse response = GSON.fromJson(HttpRequest.get(initialUrl)
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8"), TypeToken.get(SignedPasteResponse.class).getType());
|
||||
.execute()
|
||||
.expectResponseCode(200)
|
||||
.returnContent()
|
||||
.asString("UTF-8"), TypeToken.get(SignedPasteResponse.class).getType());
|
||||
|
||||
HttpRequest.Form form = HttpRequest.Form.create();
|
||||
for (Map.Entry<String, String> entry : response.uploadFields.entrySet()) {
|
||||
@ -69,11 +70,15 @@ public class EngineHubPaste implements Paster {
|
||||
|
||||
return new URL(response.viewUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class SignedPasteResponse {
|
||||
|
||||
String viewUrl;
|
||||
String uploadUrl;
|
||||
Map<String, String> uploadFields;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,8 @@ final class Pasters {
|
||||
MoreExecutors.listeningDecorator(
|
||||
new ThreadPoolExecutor(0, Integer.MAX_VALUE,
|
||||
2L, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<>()));
|
||||
new SynchronousQueue<>()
|
||||
));
|
||||
|
||||
private Pasters() {
|
||||
}
|
||||
|
@ -169,6 +169,7 @@ public class DataReport implements Report {
|
||||
}
|
||||
|
||||
private static class Line {
|
||||
|
||||
private final String key;
|
||||
private final String value;
|
||||
|
||||
@ -176,6 +177,7 @@ public class DataReport implements Report {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,4 +29,5 @@ public class HierarchyObjectReport extends ShallowObjectReport {
|
||||
scanClass(object, type);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class ReportList implements Report, List<Report> {
|
||||
.append(report.getTitle())
|
||||
.append("\n================================")
|
||||
.append("\n\n")
|
||||
.append(report.toString())
|
||||
.append(report)
|
||||
.append("\n\n");
|
||||
}
|
||||
return builder.toString();
|
||||
|
@ -57,4 +57,5 @@ public class ShallowObjectReport extends DataReport {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,11 +44,13 @@ public class SystemInfoReport extends DataReport {
|
||||
append("Java", "%s %s (%s)",
|
||||
System.getProperty("java.vendor"),
|
||||
System.getProperty("java.version"),
|
||||
System.getProperty("java.vendor.url"));
|
||||
System.getProperty("java.vendor.url")
|
||||
);
|
||||
append("Operating System", "%s %s (%s)",
|
||||
System.getProperty("os.name"),
|
||||
System.getProperty("os.version"),
|
||||
System.getProperty("os.arch"));
|
||||
System.getProperty("os.arch")
|
||||
);
|
||||
append("Available Processors", runtime.availableProcessors());
|
||||
append("Free Memory", runtime.freeMemory() / 1024 / 1024 + " MB");
|
||||
append("Max Memory", runtime.maxMemory() / 1024 / 1024 + " MB");
|
||||
|
@ -30,4 +30,5 @@ import java.lang.annotation.Target;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Unreported {
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package com.sk89q.worldedit.util.task;
|
||||
|
||||
import com.google.common.util.concurrent.AbstractFuture;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -42,7 +42,7 @@ public abstract class AbstractTask<V> extends AbstractFuture<V> implements Task<
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param name the name
|
||||
* @param name the name
|
||||
* @param owner the owner
|
||||
*/
|
||||
protected AbstractTask(String name, @Nullable Object owner) {
|
||||
@ -71,4 +71,5 @@ public abstract class AbstractTask<V> extends AbstractFuture<V> implements Task<
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,11 +22,11 @@ package com.sk89q.worldedit.util.task;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.sk89q.worldedit.util.task.progress.Progress;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -109,9 +109,9 @@ public class FutureForwardingTask<V> extends AbstractTask<V> {
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param future the future
|
||||
* @param name the name of the task
|
||||
* @param owner the owner of the task, or {@code null}
|
||||
* @param <V> the type returned by the future
|
||||
* @param name the name of the task
|
||||
* @param owner the owner of the task, or {@code null}
|
||||
* @param <V> the type returned by the future
|
||||
* @return a new instance
|
||||
*/
|
||||
public static <V> FutureForwardingTask<V> create(ListenableFuture<V> future, String name, @Nullable Object owner) {
|
||||
|
@ -22,9 +22,9 @@ package com.sk89q.worldedit.util.task;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.sk89q.worldedit.util.task.progress.ProgressObservable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A task is a job that can be scheduled, run, or cancelled. Tasks can report
|
||||
|
@ -44,7 +44,7 @@ public class ProgressIterator<V> implements Iterator<V>, ProgressObservable {
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param iterator the iterator
|
||||
* @param count the count
|
||||
* @param count the count
|
||||
*/
|
||||
private ProgressIterator(Iterator<V> iterator, int count) {
|
||||
checkNotNull(iterator);
|
||||
@ -78,8 +78,8 @@ public class ProgressIterator<V> implements Iterator<V>, ProgressObservable {
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param iterator the iterator
|
||||
* @param count the number of objects
|
||||
* @param <V> the type
|
||||
* @param count the number of objects
|
||||
* @param <V> the type
|
||||
* @return an instance
|
||||
*/
|
||||
public static <V> ProgressIterator<V> create(Iterator<V> iterator, int count) {
|
||||
@ -90,7 +90,7 @@ public class ProgressIterator<V> implements Iterator<V>, ProgressObservable {
|
||||
* Create a new instance from a list.
|
||||
*
|
||||
* @param list a list
|
||||
* @param <V> the type
|
||||
* @param <V> the type
|
||||
* @return an instance
|
||||
*/
|
||||
public static <V> ProgressIterator<V> create(List<V> list) {
|
||||
|
@ -22,13 +22,13 @@ package com.sk89q.worldedit.util.time;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.sk89q.worldedit.util.io.file.MorePaths;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.StreamSupport;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Parses date-times by looking at the file name. File names without a time
|
||||
@ -65,11 +65,11 @@ public class FileNameDateTimeParser implements SnapshotDateTimeParser {
|
||||
private static final String SEP = "[ \\-_:]";
|
||||
|
||||
private static final Pattern BASIC_FILTER = Pattern.compile(
|
||||
"^(?<year>\\d{4})" + SEP + "(?<month>\\d{1,2})" + SEP + "(?<day>\\d{1,2})"
|
||||
// Optionally:
|
||||
+ "(?:" + "[ \\-_:T]"
|
||||
+ "(?<hour>\\d{1,2})" + SEP + "(?<minute>\\d{1,2})" + SEP + "(?<second>\\d{1,2})"
|
||||
+ ")?"
|
||||
"^(?<year>\\d{4})" + SEP + "(?<month>\\d{1,2})" + SEP + "(?<day>\\d{1,2})"
|
||||
// Optionally:
|
||||
+ "(?:" + "[ \\-_:T]"
|
||||
+ "(?<hour>\\d{1,2})" + SEP + "(?<minute>\\d{1,2})" + SEP + "(?<second>\\d{1,2})"
|
||||
+ ")?"
|
||||
);
|
||||
|
||||
private FileNameDateTimeParser() {
|
||||
@ -80,9 +80,9 @@ public class FileNameDateTimeParser implements SnapshotDateTimeParser {
|
||||
public ZonedDateTime detectDateTime(Path path) {
|
||||
// Make this perform a little better:
|
||||
Matcher matcher = Streams.findLast(
|
||||
StreamSupport.stream(MorePaths.optimizedSpliterator(path), false)
|
||||
.map(p -> BASIC_FILTER.matcher(p.toString()))
|
||||
.filter(Matcher::find)
|
||||
StreamSupport.stream(MorePaths.optimizedSpliterator(path), false)
|
||||
.map(p -> BASIC_FILTER.matcher(p.toString()))
|
||||
.filter(Matcher::find)
|
||||
).orElse(null);
|
||||
if (matcher != null) {
|
||||
int year = matchAndParseOrZero(matcher, "year");
|
||||
@ -92,7 +92,8 @@ public class FileNameDateTimeParser implements SnapshotDateTimeParser {
|
||||
int minute = matchAndParseOrZero(matcher, "minute");
|
||||
int second = matchAndParseOrZero(matcher, "second");
|
||||
return ZonedDateTime.of(year, month, day, hour, minute, second,
|
||||
0, ZoneId.systemDefault());
|
||||
0, ZoneId.systemDefault()
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -19,9 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.util.time;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZonedDateTime;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Instances of this interface try to determine an {@link ZonedDateTime} from a given
|
||||
|
@ -66,7 +66,8 @@ import static java.util.stream.Collectors.toMap;
|
||||
public class TranslationManager {
|
||||
|
||||
private static final Gson gson = new GsonBuilder().create();
|
||||
private static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>() {}.getType();
|
||||
private static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>() {
|
||||
}.getType();
|
||||
|
||||
public static String makeTranslationKey(String type, String id) {
|
||||
String[] parts = id.split(":", 2);
|
||||
@ -75,14 +76,14 @@ public class TranslationManager {
|
||||
|
||||
private final Map<Locale, Map<String, String>> translationMap = new ConcurrentHashMap<>();
|
||||
private final TranslatableComponentRenderer<Locale> friendlyComponentRenderer = TranslatableComponentRenderer.from(
|
||||
(locale, key) -> {
|
||||
String translation = getTranslationMap(locale).get(key);
|
||||
if (translation == null) {
|
||||
// let it pass through (for e.g. MC messages)
|
||||
return null;
|
||||
(locale, key) -> {
|
||||
String translation = getTranslationMap(locale).get(key);
|
||||
if (translation == null) {
|
||||
// let it pass through (for e.g. MC messages)
|
||||
return null;
|
||||
}
|
||||
return new MessageFormat(translation, locale);
|
||||
}
|
||||
return new MessageFormat(translation, locale);
|
||||
}
|
||||
);
|
||||
private Locale defaultLocale = Locale.ENGLISH;
|
||||
|
||||
@ -101,9 +102,9 @@ public class TranslationManager {
|
||||
|
||||
private Map<String, String> filterTranslations(Map<String, String> translations) {
|
||||
return translations.entrySet().stream()
|
||||
.filter(e -> !e.getValue().isEmpty())
|
||||
.map(e -> Maps.immutableEntry(e.getKey(), e.getValue().replace("'", "''")))
|
||||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
.filter(e -> !e.getValue().isEmpty())
|
||||
.map(e -> Maps.immutableEntry(e.getKey(), e.getValue().replace("'", "''")))
|
||||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
private Map<String, String> parseTranslationFile(InputStream inputStream) throws IOException {
|
||||
@ -163,7 +164,7 @@ public class TranslationManager {
|
||||
}
|
||||
if (locale.equals(defaultLocale)) {
|
||||
translationMap.put(Locale.ENGLISH, loadTranslationFile("strings.json").orElseThrow(
|
||||
() -> new RuntimeException("Failed to load WorldEdit strings!")
|
||||
() -> new RuntimeException("Failed to load WorldEdit strings!")
|
||||
));
|
||||
return true;
|
||||
}
|
||||
@ -191,4 +192,5 @@ public class TranslationManager {
|
||||
public Locale getDefaultLocale() {
|
||||
return defaultLocale;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user