diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 2e5e3c2ef..1469ffb96 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -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) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/ClipboardShareMetadata.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/ClipboardShareMetadata.java index 2e5f6c042..a670ea7cc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/ClipboardShareMetadata.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/share/ClipboardShareMetadata.java @@ -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) { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index b4ccd0a55..6dea78892 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -167,24 +167,14 @@ public class Deform implements Contextual { ); } - 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 { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java index 3c4cb1378..94141278d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java @@ -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); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index d3cb4cad7..478d2732a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -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) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BiomeChange3D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BiomeChange3D.java index 74a16e90e..1106899f8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BiomeChange3D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BiomeChange3D.java @@ -33,34 +33,30 @@ import static com.google.common.base.Preconditions.checkNotNull; *

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.

+ * + * @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; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java index ec9bb104d..16fc50e0d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java @@ -34,12 +34,21 @@ import static com.google.common.base.Preconditions.checkNotNull; *

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.

+ * + * @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; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/ExceptionConverterHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/ExceptionConverterHelper.java index 73f76280e..64e78250a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/ExceptionConverterHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/exception/ExceptionConverterHelper.java @@ -87,16 +87,10 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter { } } - private static class ExceptionHandler implements Comparable { - - final Class cls; - final Method method; - - private ExceptionHandler(Class cls, Method method) { - this.cls = cls; - this.method = method; - } - + private record ExceptionHandler( + Class cls, + Method method + ) implements Comparable { @Override public int compareTo(ExceptionHandler o) { if (cls.equals(o.cls)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/event/InteractionDebouncer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/event/InteractionDebouncer.java index b33570cd9..37e9442b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/event/InteractionDebouncer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/event/InteractionDebouncer.java @@ -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) { } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExecutionData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExecutionData.java index 1fef5aa81..bcf04b907 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExecutionData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExecutionData.java @@ -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."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExpressionHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExpressionHelper.java index 0afeb6dd3..0521c0a50 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExpressionHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/ExpressionHelper.java @@ -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()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Functions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Functions.java index 6f3a63787..ef219e3f8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Functions.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/Functions.java @@ -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); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/LocalSlot.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/LocalSlot.java index 2b02fa036..0b2a5bc48 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/LocalSlot.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/LocalSlot.java @@ -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(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/SlotTable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/SlotTable.java index a94c9dc62..e7090f461 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/SlotTable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/SlotTable.java @@ -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()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java index 7645c8413..0c6e87810 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java @@ -106,7 +106,7 @@ class CompilingVisitor extends ExpressionBaseVisitor { 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 { 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 { // 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 { @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 { 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 { @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 { 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 { 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 { value = arg; } else { variable = ExpressionHandles.getVariable(data, target); - value = variable.getValue(); + value = variable.value(); switch (type) { case POWER_ASSIGN: value = Math.pow(value, arg); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExecNode.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExecNode.java index 6c53a13e5..86a944f03 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExecNode.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExecNode.java @@ -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) { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExpressionHandles.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExpressionHandles.java index a2d0ad483..dab0be01b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExpressionHandles.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/ExpressionHandles.java @@ -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; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Keyed.java b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Keyed.java index e892ba1f1..b31e62d7f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Keyed.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/registry/Keyed.java @@ -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(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java new file mode 100644 index 000000000..3171bc66e --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/Placement.java @@ -0,0 +1,52 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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()) + ); + } + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PlacementType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PlacementType.java new file mode 100644 index 000000000..90b6ff01e --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PlacementType.java @@ -0,0 +1,119 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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; + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java index 2ea1d1d59..ff946e458 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java @@ -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; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/DataReport.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/DataReport.java index 8a18f07b3..62e83a7b0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/DataReport.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/report/DataReport.java @@ -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) { } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java index e8501da69..e7ec152a9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/biome/BiomeType.java @@ -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 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) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java index 5a530c8a6..1faf3bc4c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/entity/EntityType.java @@ -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 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 } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java index d62d13b51..1642ed4e9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/fluid/FluidType.java @@ -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 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 diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java index 312caa3b5..94b7b7cfe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/gamemode/GameMode.java @@ -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 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); - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemMaterial.java index 19fe653fc..db63b53a4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/ItemMaterial.java @@ -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(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/PassthroughItemMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/PassthroughItemMaterial.java index 681add8cc..e5dac8a7f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/PassthroughItemMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/PassthroughItemMaterial.java @@ -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(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleItemMaterial.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleItemMaterial.java index 40ed03515..9e552e18a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleItemMaterial.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleItemMaterial.java @@ -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 { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java index ea78ee112..4a7b3cd0c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/weather/WeatherType.java @@ -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 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); - } - }