ItemTranslationProperties class
Пакет: com.hypixel.hytale.server.core.asset.type.item.config
Файл: com/hypixel/hytale/server/core/asset/type/item/config/ItemTranslationProperties.java
implements: NetworkSerializable<com.hypixel.hytale.protocol.ItemTranslationProperties>
Поля (3)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
Validator<String> |
SERVER_LANG_KEY_VALIDATOR |
|
HashMap |
var1 |
|
com.hypixel.hytale.protocol.ItemTranslationProperties |
var1 |
Методы (7)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
|
public void |
acceptpublic void accept(@Nullable String var1, @Nonnull ValidationResults var2) |
|
public void |
acceptpublic void accept(@Nullable Map<String, String> var1, @Nonnull ValidationResults var2) |
|
|
if if(var3 != null) |
|
|
if if(var1 != null) |
private |
void |
resolveArgumentsvoid resolveArguments() |
|
public void |
updateSchemapublic void updateSchema(SchemaContext var1, Schema var2) |
|
public void |
updateSchemapublic void updateSchema(SchemaContext var1, Schema var2) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.asset.type.item.config;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.map.MapCodec;
class="kw">import com.hypixel.hytale.codec.schema.SchemaContext;
class="kw">import com.hypixel.hytale.codec.schema.config.Schema;
class="kw">import com.hypixel.hytale.codec.schema.metadata.ui.UIEditor;
class="kw">import com.hypixel.hytale.codec.validation.ValidationResults;
class="kw">import com.hypixel.hytale.codec.validation.Validator;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import com.hypixel.hytale.server.core.modules.i18n.I18nModule;
class="kw">import java.util.HashMap;
class="kw">import java.util.Map;
class="kw">import java.util.Map.Entry;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class ItemTranslationProperties class="kw">implements NetworkSerializable<com.hypixel.hytale.protocol.ItemTranslationProperties> {
class="kw">private class="kw">static class="kw">final Validator<String> SERVER_LANG_KEY_VALIDATOR = new Validator<String>() {
class="kw">public void accept(@Nullable String var1, @Nonnull ValidationResults var2) {
if (var1 != null && var1.startsWith("server.")) {
I18nModule var3 = I18nModule.get();
if (var3 != null) {
if (!var3.getMessages("en-US").containsKey(var1)) {
var2.warn("[LOC] Key '" + var1 + "' does not exist in server.lang!");
}
}
}
}
@Override
class="kw">public void updateSchema(SchemaContext var1, Schema var2) {
}
};
class="kw">private class="kw">static class="kw">final Validator<Map<String, String>> ARGUMENT_LANG_KEYS_VALIDATOR = new Validator<Map<String, String>>() {
class="kw">public void accept(@Nullable Map<String, String> var1, @Nonnull ValidationResults var2) {
if (var1 != null) {
for (String var4 : var1.values()) {
ItemTranslationProperties.SERVER_LANG_KEY_VALIDATOR.accept(var4, var2);
}
}
}
@Override
class="kw">public void updateSchema(SchemaContext var1, Schema var2) {
}
};
class="kw">public class="kw">static class="kw">final BuilderCodec<ItemTranslationProperties> CODEC = BuilderCodec.builder(ItemTranslationProperties.class, ItemTranslationProperties::new)
.appendInherited(new KeyedCodec<>("Name", Codec.STRING), (var0, var1) -> var0.name = var1, var0 -> var0.name, (var0, var1) -> var0.name = var1.name)
.addValidator(SERVER_LANG_KEY_VALIDATOR)
.documentation("The translation key for the name of this item.")
.metadata(new UIEditor(new UIEditor.LocalizationKeyField("server.items.{assetId}.name", true)))
.add()
.<Map>appendInherited(
new KeyedCodec<>("NameArguments", new MapCodec<>(Codec.STRING, HashMap::new)),
(var0, var1) -> var0.nameArgumentKeys = var1,
var0 -> var0.nameArgumentKeys,
(var0, var1) -> var0.nameArgumentKeys = var1.nameArgumentKeys
)
.addValidator(ARGUMENT_LANG_KEYS_VALIDATOR)
.documentation("The map of arguments used in the item name loc key, if any.")
.add()
.<String>appendInherited(
new KeyedCodec<>("Description", Codec.STRING),
(var0, var1) -> var0.description = var1,
var0 -> var0.description,
(var0, var1) -> var0.description = var1.description
)
.addValidator(SERVER_LANG_KEY_VALIDATOR)
.documentation("The translation key for the description of this item.")
.metadata(new UIEditor(new UIEditor.LocalizationKeyField("server.items.{assetId}.description")))
.add()
.<Map>appendInherited(
new KeyedCodec<>("DescriptionArguments", new MapCodec<>(Codec.STRING, HashMap::new)),
(var0, var1) -> var0.descriptionArgumentKeys = var1,
var0 -> var0.descriptionArgumentKeys,
(var0, var1) -> var0.descriptionArgumentKeys = var1.descriptionArgumentKeys
)
.addValidator(ARGUMENT_LANG_KEYS_VALIDATOR)
.documentation("The map of arguments used in the item description loc key, if any.")
.add()
.afterDecode(ItemTranslationProperties::resolveArguments)
.build();
@Nullable
class="kw">private String name;
@Nullable
class="kw">private Map<String, String> nameArgumentKeys;
@Nullable
class="kw">private Map<String, Message> nameArguments;
@Nullable
class="kw">private String description;
@Nullable
class="kw">private Map<String, String> descriptionArgumentKeys;
@Nullable
class="kw">private Map<String, Message> descriptionArguments;
ItemTranslationProperties() {
}
class="kw">public ItemTranslationProperties(@Nonnull String var1, @Nonnull String var2) {
this.name = var1;
this.description = var2;
}
@Nullable
class="kw">public String getName() {
class="kw">return this.name;
}
@Nullable
class="kw">public Map<String, Message> getNameArguments() {
class="kw">return this.nameArguments;
}
@Nullable
class="kw">public String getDescription() {
class="kw">return this.description;
}
@Nullable
class="kw">public Map<String, Message> getDescriptionArguments() {
class="kw">return this.descriptionArguments;
}
class="kw">private void resolveArguments() {
this.nameArguments = wrapKeys(this.nameArgumentKeys);
this.descriptionArguments = wrapKeys(this.descriptionArgumentKeys);
}
@Nullable
class="kw">private class="kw">static Map<String, Message> wrapKeys(@Nullable Map<String, String> var0) {
if (var0 != null && !var0.isEmpty()) {
HashMap var1 = new HashMap<>(var0.size());
for (Entry var3 : var0.entrySet()) {
var1.put(var3.getKey(), Message.translation(var3.getValue()));
}
class="kw">return var1;
} else {
class="kw">return null;
}
}
@Nonnull
class="kw">public com.hypixel.hytale.protocol.ItemTranslationProperties toPacket() {
com.hypixel.hytale.protocol.ItemTranslationProperties var1 = new com.hypixel.hytale.protocol.ItemTranslationProperties();
var1.name = this.name;
var1.description = this.description;
if (this.nameArguments != null && !this.nameArguments.isEmpty()) {
var1.nameArguments = new HashMap<>(this.nameArguments.size());
for (Entry var3 : this.nameArguments.entrySet()) {
var1.nameArguments.put(var3.getKey(), var3.getValue().getFormattedMessage());
}
}
if (this.descriptionArguments != null && !this.descriptionArguments.isEmpty()) {
var1.descriptionArguments = new HashMap<>(this.descriptionArguments.size());
for (Entry var5 : this.descriptionArguments.entrySet()) {
var1.descriptionArguments.put(var5.getKey(), var5.getValue().getFormattedMessage());
}
}
class="kw">return var1;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "ItemTranslationProperties{name="
+ this.name
+ ", nameArguments="
+ this.nameArguments
+ ", description="
+ this.description
+ ", descriptionArguments="
+ this.descriptionArguments
+ "}";
}
}