mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Add methods to get translation keys
== AT == public org.bukkit.craftbukkit.inventory.CraftMetaFirework public org.bukkit.craftbukkit.inventory.CraftMetaFirework power public org.bukkit.craftbukkit.inventory.CraftMetaFirework getNBT(Lorg/bukkit/FireworkEffect$Type;)Lnet/minecraft/world/item/component/FireworkExplosion$Shape; Co-authored-by: MeFisto94 <MeFisto94@users.noreply.github.com>
This commit is contained in:
parent
4f4d4ac73e
commit
97620482eb
8 changed files with 121 additions and 1 deletions
|
@ -68,6 +68,16 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start - add translationKey methods
|
||||||
|
@Override
|
||||||
|
public @NotNull String translationKey() {
|
||||||
|
if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
|
||||||
|
throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||||
|
}
|
||||||
|
return translatableContents.getKey();
|
||||||
|
}
|
||||||
|
// Paper end - add translationKey methods
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (this == other) {
|
if (this == other) {
|
||||||
|
|
|
@ -98,6 +98,11 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
|
||||||
return this.attributeBase.getDescriptionId();
|
return this.attributeBase.getDescriptionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String translationKey() {
|
||||||
|
return this.attributeBase.getDescriptionId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NotNull Attribute attribute) {
|
public int compareTo(@NotNull Attribute attribute) {
|
||||||
return this.ordinal - attribute.ordinal();
|
return this.ordinal - attribute.ordinal();
|
||||||
|
|
|
@ -669,5 +669,10 @@ public class CraftBlock implements Block {
|
||||||
public org.bukkit.SoundGroup getBlockSoundGroup() {
|
public org.bukkit.SoundGroup getBlockSoundGroup() {
|
||||||
return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType());
|
return org.bukkit.craftbukkit.CraftSoundGroup.getSoundGroup(this.getNMS().getSoundType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String translationKey() {
|
||||||
|
return this.getNMS().getBlock().getDescriptionId();
|
||||||
|
}
|
||||||
// Paper end
|
// Paper end
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,4 +234,11 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
|
||||||
public Material asMaterial() {
|
public Material asMaterial() {
|
||||||
return Registry.MATERIAL.get(this.key);
|
return Registry.MATERIAL.get(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start - add Translatable
|
||||||
|
@Override
|
||||||
|
public String translationKey() {
|
||||||
|
return this.block.getDescriptionId();
|
||||||
|
}
|
||||||
|
// Paper end - add Translatable
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,17 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
||||||
}
|
}
|
||||||
// Paper end
|
// Paper end
|
||||||
|
|
||||||
|
// Paper start - add translationKey methods
|
||||||
|
@Override
|
||||||
|
public String translationKey() {
|
||||||
|
if (!(this.getHandle().description().getContents() instanceof final net.minecraft.network.chat.contents.TranslatableContents translatableContents)) {
|
||||||
|
throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||||
|
}
|
||||||
|
return translatableContents.getKey();
|
||||||
|
|
||||||
|
}
|
||||||
|
// Paper end - add translationKey methods
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTranslationKey() {
|
public String getTranslationKey() {
|
||||||
return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location());
|
return Util.makeDescriptionId("enchantment", this.handle.unwrapKey().get().location());
|
||||||
|
|
|
@ -237,4 +237,11 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
|
||||||
public Material asMaterial() {
|
public Material asMaterial() {
|
||||||
return Registry.MATERIAL.get(this.key);
|
return Registry.MATERIAL.get(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start - add Translatable
|
||||||
|
@Override
|
||||||
|
public String translationKey() {
|
||||||
|
return this.item.getDescriptionId();
|
||||||
|
}
|
||||||
|
// Paper end - add Translatable
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta {
|
||||||
return new FireworkExplosion(CraftMetaFirework.getNBT(effect.getType()), colors, fadeColors, effect.hasTrail(), effect.hasFlicker());
|
return new FireworkExplosion(CraftMetaFirework.getNBT(effect.getType()), colors, fadeColors, effect.hasTrail(), effect.hasFlicker());
|
||||||
}
|
}
|
||||||
|
|
||||||
static FireworkExplosion.Shape getNBT(Type type) {
|
public static FireworkExplosion.Shape getNBT(Type type) { // Paper - package-private -> public
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BALL:
|
case BALL:
|
||||||
return FireworkExplosion.Shape.SMALL_BALL;
|
return FireworkExplosion.Shape.SMALL_BALL;
|
||||||
|
|
|
@ -1,11 +1,29 @@
|
||||||
package io.papermc.paper.world;
|
package io.papermc.paper.world;
|
||||||
|
|
||||||
import com.destroystokyo.paper.ClientOption;
|
import com.destroystokyo.paper.ClientOption;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.level.ParticleStatus;
|
import net.minecraft.server.level.ParticleStatus;
|
||||||
import net.minecraft.world.entity.player.ChatVisiblity;
|
import net.minecraft.world.entity.player.ChatVisiblity;
|
||||||
|
import net.minecraft.world.flag.FeatureFlags;
|
||||||
|
import net.minecraft.world.level.GameRules;
|
||||||
|
import net.minecraft.world.level.GameType;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import org.bukkit.Difficulty;
|
||||||
|
import org.bukkit.FireworkEffect;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.GameRule;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
import org.bukkit.support.RegistryHelper;
|
||||||
|
import org.bukkit.support.environment.AllFeatures;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@AllFeatures
|
||||||
public class TranslationKeyTest {
|
public class TranslationKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,4 +40,61 @@ public class TranslationKeyTest {
|
||||||
Assertions.assertEquals(ParticleStatus.valueOf(particleVisibility.name()).getKey(), particleVisibility.translationKey(), particleVisibility + "'s translation key doesn't match");
|
Assertions.assertEquals(ParticleStatus.valueOf(particleVisibility.name()).getKey(), particleVisibility.translationKey(), particleVisibility + "'s translation key doesn't match");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDifficultyKeys() {
|
||||||
|
for (Difficulty bukkitDifficulty : Difficulty.values()) {
|
||||||
|
Assertions.assertEquals(((TranslatableContents) net.minecraft.world.Difficulty.byId(bukkitDifficulty.ordinal()).getDisplayName().getContents()).getKey(), bukkitDifficulty.translationKey(), bukkitDifficulty + "'s translation key doesn't match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGameruleKeys() {
|
||||||
|
final Map<String, GameRules.Key<?>> gameRules = CraftWorld.getGameRulesNMS(new GameRules(FeatureFlags.REGISTRY.allFlags()));
|
||||||
|
for (GameRule<?> rule : GameRule.values()) {
|
||||||
|
Assertions.assertEquals(gameRules.get(rule.getName()).getDescriptionId(), rule.translationKey(), rule.getName() + "'s translation doesn't match");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAttributeKeys() {
|
||||||
|
for (Attribute attribute : Attribute.values()) {
|
||||||
|
Assertions.assertEquals(org.bukkit.craftbukkit.attribute.CraftAttribute.bukkitToMinecraft(attribute).getDescriptionId(), attribute.translationKey(), "translation key mismatch for " + attribute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFireworkEffectType() {
|
||||||
|
for (final FireworkEffect.Type type : FireworkEffect.Type.values()) {
|
||||||
|
final net.minecraft.world.item.component.FireworkExplosion.Shape nmsType = org.bukkit.craftbukkit.inventory.CraftMetaFirework.getNBT(type);
|
||||||
|
Assertions.assertTrue(nmsType.getName().getContents() instanceof TranslatableContents, "contents aren't translatable");
|
||||||
|
Assertions.assertEquals(((TranslatableContents) nmsType.getName().getContents()).getKey(), type.translationKey(), "translation key mismatch for " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled // TODO fix
|
||||||
|
public void testCreativeCategory() {
|
||||||
|
// for (CreativeModeTab tab : CreativeModeTabs.tabs()) {
|
||||||
|
// CreativeCategory category = Objects.requireNonNull(CraftCreativeCategory.fromNMS(tab));
|
||||||
|
// Assertions.assertEquals("translation key mismatch for " + category, ((TranslatableContents) tab.getDisplayName().getContents()).getKey(), category.translationKey());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGameMode() {
|
||||||
|
for (GameType nms : GameType.values()) {
|
||||||
|
GameMode bukkit = GameMode.getByValue(nms.getId());
|
||||||
|
Assertions.assertNotNull(bukkit);
|
||||||
|
Assertions.assertEquals(((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBiome() {
|
||||||
|
for (Map.Entry<ResourceKey<Biome>, Biome> nms : RegistryHelper.getBiomes().entrySet()) {
|
||||||
|
org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase(Locale.ROOT));
|
||||||
|
Assertions.assertEquals(nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey(), "translation key mismatch for " + bukkit);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue