From e2a1721a5c4d94e18c3bae35bdc86b0785c83f48 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Wed, 29 Dec 2021 16:12:43 +0000 Subject: [PATCH] Use new language features --- .../nbt/PaperweightLazyCompoundTag.java | 19 +++++++++---------- .../v1_17_R1_2/regen/PaperweightRegen.java | 14 +++++--------- .../nbt/PaperweightLazyCompoundTag.java | 19 +++++++++---------- .../fawe/v1_18_R1/regen/PaperweightRegen.java | 14 +++++--------- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/nbt/PaperweightLazyCompoundTag.java b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/nbt/PaperweightLazyCompoundTag.java index 41cc94827..f71a3954e 100644 --- a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/nbt/PaperweightLazyCompoundTag.java +++ b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/nbt/PaperweightLazyCompoundTag.java @@ -66,8 +66,8 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public double asDouble(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsDouble(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsDouble(); } return 0; } @@ -86,20 +86,19 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public int asInt(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsInt(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsInt(); } return 0; } public List getList(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof net.minecraft.nbt.ListTag) { + if (tag instanceof net.minecraft.nbt.ListTag nbtList) { ArrayList list = new ArrayList<>(); - net.minecraft.nbt.ListTag nbtList = (net.minecraft.nbt.ListTag) tag; for (net.minecraft.nbt.Tag elem : nbtList) { - if (elem instanceof net.minecraft.nbt.CompoundTag) { - list.add(new PaperweightLazyCompoundTag((net.minecraft.nbt.CompoundTag) elem)); + if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) { + list.add(new PaperweightLazyCompoundTag(compoundTag)); } else { list.add(WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(elem)); } @@ -137,8 +136,8 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public long asLong(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsLong(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsLong(); } return 0; } diff --git a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/regen/PaperweightRegen.java b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/regen/PaperweightRegen.java index 52161adfd..12a12d059 100644 --- a/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/regen/PaperweightRegen.java +++ b/worldedit-bukkit/adapters/adapter-1_17_1/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_17_R1_2/regen/PaperweightRegen.java @@ -414,15 +414,11 @@ public class PaperweightRegen extends Regenerator getWorldDimKey(org.bukkit.World.Environment env) { - switch (env) { - case NETHER: - return LevelStem.NETHER; - case THE_END: - return LevelStem.END; - case NORMAL: - default: - return LevelStem.OVERWORLD; - } + return switch (env) { + case NETHER -> LevelStem.NETHER; + case THE_END -> LevelStem.END; + default -> LevelStem.OVERWORLD; + }; } private BiomeSource fastOverworldBiomeSource(BiomeSource biomeSource) throws Exception { diff --git a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/nbt/PaperweightLazyCompoundTag.java b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/nbt/PaperweightLazyCompoundTag.java index 3dfebd31c..1639ac951 100644 --- a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/nbt/PaperweightLazyCompoundTag.java +++ b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/nbt/PaperweightLazyCompoundTag.java @@ -66,8 +66,8 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public double asDouble(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsDouble(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsDouble(); } return 0; } @@ -86,20 +86,19 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public int asInt(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsInt(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsInt(); } return 0; } public List getList(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof net.minecraft.nbt.ListTag) { + if (tag instanceof net.minecraft.nbt.ListTag nbtList) { ArrayList list = new ArrayList<>(); - net.minecraft.nbt.ListTag nbtList = (net.minecraft.nbt.ListTag) tag; for (net.minecraft.nbt.Tag elem : nbtList) { - if (elem instanceof net.minecraft.nbt.CompoundTag) { - list.add(new PaperweightLazyCompoundTag((net.minecraft.nbt.CompoundTag) elem)); + if (elem instanceof net.minecraft.nbt.CompoundTag compoundTag) { + list.add(new PaperweightLazyCompoundTag(compoundTag)); } else { list.add(WorldEditPlugin.getInstance().getBukkitImplAdapter().toNative(elem)); } @@ -138,8 +137,8 @@ public class PaperweightLazyCompoundTag extends LazyCompoundTag { public long asLong(String key) { net.minecraft.nbt.Tag tag = compoundTagSupplier.get().get(key); - if (tag instanceof NumericTag) { - return ((NumericTag) tag).getAsLong(); + if (tag instanceof NumericTag numTag) { + return numTag.getAsLong(); } return 0; } diff --git a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/regen/PaperweightRegen.java b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/regen/PaperweightRegen.java index 71cebcade..4269b48a5 100644 --- a/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/regen/PaperweightRegen.java +++ b/worldedit-bukkit/adapters/adapter-1_18/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_18_R1/regen/PaperweightRegen.java @@ -397,15 +397,11 @@ public class PaperweightRegen extends Regenerator getWorldDimKey(org.bukkit.World.Environment env) { - switch (env) { - case NETHER: - return LevelStem.NETHER; - case THE_END: - return LevelStem.END; - case NORMAL: - default: - return LevelStem.OVERWORLD; - } + return switch (env) { + case NETHER -> LevelStem.NETHER; + case THE_END -> LevelStem.END; + default -> LevelStem.OVERWORLD; + }; } private static class RegenNoOpWorldLoadListener implements ChunkProgressListener {