diff --git a/src/main/src/me/skymc/taboolib/string/language2/Language2.java b/src/main/src/me/skymc/taboolib/string/language2/Language2.java index a8ba3d4..4df7985 100644 --- a/src/main/src/me/skymc/taboolib/string/language2/Language2.java +++ b/src/main/src/me/skymc/taboolib/string/language2/Language2.java @@ -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; + } + /** * 重载语言文件 */ diff --git a/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java b/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java index e54da6b..74f20ed 100644 --- a/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java +++ b/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java @@ -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 + "[]" : 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 + "[]" : 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 setPlaceholder(List list, Player player) { + List _list = new ArrayList<>(list); + for (int i = 0 ; i < _list.size() ; i++) { + _list.set(i, setPlaceholder(_list.get(i), player)); + } + return _list; + } + /** * 变量替换构造 *