Skip to content

Commit

Permalink
use enabled global key in relevant containers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 16, 2022
1 parent d6256f6 commit 718ba40
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 18 deletions.
Expand Up @@ -31,7 +31,7 @@ public ServerPrestartScriptEvent() {

public void specialHackRunEvent() {
for (WorldScriptContainer container : ScriptEvent.worldContainers) {
if (container.containsScriptSection("events.on server prestart")) {
if (container.containsScriptSection("events.on server prestart") && container.shouldEnable()) {
ScriptPath path = new ScriptPath(container, "server prestart", "on server prestart");
clone().run(path);
}
Expand Down
Expand Up @@ -348,7 +348,7 @@ public ListTag action(String actionName, PlayerTag player, Map<String, ObjectTag
if (getCitizen() != null) {
if (getCitizen().hasTrait(AssignmentTrait.class)) {
for (AssignmentScriptContainer container : getCitizen().getOrAddTrait(AssignmentTrait.class).containerCache) {
if (container != null) {
if (container != null && container.shouldEnable()) {
ListTag singleResult = Denizen.getInstance().npcHelper.getActionHandler().doAction(actionName, this, player, container, context);
if (singleResult != null) {
result.addAll(singleResult);
Expand Down
Expand Up @@ -25,6 +25,9 @@ public class AssignmentScriptContainer extends ScriptContainer {
// interact scripts can provide more functionality.
// See also <@link language interact script containers>
//
// Assignments scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
// This will disable any "actions" on the script (but not interact scripts steps - disable the interact for that).
//
// Basic structure of an assignment script:
// <code>
// Assignment_Script_Name:
Expand Down
Expand Up @@ -46,6 +46,9 @@ public class CommandScriptContainer extends ScriptContainer {
// and 'usage:' is for documentation in the '/help' command.
// These two options should almost always show the same name.
//
//
// Command scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
//
// <code>
// # The name of the script doesn't matter, and will not affect the command in any way.
// Command_Script_Name:
Expand Down
Expand Up @@ -109,7 +109,9 @@ public void run() {
@EventHandler
public void scriptReload(ScriptReloadEvent event) {
for (CommandScriptContainer script : commandScripts.values()) {
registerDenizenCommand(new DenizenCommand(script));
if (script.shouldEnable()) {
registerDenizenCommand(new DenizenCommand(script));
}
}
syncDenizenCommands();
}
Expand Down
Expand Up @@ -45,6 +45,8 @@ public class EconomyScriptContainer extends ScriptContainer {
//
// ALL SCRIPT KEYS ARE REQUIRED.
//
// Economy scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
//
// <code>
// # The script name will be shown to the economy provider as the name of the economy system.
// Economy_Script_Name:
Expand Down Expand Up @@ -389,6 +391,8 @@ public static void cleanup() {

public EconomyScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
super(configurationSection, scriptContainerName);
providersRegistered.add(register());
if (shouldEnable()) {
providersRegistered.add(register());
}
}
}
Expand Up @@ -47,6 +47,8 @@ public class EnchantmentScriptContainer extends ScriptContainer {
//
// Using these may cause unpredictable compatibility issues with external plugins.
//
// Enchantment scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
//
// <code>
// Enchantment_Script_Name:
//
Expand Down Expand Up @@ -197,19 +199,21 @@ public EnchantmentScriptContainer(YamlConfiguration configurationSection, String
maxCostTaggable = getString("max_cost", "1");
damageBonusTaggable = getString("damage_bonus", "0.0");
damageProtectionTaggable = getString("damage_protection", "0");
EnchantmentReference ref = registeredEnchantmentContainers.get(id);
boolean isNew = ref == null;
if (isNew) {
ref = new EnchantmentReference();
}
EnchantmentScriptContainer old = ref.script;
ref.script = this;
registeredEnchantmentContainers.put(id, ref);
if (isNew) {
enchantment = NMSHandler.enchantmentHelper.registerFakeEnchantment(ref);
}
else {
enchantment = old.enchantment;
if (shouldEnable()) {
EnchantmentReference ref = registeredEnchantmentContainers.get(id);
boolean isNew = ref == null;
if (isNew) {
ref = new EnchantmentReference();
}
EnchantmentScriptContainer old = ref.script;
ref.script = this;
registeredEnchantmentContainers.put(id, ref);
if (isNew) {
enchantment = NMSHandler.enchantmentHelper.registerFakeEnchantment(ref);
}
else {
enchantment = old.enchantment;
}
}
}

Expand Down
Expand Up @@ -40,6 +40,8 @@ public class InteractScriptContainer extends ScriptContainer {
// Note that script commands ran in interact scripts by default have a delay between each command.
// To override this delay, set 'speed: 0' on the container or change the relevant config setting.
//
// Interact scripts can be automatically disabled by adding "enabled: false" as a root key (supports any load-time-parseable tags).
//
// <code>
// Interact_Script_Name:
//
Expand Down
Expand Up @@ -29,7 +29,7 @@ public static List<InteractScriptContainer> getInteractScripts(NPCTag npc) {
for (AssignmentScriptContainer container : trait.containerCache) {
if (container != null) {
InteractScriptContainer interact = container.getInteract();
if (interact != null) {
if (interact != null && interact.shouldEnable()) {
result.add(interact);
}
}
Expand Down

0 comments on commit 718ba40

Please sign in to comment.