Add methods to get translation keys

Co-authored-by: MeFisto94 <MeFisto94@users.noreply.github.com>
This commit is contained in:
Jake Potrebic
2020-08-11 19:17:46 +02:00
parent a3e3ba54a0
commit f610d0b477
18 changed files with 186 additions and 30 deletions

View File

@@ -3,51 +3,64 @@ 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 end
}

View File

@@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable;
* use this class to encapsulate Materials for which {@link Material#isItem()}
* returns false.</b>
*/
public class ItemStack implements Cloneable, ConfigurationSerializable, Translatable, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowItem> { // Paper
public class ItemStack implements Cloneable, ConfigurationSerializable, Translatable, net.kyori.adventure.text.event.HoverEventSource<net.kyori.adventure.text.event.HoverEvent.ShowItem>, net.kyori.adventure.translation.Translatable { // Paper
private Material type = Material.AIR;
private int amount = 0;
private MaterialData data = null;
@@ -628,6 +628,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
@Override
@NotNull
@Deprecated(forRemoval = true) // Paper
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
@@ -982,5 +983,16 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
ItemMeta itemMeta = getItemMeta();
return itemMeta != null && itemMeta.hasItemFlag(flag);
}
/**
* {@inheritDoc}
* <p>
* This is not the same as getting the translation key
* for the material of this itemstack.
*/
@Override
public @NotNull String translationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
// Paper end
}

View File

@@ -47,7 +47,7 @@ import org.jetbrains.annotations.Nullable;
* changes may occur. Do not use this API in plugins.
*/
@ApiStatus.Internal
public interface ItemType extends Keyed, Translatable {
public interface ItemType extends Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - add Translatable
/**
* Typed represents a subtype of {@link ItemType}s that have a known item meta type
@@ -2409,4 +2409,13 @@ public interface ItemType extends Keyed, Translatable {
@Nullable
@Deprecated(since = "1.20.6")
Material asMaterial();
// Paper start - add Translatable
/**
* @deprecated use {@link #translationKey()} and {@link net.kyori.adventure.text.Component#translatable(net.kyori.adventure.translation.Translatable)}
*/
@Deprecated(forRemoval = true)
@Override
@NotNull String getTranslationKey();
// Paper end - add Translatable
}