Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data-persists config option #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public boolean execute(CommandSender sender, String label, String[] args) {
}

final String script = String.join(" ", Arrays.copyOfRange(args, 2, args.length));
final JavascriptPlaceholder placeholder = new JavascriptPlaceholder(expansion.getGlobalEngine(), "parse-command", String.join(" ", script));
final JavascriptPlaceholder placeholder = new JavascriptPlaceholder(expansion.getGlobalEngine(), "parse-command", String.join(" ", script), true);

if ("me".equalsIgnoreCase(args[1])) {
if (!(sender instanceof Player)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ public class JavascriptPlaceholder {
private final ScriptEngine engine;
private final String identifier;
private final String script;
private final boolean dataPersists;
private ScriptData scriptData;
private final File dataFile;
private YamlConfiguration yaml;

public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script) {
public JavascriptPlaceholder(ScriptEngine engine, String identifier, String script, boolean dataPersists) {
Validate.notNull(engine, "ScriptEngine can not be null");
Validate.notNull(identifier, "Identifier can not be null");
Validate.notNull(script, "Script can not be null");

this.engine = engine;
this.identifier = identifier;
this.script = script;
this.dataPersists = dataPersists;
final File directory = new File(DIRECTORY);

if (!directory.exists()) {
Expand Down Expand Up @@ -170,7 +172,7 @@ public boolean loadData() {
}

public boolean saveData() {
if (scriptData == null || scriptData.isEmpty() || yaml == null) {
if (!dataPersists || scriptData == null || scriptData.isEmpty() || yaml == null) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public int loadPlaceholders() {
continue;
}

final JavascriptPlaceholder placeholder = new JavascriptPlaceholder(engine, identifier, script);
final JavascriptPlaceholder placeholder = new JavascriptPlaceholder(engine, identifier, script, (!config.contains(identifier + ".data_persists")) || config.getBoolean(identifier + ".data_persists"));
final boolean added = ex.addJSPlaceholder(placeholder);

if (added) {
Expand Down