mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Implement Translatable on CreativeCategory (#7587)
This commit is contained in:
parent
a063840a0e
commit
63ffb7fd84
@ -336,6 +336,85 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Paper start - Add villager reputation API
|
// Paper start - Add villager reputation API
|
||||||
|
diff --git a/src/main/java/org/bukkit/inventory/CreativeCategory.java b/src/main/java/org/bukkit/inventory/CreativeCategory.java
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/inventory/CreativeCategory.java
|
||||||
|
+++ b/src/main/java/org/bukkit/inventory/CreativeCategory.java
|
||||||
|
@@ -0,0 +0,0 @@ package org.bukkit.inventory;
|
||||||
|
/**
|
||||||
|
* Represents a category in the creative inventory.
|
||||||
|
*/
|
||||||
|
-public enum CreativeCategory {
|
||||||
|
+public enum CreativeCategory implements net.kyori.adventure.translation.Translatable { // Paper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An assortment of building blocks including dirt, bricks, planks, ores
|
||||||
|
* slabs, etc.
|
||||||
|
*/
|
||||||
|
- BUILDING_BLOCKS,
|
||||||
|
+ BUILDING_BLOCKS("buildingBlocks"), // Paper
|
||||||
|
/**
|
||||||
|
* Blocks and items typically used for decorative purposes including
|
||||||
|
* candles, saplings, flora, fauna, fences, walls, carpets, etc.
|
||||||
|
*/
|
||||||
|
- DECORATIONS,
|
||||||
|
+ DECORATIONS("decorations"), // Paper
|
||||||
|
/**
|
||||||
|
* Blocks used and associated with redstone contraptions including buttons,
|
||||||
|
* levers, pressure plates, redstone components, pistons, etc.
|
||||||
|
*/
|
||||||
|
- REDSTONE,
|
||||||
|
+ REDSTONE("redstone"), // Paper
|
||||||
|
/**
|
||||||
|
* Items pertaining to transportation including minecarts, rails, boats,
|
||||||
|
* elytra, etc.
|
||||||
|
*/
|
||||||
|
- TRANSPORTATION,
|
||||||
|
+ TRANSPORTATION("transportation"), // Paper
|
||||||
|
/**
|
||||||
|
* Miscellaneous items and blocks that do not fit into other categories
|
||||||
|
* including gems, dyes, spawn eggs, discs, banner patterns, etc.
|
||||||
|
*/
|
||||||
|
- MISC,
|
||||||
|
+ MISC("misc"), // Paper
|
||||||
|
/**
|
||||||
|
* Food items consumable by the player including meats, berries, edible
|
||||||
|
* drops from creatures, etc.
|
||||||
|
*/
|
||||||
|
- FOOD,
|
||||||
|
+ FOOD("food"), // Paper
|
||||||
|
/**
|
||||||
|
* Equipment items meant for general utility including pickaxes, axes, hoes,
|
||||||
|
* flint and steel, and useful enchantment books for said tools.
|
||||||
|
*/
|
||||||
|
- TOOLS,
|
||||||
|
+ TOOLS("tools"), // Paper
|
||||||
|
/**
|
||||||
|
* Equipment items meant for combat including armor, swords, bows, tipped
|
||||||
|
* arrows, and useful enchantment books for said equipment.
|
||||||
|
*/
|
||||||
|
- COMBAT,
|
||||||
|
+ COMBAT("combat"), // Paper
|
||||||
|
/**
|
||||||
|
* All items related to brewing and potions including all types of potions,
|
||||||
|
* their variants, and ingredients to brew them.
|
||||||
|
*/
|
||||||
|
- BREWING;
|
||||||
|
+ BREWING("brewing"); // Paper
|
||||||
|
+ // Paper start
|
||||||
|
+ private final String translationKey;
|
||||||
|
+
|
||||||
|
+ CreativeCategory(String translationKey) {
|
||||||
|
+ this.translationKey = "itemGroup." + translationKey;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public @org.jetbrains.annotations.NotNull String translationKey() {
|
||||||
|
+ return this.translationKey;
|
||||||
|
+ }
|
||||||
|
+ // Paper start
|
||||||
|
+
|
||||||
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||||
|
@ -80,12 +80,25 @@ diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/
|
|||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
||||||
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
||||||
@@ -0,0 +0,0 @@ import org.bukkit.Difficulty;
|
@@ -0,0 +0,0 @@ package io.papermc.paper.world;
|
||||||
|
import com.destroystokyo.paper.ClientOption;
|
||||||
|
import net.minecraft.network.chat.TranslatableComponent;
|
||||||
|
import net.minecraft.world.entity.player.ChatVisiblity;
|
||||||
|
+import net.minecraft.world.item.CreativeModeTab;
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
+import org.bukkit.FireworkEffect;
|
||||||
|
+import org.bukkit.GameRule;
|
||||||
|
+import org.bukkit.attribute.Attribute;
|
||||||
|
+import org.bukkit.craftbukkit.inventory.CraftCreativeCategory;
|
||||||
|
+import org.bukkit.inventory.CreativeCategory;
|
||||||
|
+import org.bukkit.support.AbstractTestingBase;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
-public class TranslationKeyTest {
|
-public class TranslationKeyTest {
|
||||||
+public class TranslationKeyTest extends org.bukkit.support.AbstractTestingBase {
|
+import java.util.Objects;
|
||||||
|
+
|
||||||
|
+public class TranslationKeyTest extends AbstractTestingBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChatVisibilityKeys() {
|
public void testChatVisibilityKeys() {
|
||||||
@ -103,22 +116,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+
|
+
|
||||||
+ @Test
|
+ @Test
|
||||||
+ public void testGameruleKeys() {
|
+ public void testGameruleKeys() {
|
||||||
+ for (org.bukkit.GameRule<?> rule : org.bukkit.GameRule.values()) {
|
+ for (GameRule<?> rule : GameRule.values()) {
|
||||||
+ Assert.assertEquals(rule.getName() + "'s translation doesn't match", org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey());
|
+ Assert.assertEquals(rule.getName() + "'s translation doesn't match", org.bukkit.craftbukkit.CraftWorld.getGameRulesNMS().get(rule.getName()).getDescriptionId(), rule.translationKey());
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Test
|
+ @Test
|
||||||
+ public void testAttributeKeys() {
|
+ public void testAttributeKeys() {
|
||||||
+ for (org.bukkit.attribute.Attribute attribute : org.bukkit.attribute.Attribute.values()) {
|
+ for (Attribute attribute : Attribute.values()) {
|
||||||
+ Assert.assertEquals("translation key mismatch for " + attribute, org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute).getDescriptionId(), attribute.translationKey());
|
+ Assert.assertEquals("translation key mismatch for " + attribute, org.bukkit.craftbukkit.attribute.CraftAttributeMap.toMinecraft(attribute).getDescriptionId(), attribute.translationKey());
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Test
|
+ @Test
|
||||||
+ public void testFireworkEffectType() {
|
+ public void testFireworkEffectType() {
|
||||||
+ for (org.bukkit.FireworkEffect.Type type : org.bukkit.FireworkEffect.Type.values()) {
|
+ for (FireworkEffect.Type type : FireworkEffect.Type.values()) {
|
||||||
+ Assert.assertEquals("translation key mismatch for " + type, net.minecraft.world.item.FireworkRocketItem.Shape.byId(org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type)).getName(), org.bukkit.FireworkEffect.Type.NAMES.key(type));
|
+ Assert.assertEquals("translation key mismatch for " + type, net.minecraft.world.item.FireworkRocketItem.Shape.byId(org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type)).getName(), org.bukkit.FireworkEffect.Type.NAMES.key(type));
|
||||||
+ }
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Test
|
||||||
|
+ public void testCreativeCategory() {
|
||||||
|
+ for (CreativeModeTab tab : CreativeModeTab.TABS) {
|
||||||
|
+ if (tab == CreativeModeTab.TAB_SEARCH || tab == CreativeModeTab.TAB_HOTBAR || tab == CreativeModeTab.TAB_INVENTORY) { // not implemented in the api
|
||||||
|
+ continue;
|
||||||
|
+ }
|
||||||
|
+ CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab));
|
||||||
|
+ Assert.assertEquals("translation key mismatch for " + category, ((TranslatableComponent) tab.getDisplayName()).getKey(), category.translationKey());
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user