[ci skip] Replace some magic values with constant references

This commit is contained in:
Nassim Jahnke 2024-01-04 14:38:26 +01:00
parent 0f3d126ce1
commit 635ece80cf
10 changed files with 17 additions and 17 deletions

View file

@ -191,8 +191,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ private static void mergeChunkList(CompoundTag level, CompoundTag oversizedLevel, String key, String oversizedKey) { + private static void mergeChunkList(CompoundTag level, CompoundTag oversizedLevel, String key, String oversizedKey) {
+ net.minecraft.nbt.ListTag levelList = level.getList(key, 10); + net.minecraft.nbt.ListTag levelList = level.getList(key, net.minecraft.nbt.Tag.TAG_COMPOUND);
+ net.minecraft.nbt.ListTag oversizedList = oversizedLevel.getList(oversizedKey, 10); + net.minecraft.nbt.ListTag oversizedList = oversizedLevel.getList(oversizedKey, net.minecraft.nbt.Tag.TAG_COMPOUND);
+ +
+ if (!oversizedList.isEmpty()) { + if (!oversizedList.isEmpty()) {
+ levelList.addAll(oversizedList); + levelList.addAll(oversizedList);

View file

@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public static InProgressChunkHolder loadChunk(ServerLevel world, PoiManager poiStorage, ChunkPos chunkPos, CompoundTag nbt, boolean distinguish) { public static InProgressChunkHolder loadChunk(ServerLevel world, PoiManager poiStorage, ChunkPos chunkPos, CompoundTag nbt, boolean distinguish) {
+ // Paper start - Do NOT attempt to load chunks saved with newer versions + // Paper start - Do NOT attempt to load chunks saved with newer versions
+ if (nbt.contains("DataVersion", 99)) { + if (nbt.contains("DataVersion", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
+ int dataVersion = nbt.getInt("DataVersion"); + int dataVersion = nbt.getInt("DataVersion");
+ if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) { + if (!JUST_CORRUPT_IT && dataVersion > CURRENT_DATA_VERSION) {
+ new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace(); + new RuntimeException("Server attempted to load chunk saved with newer version of minecraft! " + dataVersion + " > " + CURRENT_DATA_VERSION).printStackTrace();

View file

@ -77,7 +77,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// CraftBukkit end // CraftBukkit end
+ // Paper start - Restore the entity's origin location + // Paper start - Restore the entity's origin location
+ ListTag originTag = nbt.getList("Paper.Origin", 6); + ListTag originTag = nbt.getList("Paper.Origin", net.minecraft.nbt.Tag.TAG_DOUBLE);
+ if (!originTag.isEmpty()) { + if (!originTag.isEmpty()) {
+ UUID originWorld = null; + UUID originWorld = null;
+ if (nbt.contains("Paper.OriginWorld")) { + if (nbt.contains("Paper.OriginWorld")) {

View file

@ -36,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public org.bukkit.entity.ExperienceOrb.SpawnReason spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN; + public org.bukkit.entity.ExperienceOrb.SpawnReason spawnReason = org.bukkit.entity.ExperienceOrb.SpawnReason.UNKNOWN;
+ +
+ private void loadPaperNBT(CompoundTag nbttagcompound) { + private void loadPaperNBT(CompoundTag nbttagcompound) {
+ if (!nbttagcompound.contains("Paper.ExpData", 10)) { // 10 = compound + if (!nbttagcompound.contains("Paper.ExpData", net.minecraft.nbt.Tag.TAG_COMPOUND)) {
+ return; + return;
+ } + }
+ CompoundTag comp = nbttagcompound.getCompound("Paper.ExpData"); + CompoundTag comp = nbttagcompound.getCompound("Paper.ExpData");

View file

@ -28,10 +28,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start + // Paper start
+ private static final java.util.Comparator<? super CompoundTag> enchantSorter = java.util.Comparator.comparing(o -> o.getString("id")); + private static final java.util.Comparator<? super CompoundTag> enchantSorter = java.util.Comparator.comparing(o -> o.getString("id"));
+ private void processEnchantOrder(@Nullable CompoundTag tag) { + private void processEnchantOrder(@Nullable CompoundTag tag) {
+ if (tag == null || !tag.contains("Enchantments", 9)) { + if (tag == null || !tag.contains("Enchantments", net.minecraft.nbt.Tag.TAG_LIST)) {
+ return; + return;
+ } + }
+ ListTag list = tag.getList("Enchantments", 10); + ListTag list = tag.getList("Enchantments", net.minecraft.nbt.Tag.TAG_COMPOUND);
+ if (list.size() < 2) { + if (list.size() < 2) {
+ return; + return;
+ } + }

View file

@ -364,8 +364,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ if (comp.contains("numRefills")) { + if (comp.contains("numRefills")) {
+ this.numRefills = comp.getInt("numRefills"); + this.numRefills = comp.getInt("numRefills");
+ } + }
+ if (comp.contains("lootedPlayers", 9)) { // 9 = list + if (comp.contains("lootedPlayers", net.minecraft.nbt.Tag.TAG_LIST)) {
+ ListTag list = comp.getList("lootedPlayers", 10); // 10 = compound + ListTag list = comp.getList("lootedPlayers", net.minecraft.nbt.Tag.TAG_COMPOUND);
+ final int size = list.size(); + final int size = list.size();
+ if (size > 0) { + if (size > 0) {
+ this.lootedPlayers = new HashMap<>(list.size()); + this.lootedPlayers = new HashMap<>(list.size());

View file

@ -31,7 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
+ // Paper start - use ints if set + // Paper start - use ints if set
+ if (nbt.contains("Paper.MinSpawnDelay", 99)) { + if (nbt.contains("Paper.MinSpawnDelay", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
+ this.minSpawnDelay = nbt.getInt("Paper.MinSpawnDelay"); + this.minSpawnDelay = nbt.getInt("Paper.MinSpawnDelay");
+ this.maxSpawnDelay = nbt.getInt("Paper.MaxSpawnDelay"); + this.maxSpawnDelay = nbt.getInt("Paper.MaxSpawnDelay");
+ this.spawnCount = nbt.getShort("SpawnCount"); + this.spawnCount = nbt.getShort("SpawnCount");

View file

@ -8574,7 +8574,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ try { + try {
+ data = data.copy(); // coming from the I/O thread, so we need to copy + data = data.copy(); // coming from the I/O thread, so we need to copy
+ // run converters + // run converters
+ final int dataVersion = !data.contains(SharedConstants.DATA_VERSION_TAG, 99) ? 1945 : data.getInt(SharedConstants.DATA_VERSION_TAG); + final int dataVersion = !data.contains(SharedConstants.DATA_VERSION_TAG, net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) ? 1945 : data.getInt(SharedConstants.DATA_VERSION_TAG);
+ final CompoundTag converted = MCDataConverter.convertTag( + final CompoundTag converted = MCDataConverter.convertTag(
+ MCTypeRegistry.POI_CHUNK, data, dataVersion, SharedConstants.getCurrentVersion().getDataVersion().getVersion() + MCTypeRegistry.POI_CHUNK, data, dataVersion, SharedConstants.getCurrentVersion().getDataVersion().getVersion()
+ ); + );

View file

@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public void putUUID(String key, UUID value) { public void putUUID(String key, UUID value) {
+ // Paper start - support old format + // Paper start - support old format
+ if (this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { + if (this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
+ this.tags.remove(key + "Most"); + this.tags.remove(key + "Most");
+ this.tags.remove(key + "Least"); + this.tags.remove(key + "Least");
+ } + }
@ -29,7 +29,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
*/ */
public UUID getUUID(String key) { public UUID getUUID(String key) {
+ // Paper start - support old format + // Paper start - support old format
+ if (!contains(key, 11) && this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { + if (!contains(key, 11) && this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
+ return new UUID(this.getLong(key + "Most"), this.getLong(key + "Least")); + return new UUID(this.getLong(key + "Most"), this.getLong(key + "Least"));
+ } + }
+ // Paper end + // Paper end
@ -38,7 +38,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public boolean hasUUID(String key) { public boolean hasUUID(String key) {
+ // Paper start - support old format + // Paper start - support old format
+ if (this.contains(key + "Most", 99) && this.contains(key + "Least", 99)) { + if (this.contains(key + "Most", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC) && this.contains(key + "Least", net.minecraft.nbt.Tag.TAG_ANY_NUMERIC)) {
+ return true; + return true;
+ } + }
+ // Paper end + // Paper end

View file

@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ private void processText() { + private void processText() {
+ CompoundTag display = getTagElement("display"); + CompoundTag display = getTagElement("display");
+ if (display != null) { + if (display != null) {
+ if (display.contains("Name", 8)) { + if (display.contains("Name", net.minecraft.nbt.Tag.TAG_STRING)) {
+ String json = display.getString("Name"); + String json = display.getString("Name");
+ if (json != null && json.contains("\u00A7")) { + if (json != null && json.contains("\u00A7")) {
+ try { + try {
@ -26,8 +26,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ } + }
+ } + }
+ if (display.contains("Lore", 9)) { + if (display.contains("Lore", net.minecraft.nbt.Tag.TAG_LIST)) {
+ ListTag list = display.getList("Lore", 8); + ListTag list = display.getList("Lore", net.minecraft.nbt.Tag.TAG_STRING);
+ for (int index = 0; index < list.size(); index++) { + for (int index = 0; index < list.size(); index++) {
+ String json = list.getString(index); + String json = list.getString(index);
+ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json + if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json