Skip to content

Commit

Permalink
Warning when economy scripts accessed off-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 25, 2021
1 parent f5b5b03 commit c873bf4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
@@ -1,7 +1,6 @@
package com.denizenscript.denizen.scripts.commands.world;

import com.denizenscript.denizen.objects.*;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.abstracts.ParticleHelper;
Expand Down Expand Up @@ -194,7 +193,6 @@ else if (!scriptEntry.hasObject("targets")
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
scriptEntry.defaultObject("data", new ElementTag(0));
scriptEntry.defaultObject("radius", new ElementTag(15));
scriptEntry.defaultObject("quantity", new ElementTag(1));
Expand Down
Expand Up @@ -102,14 +102,28 @@ public String autoTagAmount(String value, OfflinePlayer player, double amount) {
return autoTag(value.replace("<amount", "<element[" + amountText + "]"), player);
}

public void validateThread() {
if (!Bukkit.isPrimaryThread()) {
try {
throw new RuntimeException("Stack reference");
}
catch (RuntimeException ex) {
Debug.echoError("Warning: economy access from wrong thread, errors will result");
Debug.echoError(ex);
}
}
}

public String autoTag(String value, OfflinePlayer player) {
if (value == null) {
return null;
}
validateThread();
return TagManager.tag(value, new BukkitTagContext(player == null ? null : new PlayerTag(player), null, new ScriptTag(backingScript)));
}

public String runSubScript(String pathName, OfflinePlayer player, double amount) {
validateThread();
List<ScriptEntry> entries = backingScript.getEntries(new BukkitScriptEntryData(new PlayerTag(player), null), pathName);
InstantQueue queue = new InstantQueue(backingScript.getName());
queue.addEntries(entries);
Expand Down
Expand Up @@ -172,7 +172,7 @@ public static AbstractFlagTracker getTrackerFor(UUID id) {
return cache.tracker;
}

public static Future loadAsync(UUID id) {
public static Future loadAsync(UUID id) { // Note: this method is called sync, but triggers an async load
try {
CachedPlayerFlag cache = playerFlagTrackerCache.get(id);
if (cache != null) {
Expand Down

0 comments on commit c873bf4

Please sign in to comment.