Search in sources :

Example 6 with TimeTag

use of com.denizenscript.denizencore.objects.core.TimeTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemFlags method getObjectAttribute.

@Override
public ObjectTag getObjectAttribute(Attribute attribute) {
    if (attribute == null) {
        return null;
    }
    // -->
    if (attribute.startsWith("with_flag")) {
        ItemTag item = new ItemTag(this.item.getItemStack().clone());
        FlagCommand.FlagActionProvider provider = new FlagCommand.FlagActionProvider();
        provider.tracker = item.getFlagTracker();
        DataAction action = DataActionHelper.parse(provider, attribute.getParam(), attribute.context);
        // -->
        if (attribute.startsWith("duration", 2)) {
            provider.expiration = new TimeTag(TimeTag.now().millis() + attribute.getContextObject(2).asType(DurationTag.class, attribute.context).getMillis());
            attribute.fulfill(1);
        }
        action.execute(attribute.context);
        item.reapplyTracker(provider.tracker);
        return item.getObjectAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : FlagCommand(com.denizenscript.denizencore.scripts.commands.core.FlagCommand) DataAction(com.denizenscript.denizencore.utilities.data.DataAction) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 7 with TimeTag

use of com.denizenscript.denizencore.objects.core.TimeTag in project Denizen-For-Bukkit by DenizenScript.

the class LegacySavesUpdater method applyFlags.

public static void applyFlags(String object, AbstractFlagTracker tracker, YamlConfiguration section) {
    try {
        if (section == null || section.getKeys(false).isEmpty()) {
            return;
        }
        for (StringHolder flagName : section.getKeys(false)) {
            if (flagName.low.endsWith("-expiration")) {
                continue;
            }
            TimeTag expireAt = null;
            if (section.contains(flagName + "-expiration")) {
                long expireTime = Long.parseLong(section.getString(flagName + "-expiration"));
                expireAt = new TimeTag(expireTime);
            }
            Object value = section.get(flagName.str);
            ObjectTag setAs = CoreUtilities.objectToTagForm(value, CoreUtilities.errorButNoDebugContext);
            tracker.setFlag(flagName.low, setAs, expireAt);
        }
    } catch (Throwable ex) {
        Debug.echoError("Error while updating legacy flags for " + object);
        Debug.echoError(ex);
    }
}
Also used : StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) TimeTag(com.denizenscript.denizencore.objects.core.TimeTag)

Aggregations

TimeTag (com.denizenscript.denizencore.objects.core.TimeTag)7 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)4 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)3 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)3 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)2 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)2 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)1 AbstractFlagTracker (com.denizenscript.denizencore.flags.AbstractFlagTracker)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 FlagCommand (com.denizenscript.denizencore.scripts.commands.core.FlagCommand)1 YamlConfiguration (com.denizenscript.denizencore.utilities.YamlConfiguration)1 DataAction (com.denizenscript.denizencore.utilities.data.DataAction)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Date (java.util.Date)1 List (java.util.List)1