Skip to content

Commit

Permalink
FlaggableObject.clean_flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 22, 2022
1 parent 0972545 commit a6fc02b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
@@ -1,5 +1,6 @@
package com.denizenscript.denizencore.flags;

import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.*;
import com.denizenscript.denizencore.tags.Attribute;
Expand Down Expand Up @@ -121,6 +122,23 @@ public static <T extends FlaggableObject> void registerFlagHandlers(ObjectTagPro
});
}

public static void tryFlagAdjusts(FlaggableObject object, Mechanism mechanism) {

// <--[mechanism]
// @object FlaggableObject
// @name clean_flags
// @input None
// @description
// Cleans any expired flags from the object.
// Generally doesn't need to be called, using the 'skip flag cleanings' setting was enabled.
// This is an internal/special case mechanism, and should be avoided where possible.
// Does not function on all flaggable objects, particularly those that just store their flags into other objects.
// -->
if (mechanism.matches("clean_flags")) {
object.getFlagTracker().doTotalClean();
}
}

public ElementTag doHasFlagTag(Attribute attribute) {
if (!attribute.hasParam()) {
attribute.echoError("The has_flag[...] tag must have an input!");
Expand Down Expand Up @@ -202,4 +220,8 @@ public MapTag doFlagMapTag(Attribute attribute) {
}
return result;
}

public void doTotalClean() {
// Do nothing by default
}
}
Expand Up @@ -83,10 +83,8 @@ public SavableMapFlagTracker(String input) {
}
}

@Override
public void doTotalClean() {
if (CoreConfiguration.skipAllFlagCleanings) {
return;
}
if (CoreConfiguration.debugVerbose) {
Debug.echoError("Verbose - savable tracker is beginning doTotalClean");
}
Expand Down Expand Up @@ -237,7 +235,7 @@ public static SavableMapFlagTracker loadFlagFile(String filePath, boolean doClea
if (CoreConfiguration.debugVerbose) {
Debug.echoError("Verbose - loading flag file path at " + filePath + " to tracker of " + tracker.map.size() + " flags... doClean=" + doClean);
}
if (doClean) {
if (doClean && !CoreConfiguration.skipAllFlagCleanings) {
tracker.doTotalClean();
}
return tracker;
Expand Down
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.core.EscapeTagBase;
import com.denizenscript.denizencore.utilities.CoreConfiguration;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import com.denizenscript.denizencore.utilities.debugging.Debug;
Expand Down Expand Up @@ -111,7 +112,9 @@ private static void loadFromConfig() {
obj.makeUnique(note);
if (flagText != null && obj instanceof FlaggableObject) {
SavableMapFlagTracker tracker = new SavableMapFlagTracker(flagText);
tracker.doTotalClean();
if (!CoreConfiguration.skipAllFlagCleanings) {
tracker.doTotalClean();
}
((FlaggableObject) getSavedObject(note)).reapplyTracker(tracker);
}
}
Expand Down

0 comments on commit a6fc02b

Please sign in to comment.