Skip to content

Commit

Permalink
RunLater
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 28, 2021
1 parent 649d574 commit 41d0bfc
Show file tree
Hide file tree
Showing 9 changed files with 482 additions and 71 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/denizenscript/denizencore/DenizenCore.java
Expand Up @@ -6,6 +6,7 @@
import com.denizenscript.denizencore.scripts.ScriptHelper;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.commands.CommandRegistry;
import com.denizenscript.denizencore.scripts.commands.queue.RunLaterCommand;
import com.denizenscript.denizencore.scripts.queues.ScriptEngine;
import com.denizenscript.denizencore.utilities.debugging.LogInterceptor;
import com.denizenscript.denizencore.utilities.debugging.Debug;
Expand Down Expand Up @@ -164,6 +165,7 @@ public static void tick(int ms_elapsed) {
if (TickScriptEvent.instance.enabled) {
TickScriptEvent.instance.fire();
}
RunLaterCommand.tickFutureRuns();
tMS += ms_elapsed;
while (tMS > 1000) {
tMS -= 1000;
Expand Down
Expand Up @@ -545,6 +545,8 @@ public String toString() {
// This can be combined with other match modes, like "on player breaks !*wood|*planks|*log:" will fire for any block break other than any wood variant.
//
// See also <@link language script event object matchables>.
//
// These advanced matchers are also used in some commands and tags.
// -->

public static abstract class MatchHelper {
Expand Down
Expand Up @@ -3,17 +3,10 @@
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.scripts.ScriptHelper;
import com.denizenscript.denizencore.utilities.AsciiMatcher;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.text.StringHolder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -207,66 +200,14 @@ public String toString() {
}

public static SavableMapFlagTracker loadFlagFile(String filePath) {
try {
File realPath;
File flagFile = new File(filePath + ".dat");
if (flagFile.exists()) {
realPath = flagFile;
}
else {
File bakFile = new File(filePath + ".dat~2");
if (bakFile.exists()) {
realPath = bakFile;
}
// Note: ~1 are likely corrupted, so ignore them.
else {
return new SavableMapFlagTracker();
}
}
FileInputStream fis = new FileInputStream(realPath);
String str = ScriptHelper.convertStreamToString(fis);
fis.close();
return new SavableMapFlagTracker(str);
}
catch (Throwable ex) {
Debug.echoError("Failed to load flag data for path '" + filePath + "'");
Debug.echoError(ex);
String content = CoreUtilities.journallingLoadFile(filePath + ".dat");
if (content == null) {
return new SavableMapFlagTracker();
}
return new SavableMapFlagTracker(content);
}

public void saveToFile(String filePath) {
saveToFile(filePath, toString());
}

public static void saveToFile(String filePath, String flagData) {
File saveToFile = new File(filePath + ".dat~1");
try {
saveToFile.getParentFile().mkdirs();
Charset charset = ScriptHelper.encoding == null ? null : ScriptHelper.encoding.charset();
FileOutputStream fiout = new FileOutputStream(saveToFile);
OutputStreamWriter writer;
if (charset == null) {
writer = new OutputStreamWriter(fiout);
}
else {
writer = new OutputStreamWriter(fiout, charset);
}
writer.write(flagData);
writer.close();
File bakFile = new File(filePath + ".dat~2");
File realFile = new File(filePath + ".dat");
if (realFile.exists()) {
realFile.renameTo(bakFile);
}
saveToFile.renameTo(realFile);
if (bakFile.exists()) {
bakFile.delete();
}
}
catch (Throwable ex) {
Debug.echoError("Failed to save flag data to path '" + filePath + "'");
Debug.echoError(ex);
}
CoreUtilities.journallingFileSave(filePath + ".dat", toString());
}
}
@@ -1,5 +1,6 @@
package com.denizenscript.denizencore.scripts;

import com.denizenscript.denizencore.utilities.YamlConfiguration;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.tags.TagContext;

Expand All @@ -26,4 +27,8 @@ public ScriptEntryData clone() {
public String toString() {
return "{{ Unimplemented toString method in ScriptEntryData! }}";
}

public abstract YamlConfiguration save();

public abstract void load(YamlConfiguration config);
}
Expand Up @@ -117,6 +117,7 @@ public void registerCoreCommands() {
registerCommand(RateLimitCommand.class);
registerCommand(RepeatCommand.class);
registerCommand(RunCommand.class);
registerCommand(RunLaterCommand.class);
registerCommand(StopCommand.class);
registerCommand(WaitCommand.class);
registerCommand(WaitUntilCommand.class);
Expand Down

0 comments on commit 41d0bfc

Please sign in to comment.