mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 10:39:04 +00:00
Code cleanup and PlaceholderAPI script variable added (use PlaceholderAPI.static to access it)
This commit is contained in:
parent
69a514f62d
commit
be00944461
@ -21,229 +21,226 @@
|
|||||||
package com.extendedclip.papi.expansion.javascript;
|
package com.extendedclip.papi.expansion.javascript;
|
||||||
|
|
||||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
||||||
import java.lang.reflect.Field;
|
import me.clip.placeholderapi.expansion.Cacheable;
|
||||||
import java.util.ArrayList;
|
import me.clip.placeholderapi.expansion.Configurable;
|
||||||
import java.util.HashMap;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import java.util.HashSet;
|
import org.bukkit.Bukkit;
|
||||||
import java.util.List;
|
import org.bukkit.OfflinePlayer;
|
||||||
import java.util.Map;
|
import org.bukkit.command.CommandMap;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptEngineFactory;
|
import javax.script.ScriptEngineFactory;
|
||||||
import javax.script.ScriptEngineManager;
|
import javax.script.ScriptEngineManager;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import me.clip.placeholderapi.expansion.Cacheable;
|
import java.util.*;
|
||||||
import me.clip.placeholderapi.expansion.Configurable;
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandMap;
|
|
||||||
|
|
||||||
public class JavascriptExpansion extends PlaceholderExpansion implements Cacheable, Configurable {
|
public class JavascriptExpansion extends PlaceholderExpansion implements Cacheable, Configurable {
|
||||||
|
|
||||||
private ScriptEngine globalEngine = null;
|
private ScriptEngine globalEngine = null;
|
||||||
|
|
||||||
private JavascriptPlaceholdersConfig config;
|
private JavascriptPlaceholdersConfig config;
|
||||||
private final Set<JavascriptPlaceholder> scripts = new HashSet<>();
|
private final Set<JavascriptPlaceholder> scripts = new HashSet<>();
|
||||||
private final String VERSION = getClass().getPackage().getImplementationVersion();
|
private final String VERSION = getClass().getPackage().getImplementationVersion();
|
||||||
private static JavascriptExpansion instance;
|
private static JavascriptExpansion instance;
|
||||||
private boolean debug;
|
private boolean debug;
|
||||||
private GithubScriptManager githubScripts;
|
private GithubScriptManager githubScripts;
|
||||||
private JavascriptExpansionCommands commands;
|
private JavascriptExpansionCommands commands;
|
||||||
private CommandMap commandMap;
|
private CommandMap commandMap;
|
||||||
|
|
||||||
|
|
||||||
public JavascriptExpansion() {
|
public JavascriptExpansion() {
|
||||||
instance = this;
|
instance = this;
|
||||||
try {
|
try {
|
||||||
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
commandMap = (CommandMap) f.get(Bukkit.getServer());
|
commandMap = (CommandMap) f.get(Bukkit.getServer());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return "clip";
|
return "clip";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return "javascript";
|
return "javascript";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlugin() {
|
public String getPlugin() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getVersion() {
|
|
||||||
return VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean register() {
|
|
||||||
if (globalEngine == null) {
|
|
||||||
try {
|
|
||||||
globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "nashorn"));
|
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'nashorn'");
|
|
||||||
globalEngine = new ScriptEngineManager().getEngineByName("nashorn");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug = (boolean) get("debug", false);
|
|
||||||
config = new JavascriptPlaceholdersConfig(this);
|
|
||||||
config.loadPlaceholders();
|
|
||||||
if (debug) {
|
|
||||||
System.out.println("Java version: " + System.getProperty("java.version"));
|
|
||||||
|
|
||||||
ScriptEngineManager manager = new ScriptEngineManager();
|
@Override
|
||||||
List<ScriptEngineFactory> factories = manager.getEngineFactories();
|
public String getVersion() {
|
||||||
System.out.println("displaying all script engine factories:");
|
return VERSION;
|
||||||
for (ScriptEngineFactory factory : factories) {
|
}
|
||||||
System.out.println("Engine name: " + factory.getEngineName());
|
|
||||||
System.out.println("version: " + factory.getEngineVersion());
|
|
||||||
System.out.println("lang name: " + factory.getLanguageName());
|
|
||||||
System.out.println("lang version: " + factory.getLanguageVersion());
|
|
||||||
System.out.println("extensions: " + factory.getExtensions());
|
|
||||||
System.out.println("mime types: " + factory.getMimeTypes());
|
|
||||||
System.out.println("names: " + factory.getNames());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((Boolean) get("github_script_downloads", false)) {
|
|
||||||
githubScripts = new GithubScriptManager(this);
|
|
||||||
githubScripts.fetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
registerCommand();
|
@Override
|
||||||
return super.register();
|
public boolean register() {
|
||||||
}
|
if (globalEngine == null) {
|
||||||
|
try {
|
||||||
@Override
|
globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "nashorn"));
|
||||||
public void clear() {
|
} catch (NullPointerException ex) {
|
||||||
unregisterCommand();
|
getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'nashorn'");
|
||||||
scripts.forEach(s -> {
|
globalEngine = new ScriptEngineManager().getEngineByName("nashorn");
|
||||||
s.saveData();
|
}
|
||||||
s.cleanup();
|
}
|
||||||
});
|
|
||||||
if (githubScripts != null) {
|
|
||||||
githubScripts.clear();
|
|
||||||
githubScripts = null;
|
|
||||||
}
|
|
||||||
scripts.clear();
|
|
||||||
globalEngine = null;
|
|
||||||
instance = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
debug = (boolean) get("debug", false);
|
||||||
public String onRequest( OfflinePlayer p, String identifier) {
|
config = new JavascriptPlaceholdersConfig(this);
|
||||||
if (p == null) {
|
config.loadPlaceholders();
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scripts.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (JavascriptPlaceholder script : scripts) {
|
if (debug) {
|
||||||
if (identifier.startsWith(script.getIdentifier() + "_")) {
|
System.out.println("Java version: " + System.getProperty("java.version"));
|
||||||
identifier = identifier.replace(script.getIdentifier() + "_", "");
|
|
||||||
return !identifier.contains(",") ? script.evaluate(p, identifier) : script.evaluate(p, identifier.split(","));
|
|
||||||
} else if (identifier.equalsIgnoreCase(script.getIdentifier())) {
|
|
||||||
return script.evaluate(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean addJSPlaceholder(JavascriptPlaceholder p) {
|
|
||||||
if (p == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scripts.isEmpty()) {
|
|
||||||
scripts.add(p);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier())).findFirst().orElse(null) != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
scripts.add(p);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<JavascriptPlaceholder> getJSPlaceholders() {
|
|
||||||
return scripts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getLoadedIdentifiers() {
|
|
||||||
List<String> l = new ArrayList<>();
|
|
||||||
scripts.forEach(s -> {
|
|
||||||
l.add(s.getIdentifier());
|
|
||||||
});
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavascriptPlaceholder getJSPlaceholder(String identifier) {
|
|
||||||
return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmountLoaded() {
|
|
||||||
return scripts.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScriptEngine getGlobalEngine() {
|
|
||||||
return globalEngine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavascriptPlaceholdersConfig getConfig() {
|
final ScriptEngineManager manager = new ScriptEngineManager();
|
||||||
return config;
|
final List<ScriptEngineFactory> factories = manager.getEngineFactories();
|
||||||
}
|
System.out.println("Displaying all script engine factories.");
|
||||||
|
|
||||||
@Override
|
for (ScriptEngineFactory factory : factories) {
|
||||||
public Map<String, Object> getDefaults() {
|
System.out.println(factory.getEngineName());
|
||||||
Map<String, Object> def = new HashMap<String, Object>();
|
System.out.println(" Version: " + factory.getEngineVersion());
|
||||||
def.put("engine", "javascript");
|
System.out.println(" Lang name: " + factory.getLanguageName());
|
||||||
def.put("debug", false);
|
System.out.println(" Lang version: " + factory.getLanguageVersion());
|
||||||
def.put("github_script_downloads", false);
|
System.out.println(" Extensions: ." + String.join(", .", factory.getExtensions()));
|
||||||
return def;
|
System.out.println(" Mime types: " + String.join(", ", factory.getMimeTypes()));
|
||||||
}
|
System.out.println(" Names: " + String.join(", ", factory.getNames()));
|
||||||
|
}
|
||||||
protected int reloadScripts() {
|
}
|
||||||
scripts.forEach(s -> {
|
|
||||||
s.saveData();
|
|
||||||
s.cleanup();
|
|
||||||
});
|
|
||||||
scripts.clear();
|
|
||||||
config.reload();
|
|
||||||
return config.loadPlaceholders();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JavascriptExpansion getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GithubScriptManager getGithubScriptManager() {
|
githubScripts = new GithubScriptManager(this);
|
||||||
return githubScripts;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean unregisterCommand() {
|
if ((Boolean) get("github_script_downloads", false)) {
|
||||||
if (commandMap == null || commands == null) return false;
|
githubScripts.fetch();
|
||||||
return commands.unregister(commandMap);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean registerCommand() {
|
registerCommand();
|
||||||
if (commandMap == null) return false;
|
return super.register();
|
||||||
commands = new JavascriptExpansionCommands(this);
|
}
|
||||||
commandMap.register("papi" + commands.getName(), commands);
|
|
||||||
return commands.isRegistered();
|
@Override
|
||||||
}
|
public void clear() {
|
||||||
|
unregisterCommand();
|
||||||
|
scripts.forEach(s -> {
|
||||||
|
s.saveData();
|
||||||
|
s.cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (githubScripts != null) {
|
||||||
|
githubScripts.clear();
|
||||||
|
githubScripts = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
scripts.clear();
|
||||||
|
globalEngine = null;
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String onRequest(OfflinePlayer p, String identifier) {
|
||||||
|
if (p == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scripts.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(","));
|
||||||
|
} else if (identifier.equalsIgnoreCase(script.getIdentifier())) {
|
||||||
|
return script.evaluate(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addJSPlaceholder(JavascriptPlaceholder p) {
|
||||||
|
if (p == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scripts.isEmpty()) {
|
||||||
|
scripts.add(p);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(p.getIdentifier())).findFirst().orElse(null) != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
scripts.add(p);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<JavascriptPlaceholder> getJSPlaceholders() {
|
||||||
|
return scripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getLoadedIdentifiers() {
|
||||||
|
List<String> l = new ArrayList<>();
|
||||||
|
scripts.forEach(s -> l.add(s.getIdentifier()));
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavascriptPlaceholder getJSPlaceholder(String identifier) {
|
||||||
|
return scripts.stream().filter(s -> s.getIdentifier().equalsIgnoreCase(identifier)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountLoaded() {
|
||||||
|
return scripts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScriptEngine getGlobalEngine() {
|
||||||
|
return globalEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JavascriptPlaceholdersConfig getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getDefaults() {
|
||||||
|
Map<String, Object> def = new HashMap<>();
|
||||||
|
def.put("engine", "javascript");
|
||||||
|
def.put("debug", false);
|
||||||
|
def.put("github_script_downloads", false);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int reloadScripts() {
|
||||||
|
scripts.forEach(s -> {
|
||||||
|
s.saveData();
|
||||||
|
s.cleanup();
|
||||||
|
});
|
||||||
|
scripts.clear();
|
||||||
|
config.reload();
|
||||||
|
return config.loadPlaceholders();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JavascriptExpansion getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GithubScriptManager getGithubScriptManager() {
|
||||||
|
return githubScripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean unregisterCommand() {
|
||||||
|
if (commandMap == null || commands == null) return false;
|
||||||
|
return commands.unregister(commandMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean registerCommand() {
|
||||||
|
if (commandMap == null) return false;
|
||||||
|
commands = new JavascriptExpansionCommands(this);
|
||||||
|
commandMap.register("papi" + commands.getName(), commands);
|
||||||
|
return commands.isRegistered();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,132 +22,167 @@ package com.extendedclip.papi.expansion.javascript;
|
|||||||
|
|
||||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScript;
|
import com.extendedclip.papi.expansion.javascript.cloud.GithubScript;
|
||||||
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
import com.extendedclip.papi.expansion.javascript.cloud.GithubScriptManager;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class JavascriptExpansionCommands extends Command {
|
public class JavascriptExpansionCommands extends Command {
|
||||||
|
|
||||||
private JavascriptExpansion expansion;
|
private JavascriptExpansion expansion;
|
||||||
|
private final String PERMISSION = "placeholderapi.js.admin";
|
||||||
|
private String command;
|
||||||
|
|
||||||
public JavascriptExpansionCommands(JavascriptExpansion expansion) {
|
public JavascriptExpansionCommands(JavascriptExpansion expansion) {
|
||||||
super("jsexpansion");
|
super("jsexpansion");
|
||||||
this.expansion = expansion;
|
command = getName();
|
||||||
this.setDescription("Javascript expansion commands");
|
this.expansion = expansion;
|
||||||
this.setUsage("/jsexpansion <arg>");
|
this.setDescription("Javascript expansion commands");
|
||||||
this.setPermission("placeholderapi.js.admin");
|
this.setUsage("/" + command + " <args>");
|
||||||
}
|
this.setPermission(PERMISSION);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(CommandSender s, String label, String[] args) {
|
|
||||||
if (!s.hasPermission(this.getPermission())) {
|
|
||||||
msg(s, "&cYou don't have permission to do that!");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0) {
|
@Override
|
||||||
msg(s, "&eJavascript expansion &7v: &f" + expansion.getVersion(),
|
public boolean execute(CommandSender sender, String label, String[] args) {
|
||||||
"&eCreated by: &f" + expansion.getAuthor(),
|
if (!sender.hasPermission(PERMISSION)) {
|
||||||
"&eWiki: &ahttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki",
|
msg(sender, "&cYou don't have permission to do that!");
|
||||||
"&r",
|
return true;
|
||||||
"&e/jsexpansion reload &7- &fReload your javascripts without reloading PlaceholderAPI",
|
|
||||||
"&e/jsexpansion list &7- &fList loaded script identifiers.");
|
|
||||||
if (expansion.getGithubScriptManager() != null) {
|
|
||||||
msg(s, "&e&e/jsexpansion git refresh &7- &fRefresh available Github scripts",
|
|
||||||
"&e/jsexpansion git download <name> &7- &fDownload a script from the js expansion github.",
|
|
||||||
"&e/jsexpansion git list &7- &fList available scripts in the js expansion github.",
|
|
||||||
"&e/jsexpansion git info (name) &7- &fGet the description and url of a specific script.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
msg(s, "&aJavascriptExpansion reloading...");
|
|
||||||
int l = expansion.reloadScripts();
|
|
||||||
msg(s, l + " &7script" + (l == 1 ? "" : "s") + " loaded");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("list")) {
|
|
||||||
List<String> loaded = expansion.getLoadedIdentifiers();
|
|
||||||
msg(s, loaded.size() + " &7script" + (loaded.size() == 1 ? "" : "s") + " loaded");
|
|
||||||
msg(s, String.join(", ", loaded));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("git")) {
|
|
||||||
if (expansion.getGithubScriptManager() == null) {
|
|
||||||
msg(s, "&8This feature is disabled in the PlaceholderAPI config.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length < 2) {
|
|
||||||
msg(s, "&cIncorrect usage!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
GithubScriptManager manager = expansion.getGithubScriptManager();
|
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("refresh")) {
|
|
||||||
expansion.getGithubScriptManager().fetch();
|
|
||||||
msg(s, "&aFetching available scripts... Check back in a sec!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("list")) {
|
|
||||||
msg(s, manager.getAvailableScripts().size() + " &escript"
|
|
||||||
+ (manager.getAvailableScripts().size() == 1 ? "" : "s") + " available on Github.",
|
|
||||||
String.join(", ", manager.getAvailableScripts().stream()
|
|
||||||
.map(GithubScript::getName)
|
|
||||||
.collect(Collectors.toSet())));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[1].equalsIgnoreCase("info")) {
|
|
||||||
if (args.length < 3) {
|
|
||||||
msg(s, "&4Incorrect usage! &f" + this.getName() + " git info <name>");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
GithubScript script = manager.getScript(args[2]);
|
|
||||||
if (script == null) {
|
|
||||||
msg(s, "&4The script &f" + args[2] + " &4does not exist!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
msg(s, "&eName: &f" + script.getName(),
|
|
||||||
"&eVersion: &f" + script.getVersion(),
|
|
||||||
"&eDescription: &f" + script.getDescription(),
|
|
||||||
"&eAuthor: &f" + script.getAuthor(),
|
|
||||||
"&eSource URL: &f" + script.getUrl());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args[1].equalsIgnoreCase("download")) {
|
|
||||||
if (args.length < 3) {
|
|
||||||
msg(s, "&4Incorrect usage! &f" + this.getName() + " git download <name>");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
GithubScript script = manager.getScript(args[2]);
|
|
||||||
|
|
||||||
if (script == null) {
|
|
||||||
msg(s, "&4The script &f" + args[2] + " &4does not exist!");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.downloadScript(script);
|
if (args.length == 0) {
|
||||||
msg(s, "&aDownload started... &eCheck the scripts folder in a moment...");
|
msg(sender,
|
||||||
return true;
|
"&eJavascript expansion &7v: &f" + expansion.getVersion(),
|
||||||
}
|
"&eCreated by: &f" + expansion.getAuthor(),
|
||||||
msg(s, "&4Incorrect usage! &f" + this.getName() + " &7for more help.");
|
"&eWiki: &fhttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki",
|
||||||
return true;
|
"&r",
|
||||||
|
"&e/" + command + " reload &7- &fReload your javascripts without reloading PlaceholderAPI",
|
||||||
|
"&e/" + command + " list &7- &fList loaded script identifiers."
|
||||||
|
);
|
||||||
|
|
||||||
|
if (expansion.getGithubScriptManager() != null) {
|
||||||
|
msg(sender,
|
||||||
|
"&e&e/" + command + " git refresh &7- &fRefresh available Github scripts",
|
||||||
|
"&e/" + command + " git download <name> &7- &fDownload a script from the js expansion github.",
|
||||||
|
"&e/" + command + " git list &7- &fList available scripts in the js expansion github.",
|
||||||
|
"&e/" + command + " git info (name) &7- &fGet the description and url of a specific script."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "reload": {
|
||||||
|
msg(sender, "&aJavascriptExpansion reloading...");
|
||||||
|
final int scripts = expansion.reloadScripts();
|
||||||
|
msg(sender, scripts + " &7script" + plural(scripts) + " loaded");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "list": {
|
||||||
|
final List<String> loaded = expansion.getLoadedIdentifiers();
|
||||||
|
msg(sender,
|
||||||
|
loaded.size() + " &7script" + plural(loaded.size()) + " loaded.",
|
||||||
|
String.join(", ", loaded)
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "git": {
|
||||||
|
if (expansion.getGithubScriptManager() == null) {
|
||||||
|
msg(sender, "&8This feature is disabled in the PlaceholderAPI config.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length < 2) {
|
||||||
|
msg(sender, "&cIncorrect usage!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GithubScriptManager manager = expansion.getGithubScriptManager();
|
||||||
|
|
||||||
|
switch (args[1].toLowerCase()) {
|
||||||
|
case "refresh": {
|
||||||
|
expansion.getGithubScriptManager().fetch();
|
||||||
|
msg(sender, "&aFetching available scripts... Check back in a sec!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "list": {
|
||||||
|
final List<GithubScript> availableScripts = manager.getAvailableScripts();
|
||||||
|
final Set<String> scripts = availableScripts.stream().map(GithubScript::getName).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
msg(sender, availableScripts.size() + " &escript" + plural(availableScripts.size()) + " available on Github.", String.join(", ", scripts));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "info": {
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "&4Incorrect usage! &f/" + command + " git info <name>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GithubScript script = manager.getScript(args[2]);
|
||||||
|
|
||||||
|
if (script == null) {
|
||||||
|
msg(sender, "&4The script &f" + args[2] + " &4does not exist!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg(sender,
|
||||||
|
"&eName: &f" + script.getName(),
|
||||||
|
"&eVersion: &f" + script.getVersion(),
|
||||||
|
"&eDescription: &f" + script.getDescription(),
|
||||||
|
"&eAuthor: &f" + script.getAuthor(),
|
||||||
|
"&eSource URL: &f" + script.getUrl()
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case "download": {
|
||||||
|
if (args.length < 3) {
|
||||||
|
msg(sender, "&4Incorrect usage! &f/" + command + " git download <name>");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final GithubScript script = manager.getScript(args[2]);
|
||||||
|
|
||||||
|
if (script == null) {
|
||||||
|
msg(sender, "&4The script &f" + args[2] + " &4does not exist!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.downloadScript(script);
|
||||||
|
msg(sender, "&6Download started... &eCheck the scripts folder in a moment...");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
msg(sender, "&4Incorrect usage! &f/" + command + " &7for more help.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
private String plural(final int amount) {
|
||||||
}
|
return amount > 1 ? "s" : "";
|
||||||
|
}
|
||||||
|
|
||||||
public void msg(CommandSender s, String... text) {
|
public void msg(CommandSender sender, String... text) {
|
||||||
Arrays.stream(text)
|
if (text == null) {
|
||||||
.forEach(line -> s.sendMessage(ChatColor.translateAlternateColorCodes('&', line)));
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Arrays.stream(text).forEach(line -> sender.sendMessage(ChatColor.translateAlternateColorCodes('&', line)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.extendedclip.papi.expansion.javascript;
|
package com.extendedclip.papi.expansion.javascript;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.script.ScriptEngine;
|
|
||||||
import javax.script.ScriptException;
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
@ -34,165 +29,161 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JavascriptPlaceholder {
|
public class JavascriptPlaceholder {
|
||||||
|
|
||||||
private final String FILEDIR =
|
private final String DIRECTORY = PlaceholderAPIPlugin.getInstance().getDataFolder() + "/javascripts/javascript_data";
|
||||||
PlaceholderAPIPlugin.getInstance().getDataFolder() + File.separator + "javascripts"
|
private ScriptEngine engine;
|
||||||
+ File.separator + "javascript_data";
|
private String identifier;
|
||||||
private ScriptEngine engine = null;
|
private String script;
|
||||||
private String identifier;
|
private ScriptData data;
|
||||||
private String script;
|
private File dataFile;
|
||||||
private ScriptData data = null;
|
private FileConfiguration config;
|
||||||
private File dataFile;
|
|
||||||
private FileConfiguration cfg;
|
|
||||||
|
|
||||||
public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script) {
|
public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script) {
|
||||||
Validate.notNull(engine, "ScriptEngine can not be null");
|
Validate.notNull(engine, "ScriptEngine can not be null");
|
||||||
Validate.notNull(identifier, "Identifier can not be null");
|
Validate.notNull(identifier, "Identifier can not be null");
|
||||||
Validate.notNull(script, "script can not be null");
|
Validate.notNull(script, "Script can not be null");
|
||||||
this.engine = engine;
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.script = script;
|
|
||||||
File dir = new File(FILEDIR);
|
|
||||||
|
|
||||||
try {
|
this.engine = engine;
|
||||||
if (!dir.exists()) {
|
this.identifier = identifier;
|
||||||
dir.mkdirs();
|
this.script = script;
|
||||||
}
|
final File directory = new File(DIRECTORY);
|
||||||
} catch (SecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
data = new ScriptData();
|
|
||||||
dataFile = new File(FILEDIR, identifier + "_data.yml");
|
|
||||||
engine.put("Data", data);
|
|
||||||
engine.put("BukkitServer", Bukkit.getServer());
|
|
||||||
engine.put("Expansion", JavascriptExpansion.getInstance());
|
|
||||||
engine.put("Placeholder", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
if (directory.exists()) {
|
||||||
return identifier;
|
directory.mkdirs();
|
||||||
}
|
|
||||||
|
|
||||||
public String getScript() {
|
|
||||||
return script;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String evaluate(OfflinePlayer p, String... args) {
|
|
||||||
String exp = PlaceholderAPI.setPlaceholders(p, script);
|
|
||||||
|
|
||||||
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) {
|
data = new ScriptData();
|
||||||
c = new String[]{};
|
dataFile = new File(DIRECTORY, identifier + "_data.yml");
|
||||||
}
|
engine.put("Data", data);
|
||||||
|
engine.put("BukkitServer", Bukkit.getServer());
|
||||||
engine.put("args", c);
|
engine.put("Expansion", JavascriptExpansion.getInstance());
|
||||||
engine.put("BukkitPlayer", p != null && p.isOnline() ? p.getPlayer() : null);
|
engine.put("Placeholder", this);
|
||||||
engine.put("OfflinePlayer", p);
|
engine.put("PlaceholderAPI", PlaceholderAPI.class);
|
||||||
Object result = engine.eval(exp);
|
|
||||||
return result != null ? PlaceholderAPI.setBracketPlaceholders(p, result.toString()) : "";
|
|
||||||
} catch (ScriptException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return "Script error";
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScriptData getData() {
|
|
||||||
// this should never be null but just in case setData(null) is called
|
|
||||||
if (data == null) {
|
|
||||||
data = new ScriptData();
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(ScriptData data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean loadData() {
|
|
||||||
|
|
||||||
cfg = new YamlConfiguration();
|
|
||||||
|
|
||||||
if (!dataFile.exists()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cfg.load(dataFile);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
} catch (InvalidConfigurationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Set<String> keys = cfg.getKeys(true);
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
if (keys == null || keys.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data == null) {
|
public String getScript() {
|
||||||
data = new ScriptData();
|
return script;
|
||||||
} else {
|
|
||||||
data.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keys.stream().forEach(k -> {
|
public String evaluate(OfflinePlayer player, String... args) {
|
||||||
data.set(k, cfg.get(k));
|
String exp = PlaceholderAPI.setPlaceholders(player, script);
|
||||||
});
|
|
||||||
|
|
||||||
if (!data.isEmpty()) {
|
try {
|
||||||
this.setData(data);
|
String[] arguments = null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean saveData() {
|
if (args != null && args.length > 0) {
|
||||||
if (data == null || data.isEmpty()) {
|
arguments = new String[args.length];
|
||||||
return false;
|
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if (args[i] == null || args[i].isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments[i] = PlaceholderAPI.setBracketPlaceholders(player, args[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments == null) {
|
||||||
|
arguments = new String[]{};
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.put("args", arguments);
|
||||||
|
engine.put("BukkitPlayer", player != null && player.isOnline() ? player.getPlayer() : null);
|
||||||
|
engine.put("OfflinePlayer", player);
|
||||||
|
Object result = engine.eval(exp);
|
||||||
|
return result != null ? PlaceholderAPI.setBracketPlaceholders(player, result.toString()) : "";
|
||||||
|
} catch (ScriptException ex) {
|
||||||
|
System.out.println(ex.getMessage());
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Script error";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg == null) {
|
public ScriptData getData() {
|
||||||
return false;
|
// this should never be null but just in case setData(null) is called
|
||||||
|
if (data == null) {
|
||||||
|
data = new ScriptData();
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
data.getData().entrySet().forEach(e -> {
|
public void setData(ScriptData data) {
|
||||||
cfg.set(e.getKey(), e.getValue());
|
this.data = data;
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
cfg.save(dataFile);
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void cleanup() {
|
public boolean loadData() {
|
||||||
if (this.data != null) {
|
config = new YamlConfiguration();
|
||||||
this.data.clear();
|
|
||||||
this.data = null;
|
if (!dataFile.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.load(dataFile);
|
||||||
|
} catch (IOException | InvalidConfigurationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Set<String> keys = config.getKeys(true);
|
||||||
|
|
||||||
|
if (keys.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
data = new ScriptData();
|
||||||
|
} else {
|
||||||
|
data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
keys.forEach(key -> data.set(key, config.get(key)));
|
||||||
|
|
||||||
|
if (!data.isEmpty()) {
|
||||||
|
this.setData(data);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveData() {
|
||||||
|
if (data == null || data.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.getData().forEach((key, value) -> config.set(key, value));
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.save(dataFile);
|
||||||
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
if (this.data != null) {
|
||||||
|
this.data.clear();
|
||||||
|
this.data = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config = null;
|
||||||
}
|
}
|
||||||
this.cfg = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,214 +20,202 @@
|
|||||||
*/
|
*/
|
||||||
package com.extendedclip.papi.expansion.javascript;
|
package com.extendedclip.papi.expansion.javascript;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import javax.script.ScriptEngine;
|
|
||||||
import javax.script.ScriptEngineManager;
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
public class JavascriptPlaceholdersConfig {
|
public class JavascriptPlaceholdersConfig {
|
||||||
|
|
||||||
private JavascriptExpansion ex;
|
private JavascriptExpansion ex;
|
||||||
|
|
||||||
private PlaceholderAPIPlugin plugin;
|
private PlaceholderAPIPlugin plugin;
|
||||||
|
|
||||||
private FileConfiguration config;
|
private FileConfiguration config;
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
public JavascriptPlaceholdersConfig(JavascriptExpansion ex) {
|
public JavascriptPlaceholdersConfig(JavascriptExpansion ex) {
|
||||||
this.ex = ex;
|
this.ex = ex;
|
||||||
plugin = ex.getPlaceholderAPI();
|
plugin = ex.getPlaceholderAPI();
|
||||||
reload();
|
reload();
|
||||||
}
|
|
||||||
|
|
||||||
public void reload() {
|
|
||||||
if (file == null) {
|
|
||||||
file = new File(plugin.getDataFolder(), "javascript_placeholders.yml");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config = YamlConfiguration.loadConfiguration(file);
|
public void reload() {
|
||||||
config.options().header("Javascript Expansion: " + ex.getVersion()
|
if (file == null) {
|
||||||
+ "\nThis is the main configuration file for the Javascript Expansion."
|
file = new File(plugin.getDataFolder(), "javascript_placeholders.yml");
|
||||||
+ "\n"
|
}
|
||||||
+ "\nYou will define your javascript placeholders in this file."
|
|
||||||
+ "\n"
|
|
||||||
+ "\nJavascript files must be located in the:"
|
|
||||||
+ "\n /plugins/placeholderapi/javascripts/ folder"
|
|
||||||
+ "\n"
|
|
||||||
+ "\nA detailed guide on how to create your own javascript placeholders"
|
|
||||||
+ "\ncan be found here:"
|
|
||||||
+ "\nhttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki"
|
|
||||||
+ "\n"
|
|
||||||
+ "\nYour javascript placeholders will be identified by: %javascript_<identifier>%"
|
|
||||||
+ "\n"
|
|
||||||
+ "\nConfiguration format:"
|
|
||||||
+ "\n"
|
|
||||||
+ "\n<identifier>:"
|
|
||||||
+ "\n file: <name of file>.<file extension>"
|
|
||||||
+ "\n engine: (name of script engine)"
|
|
||||||
+ "\n"
|
|
||||||
+ "\n"
|
|
||||||
+ "\nExample:"
|
|
||||||
+ "\n"
|
|
||||||
+ "\n'my_placeholder':"
|
|
||||||
+ "\n file: 'my_placeholder.js'"
|
|
||||||
+ "\n engine: 'nashorn'");
|
|
||||||
|
|
||||||
if (config.getKeys(false) == null || config.getKeys(false).isEmpty()) {
|
config = YamlConfiguration.loadConfiguration(file);
|
||||||
config.set("example.file", "example.js");
|
config.options().header("Javascript Expansion: " + ex.getVersion()
|
||||||
config.set("example.engine", "nashorn");
|
+ "\nThis is the main configuration file for the Javascript Expansion."
|
||||||
}
|
+ "\n"
|
||||||
save();
|
+ "\nYou will define your javascript placeholders in this file."
|
||||||
}
|
+ "\n"
|
||||||
|
+ "\nJavascript files must be located in the:"
|
||||||
|
+ "\n /plugins/placeholderapi/javascripts/ folder"
|
||||||
|
+ "\n"
|
||||||
|
+ "\nA detailed guide on how to create your own javascript placeholders"
|
||||||
|
+ "\ncan be found here:"
|
||||||
|
+ "\nhttps://github.com/PlaceholderAPI-Expansions/Javascript-Expansion/wiki"
|
||||||
|
+ "\n"
|
||||||
|
+ "\nYour javascript placeholders will be identified by: %javascript_<identifier>%"
|
||||||
|
+ "\n"
|
||||||
|
+ "\nConfiguration format:"
|
||||||
|
+ "\n"
|
||||||
|
+ "\n<identifier>:"
|
||||||
|
+ "\n file: <name of file>.<file extension>"
|
||||||
|
+ "\n engine: (name of script engine)"
|
||||||
|
+ "\n"
|
||||||
|
+ "\n"
|
||||||
|
+ "\nExample:"
|
||||||
|
+ "\n"
|
||||||
|
+ "\n'my_placeholder':"
|
||||||
|
+ "\n file: 'my_placeholder.js'"
|
||||||
|
+ "\n engine: 'nashorn'");
|
||||||
|
|
||||||
public FileConfiguration load() {
|
if (config.getKeys(false).isEmpty()) {
|
||||||
if (config == null) {
|
config.set("example.file", "example.js");
|
||||||
reload();
|
config.set("example.engine", "nashorn");
|
||||||
}
|
}
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save() {
|
save();
|
||||||
if ((config == null) || (file == null)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
public FileConfiguration load() {
|
||||||
load().save(file);
|
if (config == null) {
|
||||||
} catch (IOException ex) {
|
reload();
|
||||||
plugin.getLogger().log(Level.SEVERE, "Could not save to " + file, ex);
|
}
|
||||||
}
|
return config;
|
||||||
}
|
|
||||||
|
|
||||||
public int loadPlaceholders() {
|
|
||||||
if (config == null || config.getKeys(false) == null || config.getKeys(false).isEmpty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File dir = new File(plugin.getDataFolder() + File.separator + "javascripts");
|
public void save() {
|
||||||
|
if ((config == null) || (file == null)) {
|
||||||
try {
|
return;
|
||||||
if (!dir.exists()) {
|
}
|
||||||
dir.mkdirs();
|
|
||||||
plugin.getLogger().info(
|
|
||||||
"Creating directory: plugins" + File.separator + "PlaceholderAPI" + File.separator
|
|
||||||
+ "javascripts");
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
plugin.getLogger().severe(
|
|
||||||
"Could not create directory: plugins" + File.separator + "PlaceholderAPI" + File.separator
|
|
||||||
+ "javascripts");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String identifier : config.getKeys(false)) {
|
|
||||||
if (!config.contains(identifier + ".file")
|
|
||||||
|| config.getString(identifier + ".file", null) == null) {
|
|
||||||
plugin.getLogger()
|
|
||||||
.warning("Javascript placeholder: " + identifier + " does not have a file specified");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
File scriptFile = new File(plugin.getDataFolder() + File.separator + "javascripts",
|
|
||||||
config.getString(identifier + ".file"));
|
|
||||||
|
|
||||||
if (!scriptFile.exists()) {
|
|
||||||
plugin.getLogger().info(scriptFile.getName() + " does not exist. Creating file...");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scriptFile.createNewFile();
|
load().save(file);
|
||||||
plugin.getLogger().info(scriptFile.getName()
|
} catch (IOException ex) {
|
||||||
+ " created! Add your javascript to this file and use /placeholderapi reload to load it!");
|
plugin.getLogger().log(Level.SEVERE, "Could not save to " + file, ex);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String script = getContents(scriptFile);
|
public int loadPlaceholders() {
|
||||||
|
if (config == null || config.getKeys(false).isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (script == null || script.isEmpty()) {
|
File dir = new File(plugin.getDataFolder() + File.separator + "javascripts");
|
||||||
plugin.getLogger().warning(
|
|
||||||
"File: " + scriptFile.getName() + " for javascript placeholder: " + identifier
|
|
||||||
+ " is empty");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptEngine engine = null;
|
|
||||||
|
|
||||||
if (!config.contains(identifier + ".engine")) {
|
|
||||||
engine = ex.getGlobalEngine();
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
engine = new ScriptEngineManager()
|
if (!dir.exists()) {
|
||||||
.getEngineByName(config.getString(identifier + ".engine", "nashorn"));
|
dir.mkdirs();
|
||||||
} catch (NullPointerException e) {
|
plugin.getLogger().info("Creating directory: plugins/PlaceholderAPI/javascripts");
|
||||||
plugin.getLogger().warning("ScriptEngine type for javascript placeholder: " + identifier
|
}
|
||||||
+ " is invalid! Defaulting to global");
|
} catch (SecurityException e) {
|
||||||
engine = ex.getGlobalEngine();
|
plugin.getLogger().severe("Could not create directory: plugins/PlaceholderAPI/javascripts");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (engine == null) {
|
for (String identifier : config.getKeys(false)) {
|
||||||
plugin.getLogger()
|
if (!config.contains(identifier + ".file") || config.getString(identifier + ".file") == null) {
|
||||||
.warning("Failed to set ScriptEngine for javascript placeholder: " + identifier);
|
plugin.getLogger().warning("Javascript placeholder: " + identifier + " does not have a file specified");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
JavascriptPlaceholder pl = new JavascriptPlaceholder(engine, identifier, script);
|
File scriptFile = new File(plugin.getDataFolder() + "/javascripts", config.getString(identifier + ".file"));
|
||||||
|
|
||||||
boolean added = ex.addJSPlaceholder(pl);
|
if (!scriptFile.exists()) {
|
||||||
|
plugin.getLogger().info(scriptFile.getName() + " does not exist. Creating file...");
|
||||||
|
|
||||||
if (added) {
|
try {
|
||||||
|
scriptFile.createNewFile();
|
||||||
|
plugin.getLogger().info(scriptFile.getName()
|
||||||
|
+ " created! Add your javascript to this file and use /placeholderapi reload to load it!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (pl.loadData()) {
|
String script = getContents(scriptFile);
|
||||||
plugin.getLogger().info("Loaded data for javascript placeholder: " + identifier);
|
|
||||||
|
if (script == null || script.isEmpty()) {
|
||||||
|
plugin.getLogger().warning("File: " + scriptFile.getName() + " for javascript placeholder: " + identifier + " is empty");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptEngine engine;
|
||||||
|
|
||||||
|
if (!config.contains(identifier + ".engine")) {
|
||||||
|
engine = ex.getGlobalEngine();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
engine = new ScriptEngineManager().getEngineByName(config.getString(identifier + ".engine", "nashorn"));
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
plugin.getLogger().warning("ScriptEngine type for javascript placeholder: " + identifier + " is invalid! Defaulting to global");
|
||||||
|
engine = ex.getGlobalEngine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (engine == null) {
|
||||||
|
plugin.getLogger().warning("Failed to set ScriptEngine for javascript placeholder: " + identifier);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final JavascriptPlaceholder pl = new JavascriptPlaceholder(engine, identifier, script);
|
||||||
|
final boolean added = ex.addJSPlaceholder(pl);
|
||||||
|
|
||||||
|
if (added) {
|
||||||
|
if (pl.loadData()) {
|
||||||
|
plugin.getLogger().info("Loaded data for javascript placeholder: " + identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getLogger().info("%javascript_" + identifier + "% has been loaded!");
|
||||||
|
} else {
|
||||||
|
plugin.getLogger().warning("Javascript placeholder %javascript_" + identifier + "% is a duplicate!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
plugin.getLogger().info("%javascript_" + identifier + "% has been loaded!");
|
|
||||||
} else {
|
return ex.getAmountLoaded();
|
||||||
plugin.getLogger()
|
|
||||||
.warning("Javascript placeholder %javascript_" + identifier + "% is a duplicate!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ex.getAmountLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getContents(File f) {
|
private String getContents(File file) {
|
||||||
StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Scanner scanner = new Scanner(f);
|
Scanner scanner = new Scanner(file);
|
||||||
|
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
if (line == null || line.isEmpty()) {
|
if (line == null || line.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line.trim();
|
||||||
|
|
||||||
|
/* temp fix for single line comments
|
||||||
|
* doesnt solve every case though..
|
||||||
|
* lines that start with code and may have a comment afterward still screw stuff up...
|
||||||
|
*/
|
||||||
|
if (line.startsWith("//")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
sb.append(line).append(" ");
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
return sb.toString();
|
||||||
line = line.trim();
|
|
||||||
|
|
||||||
/* temp fix for single line comments
|
|
||||||
* doesnt solve every case though..
|
|
||||||
* lines that start with code and may have a comment afterward still screw stuff up...
|
|
||||||
*/
|
|
||||||
if (line.startsWith("//")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
sb.append(line + " ");
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,41 +25,41 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class ScriptData {
|
public class ScriptData {
|
||||||
|
|
||||||
private Map<String, Object> map;
|
private Map<String, Object> map;
|
||||||
|
|
||||||
public ScriptData(Map<String, Object> data) {
|
public ScriptData(Map<String, Object> data) {
|
||||||
this.map = data;
|
this.map = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptData() {
|
public ScriptData() {
|
||||||
this.map = new HashMap<>();
|
this.map = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getData() {
|
public Map<String, Object> getData() {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
map.clear();
|
map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean exists(String key) {
|
public boolean exists(String key) {
|
||||||
return map.containsKey(key) && map.get(key) != null;
|
return map.containsKey(key) && map.get(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object get(String key) {
|
public Object get(String key) {
|
||||||
return map.get(key);
|
return map.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(String key) {
|
public void remove(String key) {
|
||||||
map.put(key, null);
|
map.put(key, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, Object value) {
|
public void set(String key, Object value) {
|
||||||
map.put(key, value);
|
map.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return map.isEmpty();
|
return map.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,33 +22,33 @@ package com.extendedclip.papi.expansion.javascript.cloud;
|
|||||||
|
|
||||||
public class GithubScript {
|
public class GithubScript {
|
||||||
|
|
||||||
private String name, version, author, description, url;
|
private String name, version, author, description, url;
|
||||||
|
|
||||||
public GithubScript(String name, String version, String author, String description, String url) {
|
public GithubScript(String name, String version, String author, String description, String url) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,105 +23,103 @@ package com.extendedclip.papi.expansion.javascript.cloud;
|
|||||||
import com.extendedclip.papi.expansion.javascript.JavascriptExpansion;
|
import com.extendedclip.papi.expansion.javascript.JavascriptExpansion;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import java.io.BufferedReader;
|
import org.bukkit.Bukkit;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.*;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public class GithubScriptManager {
|
public class GithubScriptManager {
|
||||||
|
|
||||||
private JavascriptExpansion expansion;
|
private JavascriptExpansion expansion;
|
||||||
private String javascriptsFolder;
|
private String javascriptsFolder;
|
||||||
private List<GithubScript> availableScripts;
|
private List<GithubScript> availableScripts;
|
||||||
private final String MASTER_LIST_URL = "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/master_list.json";
|
private final String MASTER_LIST_URL = "https://raw.githubusercontent.com/PlaceholderAPI/Javascript-Expansion/master/scripts/master_list.json";
|
||||||
private final Gson GSON = new Gson();
|
private final Gson GSON = new Gson();
|
||||||
|
|
||||||
public GithubScriptManager(JavascriptExpansion expansion) {
|
public GithubScriptManager(JavascriptExpansion expansion) {
|
||||||
this.expansion = expansion;
|
this.expansion = expansion;
|
||||||
javascriptsFolder = expansion.getPlaceholderAPI().getDataFolder()
|
javascriptsFolder = expansion.getPlaceholderAPI().getDataFolder()
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ "javascripts"
|
+ "javascripts"
|
||||||
+ File.separator;
|
+ File.separator;
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
availableScripts = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fetch() {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(expansion.getPlaceholderAPI(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
String json = getContents(MASTER_LIST_URL);
|
|
||||||
if (json.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
availableScripts = GSON.fromJson(json, new TypeToken<ArrayList<GithubScript>>() {
|
|
||||||
}.getType());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void downloadScript(GithubScript script) {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(expansion.getPlaceholderAPI(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
List<String> contents = read(script.getUrl());
|
|
||||||
if (contents == null || contents.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File f = new File(javascriptsFolder, script.getName() + ".js");
|
|
||||||
try (PrintStream out = new PrintStream(new FileOutputStream(f))) {
|
|
||||||
contents.forEach(l -> out.println(l));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bukkit.getScheduler().runTask(expansion.getPlaceholderAPI(), new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
expansion.getConfig().load().set(script.getName() + ".file", script.getName() + ".js");
|
|
||||||
expansion.getConfig().save();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getContents(String url) {
|
|
||||||
return String.join("", read(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> read(String url) {
|
|
||||||
|
|
||||||
List<String> lines = new ArrayList<>();
|
|
||||||
|
|
||||||
try (BufferedReader reader = new BufferedReader(
|
|
||||||
new InputStreamReader(new URL(url).openStream()))) {
|
|
||||||
|
|
||||||
String inputLine;
|
|
||||||
while ((inputLine = reader.readLine()) != null) {
|
|
||||||
lines.add(inputLine);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
public void clear() {
|
||||||
}
|
availableScripts = null;
|
||||||
|
}
|
||||||
|
|
||||||
public List<GithubScript> getAvailableScripts() {
|
public void fetch() {
|
||||||
return availableScripts;
|
Bukkit.getScheduler().runTaskAsynchronously(expansion.getPlaceholderAPI(), new Runnable() {
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String json = getContents(MASTER_LIST_URL);
|
||||||
|
if (json.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
availableScripts = GSON.fromJson(json, new TypeToken<ArrayList<GithubScript>>() {
|
||||||
|
}.getType());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public GithubScript getScript(String name) {
|
public void downloadScript(GithubScript script) {
|
||||||
if (availableScripts == null) return null;
|
Bukkit.getScheduler().runTaskAsynchronously(expansion.getPlaceholderAPI(), new Runnable() {
|
||||||
return availableScripts.stream().filter(s -> {return s.getName().equalsIgnoreCase(name);}).findFirst().orElse(null);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
|
List<String> contents = read(script.getUrl());
|
||||||
|
if (contents == null || contents.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File f = new File(javascriptsFolder, script.getName() + ".js");
|
||||||
|
try (PrintStream out = new PrintStream(new FileOutputStream(f))) {
|
||||||
|
contents.forEach(l -> out.println(l));
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTask(expansion.getPlaceholderAPI(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
expansion.getConfig().load().set(script.getName() + ".file", script.getName() + ".js");
|
||||||
|
expansion.getConfig().save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getContents(String url) {
|
||||||
|
return String.join("", read(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> read(String url) {
|
||||||
|
|
||||||
|
List<String> lines = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(new URL(url).openStream()))) {
|
||||||
|
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = reader.readLine()) != null) {
|
||||||
|
lines.add(inputLine);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GithubScript> getAvailableScripts() {
|
||||||
|
return availableScripts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GithubScript getScript(String name) {
|
||||||
|
if (availableScripts == null) return null;
|
||||||
|
return availableScripts.stream().filter(s -> {
|
||||||
|
return s.getName().equalsIgnoreCase(name);
|
||||||
|
}).findFirst().orElse(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user