13
0
geforkt von Mirrors/Paper
Paper/patches/api/0225-Add-a-way-to-get-translation-keys-for-blocks-entitie.patch
Shane Freeder f521a18a17
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
75a0ee4f SPIGOT-6691: Material.LAVA_CAULDRON is not Levelled

CraftBukkit Changes:
e1c96e50 SPIGOT-6682: Blocking with shield not reset after die
97f629b6 SPIGOT-6220: Structures in the world with custom generator not work
85379258 Increase outdated build delay
f7f8dce4 SPIGOT-6552: Some inventory types reset cursor on switch
2021-08-04 16:26:56 +01:00

128 Zeilen
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MeFisto94 <MeFisto94@users.noreply.github.com>
Date: Tue, 11 Aug 2020 19:17:46 +0200
Subject: [PATCH] Add a way to get translation keys for blocks, entities and
materials
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
index e7af2b346253cf05923998527bdc27b1180fa3b6..90047af133a2e2e0268f84f038e5c19dac48e3d2 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -3989,6 +3989,16 @@ public enum Material implements Keyed {
}
return false;
}
+
+ /**
+ * Return the translation key for the Material, so the client can translate it into the active
+ * locale when using a TranslatableComponent.
+ * @return the translation key
+ */
+ @NotNull
+ public String getTranslationKey() {
+ return Bukkit.getUnsafe().getTranslationKey(this);
+ }
// Paper end
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index e348034288c74ab80360086d71f0b7f61551df24..2d9264ffe0fee863f1b814952ef063daa7962d76 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -101,5 +101,34 @@ public interface UnsafeValues {
byte[] serializeItem(ItemStack item);
ItemStack deserializeItem(byte[] data);
+
+ /**
+ * Return the translation key for the Material, so the client can translate it into the active
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
+ * @return the translation key
+ */
+ String getTranslationKey(Material mat);
+
+ /**
+ * Return the translation key for the Block, so the client can translate it into the active
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
+ * @return the translation key
+ */
+ String getTranslationKey(org.bukkit.block.Block block);
+
+ /**
+ * Return the translation key for the EntityType, so the client can translate it into the active
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.<br>
+ * This is <code>null</code>, when the EntityType isn't known to NMS (custom entities)
+ * @return the translation key
+ */
+ String getTranslationKey(org.bukkit.entity.EntityType type);
+
+ /**
+ * Return the translation key for the ItemStack, so the client can translate it into the active
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.<br>
+ * @return the translation key
+ */
+ String getTranslationKey(ItemStack itemStack);
// Paper end
}
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 786b8011e98b2fe93cc2418d624f6350ede62d90..024deba760c41787190d20e4ac5c541920bb4991 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -610,5 +610,13 @@ public interface Block extends Metadatable {
*/
@NotNull
com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup();
+
+ /**
+ * Return the translation key for the Block, so the client can translate it into the active
+ * locale when using a TranslatableComponent.
+ * @return the translation key
+ */
+ @NotNull
+ String getTranslationKey();
// Paper end
}
diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java
index 9be5371c7f398d0ec8241403661415ff40661067..f415b61b0d4b57e1557aaf240a0f2ad5915035fc 100644
--- a/src/main/java/org/bukkit/entity/EntityType.java
+++ b/src/main/java/org/bukkit/entity/EntityType.java
@@ -419,4 +419,15 @@ public enum EntityType implements Keyed {
public boolean isAlive() {
return living;
}
+
+ /**
+ * Return the translation key for the EntityType, so the client can translate it into the active
+ * locale when using a TranslatableComponent.<br>
+ * This is <code>null</code>, when the EntityType isn't known to NMS (custom entities)
+ * @return the translation key
+ */
+ @Nullable
+ String getTranslationKey() {
+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
+ }
}
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index b80ef2e5c23764ee68f809268185492bf5577913..f2c8ffaf8b62707e7806012d41f9cd7be1638ed9 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -852,5 +852,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
ItemMeta itemMeta = getItemMeta();
return itemMeta != null && itemMeta.hasItemFlag(flag);
}
+
+ /**
+ * Gets the translation key for this itemstack.
+ * This is not the same as getting the translation key
+ * for the material of this itemstack.
+ *
+ * @return the translation key
+ */
+ @NotNull
+ public String getTranslationKey() {
+ return Bukkit.getUnsafe().getTranslationKey(this);
+ }
// Paper end
}