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

@@ -43,7 +43,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.
/**
@@ -463,10 +463,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.
*

View File

@@ -181,7 +181,7 @@ public interface Villager extends AbstractVillager {
* Represents the various different Villager professions there may be.
* Villagers have different trading options depending on their profession,
*/
interface Profession extends OldEnum<Profession>, Keyed {
interface Profession extends OldEnum<Profession>, Keyed, net.kyori.adventure.translation.Translatable {
Profession NONE = getProfession("none");
/**
@@ -282,6 +282,13 @@ public interface Villager extends AbstractVillager {
static Profession[] values() {
return Lists.newArrayList(Registry.VILLAGER_PROFESSION).toArray(new Profession[0]);
}
// Paper start
@Override
default @NotNull String translationKey() {
return "entity.minecraft.villager." + this.getKey().getKey();
}
// Paper end
}
// Paper start - Add villager reputation API