From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MeFisto94 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 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 { } 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -0,0 +0,0 @@ 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 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 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 TranslatableComponent.
+ * This is null, when the EntityType isn't known to NMS (custom entities) + * @return the translation key + */ + String getTranslationKey(org.bukkit.entity.EntityType type); // Paper end } diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/block/Block.java +++ b/src/main/java/org/bukkit/block/Block.java @@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java +++ b/src/main/java/org/bukkit/entity/EntityType.java @@ -0,0 +0,0 @@ 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.
+ * This is null, when the EntityType isn't known to NMS (custom entities) + * @return the translation key + */ + @Nullable + String getTranslationKey() { + return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this); + } }