Skip to content

Commit

Permalink
'scripts loaded' event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 30, 2022
1 parent 9564f71 commit 998ba0e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/denizenscript/denizencore/DenizenCore.java
Expand Up @@ -197,6 +197,8 @@ public static void postLoadScripts() {
ScriptEvent.reload();
implementation.onScriptReload();
lastReloadTime = CoreUtilities.monotonicMillis();
ScriptsLoadedScriptEvent.instance.hadError = ScriptHelper.hadError();
ScriptsLoadedScriptEvent.instance.fire();
}
catch (Exception ex) {
implementation.debugMessage("Error loading scripts:");
Expand Down
Expand Up @@ -57,6 +57,7 @@ public static void registerCoreEvents() {
registerScriptEvent(ReloadScriptsScriptEvent.class);
registerScriptEvent(ScriptGeneratesErrorScriptEvent.class);
registerScriptEvent(ServerGeneratesExceptionScriptEvent.class);
registerScriptEvent(ScriptsLoadedScriptEvent.class);
registerScriptEvent(ShutdownScriptEvent.class);
registerScriptEvent(SystemTimeScriptEvent.class);
registerScriptEvent(TickScriptEvent.class);
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class ReloadScriptsScriptEvent extends ScriptEvent {
//
// @Group Core
//
// @Triggers when Denizen scripts are reloaded.
// @Triggers when Denizen scripts are reloaded. Not triggered on initial load.
//
// @Context
// <context.had_error> returns an ElementTag(Boolean) whether there was an error.
Expand Down
@@ -0,0 +1,55 @@
package com.denizenscript.denizencore.events.core;

import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;

public class ScriptsLoadedScriptEvent extends ScriptEvent {

// <--[event]
// @Events
// scripts loaded
//
// @Switch had_error:true/false to only process the event if there either was or was not an error message.
//
// @Group Core
//
// @Triggers when Denizen scripts are loaded, but on reloaded and on initial load.
//
// @Context
// <context.had_error> returns an ElementTag(Boolean) whether there was an error.
//
// -->

public static ScriptsLoadedScriptEvent instance;

public ScriptsLoadedScriptEvent() {
instance = this;
registerCouldMatcher("scripts loaded");
registerSwitches("had_error");
}

public boolean hadError = false;

@Override
public ObjectTag getContext(String name) {
switch (name) {
case "had_error":
return new ElementTag(hadError);
}
return super.getContext(name);
}

@Override
public boolean matches(ScriptPath path) {
if (!path.checkSwitch("had_error", hadError ? "true" : "false")) {
return false;
}
return super.matches(path);
}

@Override
public String getName() {
return "ScriptsLoaded";
}
}
Expand Up @@ -1275,7 +1275,7 @@ else if (CoreUtilities.toLowerCase(element).contains(CoreUtilities.toLowerCase(c
// @returns ElementTag
// @group element manipulation
// @description
// Returns the element with all instances of a element removed.
// Returns the element with all instances of an element removed.
// -->

// <--[tag]
Expand Down
Expand Up @@ -37,9 +37,6 @@ public static void reloadScripts() {
ScriptRegistry.buildCoreYamlScriptContainers(_yamlScripts);
}

/**
* Console will be alerted if error was had during reload
*/
private static boolean hadError = false;

public static boolean hadError() {
Expand Down
Expand Up @@ -13,6 +13,8 @@ public SecretTagBase() {
// @description
// Returns a SecretTag object constructed from the input value.
// Refer to <@link ObjectType SecretTag>.
// @Example
// - webget <secret[my_secret_url]> "post:Message to secret address!"
// -->
TagManager.registerStaticTagBaseHandler(SecretTag.class, "secret", (attribute) -> {
return SecretTag.valueOf(attribute.getParam(), attribute.context);
Expand Down

0 comments on commit 998ba0e

Please sign in to comment.