Skip to content

Commit

Permalink
impl for RunLater
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 28, 2021
1 parent 620619c commit f2b1cad
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion plugin/pom.xml
Expand Up @@ -32,7 +32,7 @@
<!-- Basic dependencies -->
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens</artifactId>
<artifactId>citizens-main</artifactId>
<version>${citizens.version}</version>
<type>jar</type>
<scope>provided</scope>
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Expand Up @@ -52,6 +52,7 @@
import com.denizenscript.denizencore.scripts.ScriptHelper;
import com.denizenscript.denizencore.scripts.ScriptRegistry;
import com.denizenscript.denizencore.scripts.commands.core.AdjustCommand;
import com.denizenscript.denizencore.scripts.commands.queue.RunLaterCommand;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.SlowWarning;
Expand Down Expand Up @@ -525,6 +526,7 @@ public void reloadSaves() {
}
worldFlags.shutdown();
worldFlags.init();
RunLaterCommand.init(new File(getDataFolder(), "run_later.yml").getPath());
if (new File(getDataFolder(), "saves.yml").exists()) {
LegacySavesUpdater.updateLegacySaves();
}
Expand Down Expand Up @@ -555,6 +557,7 @@ public void saveSaves(boolean canSleep) {
}
PlayerFlagHandler.saveAllNow(canSleep);
worldFlags.saveAll();
RunLaterCommand.saveToFile(canSleep);
}

@Override
Expand Down
Expand Up @@ -1793,21 +1793,8 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName(
return new ElementTag(-1);
});

// <--[tag]
// @attribute <InventoryTag.find[<item>]>
// @returns ElementTag(Number)
// @description
// Returns the location of the first slot that contains the item.
// Returns -1 if there's no match.
// -->
registerTag("find", (attribute, object) -> {
// <--[tag]
// @attribute <InventoryTag.find.material[<material>|...]>
// @returns ElementTag(Number)
// @description
// Returns the location of the first slot that contains any of the given materials.
// Returns -1 if there's no match.
// -->
Deprecations.inventoryNonMatcherTags.warn(attribute.context);
if (attribute.startsWith("material", 2)) {
ListTag list = attribute.contextAsType(2, ListTag.class);
if (list == null) {
Expand All @@ -1828,13 +1815,6 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName(
return new ElementTag(slot);
}

// <--[tag]
// @attribute <InventoryTag.find.scriptname[<item>]>
// @returns ElementTag(Number)
// @description
// Returns the location of the first slot that contains the item with the specified script name.
// Returns -1 if there's no match.
// -->
if (attribute.startsWith("scriptname", 2)) {
String scrname = attribute.contextAsType(2, ItemTag.class).getScriptName();
if (scrname == null) {
Expand Down Expand Up @@ -1870,15 +1850,8 @@ else if (meta.hasDisplayName() && CoreUtilities.toLowerCase(meta.getDisplayName(
return new ElementTag(slot);
});

// <--[tag]
// @attribute <InventoryTag.find_imperfect[<item>]>
// @returns ElementTag(Number)
// @description
// Returns the location of the first slot that contains the item.
// Returns -1 if there's no match.
// Will match item script to item script, even if one is edited.
// -->
registerTag("find_imperfect", (attribute, object) -> {
Deprecations.inventoryNonMatcherTags.warn(attribute.context);
if (!attribute.hasContext(1) || !ItemTag.matches(attribute.getContext(1))) {
return null;
}
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.SavableMapFlagTracker;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -228,7 +229,7 @@ public static void saveAllNow(boolean canSleep) {
}

public static void saveFlags(UUID id, String flagData) {
SavableMapFlagTracker.saveToFile(new File(dataFolder, id.toString()).getPath(), flagData);
CoreUtilities.journallingFileSave(new File(dataFolder, id.toString() + ".dat").getPath(), flagData);
}

@EventHandler
Expand Down
Expand Up @@ -6,6 +6,8 @@
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import org.bukkit.entity.Entity;

public class BukkitScriptEntryData extends ScriptEntryData {
Expand Down Expand Up @@ -90,4 +92,28 @@ else if (player == null) {
return "player=p@" + player.getName() + " npc=n@" + npc.getId();
}
}

@Override
public YamlConfiguration save() {
YamlConfiguration out = new YamlConfiguration();
if (hasPlayer()) {
out.set("player", getPlayer().savable());
}
if (hasNPC()) {
out.set("npc", getNPC().savable());
}
return out;
}

@Override
public void load(YamlConfiguration config) {
String player = config.getString("player", null);
if (player != null) {
setPlayer(PlayerTag.valueOf(player, CoreUtilities.errorButNoDebugContext));
}
String npc = config.getString("npc", null);
if (npc != null) {
setNPC(NPCTag.valueOf(npc, CoreUtilities.errorButNoDebugContext));
}
}
}

0 comments on commit f2b1cad

Please sign in to comment.