forked from Upstream/mmocore
Changed the way placeholders are parsed in the GUI
This commit is contained in:
parent
56996788a9
commit
735baac901
@ -7,28 +7,25 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Placeholders {
|
public class Placeholders {
|
||||||
private final Map<String, String> placeholders = new HashMap<>();
|
private final Map<String, String> placeholders = new HashMap<>();
|
||||||
|
|
||||||
public void register(String path, Object obj) {
|
public void register(String path, Object obj) {
|
||||||
placeholders.put(path, obj.toString());
|
placeholders.put(path, obj.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String apply(Player player, String str) {
|
public String apply(Player player, String str) {
|
||||||
|
|
||||||
/*
|
// Internal placeholders
|
||||||
* Remove potential conditions, apply color codes
|
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
||||||
* and external placeholders if needed.
|
|
||||||
*/
|
|
||||||
str = MMOCore.plugin.placeholderParser.parse(player, removeCondition(str));
|
|
||||||
|
|
||||||
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
|
|
||||||
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
|
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
|
||||||
str = str.replace("{" + holder + "}", placeholders.getOrDefault(holder, "Error"));
|
str = str.replace("{" + holder + "}", placeholders.getOrDefault(holder, "Error"));
|
||||||
}
|
}
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String removeCondition(String str) {
|
// External placeholders
|
||||||
return str.startsWith("{") && str.contains("}") ? str.substring(str.indexOf("}") + 1) : str;
|
return MMOCore.plugin.placeholderParser.parse(player, removeCondition(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String removeCondition(String str) {
|
||||||
|
return str.startsWith("{") && str.contains("}") ? str.substring(str.indexOf("}") + 1) : str;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user