Skip to content

Commit

Permalink
enabled global key support
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 16, 2022
1 parent 2320434 commit 2f8d3b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Expand Up @@ -352,7 +352,7 @@ public static void reload() {
totalPaths = 0;
for (ScriptContainer container : worldContainers) {
try {
if (!CoreUtilities.equalsIgnoreCase(container.getContents().getString("enabled", "true"), "true")) {
if (!container.shouldEnable()) {
continue;
}
YamlConfiguration config = container.getConfigurationSection("events");
Expand Down
Expand Up @@ -69,7 +69,7 @@ public FlagCommand() {
// and if the flag's expiration time is in the past, the flag tag will return values equivalent to if the flag doesn't exist.
// There is no system actively monitoring for flag expirations or applying them. There is no event for expirations occurring, as they don't "occur" per se.
// In other words, it is correct to say a flag "is expired" or a flag "is not expired",
// but it is incorrect to say a flag "expires", as it is not an active action (those this wording can be convenient when speaking informally).
// but it is incorrect to say a flag "expires", as it is not an active action (though this wording can be convenient when speaking informally).
// Expired flags are sometimes 'cleaned up' (meaning, any expired flags get actually removed from internal storage), usually when a flag save file is loaded into the server.
//
// As a bonus feature-combo, it is possible to transmit sets of flags exactly in-place and reapply them, this is particular useful for example to synchronize player data across Bungee servers.
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizencore.scripts.containers;

import com.denizenscript.denizencore.scripts.*;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreConfiguration;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
Expand Down Expand Up @@ -65,9 +66,24 @@ public ScriptContainer(YamlConfiguration configurationSection, String scriptCont
configurationSection.forceLoweredRootKey("debug");
configurationSection.forceLoweredRootKey("script");
configurationSection.forceLoweredRootKey("speed");
configurationSection.forceLoweredRootKey("enabled");
this.name = CoreUtilities.toUpperCase(scriptContainerName);
}

public Boolean enabledCache = null;

public boolean shouldEnable() {
if (enabledCache != null) {
return enabledCache;
}
String enabledText = contents.getString("enabled");
if (enabledText == null) {
return enabledCache = true;
}
String result = TagManager.tag(enabledText, DenizenCore.implementation.getTagContext(this));
return enabledCache = (result == null || CoreUtilities.equalsIgnoreCase(result, "true"));
}

public void postCheck() {
}

Expand Down
Expand Up @@ -16,6 +16,8 @@ public class WorldScriptContainer extends ScriptContainer {
//
// The only required key is 'events:', within which you can list any events to handle.
//
// World scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
//
// <code>
// World_Script_Name:
//
Expand Down

0 comments on commit 2f8d3b0

Please sign in to comment.