Update FaWe #7

Zusammengeführt
Lixfel hat 467 Commits von update nach main 2024-11-28 22:27:32 +01:00 zusammengeführt
30 geänderte Dateien mit 435 neuen und 321 gelöschten Zeilen
Nur Änderungen aus Commit ee5d1caa2c werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -3082,8 +3082,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
) <= 0) {
return null;
}
int newType = (int) typeVariable.getValue();
int newData = (int) dataVariable.getValue();
int newType = (int) typeVariable.value();
int newData = (int) dataVariable.value();
if (newType != typeVar || newData != dataVar) {
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(newType, newData);
return state == null ? defaultMaterial : state.toBaseBlock();
@ -3181,9 +3181,9 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
// transform
expression.evaluate(new double[]{scaled.x(), scaled.y(), scaled.z()}, timeout);
int xv = (int) Math.floor(x.getValue() * unit.x() + zero2.x());
int yv = (int) Math.floor(y.getValue() * unit.y() + zero2.y());
int zv = (int) Math.floor(z.getValue() * unit.z() + zero2.z());
int xv = (int) Math.floor(x.value() * unit.x() + zero2.x());
int yv = (int) Math.floor(y.value() * unit.y() + zero2.y());
int zv = (int) Math.floor(z.value() * unit.z() + zero2.z());
BlockState get;
if (yv >= minY && yv <= maxY) {

Datei anzeigen

@ -23,27 +23,10 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
/**
* Items of metadata about shared clipboards.
*
* @param format the format of the clipboard
* @param name the name of the clipboard
* @param author the author of the clipboard
*/
public class ClipboardShareMetadata {
private final ClipboardFormat format;
private final String name;
private final String author;
public ClipboardShareMetadata(ClipboardFormat format, String name, String author) {
this.format = format;
this.name = name;
this.author = author;
}
public ClipboardFormat format() {
return this.format;
}
public String name() {
return this.name;
}
public String author() {
return this.author;
}
public record ClipboardShareMetadata(ClipboardFormat format, String name, String author) {
}

Datei anzeigen

@ -167,24 +167,14 @@ public class Deform implements Contextual<Operation> {
);
}
private static final class DeformOperation implements Operation {
private final Extent destination;
private final Region region;
private final Vector3 zero;
private final Vector3 unit;
private final String expression;
private final int timeout;
private DeformOperation(Extent destination, Region region, Vector3 zero, Vector3 unit, String expression, int timeout) {
this.destination = destination;
this.region = region;
this.zero = zero;
this.unit = unit;
this.expression = expression;
this.timeout = timeout;
}
private record DeformOperation(
Extent destination,
Region region,
Vector3 zero,
Vector3 unit,
String expression, //FAWE: Expression -> String
int timeout
) implements Operation {
@Override
public Operation resume(RunContext run) throws WorldEditException {
try {

Datei anzeigen

@ -87,7 +87,7 @@ public interface Mask {
} else if (this instanceof Masks.AlwaysFalse) {
return Masks.ALWAYS_TRUE;
} else if (this instanceof Masks.NegatedMask) {
return ((Masks.NegatedMask) this).mask;
return ((Masks.NegatedMask) this).mask();
}
return new InverseMask(this);
}

Datei anzeigen

@ -211,15 +211,7 @@ public final class Masks {
}
//FAWE start - protected > private
protected static class NegatedMask implements Mask {
//FAWE end
protected final Mask mask;
private NegatedMask(Mask mask) {
this.mask = mask;
}
protected record NegatedMask(Mask mask) implements Mask {
@Override
public boolean test(BlockVector3 vector) {
@ -245,13 +237,7 @@ public final class Masks {
}
private static class NegatedMask2D implements Mask2D {
private final Mask2D mask;
private NegatedMask2D(Mask2D mask) {
this.mask = mask;
}
private record NegatedMask2D(Mask2D mask) implements Mask2D {
@Override
public boolean test(BlockVector2 vector) {

Datei anzeigen

@ -33,34 +33,30 @@ import static com.google.common.base.Preconditions.checkNotNull;
* <p>This biome change does not have an {@link Extent} assigned to it because
* one will be taken from the passed {@link UndoContext}. If the context
* does not have an extent (it is null), cryptic errors may occur.</p>
*
* @param position the position
* @param previous the previous biome
* @param current the current biome
*/
public class BiomeChange3D implements Change {
private final BlockVector3 position;
private final BiomeType previous;
private final BiomeType current;
public record BiomeChange3D(BlockVector3 position, BiomeType previous, BiomeType current) implements Change {
/**
* Create a new biome change.
*
* @param position the position
* @param previous the previous biome
* @param current the current biome
*/
public BiomeChange3D(BlockVector3 position, BiomeType previous, BiomeType current) {
public BiomeChange3D {
checkNotNull(position);
checkNotNull(previous);
checkNotNull(current);
this.position = position;
this.previous = previous;
this.current = current;
}
/**
* Get the position.
*
* @return the position
* @deprecated Use {@link #position()}.
*/
@Deprecated(forRemoval = true, since = "TODO")
public BlockVector3 getPosition() {
return position;
}
@ -69,7 +65,9 @@ public class BiomeChange3D implements Change {
* Get the previous biome.
*
* @return the previous biome
* @deprecated Use {@link #previous()}.
*/
@Deprecated(forRemoval = true, since = "TODO")
public BiomeType getPrevious() {
return previous;
}
@ -78,7 +76,9 @@ public class BiomeChange3D implements Change {
* Get the current biome.
*
* @return the current biome
* @deprecated Use {@link #current()}.
*/
@Deprecated(forRemoval = true, since = "TODO")
public BiomeType getCurrent() {
return current;
}

Datei anzeigen

@ -34,12 +34,21 @@ import static com.google.common.base.Preconditions.checkNotNull;
* <p>This block change does not have an {@link Extent} assigned to it because
* one will be taken from the passed {@link UndoContext}. If the context
* does not have an extent (it is null), cryptic errors may occur.</p>
*
* @param position the position
* @param previous the previous block
* @param current the current block
*/
public class BlockChange implements Change {
public record BlockChange(BlockVector3 position, BaseBlock previous, BaseBlock current) implements Change {
private final BlockVector3 position;
private final BaseBlock previous;
private final BaseBlock current;
/**
* Create a new block change.
*/
public BlockChange {
checkNotNull(position);
checkNotNull(previous);
checkNotNull(current);
}
/**
* Create a new block change.
@ -53,19 +62,16 @@ public class BlockChange implements Change {
BP previous,
BC current
) {
checkNotNull(position);
checkNotNull(previous);
checkNotNull(current);
this.position = position;
this.previous = previous.toBaseBlock();
this.current = current.toBaseBlock();
this(position, previous.toBaseBlock(), current.toBaseBlock());
}
/**
* Get the position.
*
* @return the position
* @deprecated use {@link #position()}
*/
@Deprecated(forRemoval = true, since = "TODO")
public BlockVector3 getPosition() {
return position;
}
@ -74,7 +80,9 @@ public class BlockChange implements Change {
* Get the previous block.
*
* @return the previous block
* @deprecated use {@link #previous()}
*/
@Deprecated(forRemoval = true, since = "TODO")
public BaseBlock getPrevious() {
return previous;
}
@ -83,7 +91,9 @@ public class BlockChange implements Change {
* Get the current block.
*
* @return the current block
* @deprecated use {@link #current()}
*/
@Deprecated(forRemoval = true, since = "TODO")
public BaseBlock getCurrent() {
return current;
}

Datei anzeigen

@ -87,16 +87,10 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter {
}
}
private static class ExceptionHandler implements Comparable<ExceptionHandler> {
final Class<? extends Throwable> cls;
final Method method;
private ExceptionHandler(Class<? extends Throwable> cls, Method method) {
this.cls = cls;
this.method = method;
}
private record ExceptionHandler(
Class<? extends Throwable> cls,
Method method
) implements Comparable<ExceptionHandler> {
@Override
public int compareTo(ExceptionHandler o) {
if (cls.equals(o.cls)) {

Datei anzeigen

@ -57,13 +57,6 @@ public class InteractionDebouncer {
return Optional.empty();
}
private static class Interaction {
public final long tick;
public final boolean result;
public Interaction(long tick, boolean result) {
this.tick = tick;
this.result = result;
}
private record Interaction(long tick, boolean result) {
}
}

Datei anzeigen

@ -23,36 +23,23 @@ import java.time.Instant;
import static java.util.Objects.requireNonNull;
public class ExecutionData {
public record ExecutionData(SlotTable slots, Functions functions, Instant deadline) {
/**
* Special execution context for evaluating constant values. As long as no variables are used,
* it can be considered constant.
* Special execution context for evaluating constant values. As long as no variables are used, it can be considered
* constant.
*/
public static final ExecutionData CONSTANT_EVALUATOR = new ExecutionData(null, null, Instant.MAX);
private final SlotTable slots;
private final Functions functions;
private final Instant deadline;
public ExecutionData(SlotTable slots, Functions functions, Instant deadline) {
this.slots = slots;
this.functions = functions;
this.deadline = deadline;
}
public SlotTable getSlots() {
@Override
public SlotTable slots() {
return requireNonNull(slots, "Cannot use variables in a constant");
}
public Functions getFunctions() {
@Override
public Functions functions() {
return requireNonNull(functions, "Cannot use functions in a constant");
}
public Instant getDeadline() {
return deadline;
}
public void checkDeadline() {
if (Instant.now().isAfter(deadline)) {
throw new ExpressionTimeoutException("Calculations exceeded time limit.");

Datei anzeigen

@ -40,6 +40,12 @@ public class ExpressionHelper {
}
}
public static void check(boolean condition, int positionInLine, String message) {
if (!condition) {
throw evalException(positionInLine, message);
}
}
public static int getErrorPosition(Token token) {
return token.getCharPositionInLine();
}
@ -49,14 +55,18 @@ public class ExpressionHelper {
}
public static EvaluationException evalException(Token token, String message) {
return evalException(getErrorPosition(token), message);
}
public static EvaluationException evalException(int positionInLine, String message) {
return new EvaluationException(
getErrorPosition(token),
message
positionInLine,
message
);
}
public static void checkIterations(int iterations, ParserRuleContext ctx) {
check(iterations <= 256, ctx, "Loop exceeded 256 iterations");
public static void checkIterations(int iterations, int positionInLine) {
check(iterations <= 256, positionInLine, "Loop exceeded 256 iterations");
}
public static MethodHandle resolveFunction(
@ -72,10 +82,10 @@ public class ExpressionHelper {
// last param is the array, turn that varargs
int keptParams = nParams - 1;
function = function.asCollector(
// collect into the last array
function.type().parameterType(nParams - 1),
// collect the variable args (args over kept)
ctx.args.size() - keptParams
// collect into the last array
function.type().parameterType(nParams - 1),
// collect the variable args (args over kept)
ctx.args.size() - keptParams
);
// re-wrap it for the inner arguments
function = function.asType(function.type().wrap());

Datei anzeigen

@ -211,8 +211,8 @@ public final class Functions {
final double cosF = Math.cos(angle);
final double sinF = Math.sin(angle);
final double xOld = x.getValue();
final double yOld = y.getValue();
final double xOld = x.value();
final double yOld = y.value();
x.setValue(xOld * cosF - yOld * sinF);
y.setValue(xOld * sinF + yOld * cosF);
@ -221,9 +221,9 @@ public final class Functions {
}
private static double swap(Variable x, Variable y) {
final double tmp = x.getValue();
final double tmp = x.value();
x.setValue(y.getValue());
x.setValue(y.value());
y.setValue(tmp);
return 0.0;
@ -391,8 +391,8 @@ public final class Functions {
private static double queryInternal(LocalSlot type, LocalSlot data, double typeId, double dataValue) {
// Compare to input values and determine return value
// -1 is a wildcard, always true
double ret = ((type.getValue() == -1 || typeId == type.getValue())
&& (data.getValue() == -1 || dataValue == data.getValue())) ? 1.0 : 0.0;
double ret = ((type.value() == -1 || typeId == type.value())
&& (data.value() == -1 || dataValue == data.value())) ? 1.0 : 0.0;
if (type instanceof Variable) {
((Variable) type).setValue(typeId);

Datei anzeigen

@ -24,19 +24,7 @@ package com.sk89q.worldedit.internal.expression;
*/
public interface LocalSlot {
final class Constant implements LocalSlot {
private final double value;
public Constant(double value) {
this.value = value;
}
@Override
public double getValue() {
return value;
}
record Constant(double value) implements LocalSlot {
@Override
public String toString() {
return String.valueOf(value);
@ -57,7 +45,7 @@ public interface LocalSlot {
}
@Override
public double getValue() {
public double value() {
return value;
}
@ -65,9 +53,8 @@ public interface LocalSlot {
public String toString() {
return String.valueOf(value);
}
}
double getValue();
double value();
}

Datei anzeigen

@ -58,7 +58,7 @@ public class SlotTable {
public OptionalDouble getSlotValue(String name) {
LocalSlot slot = slots.get(name);
return slot == null ? OptionalDouble.empty() : OptionalDouble.of(slot.getValue());
return slot == null ? OptionalDouble.empty() : OptionalDouble.of(slot.value());
}
}

Datei anzeigen

@ -106,7 +106,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
if (ctx.parent instanceof ParserRuleContext) {
checkHandle(mh, (ParserRuleContext) ctx.parent);
}
return new ExecNode(ctx, mh);
return new ExecNode(ctx.start.getCharPositionInLine(), mh);
}
private void checkHandle(MethodHandle mh, ParserRuleContext ctx) {
@ -127,7 +127,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
MethodHandles.identity(Double.class)
);
// now pass `result` into `guard`
MethodHandle result = evaluate(ctx).handle;
MethodHandle result = evaluate(ctx).handle();
return MethodHandles.collectArguments(guard, 0, result);
}
@ -151,8 +151,8 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
// easiest one of the bunch
return MethodHandles.guardWithTest(
evaluateBoolean(condition),
trueBranch == null ? NULL_DOUBLE : evaluate(trueBranch).handle,
falseBranch == null ? NULL_DOUBLE : evaluate(falseBranch).handle
trueBranch == null ? NULL_DOUBLE : evaluate(trueBranch).handle(),
falseBranch == null ? NULL_DOUBLE : evaluate(falseBranch).handle()
);
}
@ -185,10 +185,10 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
@Override
public MethodHandle visitForStatement(ExpressionParser.ForStatementContext ctx) {
return ExpressionHandles.forLoop(
evaluate(ctx.init).handle,
evaluate(ctx.init).handle(),
evaluateBoolean(ctx.condition),
evaluate(ctx.body),
evaluate(ctx.update).handle
evaluate(ctx.update).handle()
);
}
@ -235,7 +235,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
RETURN_STATEMENT_BASE,
0,
// map the Double back to ExecutionData via the returnValue
evaluate(ctx.value).handle
evaluate(ctx.value).handle()
);
}
@ -262,7 +262,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
@Override
public MethodHandle visitExpressionStatement(ExpressionParser.ExpressionStatementContext ctx) {
return evaluate(ctx.expression()).handle;
return evaluate(ctx.expression()).handle();
}
@Override
@ -271,7 +271,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
int opType = ctx.op.getType();
return ExpressionHandles.call(data -> {
LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target);
double value = variable.getValue();
double value = variable.value();
double result = value;
if (opType == INCREMENT) {
value++;
@ -289,7 +289,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
int opType = ctx.op.getType();
return ExpressionHandles.call(data -> {
LocalSlot.Variable variable = ExpressionHandles.getVariable(data, target);
double value = variable.getValue();
double value = variable.value();
if (opType == INCREMENT) {
value++;
} else {
@ -547,7 +547,7 @@ class CompilingVisitor extends ExpressionBaseVisitor<MethodHandle> {
value = arg;
} else {
variable = ExpressionHandles.getVariable(data, target);
value = variable.getValue();
value = variable.value();
switch (type) {
case POWER_ASSIGN:
value = Math.pow(value, arg);

Datei anzeigen

@ -19,18 +19,7 @@
package com.sk89q.worldedit.internal.expression.invoke;
import org.antlr.v4.runtime.ParserRuleContext;
import java.lang.invoke.MethodHandle;
class ExecNode {
final ParserRuleContext ctx;
final MethodHandle handle;
ExecNode(ParserRuleContext ctx, MethodHandle handle) {
this.ctx = ctx;
this.handle = handle;
}
record ExecNode(int positionInLine, MethodHandle handle) {
}

Datei anzeigen

@ -200,7 +200,7 @@ class ExpressionHandles {
static LocalSlot.Variable initVariable(ExecutionData data, Token nameToken) {
String name = nameToken.getText();
return data.getSlots().initVariable(name)
return data.slots().initVariable(name)
.orElseThrow(() -> ExpressionHelper.evalException(
nameToken, "Cannot overwrite non-variable '" + name + "'"
));
@ -218,7 +218,7 @@ class ExpressionHandles {
static LocalSlot.Variable getVariable(ExecutionData data, Token nameToken) {
String name = nameToken.getText();
LocalSlot slot = data.getSlots().getSlot(name)
LocalSlot slot = data.slots().getSlot(name)
.orElseThrow(varNotInitException(nameToken));
if (!(slot instanceof LocalSlot.Variable)) {
throw ExpressionHelper.evalException(
@ -230,7 +230,7 @@ class ExpressionHandles {
static double getSlotValue(ExecutionData data, Token nameToken) {
String name = nameToken.getText();
return data.getSlots().getSlotValue(name)
return data.slots().getSlotValue(name)
.orElseThrow(varNotInitException(nameToken));
}
@ -302,11 +302,11 @@ class ExpressionHandles {
standardInvoke(init, data);
}
while ((boolean) standardInvoke(condition, data)) {
checkIterations(iterations, body.ctx);
checkIterations(iterations, body.positionInLine());
data.checkDeadline();
iterations++;
try {
result = (Double) standardInvoke(body.handle, data);
result = (Double) standardInvoke(body.handle(), data);
} catch (BreakException ex) {
if (!ex.doContinue) {
break;
@ -331,11 +331,11 @@ class ExpressionHandles {
Double result = null;
int iterations = 0;
do {
checkIterations(iterations, body.ctx);
checkIterations(iterations, body.positionInLine());
data.checkDeadline();
iterations++;
try {
result = (Double) standardInvoke(body.handle, data);
result = (Double) standardInvoke(body.handle(), data);
} catch (BreakException ex) {
if (!ex.doContinue) {
break;
@ -369,12 +369,12 @@ class ExpressionHandles {
double last = (double) standardInvoke(getLast, data);
LocalSlot.Variable variable = initVariable(data, counterToken);
for (double i = first; i <= last; i++) {
checkIterations(iterations, body.ctx);
checkIterations(iterations, body.positionInLine());
data.checkDeadline();
iterations++;
variable.setValue(i);
try {
result = (Double) standardInvoke(body.handle, data);
result = (Double) standardInvoke(body.handle(), data);
} catch (BreakException ex) {
if (!ex.doContinue) {
break;
@ -406,10 +406,10 @@ class ExpressionHandles {
if (falling || entry.getDoubleKey() == value) {
matched = true;
try {
evaluated = (Double) standardInvoke(entry.getValue().handle, data);
evaluated = (Double) standardInvoke(entry.getValue().handle(), data);
falling = true;
} catch (BreakException brk) {
check(!brk.doContinue, entry.getValue().ctx, "Cannot continue in a switch");
check(!brk.doContinue, entry.getValue().positionInLine(), "Cannot continue in a switch");
falling = false;
break;
}
@ -418,9 +418,9 @@ class ExpressionHandles {
// This if is like the one in the loop, default's "case" is `!matched` & present
if ((falling || !matched) && defaultCase != null) {
try {
evaluated = (Double) standardInvoke(defaultCase.handle, data);
evaluated = (Double) standardInvoke(defaultCase.handle(), data);
} catch (BreakException brk) {
check(!brk.doContinue, defaultCase.ctx, "Cannot continue in a switch");
check(!brk.doContinue, defaultCase.positionInLine(), "Cannot continue in a switch");
}
}
return evaluated;

Datei anzeigen

@ -19,6 +19,9 @@
package com.sk89q.worldedit.registry;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
/**
* Represents an objects that can be added to a registry and referenced by an id which is unique within its registry.
*/
@ -28,7 +31,24 @@ public interface Keyed {
* The id of this object in the registry. Must be unique, and lowercase. Certain registries (e.g Namespaced ones) may have additional restrictions.
*
* @return an id
* @deprecated Use {@link #id()} instead.
*/
String getId();
@Deprecated(forRemoval = true, since = "TODO")
default String getId() {
return id();
}
/**
* The id of this object in the registry. Must be unique and lowercase. Certain registries (e.g namespaced ones)
* may have additional restrictions.
*
* @return an id
* @since TODO
*/
@NonAbstractForCompatibility(delegateName = "getId", delegateParams = {})
default String id() {
DeprecationUtil.checkDelegatingOverride(getClass());
return getId();
}
}

Datei anzeigen

@ -0,0 +1,52 @@
/*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
//FAWE: not in use (yet)
public record Placement(PlacementType placementType, BlockVector3 offset) {
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return placementType.getPlacementPosition(selector, actor).add(offset);
}
public boolean canBeUsedBy(Actor actor) {
return placementType.canBeUsedBy(actor);
}
public Component getInfo() {
if (offset.equals(BlockVector3.ZERO)) {
return TranslatableComponent.of(placementType.getTranslationKey());
} else {
return TranslatableComponent.of(
placementType.getTranslationKeyWithOffset(),
TextComponent.of(offset.getX()),
TextComponent.of(offset.getY()),
TextComponent.of(offset.getZ())
);
}
}
}

Datei anzeigen

@ -0,0 +1,119 @@
/*
* 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 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.session;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.RegionSelector;
import static com.google.common.base.Preconditions.checkNotNull;
//FAWE: not in use (yet)
public enum PlacementType {
WORLD("worldedit.toggleplace.world", "worldedit.toggleplace.world-offset") {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return BlockVector3.ZERO;
}
},
PLAYER("worldedit.toggleplace.player", "worldedit.toggleplace.player-offset") {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
if (!canBeUsedBy(actor)) {
throw new IncompleteRegionException();
}
return ((Locatable) actor).getBlockLocation().toVector().toBlockPoint();
}
@Override
public boolean canBeUsedBy(Actor actor) {
checkNotNull(actor);
return actor instanceof Locatable;
}
},
HERE(null, null) {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
throw new IllegalStateException("PlacementType.HERE cannot be used. Use PLAYER or WORLD instead.");
}
@Override
public boolean canBeUsedBy(Actor actor) {
return PLAYER.canBeUsedBy(actor);
}
@Override
public String getTranslationKey() {
throw new IllegalStateException("PlacementType.HERE cannot be used. Use PLAYER or WORLD instead.");
}
@Override
public String getTranslationKeyWithOffset() {
throw new IllegalStateException("PlacementType.HERE cannot be used. Use PLAYER or WORLD instead.");
}
},
POS1("worldedit.toggleplace.pos1", "worldedit.toggleplace.pos1-offset") {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return selector.getPrimaryPosition();
}
},
MIN("worldedit.toggleplace.min", "worldedit.toggleplace.min-offset") {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return selector.getRegion().getMinimumPoint();
}
},
MAX("worldedit.toggleplace.max", "worldedit.toggleplace.max-offset") {
@Override
public BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException {
return selector.getRegion().getMaximumPoint();
}
};
private final String translationKey;
private final String translationKeyWithOffset;
PlacementType(String translationKey, String translationKeyWithOffset) {
this.translationKey = translationKey;
this.translationKeyWithOffset = translationKeyWithOffset;
}
public abstract BlockVector3 getPlacementPosition(RegionSelector selector, Actor actor) throws IncompleteRegionException;
public boolean canBeUsedBy(Actor actor) {
return true;
}
public String getTranslationKey() {
return translationKey;
}
public String getTranslationKeyWithOffset() {
return translationKeyWithOffset;
}
}

Datei anzeigen

@ -22,46 +22,38 @@ package com.sk89q.worldedit.util;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Represents a block located at some position.
*/
public final class LocatedBlock {
public record LocatedBlock(BlockVector3 location, BaseBlock block) {
private final BlockVector3 location;
private final BaseBlock block;
public LocatedBlock(BlockVector3 location, BaseBlock block) {
this.location = checkNotNull(location);
this.block = checkNotNull(block);
public LocatedBlock {
checkNotNull(location);
checkNotNull(block);
}
/**
* Gets the location.
*
* @return The location
* @deprecated This class is now a record. Use {@link #location()} instead.
*/
@Deprecated(forRemoval = true, since = "TODO")
public BlockVector3 getLocation() {
return location;
return this.location;
}
/**
* Gets the block.
*
* @return The block
* @deprecated This class is now a record. Use {@link #block()} instead.
*/
@Deprecated(forRemoval = true, since = "TODO")
public BaseBlock getBlock() {
return block;
}
@Override
public int hashCode() {
return Objects.hash(location, block);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (this.getClass() != obj.getClass()) {
return false;
}
LocatedBlock lb = (LocatedBlock) obj;
return Objects.equals(location, lb.location) && Objects.equals(block, lb.block);
return this.block;
}
}

Datei anzeigen

@ -168,16 +168,7 @@ public class DataReport implements Report {
}
}
private static class Line {
private final String key;
private final String value;
public Line(String key, String value) {
this.key = key;
this.value = value;
}
private record Line(String key, String value) {
}
}

Datei anzeigen

@ -28,21 +28,32 @@ import com.sk89q.worldedit.registry.NamespacedRegistry;
/**
* All the types of biomes in the game.
*/
//FAWE start - RegistryItem
//FAWE start - RegistryItem + not a record (legacyId + internalId need mutability)
public class BiomeType implements RegistryItem, Keyed, BiomePattern {
//FAWE end
public static final NamespacedRegistry<BiomeType> REGISTRY = new NamespacedRegistry<>("biome type", true);
//FAWE start
private final String id;
private int legacyId = -1;
private int internalId;
//FAWE start
public BiomeType(String id) {
this.id = id;
}
/**
* Gets the ID of this biome.
*
* @return The id
* @since TODO
*/
@Override
public String id() {
return this.id;
}
public int getLegacyId() {
return legacyId;
}
@ -60,13 +71,14 @@ public class BiomeType implements RegistryItem, Keyed, BiomePattern {
public int getInternalId() {
return internalId;
}
//FAWE end
/**
* Gets the ID of this biome.
*
* @return The id
* @deprecated use {@link #id()}
*/
@Deprecated(forRemoval = true, since = "TODO")
@Override
public String getId() {
return this.id;
@ -74,20 +86,19 @@ public class BiomeType implements RegistryItem, Keyed, BiomePattern {
@Override
public String toString() {
return getId();
return id();
}
@Override
public int hashCode() {
//FAWE start - internalId > hashCode
return this.internalId; // stop changing this
//FAWE end
return this.internalId; // stop changing this (ok)
}
@Override
public boolean equals(Object obj) {
return obj instanceof BiomeType && this.id.equals(((BiomeType) obj).id);
}
//FAWE end
@Override
public BiomeType applyBiome(BlockVector3 position) {

Datei anzeigen

@ -23,13 +23,15 @@ import com.fastasyncworldedit.core.registry.RegistryItem;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
//FAWE start - implements RegistryItem
//FAWE start - implements RegistryItem, not a record (internalId needs mutability)
public class EntityType implements RegistryItem, Keyed {
//FAWE end
public static final NamespacedRegistry<EntityType> REGISTRY = new NamespacedRegistry<>("entity type", true);
//FAWE start
private final String id;
private int internalId;
public EntityType(String id) {
// If it has no namespace, assume minecraft.
@ -39,14 +41,28 @@ public class EntityType implements RegistryItem, Keyed {
this.id = id;
}
/**
* Gets the id of this entity type.
*
* @return the id
* @since TODO
*/
public String id() {
return this.id;
}
/**
* Gets the id of this entity type.
*
* @return the id
* @deprecated use {@link #id()}
*/
@Deprecated(forRemoval = true, since = "TODO")
@Override
public String getId() {
return this.id;
}
//FAWE start
private int internalId;
@Override
public void setInternalId(int internalId) {
this.internalId = internalId;
@ -64,14 +80,15 @@ public class EntityType implements RegistryItem, Keyed {
* @return The name, or ID
*/
public String getName() {
return getId();
return id();
}
@Override
public String toString() {
return getId();
return id();
}
//FAWE start
@Override
public int hashCode() {
return this.id.hashCode();
@ -81,5 +98,6 @@ public class EntityType implements RegistryItem, Keyed {
public boolean equals(Object obj) {
return obj instanceof EntityType && this.id.equals(((EntityType) obj).id);
}
//FAWE end
}

Datei anzeigen

@ -24,15 +24,15 @@ import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
/**
* Minecraft now has a 'fluid' system. This is a
* stub class to represent what it may be in the future.
* Minecraft now has a 'fluid' system. This is a stub class to represent what it may be in the future.
*/
//FAWE start - implements RegistryItem
//FAWE start - implements RegistryItem, not a record (internalId needs mutability)
public class FluidType implements RegistryItem, Keyed {
//FAWE end
public static final NamespacedRegistry<FluidType> REGISTRY = new NamespacedRegistry<>("fluid type");
//FAWE start
private final String id;
public FluidType(String id) {
@ -43,7 +43,19 @@ public class FluidType implements RegistryItem, Keyed {
* Gets the ID of this block.
*
* @return The id
* @since TODO
*/
public String id() {
return this.id;
}
/**
* Gets the ID of this block.
*
* @return The id
* @deprecated use {@link #id()}
*/
@Deprecated(forRemoval = true, since = "TODO")
@Override
public String getId() {
return this.id;
@ -67,7 +79,7 @@ public class FluidType implements RegistryItem, Keyed {
@Override
public String toString() {
return getId();
return id();
}
@Override

Datei anzeigen

@ -22,43 +22,21 @@ package com.sk89q.worldedit.world.gamemode;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.Registry;
public class GameMode implements Keyed {
public record GameMode(String id) implements Keyed {
public static final Registry<GameMode> REGISTRY = new Registry<>("game mode");
private final String id;
public GameMode(String id) {
this.id = id;
}
@Override
public String getId() {
return this.id;
}
/**
* Gets the name of this game mode, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
public String getName() {
return getId();
return id();
}
@Override
public String toString() {
return getId();
return id();
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof GameMode && this.id.equals(((GameMode) obj).id);
}
}

Datei anzeigen

@ -19,20 +19,53 @@
package com.sk89q.worldedit.world.registry;
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;
public interface ItemMaterial {
/**
* Gets the the maximum quantity of this item that can be in a single stack.
*
* @return the maximum quantity
* @deprecated Use {@link #maxStackSize()} instead.
*/
@Deprecated(forRemoval = true, since = "TODO")
default int getMaxStackSize() {
return maxStackSize();
}
/**
* Gets the the maximum quantity of this item that can be in a single stack.
*
* @return the maximum quantity
* @since TODO
*/
int getMaxStackSize();
@NonAbstractForCompatibility(delegateName = "getMaxStackSize", delegateParams = {})
default int maxStackSize() {
DeprecationUtil.checkDelegatingOverride(getClass());
return getMaxStackSize();
}
/**
* Gets the the maximum damage this item can take before being broken.
*
* @return the maximum damage, or 0 if not applicable
* @deprecated Use {@link #maxDamage()} instead.
*/
int getMaxDamage();
@Deprecated(forRemoval = true, since = "TODO")
default int getMaxDamage() {
return maxDamage();
}
/**
* Gets the the maximum damage this item can take before being broken.
*
* @return the maximum damage, or 0 if not applicable
* @since TODO
*/
@NonAbstractForCompatibility(delegateName = "getMaxDamage", delegateParams = {})
default int maxDamage() {
DeprecationUtil.checkDelegatingOverride(getClass());
return getMaxDamage();
}
}

Datei anzeigen

@ -34,13 +34,13 @@ public class PassthroughItemMaterial implements ItemMaterial {
}
@Override
public int getMaxStackSize() {
return itemMaterial.getMaxStackSize();
public int maxStackSize() {
return itemMaterial.maxStackSize();
}
@Override
public int getMaxDamage() {
return itemMaterial.getMaxDamage();
public int maxDamage() {
return itemMaterial.maxDamage();
}
}

Datei anzeigen

@ -19,24 +19,6 @@
package com.sk89q.worldedit.world.registry;
public class SimpleItemMaterial implements ItemMaterial {
private final int maxStackSize;
private final int maxDamage;
public SimpleItemMaterial(int maxStackSize, int maxDamage) {
this.maxStackSize = maxStackSize;
this.maxDamage = maxDamage;
}
@Override
public int getMaxStackSize() {
return maxStackSize;
}
@Override
public int getMaxDamage() {
return maxDamage;
}
public record SimpleItemMaterial(int maxStackSize, int maxDamage) implements ItemMaterial {
}

Datei anzeigen

@ -22,43 +22,20 @@ package com.sk89q.worldedit.world.weather;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.Registry;
public class WeatherType implements Keyed {
public record WeatherType(String id) implements Keyed {
public static final Registry<WeatherType> REGISTRY = new Registry<>("weather type");
private final String id;
public WeatherType(String id) {
this.id = id;
}
@Override
public String getId() {
return this.id;
}
/**
* Gets the name of this weather, or the ID if the name cannot be found.
*
* @return The name, or ID
*/
public String getName() {
return getId();
return id();
}
@Override
public String toString() {
return getId();
return id();
}
@Override
public int hashCode() {
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof WeatherType && this.id.equals(((WeatherType) obj).id);
}
}