This commit is contained in:
Aurora
2020-07-26 19:03:46 +02:00
608 changed files with 4704 additions and 3740 deletions

View File

@ -38,7 +38,6 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;

View File

@ -23,9 +23,9 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.registry.BlockRegistry;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import javax.annotation.Nullable;
import java.util.BitSet;
import java.util.OptionalInt;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkState;

View File

@ -22,13 +22,13 @@ package com.sk89q.worldedit.internal.command;
import com.sk89q.worldedit.command.util.annotation.Confirm;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import java.util.Optional;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.exception.StopExecutionException;
import org.enginehub.piston.gen.CommandCallListener;
import org.enginehub.piston.inject.Key;
import java.lang.reflect.Method;
import java.util.Optional;
/**
* Logs called commands to a logger.

View File

@ -2,13 +2,11 @@ package com.sk89q.worldedit.internal.command;
import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.gen.CommandCallListener;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.util.ValueProvider;
import java.lang.reflect.Method;
import java.util.Optional;
public class MethodInjector implements CommandCallListener {
@Override

View File

@ -38,7 +38,6 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
/**

View File

@ -30,7 +30,6 @@ import it.unimi.dsi.fastutil.doubles.Double2ObjectMaps;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@ -38,6 +37,7 @@ import java.util.Objects;
import java.util.function.DoubleBinaryOperator;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.sk89q.worldedit.internal.expression.ExpressionHelper.check;
import static com.sk89q.worldedit.internal.expression.ExpressionHelper.checkIterations;

View File

@ -22,9 +22,11 @@ package com.sk89q.worldedit.internal.expression.invoke;
/**
* Thrown when a return is encountered, to pop the stack frames and return the value easily.
*
* <p>
* Should be caught by the executor.
* </p>
*/
class ReturnException extends RuntimeException {
public class ReturnException extends RuntimeException {
private final Double result;

View File

@ -19,8 +19,6 @@
package com.sk89q.worldedit.internal.registry;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.NoMatchException;
@ -31,6 +29,8 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An abstract implementation of a factory for internal usage.
*
@ -58,7 +58,9 @@ public abstract class AbstractFactory<E> {
/**
* Gets an immutable list of parsers.
*
* <p>
* To add parsers, use the register method.
* </p>
*
* @return the parsers
*/
@ -82,12 +84,12 @@ public abstract class AbstractFactory<E> {
public List<String> getSuggestions(String input) {
return parsers.stream().flatMap(
p -> p.getSuggestions(input)
p -> p.getSuggestions(input)
).collect(Collectors.toList());
}
/**
* Registers an InputParser to this factory
* Registers an InputParser to this factory.
*
* @param inputParser The input parser
*/

View File

@ -25,7 +25,7 @@ public class BiomeMath {
// From BiomeArray / BiomeContainer
public static final int HORIZONTAL_SECTION_COUNT = (int) Math.round(Math.log(16.0D) / Math.log(2.0D)) - 2;
public static final int VERTICAL_SECTION_COUNT = (int)Math.round(Math.log(256.0D) / Math.log(2.0D)) - 2;
public static final int VERTICAL_SECTION_COUNT = (int) Math.round(Math.log(256.0D) / Math.log(2.0D)) - 2;
public static final int HORIZONTAL_BIT_MASK = (1 << HORIZONTAL_SECTION_COUNT) - 1;
public static final int VERTICAL_BIT_MASK = (1 << VERTICAL_SECTION_COUNT) - 1;
@ -41,9 +41,9 @@ public class BiomeMath {
* @return the index into the standard MC biome array
*/
public static int computeBiomeIndex(int x, int y, int z) {
int l = x & HORIZONTAL_BIT_MASK;
int m = MathHelper.clamp(y, 0, VERTICAL_BIT_MASK);
int n = z & HORIZONTAL_BIT_MASK;
int l = (x >> 2) & HORIZONTAL_BIT_MASK;
int m = MathHelper.clamp(y >> 2, 0, VERTICAL_BIT_MASK);
int n = (z >> 2) & HORIZONTAL_BIT_MASK;
return m << HORIZONTAL_SECTION_COUNT + HORIZONTAL_SECTION_COUNT
| n << HORIZONTAL_SECTION_COUNT
| l;

View File

@ -0,0 +1,109 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.util;
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.lang.reflect.Method;
import java.util.stream.Stream;
public class DeprecationUtil {
private DeprecationUtil() {
}
/**
* Verify that one of the two functions is overridden. Caller method must be the new method,
* annotated with {@link NonAbstractForCompatibility}.
*
* @param implementingClass the result of calling {@link Object#getClass()}
*/
public static void checkDelegatingOverride(Class<?> implementingClass) {
// pull the information about the caller
StackTraceElement caller = Throwables.lazyStackTrace(new Throwable()).get(1);
// find the matching caller method
Method callingMethod = getCallingMethod(caller);
NonAbstractForCompatibility annotation =
callingMethod.getAnnotation(NonAbstractForCompatibility.class);
// get the deprecated method
Method deprecatedMethod;
try {
deprecatedMethod = implementingClass.getMethod(
annotation.delegateName(), annotation.delegateParams()
);
} catch (NoSuchMethodException e) {
throw new AssertionError(
"Missing method referenced by " + NonAbstractForCompatibility.class, e
);
}
// Check if the deprecated method was overridden. If the declaring class is the caller's
// class, then it wasn't. That means that the caller method (i.e. the new method) should be
// overridden by the implementing class.
// There's no need to check if the new method has been overridden, since the only other
// way this could be reached is if someone calls `super.xyz`, which they have no reason to.
if (deprecatedMethod.getDeclaringClass().getName().equals(caller.getClassName())) {
throw new IllegalStateException("Class " + implementingClass.getName()
+ " must override " + methodToString(callingMethod));
}
}
private static Method getCallingMethod(StackTraceElement callerInfo) {
Method[] declaredMethods;
try {
declaredMethods = Class.forName(callerInfo.getClassName()).getDeclaredMethods();
} catch (ClassNotFoundException e) {
throw new AssertionError("Caller class missing?", e);
}
for (Method declaredMethod : declaredMethods) {
if (declaredMethod.isAnnotationPresent(NonAbstractForCompatibility.class)
&& declaredMethod.getName().equals(callerInfo.getMethodName())) {
return declaredMethod;
}
}
throw new IllegalStateException("Failed to find caller method "
+ callerInfo.getMethodName() + " annotated with " + NonAbstractForCompatibility.class);
}
private static String methodToString(Method method) {
StringBuilder builder = new StringBuilder(method.getDeclaringClass().getCanonicalName())
.append('.')
.append(method.getName())
.append('(');
Joiner.on(", ").appendTo(builder, Stream.of(method.getParameterTypes())
.map(Class::getSimpleName)
.iterator());
builder.append(')');
return builder.toString();
}
public static boolean isSign(BlockType blockType) {
@SuppressWarnings("deprecation")
BlockType sign = BlockTypes.SIGN;
@SuppressWarnings("deprecation")
BlockType wallSign = BlockTypes.WALL_SIGN;
return blockType == sign || blockType == wallSign
|| BlockCategories.SIGNS.contains(blockType);
}
}

View File

@ -0,0 +1,57 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.util;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The annotated method is only non-{@code abstract} for compatibility with old subclasses,
* and will be made {@code abstract} in the next major version of WorldEdit.
*
* <p>
* Any new subclasses <em>must</em> override the annotated method, failing to do so will result in
* an exception at runtime.
* </p>
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NonAbstractForCompatibility {
// Note that this annotation only functions properly if no other method in the same class
// shares the name of the annotated function AND is also annotated with this annotation.
// Otherwise, we cannot uniquely determine the calling method via reflection hacks.
// This could be changed, but it's not currently necessary.
/**
* The name of the method delegated to by the annotated method.
*/
String delegateName();
/**
* The parameter types of the method delegated to by the annotated method.
*/
Class<?>[] delegateParams();
}

View File

@ -77,12 +77,16 @@ public final class Substring {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Substring substring1 = (Substring) o;
return start == substring1.start &&
end == substring1.end &&
substring.equals(substring1.substring);
return start == substring1.start
&& end == substring1.end
&& substring.equals(substring1.substring);
}
@Override
@ -92,10 +96,10 @@ public final class Substring {
@Override
public String toString() {
return "Substring{" +
"substring='" + substring + "'" +
",start=" + start +
",end=" + end +
"}";
return "Substring{"
+ "substring='" + substring + "'"
+ ",start=" + start
+ ",end=" + end
+ "}";
}
}