From 45bc531dd337819887bfd08af9d1dcb1a683383e Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 2 Mar 2021 16:27:34 -0800 Subject: [PATCH] Fix Material#getTranslationKey for Block Materials (#5294) * Fix Material#getTranslationKey for Block Materials * Cache the result of Material#isBlock --- ...Cache-the-result-of-Material-isBlock.patch | 38 +++++++++++++++++++ ...-translation-keys-for-blocks-entitie.patch | 7 +++- ...y-Counter-to-allow-plugins-to-use-va.patch | 6 +-- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 Spigot-API-Patches/0276-Cache-the-result-of-Material-isBlock.patch diff --git a/Spigot-API-Patches/0276-Cache-the-result-of-Material-isBlock.patch b/Spigot-API-Patches/0276-Cache-the-result-of-Material-isBlock.patch new file mode 100644 index 0000000000..70795d6709 --- /dev/null +++ b/Spigot-API-Patches/0276-Cache-the-result-of-Material-isBlock.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: jmp +Date: Tue, 2 Mar 2021 15:24:58 -0800 +Subject: [PATCH] Cache the result of Material#isBlock + + +diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java +index 2a3becabbd10fa8ffd19f35a3f6d8a6bfcb388c3..7b77c7132723a01e8c38ddaa616b363be300b653 100644 +--- a/src/main/java/org/bukkit/Material.java ++++ b/src/main/java/org/bukkit/Material.java +@@ -3521,6 +3521,7 @@ public enum Material implements Keyed { + public final Class data; + private final boolean legacy; + private final NamespacedKey key; ++ private boolean isBlock; // Paper + + private Material(final int id) { + this(id, 64); +@@ -3718,6 +3719,11 @@ public enum Material implements Keyed { + * @return true if this material is a block + */ + public boolean isBlock() { ++ // Paper start - cache isBlock ++ return this.isBlock; ++ } ++ private boolean isBlock0() { ++ // Paper end + switch (this) { + // + case ACACIA_BUTTON: +@@ -4663,6 +4669,7 @@ public enum Material implements Keyed { + static { + for (Material material : values()) { + BY_NAME.put(material.name(), material); ++ material.isBlock = material.isBlock0(); // Paper + } + } + diff --git a/Spigot-Server-Patches/0566-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch b/Spigot-Server-Patches/0566-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch index f427447a52..f5a9e7d202 100644 --- a/Spigot-Server-Patches/0566-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch +++ b/Spigot-Server-Patches/0566-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch @@ -74,7 +74,7 @@ index f787238575ed7ac9108a2fd9782af55056219767..3524b677525bf2bb529b797fe1f258ef // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..865c1e4cf18b25ecf2ba8d592d9ca40f631e2215 100644 +index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..8f13e2685b8e68005d2c4d1613089f4d606fba94 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -45,6 +45,7 @@ import org.bukkit.Registry; @@ -85,13 +85,16 @@ index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..865c1e4cf18b25ecf2ba8d592d9ca40f import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.legacy.CraftLegacy; -@@ -393,6 +394,22 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -393,6 +394,25 @@ public final class CraftMagicNumbers implements UnsafeValues { throw new RuntimeException(); } } + + @Override + public String getTranslationKey(Material mat) { ++ if (mat.isBlock()) { ++ return getBlock(mat).getDescriptionId(); ++ } + return getItem(mat).getOrCreateDescriptionId(); + } + diff --git a/Spigot-Server-Patches/0574-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch b/Spigot-Server-Patches/0574-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch index 4509ab74a2..732bea475a 100644 --- a/Spigot-Server-Patches/0574-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch +++ b/Spigot-Server-Patches/0574-Expose-the-Entity-Counter-to-allow-plugins-to-use-va.patch @@ -6,7 +6,7 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java -index e65cb9c72e46d50b871d1c7b5789a1855622d934..9415588d7df27fb6907381cff802fd8ad983663f 100644 +index a7b225249f7ffafa2c6e1fc60657067229e02960..fcb5cf78d1deff3c2593c7470f5501be8fed567b 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -3382,4 +3382,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke @@ -21,10 +21,10 @@ index e65cb9c72e46d50b871d1c7b5789a1855622d934..9415588d7df27fb6907381cff802fd8a + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 865c1e4cf18b25ecf2ba8d592d9ca40f631e2215..e073db219a35c3ac02e4c5f65a9ad405cd148d1d 100644 +index 8f13e2685b8e68005d2c4d1613089f4d606fba94..f37ab6dc33cda2aeb997db060b255acda3316b61 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -@@ -410,6 +410,10 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -413,6 +413,10 @@ public final class CraftMagicNumbers implements UnsafeValues { return net.minecraft.server.EntityTypes.getByName(type.getName()).map(net.minecraft.server.EntityTypes::getDescriptionId).orElse(null); }