2020-08-11 21:20:44 +02:00
|
|
|
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
|
2021-04-13 11:27:34 +02:00
|
|
|
index 2b53e68e96ea346a6f2b5cadcf9f81b2c231c408..e453e5eb7245aad3ecbb19652ebb34abe030c0a9 100644
|
2020-08-11 21:20:44 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Material.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Material.java
|
2021-04-13 11:27:34 +02:00
|
|
|
@@ -3578,6 +3578,16 @@ public enum Material implements Keyed {
|
2020-08-11 21:20:44 +02:00
|
|
|
}
|
|
|
|
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
|
2021-05-12 13:12:28 +02:00
|
|
|
index e348034288c74ab80360086d71f0b7f61551df24..2d9264ffe0fee863f1b814952ef063daa7962d76 100644
|
2020-08-11 21:20:44 +02:00
|
|
|
--- a/src/main/java/org/bukkit/UnsafeValues.java
|
|
|
|
+++ b/src/main/java/org/bukkit/UnsafeValues.java
|
2021-05-12 13:12:28 +02:00
|
|
|
@@ -101,5 +101,34 @@ public interface UnsafeValues {
|
2020-08-11 21:20:44 +02:00
|
|
|
byte[] serializeItem(ItemStack item);
|
|
|
|
|
|
|
|
ItemStack deserializeItem(byte[] data);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Return the translation key for the Material, so the client can translate it into the active
|
2021-05-12 13:12:28 +02:00
|
|
|
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
|
2020-08-11 21:20:44 +02:00
|
|
|
+ * @return the translation key
|
|
|
|
+ */
|
|
|
|
+ String getTranslationKey(Material mat);
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Return the translation key for the Block, so the client can translate it into the active
|
2021-05-12 13:12:28 +02:00
|
|
|
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.
|
2020-08-11 21:20:44 +02:00
|
|
|
+ * @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
|
2021-05-12 13:12:28 +02:00
|
|
|
+ * locale when using a {@link net.kyori.adventure.text.TranslatableComponent}.<br>
|
2020-08-11 21:20:44 +02:00
|
|
|
+ * 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);
|
2021-05-12 13:12:28 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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);
|
2020-08-11 21:20:44 +02:00
|
|
|
// Paper end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
|
2021-04-21 09:42:33 +02:00
|
|
|
index e1cc36fbe808973227c0e8ca7166453235c90279..e6647c45f65bae916759cd899256f8130790d242 100644
|
2020-08-11 21:20:44 +02:00
|
|
|
--- a/src/main/java/org/bukkit/block/Block.java
|
|
|
|
+++ b/src/main/java/org/bukkit/block/Block.java
|
2021-04-21 09:42:33 +02:00
|
|
|
@@ -584,5 +584,13 @@ public interface Block extends Metadatable {
|
2020-08-11 21:20:44 +02:00
|
|
|
*/
|
|
|
|
@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 774363a8186b3861f10c0452ac63726cae365169..692b75eb78405874077c850bfc72e247ccc80860 100644
|
|
|
|
--- a/src/main/java/org/bukkit/entity/EntityType.java
|
|
|
|
+++ b/src/main/java/org/bukkit/entity/EntityType.java
|
|
|
|
@@ -414,4 +414,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);
|
|
|
|
+ }
|
|
|
|
}
|
2021-05-12 13:12:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
2021-05-13 08:16:33 +02:00
|
|
|
index 15b48ad1ba5bcf7394fb3f52ce2cc6baa6632f66..c236cb81b7ec7993b63da929c0492564e75581ee 100644
|
2021-05-12 13:12:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
|
|
|
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
2021-05-13 08:16:33 +02:00
|
|
|
@@ -851,5 +851,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
|
2021-05-12 13:12:28 +02:00
|
|
|
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
|
|
|
|
}
|