2021-08-14 06:11:12 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Tue, 11 Aug 2020 19:17:46 +0200
Subject: [PATCH] Add methods to get translation keys
Co-authored-by: MeFisto94 <MeFisto94@users.noreply.github.com>
diff --git a/src/main/java/org/bukkit/Difficulty.java b/src/main/java/org/bukkit/Difficulty.java
2023-11-11 23:21:22 +01:00
index f35801783538d3377b04131b8bf6effd7eb8e1a5..427ce8cfd6f63e5c7ec7b264b15ab4111b947729 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/Difficulty.java
+++ b/src/main/java/org/bukkit/Difficulty.java
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents the various difficulty levels that are available.
*/
-public enum Difficulty {
+public enum Difficulty implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
/**
* Players regain health over time, hostile mobs don't spawn, the hunger
* bar does not deplete.
@@ -51,6 +51,12 @@ public enum Difficulty {
return value;
}
+ // Paper start
+ @Override
+ public @org.jetbrains.annotations.NotNull String translationKey() {
+ return "options.difficulty." + this.name().toLowerCase(java.util.Locale.ENGLISH);
+ }
+ // Paper end
/**
* Gets the Difficulty represented by the specified value
*
diff --git a/src/main/java/org/bukkit/FireworkEffect.java b/src/main/java/org/bukkit/FireworkEffect.java
2022-06-07 19:20:30 +02:00
index bf7db5b3e7c2ac15016a48e520fba674726718ee..637fa73d4366c2d88e2716e5c8d3465706d788a7 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/FireworkEffect.java
+++ b/src/main/java/org/bukkit/FireworkEffect.java
@@ -18,28 +18,44 @@ public final class FireworkEffect implements ConfigurationSerializable {
/**
* The type or shape of the effect.
*/
- public enum Type {
+ public enum Type implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
/**
* A small ball effect.
*/
- BALL,
+ BALL("small_ball"), // Paper - add name
/**
* A large ball effect.
*/
- BALL_LARGE,
+ BALL_LARGE("large_ball"), // Paper - add name
/**
* A star-shaped effect.
*/
- STAR,
+ STAR("star"), // Paper - add name
/**
* A burst effect.
*/
- BURST,
+ BURST("burst"), // Paper - add name
/**
* A creeper-face effect.
*/
- CREEPER,
+ CREEPER("creeper"), // Paper - add name
;
+ // Paper start
+ /**
+ * The name map.
+ */
+ public static final net.kyori.adventure.util.Index<String, org.bukkit.FireworkEffect.Type> NAMES = net.kyori.adventure.util.Index.create(Type.class, type -> type.name);
+ private final String name;
+
+ Type(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public @NotNull String translationKey() {
+ return "item.minecraft.firework_star.shape." + this.name;
+ }
+ // Paper end
}
2022-06-02 03:30:29 +02:00
/**
diff --git a/src/main/java/org/bukkit/GameMode.java b/src/main/java/org/bukkit/GameMode.java
2023-11-11 23:21:22 +01:00
index 81e45984a88fc84acd0f76d825abf4ddaed0ac3b..fdc42a79c5af30fdade41ee99245e6641f353571 100644
2022-06-02 03:30:29 +02:00
--- a/src/main/java/org/bukkit/GameMode.java
+++ b/src/main/java/org/bukkit/GameMode.java
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
* Represents the various type of game modes that {@link HumanEntity}s may
* have
*/
-public enum GameMode {
+public enum GameMode implements net.kyori.adventure.translation.Translatable { // Paper - implement Translatable
/**
* Creative mode may fly, build instantly, become invulnerable and create
* free items.
@@ -35,9 +35,18 @@ public enum GameMode {
private final int value;
private static final Map<Integer, GameMode> BY_ID = Maps.newHashMap();
+ // Paper start - translation keys
+ private final String translationKey;
+
+ @Override
+ public @org.jetbrains.annotations.NotNull String translationKey() {
+ return this.translationKey;
+ }
+ // Paper end
private GameMode(final int value) {
this.value = value;
+ this.translationKey = "gameMode." + this.name().toLowerCase(java.util.Locale.ENGLISH); // Paper
}
2021-08-14 06:11:12 +02:00
/**
diff --git a/src/main/java/org/bukkit/GameRule.java b/src/main/java/org/bukkit/GameRule.java
2024-04-23 19:02:08 +02:00
index dc66bd69646ac949d1386ce8f6ff913e9475439d..4482e8f2c617c2f51b2b53762e775d118002363a 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/GameRule.java
+++ b/src/main/java/org/bukkit/GameRule.java
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
*
* @param <T> type of rule (Boolean or Integer)
*/
-public final class GameRule<T> {
+public final class GameRule<T> implements net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
private static Map<String, GameRule<?>> gameRules = new HashMap<>();
// Boolean rules
2024-04-23 19:02:08 +02:00
@@ -355,4 +355,11 @@ public final class GameRule<T> {
2021-08-14 06:11:12 +02:00
public static GameRule<?>[] values() {
return gameRules.values().toArray(new GameRule<?>[gameRules.size()]);
}
+
+ // Paper start
+ @Override
+ public @NotNull String translationKey() {
+ return "gamerule." + this.name;
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
2024-06-13 17:45:43 +02:00
index 444406eb7f0c3cd13039bf809254e480ee6fa24f..c12bb07fcf29be1a284f5f272b35edf206633d4a 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
2024-06-13 17:45:43 +02:00
@@ -128,7 +128,7 @@ import org.jetbrains.annotations.Nullable;
2021-08-14 06:11:12 +02:00
* An enum of all material IDs accepted by the official server and client
*/
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"}) // Paper
2023-02-15 23:10:14 +01:00
-public enum Material implements Keyed, Translatable {
+public enum Material implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper
2021-08-14 06:11:12 +02:00
//<editor-fold desc="Materials" defaultstate="collapsed">
AIR(9648, 0),
STONE(22948),
2024-06-13 17:45:43 +02:00
@@ -4677,6 +4677,17 @@ public enum Material implements Keyed, Translatable {
2021-08-14 06:11:12 +02:00
}
2024-05-23 19:32:02 +02:00
// Paper end
+ // Paper start - add Translatable
2021-08-14 06:11:12 +02:00
+ @Override
+ public @NotNull String translationKey() {
2023-02-15 23:10:14 +01:00
+ if (this.isItem()) {
2024-05-23 19:32:02 +02:00
+ return java.util.Objects.requireNonNull(this.asItemType()).translationKey();
2023-02-15 23:10:14 +01:00
+ } else {
2024-05-23 19:32:02 +02:00
+ return java.util.Objects.requireNonNull(this.asBlockType()).translationKey();
2023-02-15 23:10:14 +01:00
+ }
2021-08-14 06:11:12 +02:00
+ }
2024-05-23 19:32:02 +02:00
+ // Paper end - add Translatable
+
2021-08-14 06:11:12 +02:00
/**
2024-05-23 19:32:02 +02:00
* Do not use for any reason.
*
2024-06-13 17:45:43 +02:00
@@ -5426,9 +5437,11 @@ public enum Material implements Keyed, Translatable {
2023-02-15 23:10:14 +01:00
* material
* @see #getBlockTranslationKey()
* @see #getItemTranslationKey()
+ * @deprecated use {@link #translationKey()}
*/
@Override
@NotNull
+ @Deprecated(forRemoval = true) // Paper
public String getTranslationKey() {
if (this.isItem()) {
2024-05-11 23:48:37 +02:00
return asItemType().getTranslationKey();
2023-07-29 00:06:27 +02:00
diff --git a/src/main/java/org/bukkit/MusicInstrument.java b/src/main/java/org/bukkit/MusicInstrument.java
2024-04-23 19:02:08 +02:00
index eae90e72b1dff5ab3b1a4fdcfe57187e85fe4d49..62d2b3f950860dee0898d77b0a29635c3f9a7e23 100644
2023-07-29 00:06:27 +02:00
--- a/src/main/java/org/bukkit/MusicInstrument.java
+++ b/src/main/java/org/bukkit/MusicInstrument.java
2023-09-21 18:48:55 +02:00
@@ -7,7 +7,7 @@ import java.util.Collections;
2023-07-29 00:06:27 +02:00
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2023-09-21 18:48:55 +02:00
-public abstract class MusicInstrument implements Keyed {
+public abstract class MusicInstrument implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - translation keys
2023-07-29 00:06:27 +02:00
2024-04-23 19:02:08 +02:00
public static final MusicInstrument PONDER_GOAT_HORN = getInstrument("ponder_goat_horn");
public static final MusicInstrument SING_GOAT_HORN = getInstrument("sing_goat_horn");
2023-09-21 18:48:55 +02:00
@@ -52,4 +52,11 @@ public abstract class MusicInstrument implements Keyed {
2023-07-29 00:06:27 +02:00
2023-09-21 18:48:55 +02:00
return instrument;
2023-07-29 00:06:27 +02:00
}
+
+ // Paper start - translation key
+ @Override
+ public @NotNull String translationKey() {
2023-09-21 18:48:55 +02:00
+ return "instrument.minecraft." + this.getKey().value();
2023-07-29 00:06:27 +02:00
+ }
+ // Paper end - translation key
}
2023-02-15 23:10:14 +01:00
diff --git a/src/main/java/org/bukkit/Translatable.java b/src/main/java/org/bukkit/Translatable.java
index e3faa2c675c85a9cbdbbb1debec0ff81c58a1bbd..fd1629c2d2028a88fb3d56b0aeb833d17235080a 100644
--- a/src/main/java/org/bukkit/Translatable.java
+++ b/src/main/java/org/bukkit/Translatable.java
@@ -5,14 +5,18 @@ import org.jetbrains.annotations.NotNull;
/**
* Represents an object with a text representation that can be translated by the
* Minecraft client.
+ * @deprecated use {@link net.kyori.adventure.translation.Translatable}
*/
+@Deprecated(forRemoval = true) // Paper
public interface Translatable {
2021-08-14 06:11:12 +02:00
2023-02-15 23:10:14 +01:00
/**
* Get the translation key, suitable for use in a translation component.
*
* @return the translation key
+ * @deprecated look for a {@code translationKey()} method instead
*/
@NotNull
+ @Deprecated(forRemoval = true) // Paper
String getTranslationKey();
2021-08-14 06:11:12 +02:00
}
diff --git a/src/main/java/org/bukkit/attribute/Attribute.java b/src/main/java/org/bukkit/attribute/Attribute.java
2024-06-13 17:45:43 +02:00
index ef9c998691d101c26b5247a4962628a7bc9e513f..947874c0172b690e7752e49b7bec64e0c0308515 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/attribute/Attribute.java
+++ b/src/main/java/org/bukkit/attribute/Attribute.java
2024-04-06 21:53:39 +02:00
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
2021-08-14 06:11:12 +02:00
/**
* Types of attributes which may be present on an {@link Attributable}.
*/
2024-04-06 21:53:39 +02:00
-public enum Attribute implements Keyed, Translatable {
+public enum Attribute implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
2021-08-14 06:11:12 +02:00
/**
* Maximum health of an Entity.
2024-06-13 17:45:43 +02:00
@@ -153,4 +153,12 @@ public enum Attribute implements Keyed, Translatable {
2024-04-06 21:53:39 +02:00
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
2021-08-14 06:11:12 +02:00
}
2024-04-06 21:53:39 +02:00
+
2021-08-14 06:11:12 +02:00
+ // Paper start
2024-04-06 21:53:39 +02:00
+ @SuppressWarnings("deprecation")
2021-08-14 06:11:12 +02:00
+ @Override
+ public @NotNull String translationKey() {
2024-04-06 21:53:39 +02:00
+ return Bukkit.getUnsafe().getTranslationKey(this);
2021-08-14 06:11:12 +02:00
+ }
2022-07-20 18:23:26 +02:00
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/block/Biome.java b/src/main/java/org/bukkit/block/Biome.java
2023-06-07 18:24:39 +02:00
index d3087d60378822cdd7cea25fd63d3f496e3cd2fb..5d8fa5b39a5d50cca48ba63af3a84b80f279b649 100644
2022-07-20 18:23:26 +02:00
--- a/src/main/java/org/bukkit/block/Biome.java
+++ b/src/main/java/org/bukkit/block/Biome.java
2023-06-07 18:24:39 +02:00
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
2022-07-20 18:23:26 +02:00
/**
* Holds all accepted Biomes in the default server
*/
-public enum Biome implements Keyed {
+public enum Biome implements Keyed, net.kyori.adventure.translation.Translatable { // Paper
OCEAN,
PLAINS,
DESERT,
2023-06-07 18:24:39 +02:00
@@ -89,4 +89,11 @@ public enum Biome implements Keyed {
2022-07-20 18:23:26 +02:00
public NamespacedKey getKey() {
return key;
}
+
+ // Paper start
+ @Override
+ public @NotNull String translationKey() {
+ return "biome.minecraft." + this.key.getKey();
+ }
2021-08-14 06:11:12 +02:00
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
2024-06-13 16:45:27 +02:00
index 745413357506fa7399f8ba44dfe222d1f0c919f1..25db31b2e9a6d75f0c59f75237842f9ad7d1c350 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
2023-02-15 23:10:14 +01:00
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
2021-08-14 06:11:12 +02:00
* (i.e. lighting and power) may not be able to be safely accessed during world
* generation when used in cases like BlockPhysicsEvent!!!!
*/
2023-02-15 23:10:14 +01:00
-public interface Block extends Metadatable, Translatable {
+public interface Block extends Metadatable, Translatable, net.kyori.adventure.translation.Translatable { // Paper - translatable
2021-08-14 06:11:12 +02:00
/**
* Gets the metadata for this block
2024-01-27 18:35:09 +01:00
@@ -682,5 +682,12 @@ public interface Block extends Metadatable, Translatable {
2022-04-30 22:44:22 +02:00
* @return the sound group for this block
2021-08-14 06:11:12 +02:00
*/
2022-04-30 22:44:22 +02:00
@NotNull org.bukkit.SoundGroup getBlockSoundGroup();
2021-08-14 06:11:12 +02:00
+
+ /**
+ * @deprecated use {@link #translationKey()}
+ */
+ @NotNull
2023-02-15 23:10:14 +01:00
+ @Deprecated(forRemoval = true)
2021-08-14 06:11:12 +02:00
+ String getTranslationKey();
// Paper end
}
2024-05-23 19:32:02 +02:00
diff --git a/src/main/java/org/bukkit/block/BlockType.java b/src/main/java/org/bukkit/block/BlockType.java
2024-06-13 17:45:43 +02:00
index 4288bebf690a9cee6ff9a712352d1dcbb035eb77..a08c52949af1d2416ecb089fc559db2e3b29105c 100644
2024-05-23 19:32:02 +02:00
--- a/src/main/java/org/bukkit/block/BlockType.java
+++ b/src/main/java/org/bukkit/block/BlockType.java
2024-06-13 17:45:43 +02:00
@@ -123,7 +123,7 @@ import org.jetbrains.annotations.Nullable;
2024-05-23 19:32:02 +02:00
* changes may occur. Do not use this API in plugins.
*/
@ApiStatus.Internal
-public interface BlockType extends Keyed, Translatable {
+public interface BlockType extends Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - add translatable
/**
* Typed represents a subtype of {@link BlockType}s that have a known block
2024-06-13 17:45:43 +02:00
@@ -3491,4 +3491,13 @@ public interface BlockType extends Keyed, Translatable {
2024-05-23 19:32:02 +02:00
@Nullable
@Deprecated
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
}
2021-08-14 06:11:12 +02:00
diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java
2024-06-14 00:44:26 +02:00
index 64675a3641acb50676ca0122f8473ce94de8fba7..daae9bb234d2e10530b2bed35fada98652514e0e 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/enchantments/Enchantment.java
+++ b/src/main/java/org/bukkit/enchantments/Enchantment.java
2024-06-13 17:45:43 +02:00
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
2021-08-14 06:11:12 +02:00
/**
* The various type of enchantments that may be added to armour or weapons
*/
2024-04-06 21:53:39 +02:00
-public abstract class Enchantment implements Keyed, Translatable {
+public abstract class Enchantment implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
2021-08-14 06:11:12 +02:00
/**
* Provides protection against environmental damage
*/
2024-06-14 00:44:26 +02:00
@@ -330,6 +330,16 @@ public abstract class Enchantment implements Keyed, Translatable {
public abstract net.kyori.adventure.text.@NotNull Component displayName(int level);
// Paper end
+ // Paper start - mark translation key as deprecated
+ /**
+ * @deprecated this method assumes that the enchantments description
+ * always be a translatable component which is not guaranteed.
+ */
+ @Override
+ @Deprecated(forRemoval = true)
+ public abstract @NotNull String translationKey();
+ // Paper end - mark translation key as deprecated
+
/**
* Gets the Enchantment at the specified key
*
2021-08-14 06:11:12 +02:00
diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
2023-12-05 18:33:18 +01:00
index c4f86ba1037f3f0e5d697a0962d71d6f8c7c1fbe..ac0371285370594d4de1554871b19bbcd2311730 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
+++ b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
2023-12-05 18:33:18 +01:00
@@ -26,5 +26,10 @@ public abstract class EnchantmentWrapper extends Enchantment {
2021-08-14 06:11:12 +02:00
public net.kyori.adventure.text.Component displayName(int level) {
return getEnchantment().displayName(level);
}
+
+ @Override
+ public @NotNull String translationKey() {
+ return getEnchantment().translationKey();
+ }
// Paper end
}
diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java
2024-06-13 17:45:43 +02:00
index d248069adfc67eb840951f7ab4a1fa5d30214dec..976f701ed9b9873945a5628173c580e2e6873864 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/entity/EntityType.java
+++ b/src/main/java/org/bukkit/entity/EntityType.java
2024-06-13 17:45:43 +02:00
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.Contract;
2021-08-14 06:11:12 +02:00
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2023-02-15 23:10:14 +01:00
-public enum EntityType implements Keyed, Translatable {
+public enum EntityType implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - translatable
2021-08-14 06:11:12 +02:00
// These strings MUST match the strings in nms.EntityTypes and are case sensitive.
/**
2024-06-13 17:45:43 +02:00
@@ -427,10 +427,22 @@ public enum EntityType implements Keyed, Translatable {
2023-02-15 23:10:14 +01:00
@Override
@NotNull
+ @Deprecated(forRemoval = true) // Paper
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
2021-08-14 06:11:12 +02:00
}
2023-06-06 11:09:19 +02:00
2023-02-15 23:10:14 +01:00
+ // Paper start
2021-08-14 06:11:12 +02:00
+ /**
+ * @throws IllegalArgumentException if the entity does not have a translation key (is probably a custom entity)
+ */
+ @Override
+ public @NotNull String translationKey() {
+ Preconditions.checkArgument(this != UNKNOWN, "UNKNOWN entities do not have translation keys");
+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
+ }
+ // Paper end
2023-06-06 11:09:19 +02:00
+
/**
* Gets if this EntityType is enabled by feature in a world.
*
2021-09-22 06:45:01 +02:00
diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
2023-04-09 02:00:50 +02:00
index d841d94d46462e0ceb7c6b04cc8fc36792bd9201..8c8176121cafed0ed09239b6a7b392dc846438e2 100644
2021-09-22 06:45:01 +02:00
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
2022-04-16 10:29:50 +02:00
@@ -160,7 +160,7 @@ public interface Villager extends AbstractVillager {
2021-09-22 06:45:01 +02:00
* Represents the various different Villager professions there may be.
* Villagers have different trading options depending on their profession,
*/
- public enum Profession implements Keyed {
+ public enum Profession implements Keyed, net.kyori.adventure.translation.Translatable { // Paper
NONE,
/**
* Armorer profession. Wears a black apron. Armorers primarily trade for
2022-04-16 10:29:50 +02:00
@@ -243,6 +243,13 @@ public interface Villager extends AbstractVillager {
2021-09-22 06:45:01 +02:00
public NamespacedKey getKey() {
return key;
}
+
+ // Paper start
+ @Override
+ public @NotNull String translationKey() {
+ return "entity.minecraft.villager." + this.key.getKey();
+ }
+ // Paper end
}
// Paper start - Add villager reputation API
2022-06-02 02:07:10 +02:00
diff --git a/src/main/java/org/bukkit/inventory/CreativeCategory.java b/src/main/java/org/bukkit/inventory/CreativeCategory.java
2022-07-20 18:23:26 +02:00
index 5bd252c0ae3b09fe141d131360c67bb9bfbf5422..78587d9fabe6371a23a7963917b054dbe7603694 100644
2022-06-02 02:07:10 +02:00
--- a/src/main/java/org/bukkit/inventory/CreativeCategory.java
+++ b/src/main/java/org/bukkit/inventory/CreativeCategory.java
@@ -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;
+ }
2022-07-20 18:23:26 +02:00
+ // Paper end
2022-06-02 02:07:10 +02:00
+
}
2021-08-14 06:11:12 +02:00
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
2024-06-14 14:11:52 +02:00
index abdb3b5d3bc96fc48ee53208f77ae0f9c295d771..03f50bcf60ce868d633912e53e804a2b25999f6e 100644
2021-08-14 06:11:12 +02:00
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
2024-06-14 14:11:52 +02:00
@@ -27,7 +27,7 @@ import org.jetbrains.annotations.Nullable;
2021-08-14 06:11:12 +02:00
* use this class to encapsulate Materials for which {@link Material#isItem()}
* returns false.</b>
*/
2023-02-15 23:10:14 +01:00
-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
2021-08-14 06:11:12 +02:00
private Material type = Material.AIR;
private int amount = 0;
private MaterialData data = null;
2024-06-14 14:11:52 +02:00
@@ -628,6 +628,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
2023-02-15 23:10:14 +01:00
@Override
@NotNull
+ @Deprecated(forRemoval = true) // Paper
public String getTranslationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
2024-06-14 14:11:52 +02:00
@@ -895,5 +896,16 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
2021-08-14 06:11:12 +02:00
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
}
2024-05-23 19:32:02 +02:00
diff --git a/src/main/java/org/bukkit/inventory/ItemType.java b/src/main/java/org/bukkit/inventory/ItemType.java
2024-06-13 17:45:43 +02:00
index 270f85e99084ddf029bef076c335fe6b9bbddbb5..5dd1c084e42ee93f3a358f58ed76b0a7d36f0713 100644
2024-05-23 19:32:02 +02:00
--- a/src/main/java/org/bukkit/inventory/ItemType.java
+++ b/src/main/java/org/bukkit/inventory/ItemType.java
2024-06-13 17:45:43 +02:00
@@ -47,7 +47,7 @@ import org.jetbrains.annotations.Nullable;
2024-05-23 19:32:02 +02:00
* 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
2024-06-13 17:45:43 +02:00
@@ -2302,4 +2302,13 @@ public interface ItemType extends Keyed, Translatable {
2024-05-23 19:32:02 +02:00
@Nullable
@Deprecated
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
}