Skip to content

Commit

Permalink
cleanup reload scripts event, relates to Denizen#2039
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 13, 2019
1 parent efcee3a commit 2c201fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public static void postLoadScripts() {
ScriptEvent.reload();
implementation.onScriptReload();
ReloadScriptsScriptEvent.instance.reset();
ReloadScriptsScriptEvent.instance.all = true;
ReloadScriptsScriptEvent.instance.hadError = ScriptHelper.hadError();
ReloadScriptsScriptEvent.instance.data = DenizenCore.getImplementation().getEmptyScriptEntryData();
ReloadScriptsScriptEvent.instance.fire();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.utilities.Deprecations;

public class ReloadScriptsScriptEvent extends ScriptEvent {

Expand All @@ -13,31 +14,26 @@ public class ReloadScriptsScriptEvent extends ScriptEvent {
// reload scripts
// script reload
//
// @Switch haderror true|false
// @Switch all true|false
// @Switch had_error true|false
//
// @Regex ^on ((reload scripts)|(script reload))$
//
// @Triggers when Denizen scripts are reloaded.
//
// @Context
// <context.all> returns an Element(Boolean) of whether 'reload -a' was used.
// <context.haderror> returns an Element(Boolean) whether there was an error.
// <context.had_error> returns an Element(Boolean) whether there was an error.
//
// -->

public static ReloadScriptsScriptEvent instance;

public boolean hadError = false;

public boolean all = false;

public ScriptEntryData data = null;

@Override
public void reset() {
hadError = false;
all = false;
data = DenizenCore.getImplementation().getEmptyScriptEntryData();
super.reset();
}
Expand All @@ -49,11 +45,12 @@ public ScriptEntryData getScriptEntryData() {

@Override
public ObjectTag getContext(String name) {
if (name.equals("haderror")) {
if (name.equals("had_error")) {
return new ElementTag(hadError);
}
else if (name.equals("all")) {
return new ElementTag(all);
else if (name.equals("haderror")) {
Deprecations.scriptReloadEventNoUnderscore.warn();
return new ElementTag(hadError);
}
return super.getContext(name);
}
Expand All @@ -69,8 +66,16 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {
return path.checkSwitch("haderror", hadError ? "true" : "false")
&& path.checkSwitch("all", all ? "true" : "false");
if (path.switches.containsKey("haderror")) {
Deprecations.scriptReloadEventNoUnderscore.warn();
if (!path.checkSwitch("haderror", hadError ? "true" : "false")) {
return false;
}
}
if (path.checkSwitch("had_error", hadError ? "true" : "false")) {
return false;
}
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public class Deprecations {
// This is just a message, relevant functionality already removed. Remove the script container registration after a few releases.
public static Warning versionScripts = new SlowWarning("Version script containers are deprecated due to the old script repo no longer being active.");

// Added on 2019/10/13
public static Warning scriptReloadEventNoUnderscore = new SlowWarning("In the 'on script reload' event, 'had_error' should be used instead of 'haderror'.");

// ==================== SPECIAL deprecations: Minecraft version ====================

// In Bukit impl, To be removed when Minecraft 1.12.2 is no longer supported by the Bukkit impl:
Expand Down

1 comment on commit 2c201fe

@mcmonkey4eva
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.