Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup code for latest Java versions #2404

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -2533,6 +2529,7 @@ public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws
}

outside.addAll(newOutside);
newOutside.clear();
}

outer: for (BlockVector3 position : region) {
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading