Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-23 23:00:08 +01:00
SPIGOT-6033: Bukkit.getUnsafe().getMaterial() won't match renamed block materials
Dieser Commit ist enthalten in:
Ursprung
29cce6714a
Commit
52fd29c0dc
@ -33,6 +33,7 @@ import net.minecraft.server.MinecraftServer;
|
|||||||
import net.minecraft.server.MojangsonParser;
|
import net.minecraft.server.MojangsonParser;
|
||||||
import net.minecraft.server.NBTBase;
|
import net.minecraft.server.NBTBase;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
|
import net.minecraft.server.NBTTagString;
|
||||||
import net.minecraft.server.SavedFile;
|
import net.minecraft.server.SavedFile;
|
||||||
import net.minecraft.server.SharedConstants;
|
import net.minecraft.server.SharedConstants;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -169,6 +170,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Material getMaterial(String material, int version) {
|
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!");
|
Preconditions.checkArgument(version <= this.getDataVersion(), "Newer version! Server downgrades are not supported!");
|
||||||
|
|
||||||
// Fastpath up to date materials
|
// Fastpath up to date materials
|
||||||
@ -176,13 +178,14 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|||||||
return Material.getMaterial(material);
|
return Material.getMaterial(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
NBTTagCompound stack = new NBTTagCompound();
|
Dynamic<NBTBase> name = new Dynamic<>(DynamicOpsNBT.a, NBTTagString.a("minecraft:" + material.toLowerCase(Locale.ROOT)));
|
||||||
stack.setString("id", "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());
|
if (name.equals(converted)) {
|
||||||
String newId = converted.get("id").asString("");
|
converted = DataConverterRegistry.a().update(DataConverterTypes.BLOCK_NAME, name, version, this.getDataVersion());
|
||||||
|
}
|
||||||
|
|
||||||
return Material.matchMaterial(newId);
|
return Material.matchMaterial(converted.asString(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
import org.bukkit.support.AbstractTestingBase;
|
import org.bukkit.support.AbstractTestingBase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -116,4 +117,10 @@ public class LegacyTest extends AbstractTestingBase {
|
|||||||
Assert.assertFalse("Must iterate only modern materials", material.isLegacy());
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren