Cleanup code for latest Java versions (#2404)

This commit is contained in:
Maddy Miller 2023-10-17 11:39:35 +10:00 committed by GitHub
parent 9587a7bd82
commit 7a18a449dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
51 changed files with 242 additions and 452 deletions

View File

@ -752,16 +752,12 @@ public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter)
* @throws WorldEditException thrown on a set error
*/
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws WorldEditException {
switch (stage) {
case BEFORE_HISTORY:
return bypassNone.setBlock(position, block);
case BEFORE_CHANGE:
return bypassHistory.setBlock(position, block);
case BEFORE_REORDER:
return bypassReorderHistory.setBlock(position, block);
default:
throw new RuntimeException("New enum entry added that is unhandled here");
}
return switch (stage) {
case BEFORE_HISTORY -> bypassNone.setBlock(position, block);
case BEFORE_CHANGE -> bypassHistory.setBlock(position, block);
case BEFORE_REORDER -> bypassReorderHistory.setBlock(position, block);
default -> throw new RuntimeException("New enum entry added that is unhandled here");
};
}
/**
@ -2519,8 +2515,8 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
}
}
final Set<BlockVector3> newOutside = new HashSet<>();
for (int i = 1; i < thickness; ++i) {
final Set<BlockVector3> newOutside = new HashSet<>();
outer: for (BlockVector3 position : region) {
for (BlockVector3 recurseDirection : recurseDirections) {
BlockVector3 neighbor = position.add(recurseDirection);
@ -2533,6 +2529,7 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
}
outside.addAll(newOutside);
newOutside.clear();
}
outer: for (BlockVector3 position : region) {
@ -2691,14 +2688,6 @@ public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double te
return setBlocks(vset, pattern);
}
private static double hypotSquare(double... pars) {
double sum = 0;
for (double d : pars) {
sum += Math.pow(d, 2);
}
return sum;
}
private static Set<BlockVector3> getBallooned(Set<BlockVector3> vset, double radius) {
Set<BlockVector3> returnset = new HashSet<>();
int ceilrad = (int) Math.ceil(radius);
@ -2712,7 +2701,7 @@ private static Set<BlockVector3> getBallooned(Set<BlockVector3> vset, double rad
for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) {
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
if (hypotSquare(loopx - tipx, loopy - tipy, loopz - tipz) <= radiusSquare) {
if (lengthSq(loopx - tipx, loopy - tipy, loopz - tipz) <= radiusSquare) {
returnset.add(BlockVector3.at(loopx, loopy, loopz));
}
}

View File

@ -24,8 +24,6 @@
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.world.World;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Creates new {@link EditSession}s. To get an instance of this factory,
* use {@link WorldEdit#getEditSessionFactory()}.

View File

@ -962,9 +962,7 @@ public void dispatchCUISelection(Actor actor) {
return;
}
if (selector instanceof CUIRegion) {
CUIRegion tempSel = (CUIRegion) selector;
if (selector instanceof CUIRegion tempSel) {
if (tempSel.getProtocolVersion() > cuiVersion) {
actor.dispatchCUIEvent(new SelectionShapeEvent(tempSel.getLegacyTypeID()));
tempSel.describeLegacyCUI(this, actor);
@ -988,9 +986,7 @@ public void describeCUI(Actor actor) {
return;
}
if (selector instanceof CUIRegion) {
CUIRegion tempSel = (CUIRegion) selector;
if (selector instanceof CUIRegion tempSel) {
if (tempSel.getProtocolVersion() > cuiVersion) {
tempSel.describeLegacyCUI(this, actor);
} else {

View File

@ -736,7 +736,7 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce
byte[] data = new byte[in.available()];
in.readFully(data);
in.close();
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
script = new String(data, StandardCharsets.UTF_8);
} catch (IOException e) {
player.printError(TranslatableComponent.of("worldedit.script.read-error", TextComponent.of(e.getMessage())));
return;

View File

@ -43,7 +43,6 @@
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.ExtendingCuboidRegionSelector;
import com.sk89q.worldedit.session.ClipboardHolder;

View File

@ -167,13 +167,12 @@ public int curve(Actor actor, EditSession editSession,
int thickness,
@Switch(name = 'h', desc = "Generate only a shell")
boolean shell) throws WorldEditException {
if (!(region instanceof ConvexPolyhedralRegion)) {
if (!(region instanceof ConvexPolyhedralRegion cpregion)) {
actor.printError(TranslatableComponent.of("worldedit.curve.invalid-type"));
return 0;
}
checkCommandArgument(thickness >= 0, "Thickness must be >= 0");
ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region;
List<BlockVector3> vectors = new ArrayList<>(cpregion.getVertices());
int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell);

View File

@ -125,8 +125,7 @@ void list(Actor actor, World world,
TextComponent.of(world.getName())
));
if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
FileSystemSnapshotDatabase db = (FileSystemSnapshotDatabase) config.snapshotDatabase;
if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase db) {
Path root = db.getRoot();
if (Files.isDirectory(root)) {
WorldEdit.logger.info("No snapshots were found for world '"

View File

@ -82,7 +82,7 @@ public void restore(Actor actor, World world, LocalSession session, EditSession
if (snapshotName != null) {
URI uri = resolveSnapshotName(config, snapshotName);
Optional<Snapshot> snapOpt = config.snapshotDatabase.getSnapshot(uri);
if (!snapOpt.isPresent()) {
if (snapOpt.isEmpty()) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-available"));
return;
}

View File

@ -30,7 +30,6 @@
import com.sk89q.worldedit.math.convolution.SnowHeightMap;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import javax.annotation.Nullable;

View File

@ -139,7 +139,7 @@ private static void printCommands(int page, Stream<Command> commandStream, Actor
List<Command> commands = commandStream
.filter(command -> command.getCondition().satisfied(store))
.sorted(byCleanName())
.collect(toList());
.toList();
String used = commandList.isEmpty() ? null : toCommandString(commandList);
CommandListBox box = new CommandListBox(

View File

@ -25,7 +25,6 @@
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockCategory;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import java.util.Arrays;
import java.util.HashSet;

View File

@ -116,14 +116,12 @@ public Mask parseFromInput(String input, ParserContext context) throws InputPars
masks.add(match);
}
switch (masks.size()) {
case 0:
return switch (masks.size()) {
case 0 ->
throw new NoMatchException(TranslatableComponent.of("worldedit.error.no-match", TextComponent.of(input)));
case 1:
return masks.get(0);
default:
return new MaskIntersection(masks);
}
case 1 -> masks.get(0);
default -> new MaskIntersection(masks);
};
}
}

View File

@ -519,10 +519,9 @@ public void dispatchCUIEvent(CUIEvent event) {
@Override
public boolean equals(Object other) {
if (!(other instanceof Player)) {
if (!(other instanceof Player other2)) {
return false;
}
Player other2 = (Player) other;
return other2.getName().equals(getName());
}

View File

@ -258,9 +258,7 @@ public World getWorldForEditing(World base) {
public <T extends Actor> T createProxyActor(T base) {
checkNotNull(base);
if (base instanceof Player) {
Player player = (Player) base;
if (base instanceof Player player) {
Player permActor = queryCapability(Capability.PERMISSIONS).matchPlayer(player);
if (permActor == null) {
permActor = player;
@ -361,10 +359,9 @@ public void handleBlockInteract(BlockInteractEvent event) {
Location location = event.getLocation();
// At this time, only handle interaction from players
if (!(actor instanceof Player)) {
if (!(actor instanceof Player player)) {
return;
}
Player player = (Player) actor;
LocalSession session = worldEdit.getSessionManager().get(actor);
Request.reset();

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.extent.clipboard;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;

View File

@ -272,115 +272,81 @@ public Clipboard read() throws IOException {
}
private String convertEntityId(String id) {
switch (id) {
case "AreaEffectCloud": return "area_effect_cloud";
case "ArmorStand": return "armor_stand";
case "CaveSpider": return "cave_spider";
case "MinecartChest": return "chest_minecart";
case "DragonFireball": return "dragon_fireball";
case "ThrownEgg": return "egg";
case "EnderDragon": return "ender_dragon";
case "ThrownEnderpearl": return "ender_pearl";
case "FallingSand": return "falling_block";
case "FireworksRocketEntity": return "fireworks_rocket";
case "MinecartFurnace": return "furnace_minecart";
case "MinecartHopper": return "hopper_minecart";
case "EntityHorse": return "horse";
case "ItemFrame": return "item_frame";
case "LeashKnot": return "leash_knot";
case "LightningBolt": return "lightning_bolt";
case "LavaSlime": return "magma_cube";
case "MinecartRideable": return "minecart";
case "MushroomCow": return "mooshroom";
case "Ozelot": return "ocelot";
case "PolarBear": return "polar_bear";
case "ThrownPotion": return "potion";
case "ShulkerBullet": return "shulker_bullet";
case "SmallFireball": return "small_fireball";
case "MinecartSpawner": return "spawner_minecart";
case "SpectralArrow": return "spectral_arrow";
case "PrimedTnt": return "tnt";
case "MinecartTNT": return "tnt_minecart";
case "VillagerGolem": return "villager_golem";
case "WitherBoss": return "wither";
case "WitherSkull": return "wither_skull";
case "PigZombie": return "zombie_pigman";
case "XPOrb":
case "xp_orb":
return "experience_orb";
case "ThrownExpBottle":
case "xp_bottle":
return "experience_bottle";
case "EyeOfEnderSignal":
case "eye_of_ender_signal":
return "eye_of_ender";
case "EnderCrystal":
case "ender_crystal":
return "end_crystal";
case "fireworks_rocket": return "firework_rocket";
case "MinecartCommandBlock":
case "commandblock_minecart":
return "command_block_minecart";
case "snowman": return "snow_golem";
case "villager_golem": return "iron_golem";
case "evocation_fangs": return "evoker_fangs";
case "evocation_illager": return "evoker";
case "vindication_illager": return "vindicator";
case "illusion_illager": return "illusioner";
default: return id;
}
return switch (id) {
case "AreaEffectCloud" -> "area_effect_cloud";
case "ArmorStand" -> "armor_stand";
case "CaveSpider" -> "cave_spider";
case "MinecartChest" -> "chest_minecart";
case "DragonFireball" -> "dragon_fireball";
case "ThrownEgg" -> "egg";
case "EnderDragon" -> "ender_dragon";
case "ThrownEnderpearl" -> "ender_pearl";
case "FallingSand" -> "falling_block";
case "FireworksRocketEntity" -> "fireworks_rocket";
case "MinecartFurnace" -> "furnace_minecart";
case "MinecartHopper" -> "hopper_minecart";
case "EntityHorse" -> "horse";
case "ItemFrame" -> "item_frame";
case "LeashKnot" -> "leash_knot";
case "LightningBolt" -> "lightning_bolt";
case "LavaSlime" -> "magma_cube";
case "MinecartRideable" -> "minecart";
case "MushroomCow" -> "mooshroom";
case "Ozelot" -> "ocelot";
case "PolarBear" -> "polar_bear";
case "ThrownPotion" -> "potion";
case "ShulkerBullet" -> "shulker_bullet";
case "SmallFireball" -> "small_fireball";
case "MinecartSpawner" -> "spawner_minecart";
case "SpectralArrow" -> "spectral_arrow";
case "PrimedTnt" -> "tnt";
case "MinecartTNT" -> "tnt_minecart";
case "VillagerGolem" -> "villager_golem";
case "WitherBoss" -> "wither";
case "WitherSkull" -> "wither_skull";
case "PigZombie" -> "zombie_pigman";
case "XPOrb", "xp_orb" -> "experience_orb";
case "ThrownExpBottle", "xp_bottle" -> "experience_bottle";
case "EyeOfEnderSignal", "eye_of_ender_signal" -> "eye_of_ender";
case "EnderCrystal", "ender_crystal" -> "end_crystal";
case "fireworks_rocket" -> "firework_rocket";
case "MinecartCommandBlock", "commandblock_minecart" -> "command_block_minecart";
case "snowman" -> "snow_golem";
case "villager_golem" -> "iron_golem";
case "evocation_fangs" -> "evoker_fangs";
case "evocation_illager" -> "evoker";
case "vindication_illager" -> "vindicator";
case "illusion_illager" -> "illusioner";
default -> id;
};
}
private String convertBlockEntityId(String id) {
switch (id) {
case "Cauldron":
return "brewing_stand";
case "Control":
return "command_block";
case "DLDetector":
return "daylight_detector";
case "Trap":
return "dispenser";
case "EnchantTable":
return "enchanting_table";
case "EndGateway":
return "end_gateway";
case "AirPortal":
return "end_portal";
case "EnderChest":
return "ender_chest";
case "FlowerPot":
return "flower_pot";
case "RecordPlayer":
return "jukebox";
case "MobSpawner":
return "mob_spawner";
case "Music":
case "noteblock":
return "note_block";
case "Structure":
return "structure_block";
case "Chest":
return "chest";
case "Sign":
return "sign";
case "Banner":
return "banner";
case "Beacon":
return "beacon";
case "Comparator":
return "comparator";
case "Dropper":
return "dropper";
case "Furnace":
return "furnace";
case "Hopper":
return "hopper";
case "Skull":
return "skull";
default:
return id;
}
return switch (id) {
case "Cauldron" -> "brewing_stand";
case "Control" -> "command_block";
case "DLDetector" -> "daylight_detector";
case "Trap" -> "dispenser";
case "EnchantTable" -> "enchanting_table";
case "EndGateway" -> "end_gateway";
case "AirPortal" -> "end_portal";
case "EnderChest" -> "ender_chest";
case "FlowerPot" -> "flower_pot";
case "RecordPlayer" -> "jukebox";
case "MobSpawner" -> "mob_spawner";
case "Music", "noteblock" -> "note_block";
case "Structure" -> "structure_block";
case "Chest" -> "chest";
case "Sign" -> "sign";
case "Banner" -> "banner";
case "Beacon" -> "beacon";
case "Comparator" -> "comparator";
case "Dropper" -> "dropper";
case "Furnace" -> "furnace";
case "Hopper" -> "hopper";
case "Skull" -> "skull";
default -> id;
};
}
private BlockState getBlockState(int id, int data) {

View File

@ -28,9 +28,7 @@
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.internal.util.VarIntIterator;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.stream.LinStream;
@ -42,8 +40,6 @@
import org.enginehub.linbus.tree.LinTagType;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.OptionalInt;
/**

View File

@ -67,16 +67,11 @@ public boolean isGround(BlockVector3 position) {
}
private BlockState getTargetBlock(int depth) {
switch (depth) {
case 0:
return BlockTypes.GRASS_BLOCK.getDefaultState();
case 1:
case 2:
case 3:
return BlockTypes.DIRT.getDefaultState();
default:
return BlockTypes.STONE.getDefaultState();
}
return switch (depth) {
case 0 -> BlockTypes.GRASS_BLOCK.getDefaultState();
case 1, 2, 3 -> BlockTypes.DIRT.getDefaultState();
default -> BlockTypes.STONE.getDefaultState();
};
}
private boolean naturalize(BlockVector3 position, int depth) throws WorldEditException {

View File

@ -27,7 +27,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -23,8 +23,6 @@
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockCategory;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**

View File

@ -28,7 +28,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -27,7 +27,6 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -21,8 +21,6 @@
import com.sk89q.worldedit.math.BlockVector3;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkArgument;
/**

View File

@ -22,8 +22,6 @@
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import javax.annotation.Nullable;
/**
* A mask that returns true whenever the block at the location is not
* an air block (it contains some other block).

View File

@ -22,8 +22,6 @@
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.collection.BlockMap;
import javax.annotation.Nullable;
/**
* A utility mask wrapper that memoizes the results of the given mask.
*

View File

@ -22,8 +22,6 @@
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
/**

View File

@ -23,8 +23,6 @@
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState;
import javax.annotation.Nullable;
public class SolidBlockMask extends AbstractExtentMask {
public SolidBlockMask(Extent extent) {

View File

@ -26,7 +26,6 @@
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class RandomStatePattern implements Pattern {

View File

@ -116,10 +116,8 @@ public static Command deprecate(Command command, String reason,
public static Optional<Component> footerWithoutDeprecation(Command command) {
return command.getFooter()
.filter(footer -> anyComponent(footer, Predicate.isEqual(DEPRECATION_MARKER)))
.map(footer -> Optional.of(
replaceDeprecation(footer)
))
.orElseGet(command::getFooter);
.map(CommandUtil::replaceDeprecation)
.or(command::getFooter);
}
public static Optional<Component> deprecationWarning(Command command) {

View File

@ -243,8 +243,7 @@ public MethodHandle visitSwitchStatement(ExpressionParser.SwitchStatementContext
ExpressionParser.SwitchLabelContext label = ctx.labels.get(i);
ExpressionParser.StatementsContext body = ctx.bodies.get(i);
ExecNode node = evaluate(body);
if (label instanceof ExpressionParser.CaseContext) {
ExpressionParser.CaseContext caseContext = (ExpressionParser.CaseContext) label;
if (label instanceof ExpressionParser.CaseContext caseContext) {
double key = (double) ExpressionHandles.constantInvoke(evaluateForValue(caseContext.constant));
ExpressionHelper.check(!cases.containsKey(key), body, "Duplicate cases detected.");
cases.put(key, node);

View File

@ -30,41 +30,27 @@ private MCDirections() {
}
public static Direction fromHanging(int i) {
switch (i) {
case 0:
return Direction.DOWN;
case 1:
return Direction.UP;
case 2:
return Direction.NORTH;
case 3:
return Direction.SOUTH;
case 4:
return Direction.WEST;
case 5:
return Direction.EAST;
default:
return Direction.DOWN;
}
return switch (i) {
case 0 -> Direction.DOWN;
case 1 -> Direction.UP;
case 2 -> Direction.NORTH;
case 3 -> Direction.SOUTH;
case 4 -> Direction.WEST;
case 5 -> Direction.EAST;
default -> Direction.DOWN;
};
}
public static int toHanging(Direction direction) {
switch (direction) {
case DOWN:
return 0;
case UP:
return 1;
case NORTH:
return 2;
case SOUTH:
return 3;
case WEST:
return 4;
case EAST:
return 5;
default:
return 0;
}
return switch (direction) {
case DOWN -> 0;
case UP -> 1;
case NORTH -> 2;
case SOUTH -> 3;
case WEST -> 4;
case EAST -> 5;
default -> 0;
};
}
public static Direction fromPre13Hanging(int i) {
@ -72,120 +58,76 @@ public static Direction fromPre13Hanging(int i) {
}
public static Direction fromHorizontalHanging(int i) {
switch (i) {
case 0:
return Direction.SOUTH;
case 1:
return Direction.WEST;
case 2:
return Direction.NORTH;
case 3:
return Direction.EAST;
default:
return Direction.NORTH;
}
return switch (i) {
case 0 -> Direction.SOUTH;
case 1 -> Direction.WEST;
case 2 -> Direction.NORTH;
case 3 -> Direction.EAST;
default -> Direction.NORTH;
};
}
public static int toHorizontalHanging(Direction direction) {
switch (direction) {
case SOUTH:
return 0;
case WEST:
return 1;
case NORTH:
return 2;
case EAST:
return 3;
default:
return 0;
}
return switch (direction) {
case SOUTH -> 0;
case WEST -> 1;
case NORTH -> 2;
case EAST -> 3;
default -> 0;
};
}
public static int fromLegacyHanging(byte i) {
switch (i) {
case 0: return 2;
case 1: return 1;
case 2: return 0;
default: return 3;
}
return switch (i) {
case 0 -> 2;
case 1 -> 1;
case 2 -> 0;
default -> 3;
};
}
public static Direction fromRotation(int i) {
switch (i) {
case 0:
return Direction.SOUTH;
case 1:
return Direction.SOUTH_SOUTHWEST;
case 2:
return Direction.SOUTHWEST;
case 3:
return Direction.WEST_SOUTHWEST;
case 4:
return Direction.WEST;
case 5:
return Direction.WEST_NORTHWEST;
case 6:
return Direction.NORTHWEST;
case 7:
return Direction.NORTH_NORTHWEST;
case 8:
return Direction.NORTH;
case 9:
return Direction.NORTH_NORTHEAST;
case 10:
return Direction.NORTHEAST;
case 11:
return Direction.EAST_NORTHEAST;
case 12:
return Direction.EAST;
case 13:
return Direction.EAST_SOUTHEAST;
case 14:
return Direction.SOUTHEAST;
case 15:
return Direction.SOUTH_SOUTHEAST;
default:
return Direction.NORTH;
}
return switch (i) {
case 0 -> Direction.SOUTH;
case 1 -> Direction.SOUTH_SOUTHWEST;
case 2 -> Direction.SOUTHWEST;
case 3 -> Direction.WEST_SOUTHWEST;
case 4 -> Direction.WEST;
case 5 -> Direction.WEST_NORTHWEST;
case 6 -> Direction.NORTHWEST;
case 7 -> Direction.NORTH_NORTHWEST;
case 8 -> Direction.NORTH;
case 9 -> Direction.NORTH_NORTHEAST;
case 10 -> Direction.NORTHEAST;
case 11 -> Direction.EAST_NORTHEAST;
case 12 -> Direction.EAST;
case 13 -> Direction.EAST_SOUTHEAST;
case 14 -> Direction.SOUTHEAST;
case 15 -> Direction.SOUTH_SOUTHEAST;
default -> Direction.NORTH;
};
}
public static int toRotation(Direction direction) {
switch (direction) {
case SOUTH:
return 0;
case SOUTH_SOUTHWEST:
return 1;
case SOUTHWEST:
return 2;
case WEST_SOUTHWEST:
return 3;
case WEST:
return 4;
case WEST_NORTHWEST:
return 5;
case NORTHWEST:
return 6;
case NORTH_NORTHWEST:
return 7;
case NORTH:
return 8;
case NORTH_NORTHEAST:
return 9;
case NORTHEAST:
return 10;
case EAST_NORTHEAST:
return 11;
case EAST:
return 12;
case EAST_SOUTHEAST:
return 13;
case SOUTHEAST:
return 14;
case SOUTH_SOUTHEAST:
return 15;
default:
return 0;
}
return switch (direction) {
case SOUTH -> 0;
case SOUTH_SOUTHWEST -> 1;
case SOUTHWEST -> 2;
case WEST_SOUTHWEST -> 3;
case WEST -> 4;
case WEST_NORTHWEST -> 5;
case NORTHWEST -> 6;
case NORTH_NORTHWEST -> 7;
case NORTH -> 8;
case NORTH_NORTHEAST -> 9;
case NORTHEAST -> 10;
case EAST_NORTHEAST -> 11;
case EAST -> 12;
case EAST_SOUTHEAST -> 13;
case SOUTHEAST -> 14;
case SOUTH_SOUTHEAST -> 15;
default -> 0;
};
}
}

View File

@ -538,11 +538,10 @@ public BlockVector3 toBlockVector3(int y) {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BlockVector2)) {
if (!(obj instanceof BlockVector2 other)) {
return false;
}
BlockVector2 other = (BlockVector2) obj;
return other.x == this.x && other.z == this.z;
}

View File

@ -688,11 +688,10 @@ public Vector3 toVector3() {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof BlockVector3)) {
if (!(obj instanceof BlockVector3 other)) {
return false;
}
BlockVector3 other = (BlockVector3) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
}

View File

@ -459,11 +459,10 @@ public Vector3 toVector3(double y) {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector2)) {
if (!(obj instanceof Vector2 other)) {
return false;
}
Vector2 other = (Vector2) obj;
return other.x == this.x && other.z == this.z;
}

View File

@ -590,11 +590,10 @@ public Vector2 toVector2() {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector3)) {
if (!(obj instanceof Vector3 other)) {
return false;
}
Vector3 other = (Vector3) obj;
return other.x == this.x && other.y == this.y && other.z == this.z;
}

View File

@ -25,7 +25,6 @@
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.registry.state.IntegerProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;

View File

@ -85,8 +85,7 @@ public Transform inverse() {
@Override
public Transform combine(Transform other) {
checkNotNull(other);
if (other instanceof CombinedTransform) {
CombinedTransform combinedOther = (CombinedTransform) other;
if (other instanceof CombinedTransform combinedOther) {
Transform[] newTransforms = new Transform[transforms.length + combinedOther.transforms.length];
System.arraycopy(transforms, 0, newTransforms, 0, transforms.length);
System.arraycopy(combinedOther.transforms, 0, newTransforms, transforms.length, combinedOther.transforms.length);

View File

@ -38,11 +38,10 @@ public Edge(Vector3 start, Vector3 end) {
@Override
public boolean equals(Object other) {
if (!(other instanceof Edge)) {
if (!(other instanceof Edge otherEdge)) {
return false;
}
Edge otherEdge = (Edge) other;
if (this.start.equals(otherEdge.end) && this.end.equals(otherEdge.start)) {
return true;
}

View File

@ -80,9 +80,7 @@ public ConvexPolyhedralRegionSelector(@Nullable World world) {
public ConvexPolyhedralRegionSelector(RegionSelector oldSelector) {
checkNotNull(oldSelector);
if (oldSelector instanceof ConvexPolyhedralRegionSelector) {
final ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector = (ConvexPolyhedralRegionSelector) oldSelector;
if (oldSelector instanceof ConvexPolyhedralRegionSelector convexPolyhedralRegionSelector) {
pos1 = convexPolyhedralRegionSelector.pos1;
region = new ConvexPolyhedralRegion(convexPolyhedralRegionSelector.region);
} else {

View File

@ -76,9 +76,7 @@ public CuboidRegionSelector(@Nullable World world) {
public CuboidRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof CuboidRegionSelector) {
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;
if (oldSelector instanceof CuboidRegionSelector cuboidRegionSelector) {
position1 = cuboidRegionSelector.position1;
position2 = cuboidRegionSelector.position2;
} else {

View File

@ -87,9 +87,7 @@ public CylinderRegionSelector(@Nullable World world) {
public CylinderRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof CylinderRegionSelector) {
final CylinderRegionSelector cylSelector = (CylinderRegionSelector) oldSelector;
if (oldSelector instanceof CylinderRegionSelector cylSelector) {
region = new CylinderRegion(cylSelector.region);
selectedCenter = cylSelector.selectedCenter;
selectedRadius = cylSelector.selectedRadius;

View File

@ -76,9 +76,7 @@ public EllipsoidRegionSelector(@Nullable World world) {
*/
public EllipsoidRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof EllipsoidRegionSelector) {
final EllipsoidRegionSelector ellipsoidRegionSelector = (EllipsoidRegionSelector) oldSelector;
if (oldSelector instanceof EllipsoidRegionSelector ellipsoidRegionSelector) {
region = new EllipsoidRegion(ellipsoidRegionSelector.getIncompleteRegion());
started = ellipsoidRegionSelector.started;
selectedRadius = ellipsoidRegionSelector.selectedRadius;

View File

@ -76,9 +76,7 @@ public Polygonal2DRegionSelector(@Nullable World world) {
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(checkNotNull(oldSelector).getIncompleteRegion().getWorld());
if (oldSelector instanceof Polygonal2DRegionSelector) {
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
if (oldSelector instanceof Polygonal2DRegionSelector polygonal2DRegionSelector) {
pos1 = polygonal2DRegionSelector.pos1;
region = new Polygonal2DRegion(polygonal2DRegionSelector.region);
} else {

View File

@ -184,81 +184,47 @@ public static List<Direction> valuesOf(int flags) {
* @return The direction, if applicable
*/
public static Optional<Direction> fromRotationIndex(int rotation) {
switch (rotation) {
case 0:
return Optional.of(SOUTH);
case 1:
return Optional.of(SOUTH_SOUTHWEST);
case 2:
return Optional.of(SOUTHWEST);
case 3:
return Optional.of(WEST_SOUTHWEST);
case 4:
return Optional.of(WEST);
case 5:
return Optional.of(WEST_NORTHWEST);
case 6:
return Optional.of(NORTHWEST);
case 7:
return Optional.of(NORTH_NORTHWEST);
case 8:
return Optional.of(NORTH);
case 9:
return Optional.of(NORTH_NORTHEAST);
case 10:
return Optional.of(NORTHEAST);
case 11:
return Optional.of(EAST_NORTHEAST);
case 12:
return Optional.of(EAST);
case 13:
return Optional.of(EAST_SOUTHEAST);
case 14:
return Optional.of(SOUTHEAST);
case 15:
return Optional.of(SOUTH_SOUTHEAST);
default:
return Optional.empty();
}
return switch (rotation) {
case 0 -> Optional.of(SOUTH);
case 1 -> Optional.of(SOUTH_SOUTHWEST);
case 2 -> Optional.of(SOUTHWEST);
case 3 -> Optional.of(WEST_SOUTHWEST);
case 4 -> Optional.of(WEST);
case 5 -> Optional.of(WEST_NORTHWEST);
case 6 -> Optional.of(NORTHWEST);
case 7 -> Optional.of(NORTH_NORTHWEST);
case 8 -> Optional.of(NORTH);
case 9 -> Optional.of(NORTH_NORTHEAST);
case 10 -> Optional.of(NORTHEAST);
case 11 -> Optional.of(EAST_NORTHEAST);
case 12 -> Optional.of(EAST);
case 13 -> Optional.of(EAST_SOUTHEAST);
case 14 -> Optional.of(SOUTHEAST);
case 15 -> Optional.of(SOUTH_SOUTHEAST);
default -> Optional.empty();
};
}
public OptionalInt toRotationIndex() {
switch (this) {
case SOUTH:
return OptionalInt.of(0);
case SOUTH_SOUTHWEST:
return OptionalInt.of(1);
case SOUTHWEST:
return OptionalInt.of(2);
case WEST_SOUTHWEST:
return OptionalInt.of(3);
case WEST:
return OptionalInt.of(4);
case WEST_NORTHWEST:
return OptionalInt.of(5);
case NORTHWEST:
return OptionalInt.of(6);
case NORTH_NORTHWEST:
return OptionalInt.of(7);
case NORTH:
return OptionalInt.of(8);
case NORTH_NORTHEAST:
return OptionalInt.of(9);
case NORTHEAST:
return OptionalInt.of(10);
case EAST_NORTHEAST:
return OptionalInt.of(11);
case EAST:
return OptionalInt.of(12);
case EAST_SOUTHEAST:
return OptionalInt.of(13);
case SOUTHEAST:
return OptionalInt.of(14);
case SOUTH_SOUTHEAST:
return OptionalInt.of(15);
default:
return OptionalInt.empty();
}
return switch (this) {
case SOUTH -> OptionalInt.of(0);
case SOUTH_SOUTHWEST -> OptionalInt.of(1);
case SOUTHWEST -> OptionalInt.of(2);
case WEST_SOUTHWEST -> OptionalInt.of(3);
case WEST -> OptionalInt.of(4);
case WEST_NORTHWEST -> OptionalInt.of(5);
case NORTHWEST -> OptionalInt.of(6);
case NORTH_NORTHWEST -> OptionalInt.of(7);
case NORTH -> OptionalInt.of(8);
case NORTH_NORTHEAST -> OptionalInt.of(9);
case NORTHEAST -> OptionalInt.of(10);
case EAST_NORTHEAST -> OptionalInt.of(11);
case EAST -> OptionalInt.of(12);
case EAST_SOUTHEAST -> OptionalInt.of(13);
case SOUTHEAST -> OptionalInt.of(14);
case SOUTH_SOUTHEAST -> OptionalInt.of(15);
default -> OptionalInt.empty();
};
}
/**

View File

@ -237,10 +237,10 @@ public V merge(BlockVector3 key, V value, BiFunction<? super V, ? super V, ? ext
public Set<Entry<BlockVector3, V>> entrySet() {
Set<Entry<BlockVector3, V>> es = entrySet;
if (es == null) {
entrySet = es = new AbstractSet<Entry<BlockVector3, V>>() {
entrySet = es = new AbstractSet<>() {
@Override
public Iterator<Entry<BlockVector3, V>> iterator() {
return new Iterator<Entry<BlockVector3, V>>() {
return new Iterator<>() {
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
= Long2ObjectMaps.fastIterator(maps);
@ -441,7 +441,7 @@ public int size() {
public Collection<V> values() {
Collection<V> vs = values;
if (vs == null) {
values = vs = new AbstractCollection<V>() {
values = vs = new AbstractCollection<>() {
@Override
public Iterator<V> iterator() {
return maps.values().stream()

View File

@ -34,7 +34,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public class SideEffectBox extends PaginationBox {

View File

@ -30,7 +30,6 @@
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@ -184,14 +183,11 @@ private static IOException tryDelete(Path path) {
* @return the owner-only file attributes
*/
public static FileAttribute<?>[] getOwnerOnlyFileAttributes(AttributeTarget attributeTarget) {
switch (attributeTarget) {
case FILE:
return OWNER_ONLY_FILE_ATTRS;
case DIRECTORY:
return OWNER_ONLY_DIR_ATTRS;
default:
throw new IllegalStateException("Unknown attribute target " + attributeTarget);
}
return switch (attributeTarget) {
case FILE -> OWNER_ONLY_FILE_ATTRS;
case DIRECTORY -> OWNER_ONLY_DIR_ATTRS;
default -> throw new IllegalStateException("Unknown attribute target " + attributeTarget);
};
}
private SafeFiles() {

View File

@ -20,12 +20,10 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import org.enginehub.linbus.format.snbt.LinStringIO;
import org.enginehub.linbus.stream.exception.NbtWriteException;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTagType;
@ -142,15 +140,13 @@ public void setNbtReference(@Nullable LazyReference<LinCompoundTag> nbtData) {
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof BaseBlock)) {
if (!(o instanceof BaseBlock otherBlock)) {
if (nbtData == null && o instanceof BlockStateHolder) {
return Objects.equals(toImmutableState(), ((BlockStateHolder<?>) o).toImmutableState());
}
return false;
}
final BaseBlock otherBlock = (BaseBlock) o;
return this.blockState.equalsFuzzy(otherBlock.blockState) && Objects.equals(getNbt(), otherBlock.getNbt());
}

View File

@ -195,9 +195,9 @@ public boolean equalsFuzzy(BlockStateHolder<?> o) {
}
Set<Property<?>> differingProperties = new HashSet<>();
for (Object state : o.getStates().keySet()) {
if (getState((Property<?>) state) == null) {
differingProperties.add((Property<?>) state);
for (Property<?> state : o.getStates().keySet()) {
if (getState(state) == null) {
differingProperties.add(state);
}
}
for (Property<?> property : getStates().keySet()) {

View File

@ -134,7 +134,7 @@ private Optional<Path> getRegionFolder() throws IOException {
public LinCompoundTag getChunkTag(BlockVector3 position) throws DataException, IOException {
BlockVector2 pos = position.toBlockVector2();
Optional<Path> regFolder = getRegionFolder();
if (!regFolder.isPresent()) {
if (regFolder.isEmpty()) {
Path chunkFile = getFolder().resolve(LegacyChunkStore.getFilename(pos, "/"));
if (!Files.exists(chunkFile)) {
throw new MissingChunkException();

View File

@ -24,7 +24,6 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
/**