mirror of
https://github.com/PlaceholderAPI/Javascript-Expansion.git
synced 2025-05-23 18:42:44 +00:00
Direct access to JavascriptPlacholder class.
This commit is contained in:
parent
b17620cdbf
commit
34a5893b8a
@ -30,7 +30,6 @@ import java.util.Set;
|
|||||||
import javax.script.ScriptEngine;
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptEngineManager;
|
import javax.script.ScriptEngineManager;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
|
||||||
import me.clip.placeholderapi.expansion.Cacheable;
|
import me.clip.placeholderapi.expansion.Cacheable;
|
||||||
import me.clip.placeholderapi.expansion.Configurable;
|
import me.clip.placeholderapi.expansion.Configurable;
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
@ -131,7 +130,7 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
|||||||
try {
|
try {
|
||||||
globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "javascript"));
|
globalEngine = new ScriptEngineManager().getEngineByName(getString("engine", "javascript"));
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
PlaceholderAPIPlugin.getInstance().getLogger().warning("Javascript engine type was invalid! Defaulting to 'javascript'");
|
getPlaceholderAPI().getLogger().warning("Javascript engine type was invalid! Defaulting to 'javascript'");
|
||||||
globalEngine = new ScriptEngineManager().getEngineByName("javascript");
|
globalEngine = new ScriptEngineManager().getEngineByName("javascript");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,12 +142,10 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
if (!scripts.isEmpty()) {
|
scripts.stream().forEach(s -> {
|
||||||
scripts.stream().forEach(s -> {
|
s.saveData();
|
||||||
s.saveData();
|
s.cleanup();
|
||||||
s.cleanup();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
scripts.clear();
|
scripts.clear();
|
||||||
globalEngine = null;
|
globalEngine = null;
|
||||||
instance = null;
|
instance = null;
|
||||||
@ -225,12 +222,10 @@ public class JavascriptExpansion extends PlaceholderExpansion implements Cacheab
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int reloadScripts() {
|
private int reloadScripts() {
|
||||||
if (!scripts.isEmpty()) {
|
scripts.stream().forEach(s -> {
|
||||||
scripts.stream().forEach(s -> {
|
s.saveData();
|
||||||
s.saveData();
|
s.cleanup();
|
||||||
s.cleanup();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
scripts.clear();
|
scripts.clear();
|
||||||
config.reload();
|
config.reload();
|
||||||
return config.loadPlaceholders();
|
return config.loadPlaceholders();
|
||||||
|
@ -51,16 +51,13 @@ public class JavascriptPlaceholder {
|
|||||||
|
|
||||||
private FileConfiguration cfg;
|
private FileConfiguration cfg;
|
||||||
|
|
||||||
private final String FILEDIR = PlaceholderAPIPlugin.getInstance().getDataFolder() + File.separator + "expansions" + File.separator + "javascript_data";
|
private final String FILEDIR = PlaceholderAPIPlugin.getInstance().getDataFolder() + File.separator + "javascripts" + File.separator + "javascript_data";
|
||||||
|
|
||||||
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.engine = engine;
|
||||||
engine.put("Data", getData());
|
|
||||||
engine.put("BukkitServer", Bukkit.getServer());
|
|
||||||
engine.put("Expansion", JavascriptExpansion.getInstance());
|
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.script = script;
|
this.script = script;
|
||||||
File dir = new File(FILEDIR);
|
File dir = new File(FILEDIR);
|
||||||
@ -74,6 +71,11 @@ public class JavascriptPlaceholder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dataFile = new File(FILEDIR, identifier + "_data.yml");
|
dataFile = new File(FILEDIR, identifier + "_data.yml");
|
||||||
|
|
||||||
|
engine.put("Data", getData());
|
||||||
|
engine.put("BukkitServer", Bukkit.getServer());
|
||||||
|
engine.put("Expansion", JavascriptExpansion.getInstance());
|
||||||
|
engine.put("Placeholder", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user