3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

SPIGOT-6033: Bukkit.getUnsafe().getMaterial() won't match renamed block materials

Dieser Commit ist enthalten in:
md_5 2020-07-28 18:22:34 +10:00
Ursprung 29cce6714a
Commit 52fd29c0dc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: E8E901AC7C617C11
2 geänderte Dateien mit 15 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -33,6 +33,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.MojangsonParser;
import net.minecraft.server.NBTBase;
import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.NBTTagString;
import net.minecraft.server.SavedFile;
import net.minecraft.server.SharedConstants;
import org.bukkit.Bukkit;
@ -169,6 +170,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
@Override
public Material getMaterial(String material, int version) {
Preconditions.checkArgument(material != null, "material == null");
Preconditions.checkArgument(version <= this.getDataVersion(), "Newer version! Server downgrades are not supported!");
// Fastpath up to date materials
@ -176,13 +178,14 @@ public final class CraftMagicNumbers implements UnsafeValues {
return Material.getMaterial(material);
}
NBTTagCompound stack = new NBTTagCompound();
stack.setString("id", "minecraft:" + material.toLowerCase(Locale.ROOT));
Dynamic<NBTBase> name = new Dynamic<>(DynamicOpsNBT.a, NBTTagString.a("minecraft:" + material.toLowerCase(Locale.ROOT)));
Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_NAME, name, version, this.getDataVersion());
Dynamic<NBTBase> converted = DataConverterRegistry.a().update(DataConverterTypes.ITEM_STACK, new Dynamic<>(DynamicOpsNBT.a, stack), version, this.getDataVersion());
String newId = converted.get("id").asString("");
if (name.equals(converted)) {
converted = DataConverterRegistry.a().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion());
}
return Material.matchMaterial(newId);
return Material.matchMaterial(converted.asString(""));
}
/**

Datei anzeigen

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.material.MaterialData;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Assert;
@ -116,4 +117,10 @@ public class LegacyTest extends AbstractTestingBase {
Assert.assertFalse("Must iterate only modern materials", material.isLegacy());
}
}
@Test
public void testManual() {
Assert.assertEquals(Material.YELLOW_DYE, CraftMagicNumbers.INSTANCE.getMaterial("dandelion_yellow", 1631));
Assert.assertEquals(Material.OAK_WALL_SIGN, CraftMagicNumbers.INSTANCE.getMaterial("wall_sign", 1631));
}
}