mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 10:39:04 +00:00
Allow arguments in javascript placeholders.
This commit is contained in:
parent
07fb6f911b
commit
b496a3244e
@ -89,8 +89,15 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
|
||||
for (JavascriptPlaceholder script : scripts) {
|
||||
|
||||
if (script.getIdentifier().equalsIgnoreCase(identifier)) {
|
||||
if (identifier.startsWith(script.getIdentifier() + "_")) {
|
||||
identifier = identifier.replace(script.getIdentifier() + "_", "");
|
||||
if (identifier.indexOf(",") == -1) {
|
||||
return script.evaluate(engine, p, identifier);
|
||||
} else {
|
||||
return script.evaluate(engine, p, identifier.split(","));
|
||||
}
|
||||
|
||||
} else if (identifier.equalsIgnoreCase(script.getIdentifier())) {
|
||||
return script.evaluate(engine, p);
|
||||
}
|
||||
}
|
||||
@ -121,7 +128,7 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.2.0";
|
||||
return "1.3.0";
|
||||
}
|
||||
|
||||
public boolean addJavascriptPlaceholder(JavascriptPlaceholder p) {
|
||||
|
@ -38,6 +38,7 @@ public class JavascriptPlaceholder {
|
||||
|
||||
private String falseResult;
|
||||
|
||||
|
||||
private JavascriptReturnType type;
|
||||
|
||||
public JavascriptPlaceholder(String identifier, JavascriptReturnType type, String expression, String trueResult, String falseResult) {
|
||||
@ -93,12 +94,33 @@ public class JavascriptPlaceholder {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String evaluate(ScriptEngine engine, Player p) {
|
||||
|
||||
public String evaluate(ScriptEngine engine, Player p, String... args) {
|
||||
String exp = PlaceholderAPI.setPlaceholders(p, expression);
|
||||
|
||||
try {
|
||||
|
||||
String[] c = null;
|
||||
|
||||
if (args != null && args.length > 0) {
|
||||
|
||||
for (int i = 0 ; i < args.length ; i++) {
|
||||
if (args[i] == null || args[i].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String s = PlaceholderAPI.setBracketPlaceholders(p, args[i]);
|
||||
if (c == null) {
|
||||
c = new String[args.length];
|
||||
}
|
||||
c[i] = s;
|
||||
}
|
||||
}
|
||||
|
||||
if (c == null) {
|
||||
c = new String[]{};
|
||||
}
|
||||
|
||||
engine.put("args", c);
|
||||
|
||||
engine.put("BukkitPlayer", p);
|
||||
|
||||
Object result = engine.eval(exp);
|
||||
|
@ -292,7 +292,7 @@ public class JavascriptPlaceholdersConfig {
|
||||
|
||||
String line = scanner.nextLine();
|
||||
|
||||
if (line == null || line.isEmpty()) {
|
||||
if (line == null || line.isEmpty() || line.startsWith("//")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user