Search in sources :

Example 1 with AssignmentScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class AssignmentTrait method removeAssignmentScript.

// <--[action]
// @Actions
// remove assignment
// 
// @Triggers when the assignment script is removed from an NPC.
// 
// @Context
// None
// 
// -->
public boolean removeAssignmentScript(String name, PlayerTag player) {
    int index = assignments.indexOf(CoreUtilities.toLowerCase(name));
    if (index == -1) {
        return false;
    }
    assignments.remove(index);
    AssignmentScriptContainer container = containerCache.remove(index);
    if (container != null) {
        Denizen.getInstance().npcHelper.getActionHandler().doAction("remove assignment", new NPCTag(npc), player, container, null);
    }
    return true;
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)

Example 2 with AssignmentScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class NPCTag method registerTags.

public static void registerTags() {
    AbstractFlagTracker.registerFlagHandlers(tagProcessor);
    // Defined in EntityTag
    tagProcessor.registerTag(ElementTag.class, "is_npc", (attribute, object) -> {
        return new ElementTag(true);
    });
    // Defined in EntityTag
    tagProcessor.registerTag(ObjectTag.class, "location", (attribute, object) -> {
        if (attribute.startsWith("previous_location", 2)) {
            attribute.fulfill(1);
            Deprecations.npcPreviousLocationTag.warn(attribute.context);
            return NPCTagBase.previousLocations.get(object.getId());
        }
        if (object.isSpawned()) {
            return new EntityTag(object).doLocationTag(attribute);
        }
        return object.getLocation();
    });
    // <--[tag]
    // @attribute <NPCTag.previous_location>
    // @returns LocationTag
    // @description
    // Returns the NPC's previous navigated location.
    // -->
    tagProcessor.registerTag(LocationTag.class, "previous_location", (attribute, object) -> {
        return NPCTagBase.previousLocations.get(object.getId());
    });
    // Defined in EntityTag
    tagProcessor.registerTag(LocationTag.class, "eye_location", (attribute, object) -> {
        return object.getEyeLocation();
    });
    // <--[tag]
    // @attribute <NPCTag.has_nickname>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the NPC has a nickname.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_nickname", (attribute, object) -> {
        NPC citizen = object.getCitizen();
        return new ElementTag(citizen.hasTrait(NicknameTrait.class) && citizen.getOrAddTrait(NicknameTrait.class).hasNickname());
    });
    // <--[tag]
    // @attribute <NPCTag.is_sitting>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the NPC is sitting. Relates to <@link command sit>.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_sitting", (attribute, object) -> {
        NPC citizen = object.getCitizen();
        return new ElementTag(citizen.hasTrait(SittingTrait.class) && citizen.getOrAddTrait(SittingTrait.class).isSitting());
    });
    // <--[tag]
    // @attribute <NPCTag.is_sleeping>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the NPC is sleeping. Relates to <@link command sleep>.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_sleeping", (attribute, object) -> {
        NPC citizen = object.getCitizen();
        return new ElementTag(citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping());
    });
    // <--[tag]
    // @attribute <NPCTag.nickname>
    // @returns ElementTag
    // @description
    // Returns the NPC's display name, as set by the Nickname trait (or the default NPC name).
    // -->
    tagProcessor.registerTag(ElementTag.class, "nickname", (attribute, object) -> {
        return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class).getNickname() : object.getName());
    });
    // Documented in EntityTag
    tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
        if (attribute.startsWith("nickname", 2)) {
            Deprecations.npcNicknameTag.warn(attribute.context);
            attribute.fulfill(1);
            return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class).getNickname() : object.getName());
        }
        return new ElementTag(object.getName());
    });
    // <--[tag]
    // @attribute <NPCTag.traits>
    // @returns ListTag
    // @description
    // Returns a list of all of the NPC's traits.
    // -->
    tagProcessor.registerTag(ListTag.class, "traits", (attribute, object) -> {
        List<String> list = new ArrayList<>();
        for (Trait trait : object.getCitizen().getTraits()) {
            list.add(trait.getName());
        }
        return new ListTag(list);
    }, "list_traits");
    // <--[tag]
    // @attribute <NPCTag.has_trait[<trait>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC has a specified trait.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_trait", (attribute, object) -> {
        if (attribute.hasParam()) {
            Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(attribute.getParam());
            if (trait != null) {
                return new ElementTag(object.getCitizen().hasTrait(trait));
            }
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.pushable>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is pushable.
    // -->
    tagProcessor.registerTag(ElementTag.class, "pushable", (attribute, object) -> {
        return new ElementTag(object.getPushableTrait().isPushable());
    }, "is_pushable");
    // <--[tag]
    // @attribute <NPCTag.has_trigger[<trigger>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC has a specified trigger.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_trigger", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        if (!object.getCitizen().hasTrait(TriggerTrait.class)) {
            return new ElementTag(false);
        }
        TriggerTrait trait = object.getCitizen().getOrAddTrait(TriggerTrait.class);
        return new ElementTag(trait.hasTrigger(attribute.getParam()));
    });
    // <--[tag]
    // @attribute <NPCTag.has_anchors>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC has anchors assigned.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_anchors", (attribute, object) -> {
        return (new ElementTag(object.getCitizen().getOrAddTrait(Anchors.class).getAnchors().size() > 0));
    });
    // <--[tag]
    // @attribute <NPCTag.list_anchors>
    // @returns ListTag
    // @description
    // Returns a list of anchor names currently assigned to the NPC.
    // -->
    tagProcessor.registerTag(ListTag.class, "list_anchors", (attribute, object) -> {
        ListTag list = new ListTag();
        for (Anchor anchor : object.getCitizen().getOrAddTrait(Anchors.class).getAnchors()) {
            list.add(anchor.getName());
        }
        return list;
    });
    // <--[tag]
    // @attribute <NPCTag.anchor[<name>]>
    // @returns LocationTag
    // @description
    // Returns the location associated with the specified anchor, or null if it doesn't exist.
    // -->
    tagProcessor.registerTag(ObjectTag.class, "anchor", (attribute, object) -> {
        Anchors trait = object.getCitizen().getOrAddTrait(Anchors.class);
        if (attribute.hasParam()) {
            Anchor anchor = trait.getAnchor(attribute.getParam());
            if (anchor != null) {
                return new LocationTag(anchor.getLocation());
            } else {
                attribute.echoError("NPC Anchor '" + attribute.getParam() + "' is not defined.");
                return null;
            }
        } else if (attribute.startsWith("list", 2)) {
            attribute.fulfill(1);
            Deprecations.npcAnchorListTag.warn(attribute.context);
            ListTag list = new ListTag();
            for (Anchor anchor : trait.getAnchors()) {
                list.add(anchor.getName());
            }
            return list;
        } else {
            attribute.echoError("npc.anchor[...] tag must have an input.");
        }
        return null;
    }, "anchors");
    // <--[tag]
    // @attribute <NPCTag.constant[<constant_name>]>
    // @returns ElementTag
    // @description
    // Returns the specified constant from the NPC.
    // -->
    tagProcessor.registerTag(ElementTag.class, "constant", (attribute, object) -> {
        if (attribute.hasParam()) {
            if (object.getCitizen().hasTrait(ConstantsTrait.class) && object.getCitizen().getOrAddTrait(ConstantsTrait.class).getConstant(attribute.getParam()) != null) {
                return new ElementTag(object.getCitizen().getOrAddTrait(ConstantsTrait.class).getConstant(attribute.getParam()));
            } else {
                return null;
            }
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.has_pose[<name>]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns true if the NPC has the specified pose, otherwise returns false.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_pose", (attribute, object) -> {
        if (attribute.hasParam()) {
            return new ElementTag(object.getCitizen().getOrAddTrait(Poses.class).hasPose(attribute.getParam()));
        } else {
            return null;
        }
    });
    // <--[tag]
    // @attribute <NPCTag.pose[<name>]>
    // @returns LocationTag
    // @description
    // Returns the pose as a LocationTag with x, y, and z set to 0, and the world set to the first
    // possible available world Bukkit knows about.
    // -->
    tagProcessor.registerTag(LocationTag.class, "pose", (attribute, object) -> {
        if (attribute.hasParam()) {
            Pose pose = object.getCitizen().getOrAddTrait(Poses.class).getPose(attribute.getParam());
            return new LocationTag(org.bukkit.Bukkit.getWorlds().get(0), 0, 0, 0, pose.getYaw(), pose.getPitch());
        } else {
            return null;
        }
    }, "get_pose");
    // <--[tag]
    // @attribute <NPCTag.name_hologram_npc>
    // @returns NPCTag
    // @description
    // Returns the NPCTag of a hologram attached to this NPC as its nameplate (if any).
    // Note that this can regenerate at any time.
    // -->
    tagProcessor.registerTag(ObjectTag.class, "name_hologram_npc", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(HologramTrait.class)) {
            return null;
        }
        HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
        Entity entity = hologram.getNameEntity();
        if (entity == null) {
            return null;
        }
        return new EntityTag(entity).getDenizenObject();
    });
    // <--[tag]
    // @attribute <NPCTag.hologram_npcs>
    // @returns ListTag(NPCTag)
    // @description
    // Returns the list of hologram NPCs attached to an NPC (if any).
    // Note that these can regenerate at any time.
    // -->
    tagProcessor.registerTag(ListTag.class, "hologram_npcs", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(HologramTrait.class)) {
            return null;
        }
        HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
        Collection<ArmorStand> stands = hologram.getHologramEntities();
        if (stands == null || stands.isEmpty()) {
            return null;
        }
        ListTag output = new ListTag();
        for (ArmorStand stand : stands) {
            output.addObject(new EntityTag(stand).getDenizenObject());
        }
        return output;
    });
    // <--[tag]
    // @attribute <NPCTag.hologram_lines>
    // @returns ListTag
    // @mechanism NPCTag.hologram_lines
    // @description
    // Returns the list of hologram lines attached to an NPC.
    // -->
    tagProcessor.registerTag(ListTag.class, "hologram_lines", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(HologramTrait.class)) {
            return null;
        }
        HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
        return new ListTag(hologram.getLines());
    });
    // <--[tag]
    // @attribute <NPCTag.hologram_direction>
    // @returns ElementTag
    // @mechanism NPCTag.hologram_direction
    // @description
    // Returns the direction of an NPC's hologram as "BOTTOM_UP" or "TOP_DOWN".
    // -->
    tagProcessor.registerTag(ElementTag.class, "hologram_direction", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(HologramTrait.class)) {
            return null;
        }
        HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
        return new ElementTag(hologram.getDirection().name());
    });
    // <--[tag]
    // @attribute <NPCTag.hologram_line_height>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.hologram_line_height
    // @description
    // Returns the line height for an NPC's hologram. Can be -1, indicating a default value should be used.
    // -->
    tagProcessor.registerTag(ElementTag.class, "hologram_line_height", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(HologramTrait.class)) {
            return null;
        }
        HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
        return new ElementTag(hologram.getLineHeight());
    });
    // <--[tag]
    // @attribute <NPCTag.is_sneaking>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is currently sneaking. Only works for player-type NPCs.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_sneaking", (attribute, object) -> {
        if (!object.isSpawned() && object.getEntity() instanceof Player) {
            return null;
        }
        return new ElementTag(((Player) object.getEntity()).isSneaking());
    });
    // <--[tag]
    // @attribute <NPCTag.engaged[(<player>)]>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is currently engaged.
    // See <@link command engage>
    // -->
    tagProcessor.registerTag(ElementTag.class, "engaged", (attribute, object) -> {
        return new ElementTag(EngageCommand.getEngaged(object.getCitizen(), attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : null));
    }, "is_engaged");
    // <--[tag]
    // @attribute <NPCTag.invulnerable>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is currently invulnerable.
    // See <@link command vulnerable>
    // -->
    tagProcessor.registerTag(ElementTag.class, "invulnerable", (attribute, object) -> {
        return new ElementTag(object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
    }, "vulnerable");
    // <--[tag]
    // @attribute <NPCTag.id>
    // @returns ElementTag(Number)
    // @description
    // Returns the NPC's ID number.
    // -->
    tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> {
        return new ElementTag(object.getId());
    });
    // <--[tag]
    // @attribute <NPCTag.owner>
    // @returns PlayerTag
    // @mechanism NPCTag.owner
    // @description
    // Returns the owner of the NPC as a PlayerTag, if any.
    // -->
    tagProcessor.registerTag(ObjectTag.class, "owner", (attribute, object) -> {
        UUID owner = object.getOwner();
        if (owner == null) {
            return null;
        }
        OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
        if (player.isOnline() || player.hasPlayedBefore()) {
            return new PlayerTag(player);
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.has_skin>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.skin
    // @description
    // Returns whether the NPC has a custom skin.
    // -->
    tagProcessor.registerTag(ElementTag.class, "has_skin", (attribute, object) -> {
        return new ElementTag(object.getCitizen().hasTrait(SkinTrait.class) && object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName() != null);
    });
    // <--[tag]
    // @attribute <NPCTag.skin_blob>
    // @returns ElementTag
    // @mechanism NPCTag.skin_blob
    // @description
    // Returns the NPC's custom skin blob, if any.
    // In the format: "texture;signature" (two values separated by a semicolon).
    // See also <@link language Player Entity Skins (Skin Blobs)>.
    // -->
    tagProcessor.registerTag(ElementTag.class, "skin_blob", (attribute, object) -> {
        if (object.getCitizen().hasTrait(SkinTrait.class)) {
            SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
            String tex = skin.getTexture();
            String sign = "";
            if (skin.getSignature() != null) {
                sign = ";" + skin.getSignature();
            }
            return new ElementTag(tex + sign);
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.skull_skin>
    // @returns ElementTag
    // @description
    // Returns the NPC's current skin blob, formatted for input to a Player Skull item.
    // In the format: "UUID|Texture" (two values separated by pipes).
    // See also <@link language Player Entity Skins (Skin Blobs)>.
    // -->
    tagProcessor.registerTag(ElementTag.class, "skull_skin", (attribute, object) -> {
        if (!object.getCitizen().hasTrait(SkinTrait.class)) {
            return null;
        }
        SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
        return new ElementTag(skin.getSkinName() + "|" + skin.getTexture());
    });
    // <--[tag]
    // @attribute <NPCTag.skin>
    // @returns ElementTag
    // @mechanism NPCTag.skin
    // @description
    // Returns the NPC's custom skin, if any.
    // -->
    tagProcessor.registerTag(ElementTag.class, "skin", (attribute, object) -> {
        if (object.getCitizen().hasTrait(SkinTrait.class)) {
            return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName());
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.auto_update_skin>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.auto_update_skin
    // @description
    // Returns whether the NPC is set to automatically update skins from name.
    // -->
    tagProcessor.registerTag(ElementTag.class, "auto_update_skin", (attribute, object) -> {
        if (object.getCitizen().hasTrait(SkinTrait.class)) {
            return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).shouldUpdateSkins());
        }
        return null;
    });
    // <--[tag]
    // @attribute <NPCTag.inventory>
    // @returns InventoryTag
    // @description
    // Returns the InventoryTag of the NPC.
    // -->
    tagProcessor.registerTag(InventoryTag.class, "inventory", (attribute, object) -> {
        return object.getDenizenInventory();
    });
    // <--[tag]
    // @attribute <NPCTag.is_spawned>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is spawned.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_spawned", (attribute, object) -> {
        return new ElementTag(object.isSpawned());
    });
    // <--[tag]
    // @attribute <NPCTag.is_protected>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is protected.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_protected", (attribute, object) -> {
        return new ElementTag(object.getCitizen().isProtected());
    });
    // <--[tag]
    // @attribute <NPCTag.lookclose>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.lookclose
    // @description
    // Returns whether the NPC has lookclose enabled.
    // -->
    tagProcessor.registerTag(ElementTag.class, "lookclose", (attribute, object) -> {
        NPC citizen = object.getCitizen();
        if (citizen.hasTrait(LookClose.class)) {
            // There is no method to check if the NPC has LookClose enabled...
            // LookClose.toString() returns "LookClose{" + enabled + "}"
            String lookclose = citizen.getOrAddTrait(LookClose.class).toString();
            lookclose = lookclose.substring(10, lookclose.length() - 1);
            return new ElementTag(Boolean.valueOf(lookclose));
        }
        return new ElementTag(false);
    });
    // <--[tag]
    // @attribute <NPCTag.controllable>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.controllable
    // @description
    // Returns whether the NPC has controllable enabled.
    // -->
    tagProcessor.registerTag(ElementTag.class, "controllable", (attribute, object) -> {
        if (object.getCitizen().hasTrait(Controllable.class)) {
            return new ElementTag(object.getCitizen().getOrAddTrait(Controllable.class).isEnabled());
        }
        return new ElementTag(false);
    });
    // <--[tag]
    // @attribute <NPCTag.targetable>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.targetable
    // @description
    // Returns whether the NPC is targetable.
    // -->
    tagProcessor.registerTag(ElementTag.class, "targetable", (attribute, object) -> {
        boolean targetable = object.getCitizen().data().get(NPC.TARGETABLE_METADATA, object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
        return new ElementTag(targetable);
    });
    // <--[tag]
    // @attribute <NPCTag.teleport_on_stuck>
    // @returns ElementTag(Boolean)
    // @mechanism NPCTag.teleport_on_stuck
    // @description
    // Returns whether the NPC teleports when it is stuck.
    // -->
    tagProcessor.registerTag(ElementTag.class, "teleport_on_stuck", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getDefaultParameters().stuckAction() == TeleportStuckAction.INSTANCE);
    });
    tagProcessor.registerTag(ElementTag.class, "has_script", (attribute, object) -> {
        Deprecations.hasScriptTags.warn(attribute.context);
        NPC citizen = object.getCitizen();
        return new ElementTag(citizen.hasTrait(AssignmentTrait.class));
    });
    // <--[tag]
    // @attribute <NPCTag.script>
    // @returns ScriptTag
    // @deprecated Use 'NPCTag.scripts' (plural) instead.
    // @description
    // Deprecated variant of <@link tag NPCTag.scripts>.
    // -->
    tagProcessor.registerTag(ScriptTag.class, "script", (attribute, object) -> {
        Deprecations.npcScriptSingle.warn(attribute.context);
        NPC citizen = object.getCitizen();
        if (!citizen.hasTrait(AssignmentTrait.class)) {
            return null;
        } else {
            for (AssignmentScriptContainer container : citizen.getOrAddTrait(AssignmentTrait.class).containerCache) {
                if (container != null) {
                    return new ScriptTag(container);
                }
            }
            return null;
        }
    });
    // <--[tag]
    // @attribute <NPCTag.scripts>
    // @returns ListTag(ScriptTag)
    // @description
    // Returns a list of all assignment scripts on the NPC. Returns null if none.
    // -->
    tagProcessor.registerTag(ListTag.class, "scripts", (attribute, object) -> {
        NPC citizen = object.getCitizen();
        if (!citizen.hasTrait(AssignmentTrait.class)) {
            return null;
        } else {
            ListTag result = new ListTag();
            for (AssignmentScriptContainer container : citizen.getOrAddTrait(AssignmentTrait.class).containerCache) {
                if (container != null) {
                    result.addObject(new ScriptTag(container));
                }
            }
            return result;
        }
    });
    // <--[tag]
    // @attribute <NPCTag.distance_margin>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.distance_margin
    // @description
    // Returns the NPC's current pathfinding distance margin. That is, how close it needs to get to its destination (in block-lengths).
    // -->
    tagProcessor.registerTag(ElementTag.class, "distance_margin", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getDefaultParameters().distanceMargin());
    });
    // <--[tag]
    // @attribute <NPCTag.path_distance_margin>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.path_distance_margin
    // @description
    // Returns the NPC's current pathfinding distance margin. That is, how close it needs to get to individual points along its path.
    // -->
    tagProcessor.registerTag(ElementTag.class, "path_distance_margin", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getDefaultParameters().pathDistanceMargin());
    });
    // <--[tag]
    // @attribute <NPCTag.is_navigating>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is currently navigating.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_navigating", (attribute, object) -> {
        return new ElementTag(object.getNavigator().isNavigating());
    });
    // <--[tag]
    // @attribute <NPCTag.speed>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.speed
    // @description
    // Returns the current speed of the NPC.
    // -->
    tagProcessor.registerTag(ElementTag.class, "speed", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().speed());
    });
    // <--[tag]
    // @attribute <NPCTag.range>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.range
    // @description
    // Returns the NPC's current maximum pathfinding range.
    // -->
    tagProcessor.registerTag(ElementTag.class, "range", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().range());
    });
    // <--[tag]
    // @attribute <NPCTag.attack_range>
    // @returns ElementTag(Decimal)
    // @mechanism NPCTag.attack_range
    // @description
    // Returns the NPC's current navigator attack range limit.
    // -->
    tagProcessor.registerTag(ElementTag.class, "attack_range", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().attackRange());
    });
    // <--[tag]
    // @attribute <NPCTag.attack_strategy>
    // @returns ElementTag
    // @description
    // Returns the NPC's current navigator attack strategy.
    // Not related to Sentinel combat.
    // -->
    tagProcessor.registerTag(ElementTag.class, "attack_strategy", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().attackStrategy().toString());
    });
    // <--[tag]
    // @attribute <NPCTag.speed_modifier>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the NPC's current movement speed modifier (a multiplier applied over their base speed).
    // -->
    tagProcessor.registerTag(ElementTag.class, "speed_modifier", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().speedModifier());
    });
    // <--[tag]
    // @attribute <NPCTag.base_speed>
    // @returns ElementTag(Decimal)
    // @description
    // Returns the NPC's base navigation speed.
    // -->
    tagProcessor.registerTag(ElementTag.class, "base_speed", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().baseSpeed());
    });
    // <--[tag]
    // @attribute <NPCTag.avoid_water>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC will avoid water.
    // -->
    tagProcessor.registerTag(ElementTag.class, "avoid_water", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getLocalParameters().avoidWater());
    });
    // <--[tag]
    // @attribute <NPCTag.target_location>
    // @returns LocationTag
    // @description
    // Returns the location the NPC is currently navigating towards (if any).
    // -->
    tagProcessor.registerTag(LocationTag.class, "target_location", (attribute, object) -> {
        if (object.getNavigator().getTargetAsLocation() == null) {
            return null;
        }
        return new LocationTag(object.getNavigator().getTargetAsLocation());
    });
    // <--[tag]
    // @attribute <NPCTag.navigator_look_at>
    // @returns LocationTag
    // @mechanism NPCTag.navigator_look_at
    // @description
    // Returns the location the NPC will currently look at while moving, if any.
    // -->
    tagProcessor.registerTag(LocationTag.class, "navigator_look_at", (attribute, object) -> {
        if (object.getNavigator().getLocalParameters().lookAtFunction() == null) {
            return null;
        }
        Location res = object.getNavigator().getLocalParameters().lookAtFunction().apply(object.getNavigator());
        if (res == null) {
            return null;
        }
        return new LocationTag(res);
    });
    // <--[tag]
    // @attribute <NPCTag.is_fighting>
    // @returns ElementTag(Boolean)
    // @description
    // Returns whether the NPC is currently targeting an entity for the Citizens internal punching pathfinder.
    // Not compatible with Sentinel.
    // -->
    tagProcessor.registerTag(ElementTag.class, "is_fighting", (attribute, object) -> {
        return new ElementTag(object.getNavigator().getEntityTarget() != null && object.getNavigator().getEntityTarget().isAggressive());
    });
    // <--[tag]
    // @attribute <NPCTag.target_type>
    // @returns ElementTag
    // @description
    // Returns the entity type of the NPC's current navigation target (if any).
    // -->
    tagProcessor.registerTag(ElementTag.class, "target_type", (attribute, object) -> {
        if (object.getNavigator().getTargetType() == null) {
            return null;
        }
        return new ElementTag(object.getNavigator().getTargetType().toString());
    });
    // <--[tag]
    // @attribute <NPCTag.target_entity>
    // @returns EntityTag
    // @description
    // Returns the entity being targeted by the NPC's current navigation (if any).
    // -->
    tagProcessor.registerTag(EntityTag.class, "target_entity", (attribute, object) -> {
        if (object.getNavigator().getEntityTarget() == null || object.getNavigator().getEntityTarget().getTarget() == null) {
            return null;
        }
        return new EntityTag(object.getNavigator().getEntityTarget().getTarget());
    });
    // <--[tag]
    // @attribute <NPCTag.registry_name>
    // @returns ElementTag
    // @description
    // Returns the name of the registry this NPC came from.
    // -->
    tagProcessor.registerTag(ElementTag.class, "registry_name", (attribute, object) -> {
        return new ElementTag(object.getCitizen().getOwningRegistry().getName());
    });
    // <--[tag]
    // @attribute <NPCTag.citizens_data[<key>]>
    // @returns ElementTag
    // @description
    // Returns the value of a Citizens NPC metadata key.
    // -->
    tagProcessor.registerTag(ElementTag.class, "citizens_data", (attribute, object) -> {
        if (!attribute.hasParam()) {
            return null;
        }
        Object val = object.getCitizen().data().get(attribute.getParam());
        if (val == null) {
            return null;
        }
        return new ElementTag(val.toString());
    });
    // <--[tag]
    // @attribute <NPCTag.citizens_data_keys>
    // @returns ListTag
    // @description
    // Returns a list of Citizens NPC metadata keys.
    // -->
    tagProcessor.registerTag(ListTag.class, "citizens_data_keys", (attribute, object) -> {
        DataKey holder = new MemoryDataKey();
        object.getCitizen().data().saveTo(holder);
        ListTag result = new ListTag();
        for (DataKey key : holder.getSubKeys()) {
            result.addObject(new ElementTag(key.name(), true));
        }
        return result;
    });
    tagProcessor.registerTag(NPCTag.class, "navigator", (attribute, object) -> {
        Deprecations.oldNPCNavigator.warn(attribute.context);
        return object;
    });
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) DataKey(net.citizensnpcs.api.util.DataKey) MemoryDataKey(net.citizensnpcs.api.util.MemoryDataKey) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) Pose(net.citizensnpcs.util.Pose) MemoryDataKey(net.citizensnpcs.api.util.MemoryDataKey) ListTag(com.denizenscript.denizencore.objects.core.ListTag) Anchor(net.citizensnpcs.util.Anchor) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) FlaggableObject(com.denizenscript.denizencore.flags.FlaggableObject) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Trait(net.citizensnpcs.api.trait.Trait)

