Skip to content

Commit

Permalink
Only utilize script load task if the config.yml specifies a script lo…
Browse files Browse the repository at this point in the history
…ad delay > 0
  • Loading branch information
magicmq committed Mar 27, 2024
1 parent 3734e9e commit c647c00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static boolean getMetricsEnabled() {
return config.getBoolean("metrics-enabled", true);
}

public static long getLoadScriptDelay() {
public static long getScriptLoadDelay() {
return config.getLong("script-load-delay", 20L);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,24 @@ public class ScriptManager {
private final File scriptsFolder;
private final HashMap<String, Script> scripts;

private final BukkitTask startScriptTask;
private BukkitTask startScriptTask;

private ScriptManager() {
scriptsFolder = new File(PySpigot.get().getDataFolder(), "scripts");
this.scripts = new HashMap<>();

startScriptTask = Bukkit.getScheduler().runTaskLater(PySpigot.get(), this::loadScripts, PluginConfig.getLoadScriptDelay());
if (PluginConfig.getScriptLoadDelay() > 0L)
startScriptTask = Bukkit.getScheduler().runTaskLater(PySpigot.get(), this::loadScripts, PluginConfig.getScriptLoadDelay());
else
loadScripts();
}

/**
* Called on plugin unload or server shutdown. Gracefully stops and unloads all loaded and running scripts.
*/
public void shutdown() {
startScriptTask.cancel();
if (startScriptTask != null)
startScriptTask.cancel();

unloadScripts();

Expand Down

0 comments on commit c647c00

Please sign in to comment.