Search in sources :

Example 1 with MapTagFlagTracker

use of com.denizenscript.denizencore.flags.MapTagFlagTracker in project Denizen-For-Bukkit by DenizenScript.

the class ItemTag method getFlagTracker.

// ///////////////////
// INSTANCE FIELDS/METHODS
// ///////////////
@Override
public AbstractFlagTracker getFlagTracker() {
    if (flagTrackerCache == null) {
        String value = CustomNBT.getCustomNBT(getItemStack(), "flags", "Denizen");
        if (value == null) {
            return new MapTagFlagTracker();
        }
        flagTrackerCache = new MapTagFlagTracker(value, CoreUtilities.noDebugContext);
    }
    return flagTrackerCache;
}
Also used : MapTagFlagTracker(com.denizenscript.denizencore.flags.MapTagFlagTracker)

Example 2 with MapTagFlagTracker

use of com.denizenscript.denizencore.flags.MapTagFlagTracker in project Denizen-For-Bukkit by DenizenScript.

the class ItemFlags method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("flag_map") && mechanism.requireObject(MapTag.class)) {
        item.reapplyTracker(new MapTagFlagTracker(mechanism.valueAsType(MapTag.class)));
    }
    // -->
    if (mechanism.matches("flag")) {
        FlagCommand.FlagActionProvider provider = new FlagCommand.FlagActionProvider();
        provider.tracker = item.getFlagTracker();
        DataAction action = DataActionHelper.parse(provider, mechanism.getValue().asString(), mechanism.context);
        action.execute(mechanism.context);
        item.reapplyTracker(provider.tracker);
    }
}
Also used : FlagCommand(com.denizenscript.denizencore.scripts.commands.core.FlagCommand) DataAction(com.denizenscript.denizencore.utilities.data.DataAction) MapTagFlagTracker(com.denizenscript.denizencore.flags.MapTagFlagTracker) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 3 with MapTagFlagTracker

use of com.denizenscript.denizencore.flags.MapTagFlagTracker in project Denizen-For-Bukkit by DenizenScript.

the class EntityScriptContainer method getEntityFrom.

public EntityTag getEntityFrom(PlayerTag player, NPCTag npc) {
    EntityTag entity;
    try {
        TagContext context = new BukkitTagContext(player, npc, new ScriptTag(this));
        if (contains("entity_type", String.class)) {
            String entityType = TagManager.tag((getString("entity_type", "")), context);
            entity = EntityTag.valueOf(entityType, context);
        } else {
            throw new Exception("Missing entity_type argument!");
        }
        if (contains("flags", Map.class)) {
            YamlConfiguration flagSection = getConfigurationSection("flags");
            MapTagFlagTracker tracker = new MapTagFlagTracker();
            for (StringHolder key : flagSection.getKeys(false)) {
                tracker.setFlag(key.str, CoreUtilities.objectToTagForm(flagSection.get(key.str), context, true, true), null);
            }
            entity.safeAdjust(new Mechanism("flag_map", tracker.map, context));
        }
        if (contains("mechanisms", Map.class)) {
            YamlConfiguration mechSection = getConfigurationSection("mechanisms");
            Set<StringHolder> strings = mechSection.getKeys(false);
            for (StringHolder string : strings) {
                ObjectTag obj = CoreUtilities.objectToTagForm(mechSection.get(string.low), context, true, true);
                entity.safeAdjust(new Mechanism(string.low, obj, context));
            }
        }
        boolean any = false;
        Set<StringHolder> strings = getContents().getKeys(false);
        for (StringHolder string : strings) {
            if (!nonMechanismKeys.contains(string.low)) {
                any = true;
                ObjectTag obj = CoreUtilities.objectToTagForm(getContents().get(string.low), context, true, true);
                entity.safeAdjust(new Mechanism(string.low, obj, context));
            }
        }
        if (any) {
            Deprecations.entityMechanismsFormat.warn(this);
        }
        if (entity == null || entity.isUnique()) {
            return null;
        }
        entity.setEntityScript(getName());
    } catch (Exception e) {
        Debug.echoError("Woah! An exception has been called with this entity script!");
        Debug.echoError(e);
        entity = null;
    }
    return entity;
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) TagContext(com.denizenscript.denizencore.tags.TagContext) MapTagFlagTracker(com.denizenscript.denizencore.flags.MapTagFlagTracker) YamlConfiguration(com.denizenscript.denizencore.utilities.YamlConfiguration) Mechanism(com.denizenscript.denizencore.objects.Mechanism) StringHolder(com.denizenscript.denizencore.utilities.text.StringHolder) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) EntityTag(com.denizenscript.denizen.objects.EntityTag)

Example 4 with MapTagFlagTracker

use of com.denizenscript.denizencore.flags.MapTagFlagTracker in project Denizen-For-Bukkit by DenizenScript.

the class EntityFlags method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("flag_map") && mechanism.requireObject(MapTag.class)) {
        MapTagFlagTracker flags = new MapTagFlagTracker(mechanism.valueAsType(MapTag.class));
        AbstractFlagTracker tracker = entity.getFlagTracker();
        if (!(tracker instanceof DataPersistenceFlagTracker)) {
            return;
        }
        for (String flagName : flags.map.keys()) {
            ((DataPersistenceFlagTracker) tracker).setRootMap(flagName, flags.getRootMap(flagName));
        }
        entity.reapplyTracker(tracker);
    }
}
Also used : DataPersistenceFlagTracker(com.denizenscript.denizen.utilities.flags.DataPersistenceFlagTracker) AbstractFlagTracker(com.denizenscript.denizencore.flags.AbstractFlagTracker) MapTagFlagTracker(com.denizenscript.denizencore.flags.MapTagFlagTracker) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Aggregations

MapTagFlagTracker (com.denizenscript.denizencore.flags.MapTagFlagTracker)4 MapTag (com.denizenscript.denizencore.objects.core.MapTag)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 DataPersistenceFlagTracker (com.denizenscript.denizen.utilities.flags.DataPersistenceFlagTracker)1 AbstractFlagTracker (com.denizenscript.denizencore.flags.AbstractFlagTracker)1 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1 FlagCommand (com.denizenscript.denizencore.scripts.commands.core.FlagCommand)1 TagContext (com.denizenscript.denizencore.tags.TagContext)1 YamlConfiguration (com.denizenscript.denizencore.utilities.YamlConfiguration)1 DataAction (com.denizenscript.denizencore.utilities.data.DataAction)1 StringHolder (com.denizenscript.denizencore.utilities.text.StringHolder)1