summaryrefslogtreecommitdiffhomepage
path: root/patches/api/0212-Add-methods-to-get-translation-keys.patch
blob: 96b7bbb309108a56adddf9f43efe56c4259ca33b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
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
index 3f6cbefc2b1414ba2dad709e79288013b3ef73be..122884098f08c9aa5e144876746b5ce4e8f1a4b6 100644
--- 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
index bf7db5b3e7c2ac15016a48e520fba674726718ee..637fa73d4366c2d88e2716e5c8d3465706d788a7 100644
--- 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
     }
 
     /**
diff --git a/src/main/java/org/bukkit/GameMode.java b/src/main/java/org/bukkit/GameMode.java
index 938c3217f92e6d3ef9a637269c469f8359af6347..ef49495909a37d718a87d5dfbcd644d46e27fa88 100644
--- 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
     }
 
     /**
diff --git a/src/main/java/org/bukkit/GameRule.java b/src/main/java/org/bukkit/GameRule.java
index 753bfcec441533071120d925c83789ef53afa176..c6bc84a8755b2fe5d7d8d3ec857700ec1cba3c9b 100644
--- 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
@@ -323,4 +323,11 @@ public final class GameRule<T> {
     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
index 7705fece7f58bd66f7d68da85f8f34e43b4bae12..6a89eab53f21bc4420e616cc299864fb564e1045 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -119,7 +119,7 @@ import org.jetbrains.annotations.Nullable;
  * An enum of all material IDs accepted by the official server and client
  */
 @SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"}) // Paper
-public enum Material implements Keyed, Translatable {
+public enum Material implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper
     //<editor-fold desc="Materials" defaultstate="collapsed">
     AIR(9648, 0),
     STONE(22948),
@@ -4450,6 +4450,15 @@ public enum Material implements Keyed, Translatable {
         }
         return false;
     }
+
+    @Override
+    public @NotNull String translationKey() {
+        if (this.isItem()) {
+            return Bukkit.getUnsafe().getItemTranslationKey(this);
+        } else {
+            return Bukkit.getUnsafe().getBlockTranslationKey(this);
+        }
+    }
     // Paper end
 
     /**
@@ -10949,9 +10958,11 @@ public enum Material implements Keyed, Translatable {
      * material
      * @see #getBlockTranslationKey()
      * @see #getItemTranslationKey()
+     * @deprecated use {@link #translationKey()}
      */
     @Override
     @NotNull
