Use new language features

This commit is contained in:
dordsor21 2021-12-29 16:12:43 +00:00
parent 0d79d084a5
commit e2a1721a5c
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
4 changed files with 28 additions and 38 deletions

View File

@ -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<Tag> 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<Tag> 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;
}

View File

@ -414,15 +414,11 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
}
private ResourceKey<LevelStem> 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 {

View File

@ -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<Tag> 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<Tag> 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;
}

View File

@ -397,15 +397,11 @@ public class PaperweightRegen extends Regenerator<ChunkAccess, ProtoChunk, Level
}
private ResourceKey<LevelStem> 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 {