Skip to content

Commit 82727ff

Browse files
authored
Few cleanups over the code and use more Java 9+ features (#2248)
* Few cleanups over the code and use more Java 9+ features * Address feedback * cleanup switch case * Remove TODO
1 parent d960fa2 commit 82727ff

37 files changed

Lines changed: 151 additions & 331 deletions

File tree

worldedit-bukkit/adapters/adapter-1.17.1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_17_R1_2/PaperweightAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@
174174
import java.util.concurrent.ForkJoinPool;
175175
import java.util.logging.Level;
176176
import java.util.logging.Logger;
177-
import java.util.stream.Collectors;
178177
import javax.annotation.Nullable;
179178

180179
import static com.google.common.base.Preconditions.checkNotNull;
@@ -566,10 +565,10 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
566565
return new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
567566
} else if (state instanceof DirectionProperty) {
568567
return new DirectionalProperty(state.getName(),
569-
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
568+
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).toList());
570569
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
571570
return new EnumProperty(state.getName(),
572-
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
571+
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).toList());
573572
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
574573
return new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
575574
} else {

worldedit-bukkit/adapters/adapter-1.18.2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_18_R2/PaperweightAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@
175175
import java.util.concurrent.ForkJoinPool;
176176
import java.util.logging.Level;
177177
import java.util.logging.Logger;
178-
import java.util.stream.Collectors;
179178
import javax.annotation.Nullable;
180179

181180
import static com.google.common.base.Preconditions.checkNotNull;
@@ -558,10 +557,10 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
558557
return new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
559558
} else if (state instanceof DirectionProperty) {
560559
return new DirectionalProperty(state.getName(),
561-
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
560+
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).toList());
562561
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
563562
return new EnumProperty(state.getName(),
564-
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
563+
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).toList());
565564
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
566565
return new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
567566
} else {

worldedit-bukkit/adapters/adapter-1.19.3/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R2/PaperweightAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@
174174
import java.util.concurrent.ExecutionException;
175175
import java.util.logging.Level;
176176
import java.util.logging.Logger;
177-
import java.util.stream.Collectors;
178177
import javax.annotation.Nullable;
179178

180179
import static com.google.common.base.Preconditions.checkNotNull;
@@ -558,10 +557,10 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
558557
return new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
559558
} else if (state instanceof DirectionProperty) {
560559
return new DirectionalProperty(state.getName(),
561-
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
560+
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).toList());
562561
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
563562
return new EnumProperty(state.getName(),
564-
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
563+
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).toList());
565564
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
566565
return new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
567566
} else {

worldedit-bukkit/adapters/adapter-1.19/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/v1_19_R1/PaperweightAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@
174174
import java.util.concurrent.ExecutionException;
175175
import java.util.logging.Level;
176176
import java.util.logging.Logger;
177-
import java.util.stream.Collectors;
178177
import javax.annotation.Nullable;
179178

180179
import static com.google.common.base.Preconditions.checkNotNull;
@@ -558,10 +557,10 @@ public Property<?> load(net.minecraft.world.level.block.state.properties.Propert
558557
return new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
559558
} else if (state instanceof DirectionProperty) {
560559
return new DirectionalProperty(state.getName(),
561-
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
560+
(List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).toList());
562561
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
563562
return new EnumProperty(state.getName(),
564-
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
563+
(List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).toList());
565564
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
566565
return new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
567566
} else {

worldedit-bukkit/src/main/java/com/sk89q/bukkit/util/CommandsManagerRegistration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Map;
3333

3434
@Deprecated
35-
@SuppressWarnings("deprecation")
3635
public class CommandsManagerRegistration extends CommandRegistration {
3736

3837
protected CommandsManager<?> commands;

worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private void copyDefaultConfig(InputStream input, File actual, String name) {
371371
}
372372

373373
private String rebuildArguments(String commandLabel, String[] args) {
374-
int plSep = commandLabel.indexOf(":");
374+
int plSep = commandLabel.indexOf(':');
375375
if (plSep >= 0 && plSep < commandLabel.length() + 1) {
376376
commandLabel = commandLabel.substring(plSep + 1);
377377
}
@@ -555,7 +555,7 @@ public void onAsyncTabComplete(com.destroystokyo.paper.event.server.AsyncTabComp
555555
if (owner != WorldEditPlugin.this) {
556556
return;
557557
}
558-
int plSep = label.indexOf(":");
558+
int plSep = label.indexOf(':');
559559
if (plSep >= 0 && plSep < label.length() + 1) {
560560
label = label.substring(plSep + 1);
561561
buffer = "/" + buffer.substring(plSep + 2);

worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLIBlockRegistry.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,19 @@
3333

3434
import java.util.List;
3535
import java.util.Map;
36-
import java.util.stream.Collectors;
3736
import javax.annotation.Nullable;
3837

3938
public class CLIBlockRegistry extends BundledBlockRegistry {
4039

4140
private Property<?> createProperty(String type, String key, List<String> values) {
42-
switch (type) {
43-
case "int": {
44-
List<Integer> fixedValues = values.stream().map(Integer::parseInt).collect(Collectors.toList());
45-
return new IntegerProperty(key, fixedValues);
46-
}
47-
case "bool": {
48-
List<Boolean> fixedValues = values.stream().map(Boolean::parseBoolean).collect(Collectors.toList());
49-
return new BooleanProperty(key, fixedValues);
50-
}
51-
case "enum": {
52-
return new EnumProperty(key, values);
53-
}
54-
case "direction": {
55-
List<Direction> fixedValues = values.stream().map(String::toUpperCase).map(Direction::valueOf).collect(Collectors.toList());
56-
return new DirectionalProperty(key, fixedValues);
57-
}
58-
default:
59-
throw new RuntimeException("Failed to create property");
60-
}
41+
return switch (type) {
42+
case "int" -> new IntegerProperty(key, values.stream().map(Integer::parseInt).toList());
43+
case "bool" -> new BooleanProperty(key, values.stream().map(Boolean::parseBoolean).toList());
44+
case "enum" -> new EnumProperty(key, values);
45+
case "direction" ->
46+
new DirectionalProperty(key, values.stream().map(String::toUpperCase).map(Direction::valueOf).toList());
47+
default -> throw new RuntimeException("Failed to create property");
48+
};
6149
}
6250

6351
@Nullable

worldedit-core/src/legacy/java/com/sk89q/worldedit/blocks/MobSpawnerBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void setNbtData(CompoundTag rootTag) {
172172
try {
173173
spawnDataTag = NBTUtils.getChildTag(values, "SpawnData", CompoundTag.class);
174174
mobType = spawnDataTag.getString("id");
175-
if (mobType.equals("")) {
175+
if (mobType.isEmpty()) {
176176
throw new InvalidFormatException("No spawn id.");
177177
}
178178
this.mobType = mobType;

worldedit-core/src/main/java/com/sk89q/jnbt/ListTag.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.List;
3939
import java.util.function.IntFunction;
4040
import java.util.function.Supplier;
41-
import java.util.stream.Collectors;
4241
import javax.annotation.Nullable;
4342

4443
/**
@@ -57,7 +56,7 @@ public final class ListTag<EV, E extends LinTag<EV>> extends Tag<Object, LinList
5756
public ListTag(Class<? extends Tag<EV, E>> type, List<? extends Tag<EV, E>> value) {
5857
this(LinListTag.of(
5958
LinTagType.fromId(LinTagId.fromId(NBTUtils.getTypeCode(type))),
60-
value.stream().map(Tag::toLinTag).collect(Collectors.toList())
59+
value.stream().map(Tag::toLinTag).toList()
6160
));
6261
}
6362

worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ private List<TracingExtent> getActiveTracingExtents() {
352352
}
353353
return tracingExtents.stream()
354354
.filter(TracingExtent::isActive)
355-
.collect(Collectors.toList());
355+
.toList();
356356
}
357357

358358
/**
@@ -946,7 +946,7 @@ private void dumpTracingInformation() {
946946
for (BlockVector3 loc : touchedLocations) {
947947
List<TracingExtent> stack = tracingExtents.stream()
948948
.filter(it -> it.getTouchedLocations().contains(loc))
949-
.collect(Collectors.toList());
949+
.toList();
950950
boolean anyFailed = stack.stream()
951951
.anyMatch(it -> it.getFailedActions().containsKey(loc));
952952
if (anyFailed && stacks.add(stack)) {

0 commit comments

Comments
 (0)