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;
}
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);
}
}
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;
}
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);
}
}
Aggregations