mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 10:39:04 +00:00
1.5.3
This commit is contained in:
parent
ce18d99e84
commit
d2d26e1e95
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.extendedclip.papi.expansion.javascript</groupId>
|
||||
<artifactId>javascript-expansion</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.5.3</version>
|
||||
<name>PAPI-Expansion-Javascript</name>
|
||||
<description>PlaceholderAPI expansion for javascript placeholders</description>
|
||||
|
||||
|
@ -21,6 +21,16 @@
|
||||
package com.extendedclip.papi.expansion.javascript;
|
||||
|
||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import me.clip.placeholderapi.expansion.Cacheable;
|
||||
import me.clip.placeholderapi.expansion.Configurable;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
@ -28,12 +38,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandMap;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
public class JavascriptExpansion extends PlaceholderExpansion implements Cacheable, Configurable {
|
||||
|
||||
private ScriptEngine globalEngine = null;
|
||||
@ -43,11 +47,10 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
private final String VERSION = getClass().getPackage().getImplementationVersion();
|
||||
private static JavascriptExpansion instance;
|
||||
private boolean debug;
|
||||
private GithubScriptManager githubScripts;
|
||||
private GithubScriptManager githubManager;
|
||||
private JavascriptExpansionCommands commands;
|
||||
private CommandMap commandMap;
|
||||
|
||||
|
||||
public JavascriptExpansion() {
|
||||
instance = this;
|
||||
try {
|
||||
@ -85,7 +88,8 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
try {
|
||||
globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "nashorn"));
|
||||
} catch (NullPointerException ex) {
|
||||
getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'nashorn'");
|
||||
getPlaceholderAPI().getLogger()
|
||||
.warning("Javascript engine type was invalid! Defaulting to 'nashorn'");
|
||||
globalEngine = new ScriptEngineManager().getEngineByName("nashorn");
|
||||
}
|
||||
}
|
||||
@ -96,7 +100,6 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
|
||||
if (debug) {
|
||||
System.out.println("Java version: " + System.getProperty("java.version"));
|
||||
|
||||
final ScriptEngineManager manager = new ScriptEngineManager();
|
||||
final List<ScriptEngineFactory> factories = manager.getEngineFactories();
|
||||
System.out.println("Displaying all script engine factories.");
|
||||
@ -112,10 +115,9 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
}
|
||||
}
|
||||
|
||||
githubScripts = new GithubScriptManager(this);
|
||||
|
||||
if ((Boolean) get("github_script_downloads", false)) {
|
||||
githubScripts.fetch();
|
||||
githubManager = new GithubScriptManager(this);
|
||||
githubManager.fetch();
|
||||
}
|
||||
|
||||
registerCommand();
|
||||
@ -130,9 +132,9 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
s.cleanup();
|
||||
});
|
||||
|
||||
if (githubScripts != null) {
|
||||
githubScripts.clear();
|
||||
githubScripts = null;
|
||||
if (githubManager != null) {
|
||||
githubManager.clear();
|
||||
githubManager = null;
|
||||
}
|
||||
|
||||
scripts.clear();
|
||||
@ -153,7 +155,8 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
for (JavascriptPlaceholder script : scripts) {
|
||||
if (identifier.startsWith(script.getIdentifier() + "_")) {
|
||||
identifier = identifier.replace(script.getIdentifier() + "_", "");
|
||||
return !identifier.contains(",") ? script.evaluate(p, identifier) : script.evaluate(p, identifier.split(","));
|
||||
return !identifier.contains(",") ? script.evaluate(p, identifier)
|
||||
: script.evaluate(p, identifier.split(","));
|
||||
} else if (identifier.equalsIgnoreCase(script.getIdentifier())) {
|
||||
return script.evaluate(p);
|
||||
}
|
||||
@ -171,7 +174,8 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
return true;
|
||||
}
|
||||
|
||||
if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier())).findFirst().orElse(null) != null) {
|
||||
if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier()))
|
||||
.findFirst().orElse(null) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -190,7 +194,8 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
}
|
||||
|
||||
public JavascriptPlaceholder getJSPlaceholder(String identifier) {
|
||||
return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst().orElse(null);
|
||||
return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public int getAmountLoaded() {
|
||||
@ -229,16 +234,24 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
||||
}
|
||||
|
||||
public GithubScriptManager getGithubScriptManager() {
|
||||
return githubScripts;
|
||||
return githubManager;
|
||||
}
|
||||
|
||||
public void setGithubScriptManager(GithubScriptManager manager) {
|
||||
this.githubManager = manager;
|
||||
}
|
||||
|
||||
private boolean unregisterCommand() {
|
||||
if (commandMap == null || commands == null) return false;
|
||||
if (commandMap == null || commands == null) {
|
||||
return false;
|
||||
}
|
||||
return commands.unregister(commandMap);
|
||||
}
|
||||
|
||||
private boolean registerCommand() {
|
||||
if (commandMap == null) return false;
|
||||
if (commandMap == null) {
|
||||
return false;
|
||||
}
|
||||
commands = new JavascriptExpansionCommands(this);
|
||||
commandMap.register("papi" + commands.getName(), commands);
|
||||
return commands.isRegistered();
|
||||
|
@ -22,6 +22,7 @@ package com.extendedclip.papi.expansion.javascript;
|
||||
|
||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScript;
|
||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -161,6 +162,31 @@ public class JavascriptExpansionCommands extends Command {
|
||||
return true;
|
||||
}
|
||||
|
||||
case "enabled":
|
||||
if (args.length < 3) {
|
||||
msg(sender, "&4Incorrect usage! &f/" + command + " git enabled <true/false>");
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean enabled = Boolean.parseBoolean(args[2]);
|
||||
PlaceholderAPIPlugin papi = expansion.getPlaceholderAPI();
|
||||
papi.getConfig().set("expansions." + this.getName() + ".github_script_downloads", enabled);
|
||||
papi.saveConfig();
|
||||
papi.reloadConfig();
|
||||
if (!enabled) {
|
||||
if (expansion.getGithubScriptManager() != null) {
|
||||
expansion.getGithubScriptManager().clear();
|
||||
expansion.setGithubScriptManager(null);
|
||||
}
|
||||
} else {
|
||||
if (expansion.getGithubScriptManager() == null) {
|
||||
expansion.setGithubScriptManager(new GithubScriptManager(expansion));
|
||||
}
|
||||
expansion.getGithubScriptManager().fetch();
|
||||
}
|
||||
msg(sender, "&6Git script downloads set to: &e" + enabled);
|
||||
return true;
|
||||
|
||||
default: {
|
||||
msg(sender, "&4Incorrect usage! &f/" + command + " &7for more help.");
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user