版本更新至:3.75

修复:Language2Value 对象的 asString() 方法无法识别变量的问题
新增:Language2 工具新增方法 get(String, String...)  来快速添加变量
This commit is contained in:
坏黑 2018-03-10 12:13:14 +08:00
parent ef72d76801
commit 6439e4b780
2 changed files with 32 additions and 2 deletions

View File

@ -65,6 +65,21 @@ public class Language2 {
return new Language2Value(this, key);
}
/**
* 获取语言文件
*
* @param key
* @param placeholder 替换变量 @$0 开始
* @return {@link Language2Value}
*/
public Language2Value get(String key, String... placeholder) {
Language2Value value = new Language2Value(this, key);
for (int i = 0 ; i < placeholder.length ; i++) {
value.addPlaceholder("$" + i, placeholder[i]);
}
return value;
}
/**
* 重载语言文件
*/

View File

@ -129,7 +129,7 @@ public class Language2Value extends Object {
Language2Format format = new Language2Format(null, this);
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
return text.getText().get(0);
return setPlaceholder(text.getText().get(0), null);
}
else {
return languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null);
@ -145,7 +145,7 @@ public class Language2Value extends Object {
Language2Format format = new Language2Format(null, this);
if (format.getLanguage2Lines().get(0) instanceof Language2Text) {
Language2Text text = (Language2Text) format.getLanguage2Lines().get(0);
return text.getText();
return setPlaceholder(text.getText(), null);
}
else {
return Arrays.asList(languageValue.size() == 0 ? ChatColor.DARK_RED + "[<ERROR-1>]" : setPlaceholder(languageValue.get(0), null));
@ -166,6 +166,21 @@ public class Language2Value extends Object {
return isEnablePlaceholderAPI() ? this.language.setPlaceholderAPI(player, value) : value;
}
/**
* 긴좆競뻣
*
* @param list 競뻣섞북
* @param player 쇱꿎鯤소
* @return {@link List}
*/
public List<String> setPlaceholder(List<String> list, Player player) {
List<String> _list = new ArrayList<>(list);
for (int i = 0 ; i < _list.size() ; i++) {
_list.set(i, setPlaceholder(_list.get(i), player));
}
return _list;
}
/**
* ±äÁ¿Ìæ»»¹¹Ôì
*