+    @Deprecated(forRemoval = true) // Paper
     public String getTranslationKey() {
         if (this.isItem()) {
             return Bukkit.getUnsafe().getItemTranslationKey(this);
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 {
 
     /**
      * 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();
 }
diff --git a/src/main/java/org/bukkit/attribute/Attribute.java b/src/main/java/org/bukkit/attribute/Attribute.java
index 13eac9ad2c1672051635d1c35cc49239252e7a61..107e36ef02a9481954bd770ce9a55a0b1e84be7a 100644
--- a/src/main/java/org/bukkit/attribute/Attribute.java
+++ b/src/main/java/org/bukkit/attribute/Attribute.java
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
 /**
  * Types of attributes which may be present on an {@link Attributable}.
  */
-public enum Attribute implements Keyed {
+public enum Attribute implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
 
     /**
      * Maximum health of an Entity.
@@ -73,4 +73,10 @@ public enum Attribute implements Keyed {
     public NamespacedKey getKey() {
         return key;
     }
+    // Paper start
+    @Override
+    public @NotNull String translationKey() {
+        return "attribute.name." + this.key.getKey();
+    }
+    // Paper end
 }
diff --git a/src/main/java/org/bukkit/block/Biome.java b/src/main/java/org/bukkit/block/Biome.java
index d3087d60378822cdd7cea25fd63d3f496e3cd2fb..5d8fa5b39a5d50cca48ba63af3a84b80f279b649 100644
--- a/src/main/java/org/bukkit/block/Biome.java
+++ b/src/main/java/org/bukkit/block/Biome.java
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
 /**
  * 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,
@@ -89,4 +89,11 @@ public enum Biome implements Keyed {
     public NamespacedKey getKey() {
         return key;
     }
+
+    // Paper start
+    @Override
+    public @NotNull String translationKey() {
+        return "biome.minecraft." + this.key.getKey();
+    }
+    // Paper end
 }
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 232662f3130ca49156ed8b71acf4495aea33c212..5ae85ddc2cff3145dcba877a7bf55abd818f6881 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
  * (i.e. lighting and power) may not be able to be safely accessed during world
  * generation when used in cases like BlockPhysicsEvent!!!!
  */
-public interface Block extends Metadatable, Translatable {
+public interface Block extends Metadatable, Translatable, net.kyori.adventure.translation.Translatable { // Paper - translatable
 
     /**
      * Gets the metadata for this block
@@ -673,5 +673,12 @@ public interface Block extends Metadatable, Translatable {
      * @return the sound group for this block
      */
     @NotNull org.bukkit.SoundGroup getBlockSoundGroup();
+
+    /**
+     * @deprecated use {@link #translationKey()}
+     */
+    @NotNull
+    @Deprecated(forRemoval = true)
+    String getTranslationKey();
     // Paper end
 }
diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java
index 2dc749936df6168073a5bb9f9051d55f8589ac62..1b6f42ff632b1f3f5034c825e99b72f389a890b4 100644
--- a/src/main/java/org/bukkit/enchantments/Enchantment.java
+++ b/src/main/java/org/bukkit/enchantments/Enchantment.java
@@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable;
 /**
  * The various type of enchantments that may be added to armour or weapons
  */
-public abstract class Enchantment implements Keyed {
+public abstract class Enchantment implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
     /**
      * Provides protection against environmental damage
      */
diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
index 4d5f0837bd0e02a30c943d8969fb6b13452322e0..a39f9c078f42451bd122f3e3729d10ca299bee5f 100644
--- a/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
+++ b/src/main/java/org/bukkit/enchantments/EnchantmentWrapper.java
@@ -69,5 +69,10 @@ public class EnchantmentWrapper extends Enchantment {
     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
index bb9ae81870a340c00d7480aff5106dc2c44dab8a..6c40a989eff1163c19106c1e6b4c8fc01ace7280 100644
--- a/src/main/java/org/bukkit/entity/EntityType.java
+++ b/src/main/java/org/bukkit/entity/EntityType.java
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-public enum EntityType implements Keyed, Translatable {
+public enum EntityType implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - translatable
 
     // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
     /**
@@ -435,10 +435,22 @@ public enum EntityType implements Keyed, Translatable {
 
     @Override
     @NotNull
+    @Deprecated(forRemoval = true) // Paper
     public String getTranslationKey() {
         return Bukkit.getUnsafe().getTranslationKey(this);
     }
 
+    // Paper start
+    /**
+     * @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
+
     /**
      * Gets if this EntityType is enabled by feature in a world.
      *
diff --git a/src/main/java/org/bukkit/entity/Villager.java b/src/main/java/org/bukkit/entity/Villager.java
index d841d94d46462e0ceb7c6b04cc8fc36792bd9201..8c8176121cafed0ed09239b6a7b392dc846438e2 100644
--- a/src/main/java/org/bukkit/entity/Villager.java
+++ b/src/main/java/org/bukkit/entity/Villager.java
@@ -160,7 +160,7 @@ public interface Villager extends AbstractVillager {
      * 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
@@ -243,6 +243,13 @@ public interface Villager extends AbstractVillager {
         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
diff --git a/src/main/java/org/bukkit/inventory/CreativeCategory.java b/src/main/java/org/bukkit/inventory/CreativeCategory.java
index 5bd252c0ae3b09fe141d131360c67bb9bfbf5422..78587d9fabe6371a23a7963917b054dbe7603694 100644
--- 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;
+    }
+    // Paper end
+
 }
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index 3da071798b89e1dd1453f4339af87933cdf0105e..e4ad3a550050c4bf9cc7a2a1082bfdf668050efe 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -25,7 +25,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;
@@ -606,6 +606,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
 
     @Override
     @NotNull
+    @Deprecated(forRemoval = true) // Paper
     public String getTranslationKey() {
         return Bukkit.getUnsafe().getTranslationKey(this);
     }
@@ -865,5 +866,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
 }