Example 3 with AssignmentScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class ServerTagBase method serverTag.

public void serverTag(ReplaceableTagEvent event) {
    if (!event.matches("server", "global") || event.replaced()) {
        return;
    }
    if (event.matches("global")) {
        Deprecations.globalTagName.warn(event.getScriptEntry());
    }
    Attribute attribute = event.getAttributes().fulfill(1);
    if (attribute.startsWith("economy")) {
        if (Depends.economy == null) {
            attribute.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            return;
        }
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("format") && attribute.hasParam()) {
            double amount = attribute.getDoubleParam();
            event.setReplacedObject(new ElementTag(Depends.economy.format(amount)).getObjectAttribute(attribute.fulfill(1)));
            return;
        }
        // -->
        if (attribute.startsWith("currency_name") && attribute.hasParam()) {
            double amount = attribute.getDoubleParam();
            event.setReplacedObject(new ElementTag(amount == 1 ? Depends.economy.currencyNameSingular() : Depends.economy.currencyNamePlural()).getObjectAttribute(attribute.fulfill(1)));
            return;
        }
        // -->
        if (attribute.startsWith("currency_plural")) {
            event.setReplacedObject(new ElementTag(Depends.economy.currencyNamePlural()).getObjectAttribute(attribute.fulfill(1)));
            return;
        }
        // -->
        if (attribute.startsWith("currency_singular")) {
            event.setReplacedObject(new ElementTag(Depends.economy.currencyNameSingular()).getObjectAttribute(attribute.fulfill(1)));
            return;
        }
        return;
    }
    // -->
    if (attribute.startsWith("slot_id") && attribute.hasParam()) {
        int slotId = SlotHelper.nameToIndex(attribute.getParam(), null);
        if (slotId != -1) {
            event.setReplacedObject(new ElementTag(slotId).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("parse_bukkit_item") && attribute.hasParam()) {
        YamlConfiguration config = new YamlConfiguration();
        try {
            config.loadFromString(attribute.getParam());
            ItemStack item = config.getItemStack("item");
            if (item != null) {
                event.setReplacedObject(new ItemTag(item).getObjectAttribute(attribute.fulfill(1)));
            }
        } catch (Exception ex) {
            Debug.echoError(ex);
        }
        return;
    }
    // -->
    if (attribute.startsWith("recipe_ids") || attribute.startsWith("list_recipe_ids")) {
        listDeprecateWarn(attribute);
        String type = attribute.hasParam() ? CoreUtilities.toLowerCase(attribute.getParam()) : null;
        ListTag list = new ListTag();
        Iterator<Recipe> recipeIterator = Bukkit.recipeIterator();
        while (recipeIterator.hasNext()) {
            Recipe recipe = recipeIterator.next();
            if (Utilities.isRecipeOfType(recipe, type) && recipe instanceof Keyed) {
                list.add(((Keyed) recipe).getKey().toString());
            }
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("recipe_items") && attribute.hasParam()) {
        NamespacedKey key = Utilities.parseNamespacedKey(attribute.getParam());
        Recipe recipe = NMSHandler.getItemHelper().getRecipeById(key);
        if (recipe == null) {
            return;
        }
        ListTag result = new ListTag();
        Consumer<RecipeChoice> addChoice = (choice) -> {
            if (choice == null) {
                result.addObject(new ItemTag(Material.AIR));
            } else {
                if (choice instanceof RecipeChoice.ExactChoice) {
                    result.addObject(new ItemTag(choice.getItemStack()));
                } else {
                    result.add("material:" + choice.getItemStack().getType().name());
                }
            }
        };
        if (recipe instanceof ShapedRecipe) {
            for (String row : ((ShapedRecipe) recipe).getShape()) {
                for (char column : row.toCharArray()) {
                    addChoice.accept(((ShapedRecipe) recipe).getChoiceMap().get(column));
                }
            }
        } else if (recipe instanceof ShapelessRecipe) {
            for (RecipeChoice choice : ((ShapelessRecipe) recipe).getChoiceList()) {
                addChoice.accept(choice);
            }
        } else if (recipe instanceof CookingRecipe<?>) {
            addChoice.accept(((CookingRecipe) recipe).getInputChoice());
        }
        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("recipe_shape") && attribute.hasParam()) {
        NamespacedKey key = Utilities.parseNamespacedKey(attribute.getParam());
        Recipe recipe = NMSHandler.getItemHelper().getRecipeById(key);
        if (!(recipe instanceof ShapedRecipe)) {
            return;
        }
        String[] shape = ((ShapedRecipe) recipe).getShape();
        event.setReplacedObject(new ElementTag(shape[0].length() + "x" + shape.length).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("recipe_type") && attribute.hasParam()) {
        NamespacedKey key = Utilities.parseNamespacedKey(attribute.getParam());
        Recipe recipe = NMSHandler.getItemHelper().getRecipeById(key);
        if (recipe == null) {
            return;
        }
        event.setReplacedObject(new ElementTag(Utilities.getRecipeType(recipe)).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("recipe_result") && attribute.hasParam()) {
        NamespacedKey key = Utilities.parseNamespacedKey(attribute.getParam());
        Recipe recipe = NMSHandler.getItemHelper().getRecipeById(key);
        if (recipe == null) {
            return;
        }
        event.setReplacedObject(new ItemTag(recipe.getResult()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("scoreboards")) {
        ListTag result = new ListTag();
        for (String board : ScoreboardHelper.scoreboardMap.keySet()) {
            result.addObject(new ElementTag(board));
        }
        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    if (attribute.startsWith("scoreboard")) {
        Scoreboard board;
        String name = "main";
        if (attribute.hasParam()) {
            name = attribute.getParam();
            board = ScoreboardHelper.getScoreboard(name);
        } else {
            board = ScoreboardHelper.getMain();
        }
        attribute = attribute.fulfill(1);
        // -->
        if (attribute.startsWith("exists")) {
            event.setReplacedObject(new ElementTag(board != null).getObjectAttribute(attribute.fulfill(1)));
            return;
        }
        if (board == null) {
            attribute.echoError("Scoreboard '" + name + "' does not exist.");
            return;
        }
        // -->
        if (attribute.startsWith("objectives")) {
            ListTag list = new ListTag();
            for (Objective objective : board.getObjectives()) {
                list.add(objective.getName());
            }
            event.setReplacedObject((list).getObjectAttribute(attribute.fulfill(1)));
        }
        if (attribute.startsWith("objective") && attribute.hasParam()) {
            Objective objective = board.getObjective(attribute.getParam());
            if (objective == null) {
                attribute.echoError("Scoreboard objective '" + attribute.getParam() + "' does not exist.");
                return;
            }
            attribute = attribute.fulfill(1);
            // -->
            if (attribute.startsWith("criteria")) {
                event.setReplacedObject(new ElementTag(objective.getCriteria()).getObjectAttribute(attribute.fulfill(1)));
            }
            // -->
            if (attribute.startsWith("display_name")) {
                event.setReplacedObject(new ElementTag(objective.getDisplayName()).getObjectAttribute(attribute.fulfill(1)));
            }
            // -->
            if (attribute.startsWith("display_slot")) {
                if (objective.getDisplaySlot() == null) {
                    return;
                }
                event.setReplacedObject(new ElementTag(objective.getDisplaySlot().name()).getObjectAttribute(attribute.fulfill(1)));
            }
        }
        // -->
        if (attribute.startsWith("team_names")) {
            ListTag result = new ListTag();
            for (Team team : board.getTeams()) {
                result.add(team.getName());
            }
            event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
        }
        if (attribute.startsWith("team") && attribute.hasParam()) {
            Team team = board.getTeam(attribute.getParam());
            if (team == null) {
                attribute.echoError("Scoreboard team '" + attribute.getParam() + "' does not exist.");
                return;
            }
            attribute = attribute.fulfill(1);
            // -->
            if (attribute.startsWith("members")) {
                event.setReplacedObject(new ListTag(team.getEntries()).getObjectAttribute(attribute.fulfill(1)));
            }
            return;
        }
    }
    // -->
    if (attribute.startsWith("object_is_valid")) {
        ObjectTag o = ObjectFetcher.pickObjectFor(attribute.getParam(), new BukkitTagContext(null, null, null, false, null));
        event.setReplacedObject(new ElementTag(!(o == null || o instanceof ElementTag)).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_whitelist")) {
        event.setReplacedObject(new ElementTag(Bukkit.hasWhitelist()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("whitelisted_players")) {
        ListTag result = new ListTag();
        for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) {
            result.addObject(new PlayerTag(player));
        }
        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_flag")) {
        event.setReplacedObject(DenizenCore.serverFlagMap.doHasFlagTag(attribute).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("flag_expiration")) {
        TimeTag exp = DenizenCore.serverFlagMap.doFlagExpirationTag(attribute);
        if (exp != null) {
            event.setReplacedObject(exp.getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("flag")) {
        ObjectTag flag = DenizenCore.serverFlagMap.doFlagTag(attribute);
        if (flag != null) {
            event.setReplacedObject(flag.getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("list_flags")) {
        event.setReplacedObject(DenizenCore.serverFlagMap.doListFlagsTag(attribute).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("flag_map")) {
        event.setReplacedObject(DenizenCore.serverFlagMap.doFlagMapTag(attribute).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("gamerules")) {
        ListTag allGameRules = new ListTag();
        for (GameRule rule : GameRule.values()) {
            allGameRules.add(rule.getName());
        }
        event.setReplacedObject(allGameRules.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if ((attribute.startsWith("traits") || attribute.startsWith("list_traits")) && Depends.citizens != null) {
        listDeprecateWarn(attribute);
        ListTag allTraits = new ListTag();
        for (TraitInfo trait : CitizensAPI.getTraitFactory().getRegisteredTraits()) {
            allTraits.add(trait.getTraitName());
        }
        event.setReplacedObject(allTraits.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("commands") || attribute.startsWith("list_commands")) {
        listDeprecateWarn(attribute);
        CommandScriptHelper.init();
        ListTag list = new ListTag(CommandScriptHelper.knownCommands.keySet());
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("command_plugin")) {
        PluginCommand cmd = Bukkit.getPluginCommand(attribute.getParam());
        if (cmd != null) {
            event.setReplacedObject(new PluginTag(cmd.getPlugin()).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("color_names")) {
        ListTag list = new ListTag();
        for (String color : ColorTag.colorsByName.keySet()) {
            list.add(color);
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("art_types")) {
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        for (Art art : Art.values()) {
            list.add(art.name());
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("advancement_types") || attribute.startsWith("list_advancements")) {
        if (attribute.matches("list_advancements")) {
            Debug.echoError("list_advancements is deprecated: use advancement_types");
        }
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        Bukkit.advancementIterator().forEachRemaining((adv) -> {
            list.add(adv.getKey().toString());
        });
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("nbt_attribute_types") || attribute.startsWith("list_nbt_attribute_types")) {
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        for (org.bukkit.attribute.Attribute attribType : org.bukkit.attribute.Attribute.values()) {
            list.add(attribType.name());
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("damage_causes") || attribute.startsWith("list_damage_causes")) {
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        for (EntityDamageEvent.DamageCause damageCause : EntityDamageEvent.DamageCause.values()) {
            list.add(damageCause.name());
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("teleport_causes")) {
        ListTag list = new ListTag();
        for (PlayerTeleportEvent.TeleportCause teleportCause : PlayerTeleportEvent.TeleportCause.values()) {
            list.add(teleportCause.name());
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("biome_types") || attribute.startsWith("list_biome_types")) {
        listDeprecateWarn(attribute);
        ListTag allBiomes = new ListTag();
        for (Biome biome : Biome.values()) {
            if (biome != Biome.CUSTOM) {
                allBiomes.addObject(new BiomeTag(biome));
            }
        }
        event.setReplacedObject(allBiomes.getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("list_biomes")) {
        Deprecations.serverListBiomeNames.warn(attribute.context);
        ListTag allBiomes = new ListTag();
        for (Biome biome : Biome.values()) {
            allBiomes.add(biome.name());
        }
        event.setReplacedObject(allBiomes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("enchantments")) {
        ListTag enchants = new ListTag();
        for (Enchantment ench : Enchantment.values()) {
            enchants.addObject(new EnchantmentTag(ench));
        }
        event.setReplacedObject(enchants.getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("enchantment_types") || attribute.startsWith("list_enchantments")) {
        Deprecations.echantmentTagUpdate.warn(attribute.context);
        if (attribute.matches("list_enchantments")) {
            Debug.echoError("list_enchantments is deprecated: use enchantment_types");
        }
        listDeprecateWarn(attribute);
        ListTag enchants = new ListTag();
        for (Enchantment e : Enchantment.values()) {
            enchants.add(e.getName());
        }
        event.setReplacedObject(enchants.getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("enchantment_keys") || attribute.startsWith("list_enchantment_keys")) {
        Deprecations.echantmentTagUpdate.warn(attribute.context);
        listDeprecateWarn(attribute);
        ListTag enchants = new ListTag();
        for (Enchantment e : Enchantment.values()) {
            enchants.add(e.getKey().getKey());
        }
        event.setReplacedObject(enchants.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("entity_types") || attribute.startsWith("list_entity_types")) {
        listDeprecateWarn(attribute);
        ListTag allEnt = new ListTag();
        for (EntityType entity : EntityType.values()) {
            if (entity != EntityType.UNKNOWN) {
                allEnt.add(entity.name());
            }
        }
        event.setReplacedObject(allEnt.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("material_types") || attribute.startsWith("list_material_types")) {
        listDeprecateWarn(attribute);
        ListTag allMats = new ListTag();
        for (Material mat : Material.values()) {
            allMats.addObject(new MaterialTag(mat));
        }
        event.setReplacedObject(allMats.getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("list_materials")) {
        Deprecations.serverListMaterialNames.warn(attribute.context);
        ListTag allMats = new ListTag();
        for (Material mat : Material.values()) {
            allMats.add(mat.name());
        }
        event.setReplacedObject(allMats.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("sound_types") || attribute.startsWith("list_sounds")) {
        if (attribute.matches("list_sounds")) {
            Debug.echoError("list_sounds is deprecated: use sound_types");
        }
        listDeprecateWarn(attribute);
        ListTag sounds = new ListTag();
        for (Sound s : Sound.values()) {
            sounds.add(s.toString());
        }
        event.setReplacedObject(sounds.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("particle_types") || attribute.startsWith("list_particles")) {
        if (attribute.matches("list_particles")) {
            Debug.echoError("list_particles is deprecated: use particle_types");
        }
        listDeprecateWarn(attribute);
        ListTag particleTypes = new ListTag();
        for (Particle particle : Particle.values()) {
            particleTypes.add(particle.toString());
        }
        event.setReplacedObject(particleTypes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("effect_types") || attribute.startsWith("list_effects")) {
        if (attribute.matches("list_effects")) {
            Debug.echoError("list_effects is deprecated: use effect_types");
        }
        listDeprecateWarn(attribute);
        ListTag effectTypes = new ListTag();
        for (Effect effect : Effect.values()) {
            effectTypes.add(effect.toString());
        }
        event.setReplacedObject(effectTypes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("pattern_types") || attribute.startsWith("list_patterns")) {
        if (attribute.matches("list_patterns")) {
            Debug.echoError("list_patterns is deprecated: use pattern_types");
        }
        listDeprecateWarn(attribute);
        ListTag allPatterns = new ListTag();
        for (PatternType pat : PatternType.values()) {
            allPatterns.add(pat.toString());
        }
        event.setReplacedObject(allPatterns.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("potion_effect_types") || attribute.startsWith("list_potion_effects")) {
        if (attribute.matches("list_potion_effects")) {
            Debug.echoError("list_potion_effects is deprecated: use potion_effect_types");
        }
        listDeprecateWarn(attribute);
        ListTag statuses = new ListTag();
        for (PotionEffectType effect : PotionEffectType.values()) {
            if (effect != null) {
                statuses.add(effect.getName());
            }
        }
        event.setReplacedObject(statuses.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("potion_types") || attribute.startsWith("list_potion_types")) {
        listDeprecateWarn(attribute);
        ListTag potionTypes = new ListTag();
        for (PotionType type : PotionType.values()) {
            potionTypes.add(type.toString());
        }
        event.setReplacedObject(potionTypes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("tree_types") || attribute.startsWith("list_tree_types")) {
        listDeprecateWarn(attribute);
        ListTag allTrees = new ListTag();
        for (TreeType tree : TreeType.values()) {
            allTrees.add(tree.name());
        }
        event.setReplacedObject(allTrees.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("map_cursor_types") || attribute.startsWith("list_map_cursor_types")) {
        listDeprecateWarn(attribute);
        ListTag mapCursors = new ListTag();
        for (MapCursor.Type cursor : MapCursor.Type.values()) {
            mapCursors.add(cursor.toString());
        }
        event.setReplacedObject(mapCursors.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("world_types") || attribute.startsWith("list_world_types")) {
        listDeprecateWarn(attribute);
        ListTag worldTypes = new ListTag();
        for (WorldType world : WorldType.values()) {
            worldTypes.add(world.toString());
        }
        event.setReplacedObject(worldTypes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("statistic_types") || attribute.startsWith("list_statistics")) {
        listDeprecateWarn(attribute);
        if (attribute.matches("list_statistics")) {
            Debug.echoError("list_statistics is deprecated: use statistic_types");
        }
        Statistic.Type type = null;
        if (attribute.hasParam()) {
            type = Statistic.Type.valueOf(attribute.getParam().toUpperCase());
        }
        ListTag statisticTypes = new ListTag();
        for (Statistic stat : Statistic.values()) {
            if (type == null || type == stat.getType()) {
                statisticTypes.add(stat.toString());
            }
        }
        event.setReplacedObject(statisticTypes.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("structure_types") || attribute.startsWith("list_structure_types")) {
        listDeprecateWarn(attribute);
        event.setReplacedObject(new ListTag(StructureType.getStructureTypes().keySet()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("notes") || attribute.startsWith("list_notables") || attribute.startsWith("notables")) {
        listDeprecateWarn(attribute);
        ListTag allNotables = new ListTag();
        if (attribute.hasParam()) {
            String type = CoreUtilities.toLowerCase(attribute.getParam());
            for (Map.Entry<String, Class> typeClass : NoteManager.namesToTypes.entrySet()) {
                if (type.equals(CoreUtilities.toLowerCase(typeClass.getKey()))) {
                    for (Object notable : NoteManager.getAllType(typeClass.getValue())) {
                        allNotables.addObject((ObjectTag) notable);
                    }
                    break;
                }
            }
        } else {
            for (Notable notable : NoteManager.nameToObject.values()) {
                allNotables.addObject((ObjectTag) notable);
            }
        }
        event.setReplacedObject(allNotables.getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("statistic_type") && attribute.hasParam()) {
        Statistic statistic;
        try {
            statistic = Statistic.valueOf(attribute.getParam().toUpperCase());
        } catch (IllegalArgumentException ex) {
            attribute.echoError("Statistic '" + attribute.getParam() + "' does not exist: " + ex.getMessage());
            return;
        }
        event.setReplacedObject(new ElementTag(statistic.getType().name()).getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("enchantment_max_level") && attribute.hasParam()) {
        Deprecations.echantmentTagUpdate.warn(attribute.context);
        EnchantmentTag ench = EnchantmentTag.valueOf(attribute.getParam(), attribute.context);
        if (ench == null) {
            attribute.echoError("Enchantment '" + attribute.getParam() + "' does not exist.");
            return;
        }
        event.setReplacedObject(new ElementTag(ench.enchantment.getMaxLevel()).getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("enchantment_start_level") && attribute.hasParam()) {
        Deprecations.echantmentTagUpdate.warn(attribute.context);
        EnchantmentTag ench = EnchantmentTag.valueOf(attribute.getParam(), attribute.context);
        if (ench == null) {
            attribute.echoError("Enchantment '" + attribute.getParam() + "' does not exist.");
            return;
        }
        event.setReplacedObject(new ElementTag(ench.enchantment.getStartLevel()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("started_time")) {
        event.setReplacedObject(new TimeTag(DenizenCore.startTime).getObjectAttribute(attribute.fulfill(1)));
    }
    if (attribute.startsWith("start_time")) {
        Deprecations.timeTagRewrite.warn(attribute.context);
        event.setReplacedObject(new DurationTag(DenizenCore.startTime / 50).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("disk_free")) {
        File folder = Denizen.getInstance().getDataFolder();
        event.setReplacedObject(new ElementTag(folder.getUsableSpace()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("disk_total")) {
        File folder = Denizen.getInstance().getDataFolder();
        event.setReplacedObject(new ElementTag(folder.getTotalSpace()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("disk_usage")) {
        File folder = Denizen.getInstance().getDataFolder();
        event.setReplacedObject(new ElementTag(folder.getTotalSpace() - folder.getFreeSpace()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_allocated")) {
        event.setReplacedObject(new ElementTag(Runtime.getRuntime().totalMemory()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_max")) {
        event.setReplacedObject(new ElementTag(Runtime.getRuntime().maxMemory()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_free")) {
        event.setReplacedObject(new ElementTag(Runtime.getRuntime().freeMemory()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("ram_usage")) {
        event.setReplacedObject(new ElementTag(Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("available_processors")) {
        event.setReplacedObject(new ElementTag(Runtime.getRuntime().availableProcessors()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("current_tick")) {
        event.setReplacedObject(new ElementTag(TickScriptEvent.instance.ticks).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("delta_time_since_start")) {
        event.setReplacedObject(new DurationTag(TickScriptEvent.instance.ticks).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("real_time_since_start")) {
        event.setReplacedObject(new DurationTag((System.currentTimeMillis() - serverStartTimeMillis) / 1000.0).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("current_time_millis")) {
        event.setReplacedObject(new ElementTag(System.currentTimeMillis()).getObjectAttribute(attribute.fulfill(1)));
    }
    // -->
    if (attribute.startsWith("selected_npc")) {
        NPC npc = ((Citizens) Bukkit.getPluginManager().getPlugin("Citizens")).getNPCSelector().getSelected(Bukkit.getConsoleSender());
        if (npc == null) {
            return;
        } else {
            event.setReplacedObject(new NPCTag(npc).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if ((attribute.startsWith("npcs_named") || attribute.startsWith("list_npcs_named")) && Depends.citizens != null && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        ListTag npcs = new ListTag();
        String name = attribute.getParam();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            if (CoreUtilities.equalsIgnoreCase(npc.getName(), name)) {
                npcs.addObject(new NPCTag(npc));
            }
        }
        event.setReplacedObject(npcs.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_file") && attribute.hasParam()) {
        File f = new File(Denizen.getInstance().getDataFolder(), attribute.getParam());
        try {
            if (!Utilities.canReadFile(f)) {
                Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
                return;
            }
        } catch (Exception e) {
            Debug.echoError(e);
            return;
        }
        event.setReplacedObject(new ElementTag(f.exists()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("list_files") && attribute.hasParam()) {
        File folder = new File(Denizen.getInstance().getDataFolder(), attribute.getParam());
        try {
            if (!Utilities.canReadFile(folder)) {
                Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
                return;
            }
            if (!folder.exists() || !folder.isDirectory()) {
                attribute.echoError("Invalid path specified. No directory exists at that path.");
                return;
            }
        } catch (Exception e) {
            Debug.echoError(e);
            return;
        }
        File[] files = folder.listFiles();
        if (files == null) {
            return;
        }
        ListTag list = new ListTag();
        for (File file : files) {
            list.add(file.getName());
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_permissions")) {
        event.setReplacedObject(new ElementTag(Depends.permissions != null && Depends.permissions.isEnabled()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("has_economy")) {
        event.setReplacedObject(new ElementTag(Depends.economy != null && Depends.economy.isEnabled()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("denizen_version")) {
        event.setReplacedObject(new ElementTag(Denizen.getInstance().getDescription().getVersion()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("bukkit_version")) {
        event.setReplacedObject(new ElementTag(Bukkit.getBukkitVersion()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("version")) {
        event.setReplacedObject(new ElementTag(Bukkit.getServer().getVersion()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("java_version")) {
        event.setReplacedObject(new ElementTag(System.getProperty("java.version")).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("max_players")) {
        event.setReplacedObject(new ElementTag(Bukkit.getServer().getMaxPlayers()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("sql_connections") || attribute.startsWith("list_sql_connections")) {
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        for (Map.Entry<String, Connection> entry : SQLCommand.connections.entrySet()) {
            try {
                if (!entry.getValue().isClosed()) {
                    list.add(entry.getKey());
                } else {
                    SQLCommand.connections.remove(entry.getKey());
                }
            } catch (SQLException e) {
                Debug.echoError(attribute.getScriptEntry(), e);
            }
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("group_prefix")) {
        if (Depends.permissions == null) {
            attribute.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            return;
        }
        String group = attribute.getParam();
        if (!Arrays.asList(Depends.permissions.getGroups()).contains(group)) {
            attribute.echoError("Invalid group! '" + (group != null ? group : "") + "' could not be found.");
            return;
        }
        // -->
        if (attribute.startsWith("world", 2)) {
            WorldTag world = attribute.contextAsType(2, WorldTag.class);
            if (world != null) {
                event.setReplacedObject(new ElementTag(Depends.chat.getGroupPrefix(world.getWorld(), group)).getObjectAttribute(attribute.fulfill(2)));
            }
            return;
        }
        // Prefix in default world
        event.setReplacedObject(new ElementTag(Depends.chat.getGroupPrefix(Bukkit.getWorlds().get(0), group)).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("group_suffix")) {
        if (Depends.permissions == null) {
            attribute.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            return;
        }
        String group = attribute.getParam();
        if (!Arrays.asList(Depends.permissions.getGroups()).contains(group)) {
            attribute.echoError("Invalid group! '" + (group != null ? group : "") + "' could not be found.");
            return;
        }
        // -->
        if (attribute.startsWith("world", 2)) {
            WorldTag world = attribute.contextAsType(2, WorldTag.class);
            if (world != null) {
                event.setReplacedObject(new ElementTag(Depends.chat.getGroupSuffix(world.getWorld(), group)).getObjectAttribute(attribute.fulfill(2)));
            }
            return;
        }
        // Suffix in default world
        event.setReplacedObject(new ElementTag(Depends.chat.getGroupSuffix(Bukkit.getWorlds().get(0), group)).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("permission_groups") || attribute.startsWith("list_permission_groups")) {
        if (Depends.permissions == null) {
            attribute.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
            return;
        }
        listDeprecateWarn(attribute);
        event.setReplacedObject(new ListTag(Arrays.asList(Depends.permissions.getGroups())).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    if (attribute.startsWith("list_plugin_names")) {
        Deprecations.serverPluginNamesTag.warn(attribute.context);
        ListTag plugins = new ListTag();
        for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
            plugins.add(plugin.getName());
        }
        event.setReplacedObject(plugins.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("scripts") || attribute.startsWith("list_scripts")) {
        listDeprecateWarn(attribute);
        ListTag scripts = new ListTag();
        for (ScriptContainer script : ScriptRegistry.scriptContainers.values()) {
            scripts.addObject(new ScriptTag(script));
        }
        event.setReplacedObject(scripts.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("match_player") && attribute.hasParam()) {
        Player matchPlayer = null;
        String matchInput = CoreUtilities.toLowerCase(attribute.getParam());
        if (matchInput.isEmpty()) {
            return;
        }
        for (Player player : Bukkit.getOnlinePlayers()) {
            String nameLow = CoreUtilities.toLowerCase(player.getName());
            if (nameLow.equals(matchInput)) {
                matchPlayer = player;
                break;
            } else if (nameLow.contains(matchInput)) {
                if (matchPlayer == null || nameLow.startsWith(matchInput)) {
                    matchPlayer = player;
                }
            }
        }
        if (matchPlayer != null) {
            event.setReplacedObject(new PlayerTag(matchPlayer).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("match_offline_player") && attribute.hasParam()) {
        PlayerTag matchPlayer = null;
        String matchInput = CoreUtilities.toLowerCase(attribute.getParam());
        if (matchInput.isEmpty()) {
            return;
        }
        for (Map.Entry<String, UUID> entry : PlayerTag.getAllPlayers().entrySet()) {
            String nameLow = CoreUtilities.toLowerCase(entry.getKey());
            if (nameLow.equals(matchInput)) {
                matchPlayer = new PlayerTag(entry.getValue());
                break;
            } else if (nameLow.contains(matchInput)) {
                PlayerTag newMatch = new PlayerTag(entry.getValue());
                if (matchPlayer == null) {
                    matchPlayer = newMatch;
                } else if (newMatch.isOnline() && !matchPlayer.isOnline()) {
                    matchPlayer = newMatch;
                } else if (nameLow.startsWith(matchInput) && (newMatch.isOnline() == matchPlayer.isOnline())) {
                    matchPlayer = newMatch;
                }
            }
        }
        if (matchPlayer != null) {
            event.setReplacedObject(matchPlayer.getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if ((attribute.startsWith("npcs_assigned") || attribute.startsWith("list_npcs_assigned")) && Depends.citizens != null && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        ScriptTag script = attribute.paramAsType(ScriptTag.class);
        if (script == null || !(script.getContainer() instanceof AssignmentScriptContainer)) {
            attribute.echoError("Invalid script specified.");
        } else {
            AssignmentScriptContainer container = (AssignmentScriptContainer) script.getContainer();
            ListTag npcs = new ListTag();
            for (NPC npc : CitizensAPI.getNPCRegistry()) {
                if (npc.hasTrait(AssignmentTrait.class) && npc.getOrAddTrait(AssignmentTrait.class).isAssigned(container)) {
                    npcs.addObject(new NPCTag(npc));
                }
            }
            event.setReplacedObject(npcs.getObjectAttribute(attribute.fulfill(1)));
            return;
        }
    }
    // -->
    if ((attribute.startsWith("online_players_flagged") || attribute.startsWith("list_online_players_flagged")) && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        String flag = attribute.getParam();
        ListTag players = new ListTag();
        for (Player player : Bukkit.getOnlinePlayers()) {
            PlayerTag plTag = new PlayerTag(player);
            if (plTag.getFlagTracker().hasFlag(flag)) {
                players.addObject(plTag);
            }
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if ((attribute.startsWith("players_flagged") || attribute.startsWith("list_players_flagged")) && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        String flag = attribute.getParam();
        ListTag players = new ListTag();
        for (Map.Entry<String, UUID> entry : PlayerTag.getAllPlayers().entrySet()) {
            PlayerTag plTag = new PlayerTag(entry.getValue());
            if (plTag.getFlagTracker().hasFlag(flag)) {
                players.addObject(plTag);
            }
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if ((attribute.startsWith("spawned_npcs_flagged") || attribute.startsWith("list_spawned_npcs_flagged")) && Depends.citizens != null && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        String flag = attribute.getParam();
        ListTag npcs = new ListTag();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            NPCTag dNpc = new NPCTag(npc);
            if (dNpc.isSpawned() && dNpc.hasFlag(flag)) {
                npcs.addObject(dNpc);
            }
        }
        event.setReplacedObject(npcs.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if ((attribute.startsWith("npcs_flagged") || attribute.startsWith("list_npcs_flagged")) && Depends.citizens != null && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        String flag = attribute.getParam();
        ListTag npcs = new ListTag();
        for (NPC npc : CitizensAPI.getNPCRegistry()) {
            NPCTag dNpc = new NPCTag(npc);
            if (dNpc.hasFlag(flag)) {
                npcs.addObject(dNpc);
            }
        }
        event.setReplacedObject(npcs.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("npc_registries") && Depends.citizens != null) {
        ListTag result = new ListTag();
        for (NPCRegistry registry : CitizensAPI.getNPCRegistries()) {
            result.add(registry.getName());
        }
        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if ((attribute.startsWith("npcs") || attribute.startsWith("list_npcs")) && Depends.citizens != null) {
        listDeprecateWarn(attribute);
        ListTag npcs = new ListTag();
        NPCRegistry registry = CitizensAPI.getNPCRegistry();
        if (attribute.hasParam()) {
            registry = NPCTag.getRegistryByName(attribute.getParam());
            if (registry == null) {
                attribute.echoError("NPC Registry '" + attribute.getParam() + "' does not exist.");
                return;
            }
        }
        for (NPC npc : registry) {
            npcs.addObject(new NPCTag(npc));
        }
        event.setReplacedObject(npcs.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("worlds") || attribute.startsWith("list_worlds")) {
        listDeprecateWarn(attribute);
        ListTag worlds = new ListTag();
        for (World world : Bukkit.getWorlds()) {
            worlds.addObject(WorldTag.mirrorBukkitWorld(world));
        }
        event.setReplacedObject(worlds.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("plugins") || attribute.startsWith("list_plugins")) {
        listDeprecateWarn(attribute);
        ListTag plugins = new ListTag();
        for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins()) {
            plugins.addObject(new PluginTag(plugin));
        }
        event.setReplacedObject(plugins.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("players") || attribute.startsWith("list_players")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            players.addObject(PlayerTag.mirrorBukkitPlayer(player));
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("online_players") || attribute.startsWith("list_online_players")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (Player player : Bukkit.getOnlinePlayers()) {
            players.addObject(PlayerTag.mirrorBukkitPlayer(player));
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("offline_players") || attribute.startsWith("list_offline_players")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            if (!player.isOnline()) {
                players.addObject(PlayerTag.mirrorBukkitPlayer(player));
            }
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("banned_players") || attribute.startsWith("list_banned_players")) {
        listDeprecateWarn(attribute);
        ListTag banned = new ListTag();
        for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
            banned.addObject(PlayerTag.mirrorBukkitPlayer(player));
        }
        event.setReplacedObject(banned.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("banned_addresses") || attribute.startsWith("list_banned_addresses")) {
        listDeprecateWarn(attribute);
        ListTag list = new ListTag();
        list.addAll(Bukkit.getIPBans());
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("is_banned") && attribute.hasParam()) {
        // BanList contains an isBanned method that doesn't check expiration time
        BanEntry ban = Bukkit.getBanList(BanList.Type.IP).getBanEntry(attribute.getParam());
        if (ban == null) {
            event.setReplacedObject(new ElementTag(false).getObjectAttribute(attribute.fulfill(1)));
        } else if (ban.getExpiration() == null) {
            event.setReplacedObject(new ElementTag(true).getObjectAttribute(attribute.fulfill(1)));
        } else {
            event.setReplacedObject(new ElementTag(ban.getExpiration().after(new Date())).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    if (attribute.startsWith("ban_info") && attribute.hasParam()) {
        BanEntry ban = Bukkit.getBanList(BanList.Type.IP).getBanEntry(attribute.getParam());
        attribute.fulfill(1);
        if (ban == null || (ban.getExpiration() != null && ban.getExpiration().before(new Date()))) {
            return;
        }
        // -->
        if (attribute.startsWith("expiration_time") && ban.getExpiration() != null) {
            event.setReplacedObject(new TimeTag(ban.getExpiration().getTime()).getObjectAttribute(attribute.fulfill(1)));
        } else if (attribute.startsWith("expiration") && ban.getExpiration() != null) {
            Deprecations.timeTagRewrite.warn(attribute.context);
            event.setReplacedObject(new DurationTag(ban.getExpiration().getTime() / 50).getObjectAttribute(attribute.fulfill(1)));
        } else // -->
        if (attribute.startsWith("reason")) {
            event.setReplacedObject(new ElementTag(ban.getReason()).getObjectAttribute(attribute.fulfill(1)));
        } else // -->
        if (attribute.startsWith("created_time")) {
            event.setReplacedObject(new TimeTag(ban.getCreated().getTime()).getObjectAttribute(attribute.fulfill(1)));
        } else if (attribute.startsWith("created")) {
            Deprecations.timeTagRewrite.warn(attribute.context);
            event.setReplacedObject(new DurationTag(ban.getCreated().getTime() / 50).getObjectAttribute(attribute.fulfill(1)));
        } else // -->
        if (attribute.startsWith("source")) {
            event.setReplacedObject(new ElementTag(ban.getSource()).getObjectAttribute(attribute.fulfill(1)));
        }
        return;
    }
    // -->
    if (attribute.startsWith("ops") || attribute.startsWith("list_ops")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (OfflinePlayer player : Bukkit.getOperators()) {
            players.addObject(PlayerTag.mirrorBukkitPlayer(player));
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("online_ops") || attribute.startsWith("list_online_ops")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (OfflinePlayer player : Bukkit.getOperators()) {
            if (player.isOnline()) {
                players.addObject(PlayerTag.mirrorBukkitPlayer(player));
            }
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("offline_ops") || attribute.startsWith("list_offline_ops")) {
        listDeprecateWarn(attribute);
        ListTag players = new ListTag();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            if (player.isOp() && !player.isOnline()) {
                players.addObject(PlayerTag.mirrorBukkitPlayer(player));
            }
        }
        event.setReplacedObject(players.getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("motd")) {
        event.setReplacedObject(new ElementTag(Bukkit.getServer().getMotd()).getObjectAttribute(attribute.fulfill(1)));
        return;
    }
    // -->
    if (attribute.startsWith("view_distance")) {
        event.setReplacedObject(new ElementTag(Bukkit.getServer().getViewDistance()).getObjectAttribute(attribute.fulfill(1)));
        return;
    } else if (attribute.startsWith("entity_is_spawned") && attribute.hasParam()) {
        Deprecations.isValidTag.warn(attribute.context);
        EntityTag ent = EntityTag.valueOf(attribute.getParam(), new BukkitTagContext(null, null, null, false, null));
        event.setReplacedObject(new ElementTag((ent != null && ent.isUnique() && ent.isSpawnedOrValidForTag()) ? "true" : "false").getObjectAttribute(attribute.fulfill(1)));
    } else if (attribute.startsWith("player_is_valid") && attribute.hasParam()) {
        Deprecations.isValidTag.warn(attribute.context);
        event.setReplacedObject(new ElementTag(PlayerTag.playerNameIsValid(attribute.getParam())).getObjectAttribute(attribute.fulfill(1)));
    } else if (attribute.startsWith("npc_is_valid") && attribute.hasParam()) {
        Deprecations.isValidTag.warn(attribute.context);
        NPCTag npc = NPCTag.valueOf(attribute.getParam(), new BukkitTagContext(null, null, null, false, null));
        event.setReplacedObject(new ElementTag((npc != null && npc.isValid())).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("current_bossbars")) {
        ListTag dl = new ListTag(BossBarCommand.bossBarMap.keySet());
        event.setReplacedObject(dl.getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("bossbar_viewers") && attribute.hasParam()) {
        BossBar bar = BossBarCommand.bossBarMap.get(CoreUtilities.toLowerCase(attribute.getParam()));
        if (bar != null) {
            ListTag list = new ListTag();
            for (Player player : bar.getPlayers()) {
                list.addObject(new PlayerTag(player));
            }
            event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
        }
    } else // -->
    if (attribute.startsWith("recent_tps")) {
        ListTag list = new ListTag();
        for (double tps : NMSHandler.getInstance().getRecentTps()) {
            list.addObject(new ElementTag(tps));
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("port")) {
        event.setReplacedObject(new ElementTag(NMSHandler.getInstance().getPort()).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("debug_enabled")) {
        event.setReplacedObject(new ElementTag(com.denizenscript.denizen.utilities.debugging.Debug.showDebug).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("last_reload")) {
        event.setReplacedObject(new TimeTag(DenizenCore.lastReloadTime).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("idle_timeout")) {
        event.setReplacedObject(new DurationTag(Bukkit.getIdleTimeout() * 60).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("vanilla_tags")) {
        event.setReplacedObject(new ListTag(VanillaTagHelper.tagsByKey.keySet()).getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("vanilla_tagged_materials")) {
        if (!attribute.hasParam()) {
            return;
        }
        HashSet<Material> materials = VanillaTagHelper.tagsByKey.get(CoreUtilities.toLowerCase(attribute.getParam()));
        if (materials == null) {
            return;
        }
        ListTag list = new ListTag();
        for (Material material : materials) {
            list.addObject(new MaterialTag(material));
        }
        event.setReplacedObject(list.getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if ((attribute.matches("plugins_handling_event") || attribute.matches("list_plugins_handling_event")) && attribute.hasParam()) {
        listDeprecateWarn(attribute);
        String eventName = attribute.getParam();
        if (CoreUtilities.contains(eventName, '.')) {
            try {
                Class clazz = Class.forName(eventName, false, ServerTagBase.class.getClassLoader());
                ListTag result = getHandlerPluginList(clazz);
                if (result != null) {
                    event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
                }
            } catch (ClassNotFoundException ex) {
                if (!attribute.hasAlternative()) {
                    Debug.echoError(ex);
                }
            }
        } else {
            ScriptEvent scriptEvent = ScriptEvent.eventLookup.get(CoreUtilities.toLowerCase(eventName));
            if (scriptEvent instanceof Listener) {
                Plugin plugin = Denizen.getInstance();
                for (Class eventClass : plugin.getPluginLoader().createRegisteredListeners((Listener) scriptEvent, plugin).keySet()) {
                    ListTag result = getHandlerPluginList(eventClass);
                    // Return results for the first valid match.
                    if (result != null && result.size() > 0) {
                        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
                        return;
                    }
                }
                event.setReplacedObject(new ListTag().getObjectAttribute(attribute.fulfill(1)));
            }
        }
    } else // -->
    if (attribute.startsWith("generate_loot_table") && attribute.hasParam()) {
        MapTag map = attribute.paramAsType(MapTag.class);
        ObjectTag idObj = map.getObject("id");
        ObjectTag locationObj = map.getObject("location");
        if (idObj == null || locationObj == null) {
            return;
        }
        NamespacedKey key = NamespacedKey.fromString(CoreUtilities.toLowerCase(idObj.toString()));
        if (key == null) {
            return;
        }
        LootTable table = Bukkit.getLootTable(key);
        LootContext.Builder context = new LootContext.Builder(locationObj.asType(LocationTag.class, attribute.context));
        ObjectTag killer = map.getObject("killer");
        ObjectTag luck = map.getObject("luck");
        ObjectTag bonus = map.getObject("loot_bonus");
        ObjectTag entity = map.getObject("entity");
        if (entity != null) {
            context = context.lootedEntity(entity.asType(EntityTag.class, attribute.context).getBukkitEntity());
        }
        if (killer != null) {
            context = context.killer((HumanEntity) killer.asType(EntityTag.class, attribute.context).getLivingEntity());
        }
        if (luck != null) {
            context = context.luck(luck.asElement().asFloat());
        }
        if (bonus != null) {
            context = context.lootingModifier(bonus.asElement().asInt());
        }
        Collection<ItemStack> items;
        try {
            items = table.populateLoot(CoreUtilities.getRandom(), context.build());
        } catch (Throwable ex) {
            attribute.echoError("Loot table failed to generate: " + ex.getMessage());
            if (Debug.verbose) {
                attribute.echoError(ex);
            }
            return;
        }
        ListTag result = new ListTag();
        for (ItemStack item : items) {
            if (item != null && item.getType() != Material.AIR) {
                result.addObject(new ItemTag(item));
            }
        }
        event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
    } else // -->
    if (attribute.startsWith("stack_trace")) {
        String trace = com.denizenscript.denizen.utilities.debugging.Debug.getFullExceptionMessage(new RuntimeException("TRACE"), false);
        event.setReplacedObject(new ElementTag(trace).getObjectAttribute(attribute.fulfill(1)));
    }
}
Also used : Plugin(org.bukkit.plugin.Plugin) PatternType(org.bukkit.block.banner.PatternType) Utilities(com.denizenscript.denizen.utilities.Utilities) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) Connection(java.sql.Connection) TagManager(com.denizenscript.denizencore.tags.TagManager) Enchantment(org.bukkit.enchantments.Enchantment) NMSHandler(com.denizenscript.denizen.nms.NMSHandler) SQLCommand(com.denizenscript.denizencore.scripts.commands.core.SQLCommand) CommandScriptHelper(com.denizenscript.denizen.scripts.containers.core.CommandScriptHelper) TagRunnable(com.denizenscript.denizencore.tags.TagRunnable) Event(org.bukkit.event.Event) BossBarCommand(com.denizenscript.denizen.scripts.commands.server.BossBarCommand) Player(org.bukkit.entity.Player) NoteManager(com.denizenscript.denizencore.objects.notable.NoteManager) Biome(org.bukkit.block.Biome) Objective(org.bukkit.scoreboard.Objective) org.bukkit(org.bukkit) org.bukkit.inventory(org.bukkit.inventory) Scoreboard(org.bukkit.scoreboard.Scoreboard) CitizensAPI(net.citizensnpcs.api.CitizensAPI) VanillaTagHelper(com.denizenscript.denizen.utilities.VanillaTagHelper) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PotionType(org.bukkit.potion.PotionType) EntityType(org.bukkit.entity.EntityType) PluginCommand(org.bukkit.command.PluginCommand) BukkitScriptEvent(com.denizenscript.denizen.events.BukkitScriptEvent) Settings(com.denizenscript.denizen.utilities.Settings) MapCursor(org.bukkit.map.MapCursor) SlotHelper(com.denizenscript.denizen.utilities.inventory.SlotHelper) Deprecations(com.denizenscript.denizencore.utilities.Deprecations) PotionEffectType(org.bukkit.potion.PotionEffectType) HandlerList(org.bukkit.event.HandlerList) Citizens(net.citizensnpcs.Citizens) java.util(java.util) ScriptContainer(com.denizenscript.denizencore.scripts.containers.ScriptContainer) ReplaceableTagEvent(com.denizenscript.denizencore.tags.ReplaceableTagEvent) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) Debug(com.denizenscript.denizencore.utilities.debugging.Debug) NPC(net.citizensnpcs.api.npc.NPC) LootContext(org.bukkit.loot.LootContext) DenizenCore(com.denizenscript.denizencore.DenizenCore) FutureWarning(com.denizenscript.denizencore.utilities.debugging.FutureWarning) SQLException(java.sql.SQLException) CommandContext(net.citizensnpcs.api.command.CommandContext) TickScriptEvent(com.denizenscript.denizencore.events.core.TickScriptEvent) ScriptRegistry(com.denizenscript.denizencore.scripts.ScriptRegistry) Attribute(com.denizenscript.denizencore.tags.Attribute) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Listener(org.bukkit.event.Listener) HumanEntity(org.bukkit.entity.HumanEntity) AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) LootTable(org.bukkit.loot.LootTable) Team(org.bukkit.scoreboard.Team) ScriptEvent(com.denizenscript.denizencore.events.ScriptEvent) com.denizenscript.denizencore.objects.core(com.denizenscript.denizencore.objects.core) Depends(com.denizenscript.denizen.utilities.depends.Depends) Notable(com.denizenscript.denizencore.objects.notable.Notable) File(java.io.File) com.denizenscript.denizen.objects(com.denizenscript.denizen.objects) Denizen(com.denizenscript.denizen.Denizen) RegisteredListener(org.bukkit.plugin.RegisteredListener) Consumer(java.util.function.Consumer) TraitInfo(net.citizensnpcs.api.trait.TraitInfo) BossBar(org.bukkit.boss.BossBar) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ScoreboardHelper(com.denizenscript.denizen.utilities.ScoreboardHelper) com.denizenscript.denizencore.objects(com.denizenscript.denizencore.objects) CoreUtilities(com.denizenscript.denizencore.utilities.CoreUtilities) BossBar(org.bukkit.boss.BossBar) TraitInfo(net.citizensnpcs.api.trait.TraitInfo) HumanEntity(org.bukkit.entity.HumanEntity) PatternType(org.bukkit.block.banner.PatternType) PotionEffectType(org.bukkit.potion.PotionEffectType) MapCursor(org.bukkit.map.MapCursor) PotionType(org.bukkit.potion.PotionType) Attribute(com.denizenscript.denizencore.tags.Attribute) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Biome(org.bukkit.block.Biome) Team(org.bukkit.scoreboard.Team) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) LootTable(org.bukkit.loot.LootTable) Connection(java.sql.Connection) AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) BukkitScriptEvent(com.denizenscript.denizen.events.BukkitScriptEvent) TickScriptEvent(com.denizenscript.denizencore.events.core.TickScriptEvent) ScriptEvent(com.denizenscript.denizencore.events.ScriptEvent) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) Player(org.bukkit.entity.Player) LootContext(org.bukkit.loot.LootContext) PlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent) Notable(com.denizenscript.denizencore.objects.notable.Notable) EntityType(org.bukkit.entity.EntityType) Objective(org.bukkit.scoreboard.Objective) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) ScriptContainer(com.denizenscript.denizencore.scripts.containers.ScriptContainer) BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) Enchantment(org.bukkit.enchantments.Enchantment) File(java.io.File) NPC(net.citizensnpcs.api.npc.NPC) Listener(org.bukkit.event.Listener) RegisteredListener(org.bukkit.plugin.RegisteredListener) SQLException(java.sql.SQLException) Scoreboard(org.bukkit.scoreboard.Scoreboard) PluginCommand(org.bukkit.command.PluginCommand) SQLException(java.sql.SQLException) Plugin(org.bukkit.plugin.Plugin)

Example 4 with AssignmentScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class ZapCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("script") && !scriptEntry.hasObject("step") && arg.hasPrefix() && arg.getPrefix().matchesArgumentType(ScriptTag.class)) {
            Deprecations.zapPrefix.warn(scriptEntry);
            scriptEntry.addObject("script", arg.getPrefix().asType(ScriptTag.class));
            scriptEntry.addObject("step", arg.asElement());
        } else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof InteractScriptContainer && arg.limitToOnlyPrefix("script")) {
            scriptEntry.addObject("script", arg.asType(ScriptTag.class));
        } else if (!scriptEntry.hasObject("step") && arg.limitToOnlyPrefix("step")) {
            scriptEntry.addObject("step", arg.asElement());
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.limitToOnlyPrefix("duration")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else {
            arg.reportUnhandled();
        }
    }
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    if (player == null || !player.isValid()) {
        throw new InvalidArgumentsException("Must have player context!");
    }
    if (!scriptEntry.hasObject("script")) {
        ScriptTag script = scriptEntry.getScript();
        if (script != null) {
            if (script.getContainer() instanceof InteractScriptContainer) {
                scriptEntry.addObject("script", script);
            } else if (script.getContainer() instanceof AssignmentScriptContainer) {
                InteractScriptContainer interact = ((AssignmentScriptContainer) script.getContainer()).interact;
                if (interact != null) {
                    scriptEntry.addObject("script", new ScriptTag(interact));
                }
            }
        }
        if (!scriptEntry.hasObject("script")) {
            NPCTag npc = Utilities.getEntryNPC(scriptEntry);
            if (npc != null && npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                for (AssignmentScriptContainer container : trait.containerCache) {
                    if (container != null && container.getInteract() != null) {
                        scriptEntry.addObject("script", new ScriptTag(container.getInteract()));
                        break;
                    }
                }
            }
        }
        if (!scriptEntry.hasObject("script")) {
            throw new InvalidArgumentsException("No script to zap! Must be in an interact script, or have a linked NPC with an associated interact script.");
        }
    }
}
Also used : AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) InteractScriptContainer(com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 5 with AssignmentScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class AssignmentTrait method buildCache.

public void buildCache() {
    containerCache.clear();
    for (String assignment : assignments) {
        AssignmentScriptContainer container = ScriptRegistry.getScriptContainerAs(assignment, AssignmentScriptContainer.class);
        containerCache.add(container);
        if (container == null) {
            Debug.echoError("NPC " + npc.getId() + " has assignment '" + assignment + "' which does not exist.");
        }
    }
}
Also used : AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)

Aggregations

AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)8 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)3 NPCTag (com.denizenscript.denizen.objects.NPCTag)3 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 ScriptContainer (com.denizenscript.denizencore.scripts.containers.ScriptContainer)2 NPC (net.citizensnpcs.api.npc.NPC)2 Denizen (com.denizenscript.denizen.Denizen)1 BukkitScriptEvent (com.denizenscript.denizen.events.BukkitScriptEvent)1 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)1 com.denizenscript.denizen.objects (com.denizenscript.denizen.objects)1 BossBarCommand (com.denizenscript.denizen.scripts.commands.server.BossBarCommand)1 CommandScriptHelper (com.denizenscript.denizen.scripts.containers.core.CommandScriptHelper)1 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)1 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)1 ScoreboardHelper (com.denizenscript.denizen.utilities.ScoreboardHelper)1 Settings (com.denizenscript.denizen.utilities.Settings)1 Utilities (com.denizenscript.denizen.utilities.Utilities)1 VanillaTagHelper (com.denizenscript.denizen.utilities.VanillaTagHelper)1 Depends (com.denizenscript.denizen.utilities.depends.Depends)1