Fix Material#getTranslationKey for Block Materials (#5294)
* Fix Material#getTranslationKey for Block Materials * Cache the result of Material#isBlock
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
|
||||||
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/Material.java
|
||||||
|
+++ b/src/main/java/org/bukkit/Material.java
|
||||||
|
@@ -0,0 +0,0 @@ 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);
|
||||||
|
@@ -0,0 +0,0 @@ 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) {
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="isBlock">
|
||||||
|
case ACACIA_BUTTON:
|
||||||
|
@@ -0,0 +0,0 @@ public enum Material implements Keyed {
|
||||||
|
static {
|
||||||
|
for (Material material : values()) {
|
||||||
|
BY_NAME.put(material.name(), material);
|
||||||
|
+ material.isBlock = material.isBlock0(); // Paper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -92,6 +92,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public String getTranslationKey(Material mat) {
|
+ public String getTranslationKey(Material mat) {
|
||||||
|
+ if (mat.isBlock()) {
|
||||||
|
+ return getBlock(mat).getDescriptionId();
|
||||||
|
+ }
|
||||||
+ return getItem(mat).getOrCreateDescriptionId();
|
+ return getItem(mat).getOrCreateDescriptionId();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
|||||||
Reference in New Issue
Block a user