Search in sources :

Example 76 with ElementTag

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

the class MaterialNote method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.note_octave>
    // @returns ElementTag(Number)
    // @mechanism MaterialTag.note
    // @group properties
    // @description
    // Returns the octave of note played from this note block, as 0, 1, or 2.
    // -->
    PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note_octave", (attribute, material) -> {
        return new ElementTag(material.getNoteBlock().getNote().getOctave());
    });
    // <--[tag]
    // @attribute <MaterialTag.note_tone>
    // @returns ElementTag
    // @mechanism MaterialTag.note
    // @group properties
    // @description
    // Returns the tone of note played from this note block, as a letter from A to F, sometimes with a # to indicate sharp.
    // Like A or A#.
    // -->
    PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note_tone", (attribute, material) -> {
        Note note = material.getNoteBlock().getNote();
        return new ElementTag(note.getTone().name() + (note.isSharped() ? "#" : ""));
    });
    // <--[tag]
    // @attribute <MaterialTag.note>
    // @returns ElementTag(Number)
    // @mechanism MaterialTag.note
    // @group properties
    // @description
    // Returns the note played from this note block, as an ID number from 0 to 24.
    // -->
    PropertyParser.<MaterialNote, ElementTag>registerStaticTag(ElementTag.class, "note", (attribute, material) -> {
        return new ElementTag(material.getNoteBlock().getNote().getId());
    });
}
Also used : Note(org.bukkit.Note) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 77 with ElementTag

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

the class LookcloseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag realistic = scriptEntry.getElement("realistic");
    ElementTag range = scriptEntry.getElement("range");
    ElementTag toggle = scriptEntry.getElement("toggle");
    NPCTag npc = scriptEntry.getObjectTag("npc");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), npc, realistic, range, toggle);
    }
    LookClose trait = npc.getCitizen().getOrAddTrait(LookClose.class);
    if (toggle != null) {
        trait.lookClose(toggle.asBoolean());
    }
    if (realistic != null && realistic.asBoolean()) {
        trait.setRealisticLooking(true);
    } else {
        trait.setRealisticLooking(false);
    }
    if (range != null) {
        trait.setRange(range.asInt());
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) LookClose(net.citizensnpcs.trait.LookClose) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 78 with ElementTag

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

the class PoseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    TargetType target = (TargetType) scriptEntry.getObject("target");
    NPCTag npc = Utilities.getEntryNPC(scriptEntry);
    Action action = (Action) scriptEntry.getObject("action");
    ElementTag idElement = scriptEntry.getElement("pose_id");
    LocationTag pose_loc = scriptEntry.getObjectTag("pose_loc");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("Target", target), (target == TargetType.PLAYER ? Utilities.getEntryPlayer(scriptEntry) : ""), npc, db("Action", action), idElement, pose_loc);
    }
    if (!npc.getCitizen().hasTrait(Poses.class)) {
        npc.getCitizen().addTrait(Poses.class);
    }
    Poses poses = npc.getCitizen().getOrAddTrait(Poses.class);
    String id = idElement.asString();
    switch(action) {
        case ASSUME:
            if (!poses.hasPose(id)) {
                Debug.echoError("Pose \"" + id + "\" doesn't exist for " + npc.toString());
            }
            if (target.name().equals("NPC")) {
                poses.assumePose(id);
            } else {
                Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
                Location location = player.getLocation();
                location.setYaw(poses.getPose(id).getYaw());
                location.setPitch(poses.getPose(id).getPitch());
                // The only way to change a player's yaw and pitch in Bukkit is to use teleport on them
                player.teleport(location);
            }
            break;
        case ADD:
            if (!poses.addPose(id, pose_loc)) {
                Debug.echoError(npc.toString() + " already has that pose!");
            }
            break;
        case REMOVE:
            if (!poses.removePose(id)) {
                Debug.echoError(npc.toString() + " does not have that pose!");
            }
            break;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Player(org.bukkit.entity.Player) NPCTag(com.denizenscript.denizen.objects.NPCTag) Poses(net.citizensnpcs.trait.Poses) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) Location(org.bukkit.Location)

Example 79 with ElementTag

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

the class TriggerCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ElementTag toggle = scriptEntry.getElement("toggle");
    ElementTag trigger = scriptEntry.getElement("trigger");
    ElementTag radius = scriptEntry.getElement("radius");
    DurationTag cooldown = scriptEntry.getObjectTag("cooldown");
    NPCTag npc = scriptEntry.hasObject("npc") ? (NPCTag) scriptEntry.getObject("npc") : Utilities.getEntryNPC(scriptEntry);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), trigger, toggle, radius, cooldown, npc);
    }
    // Add trigger trait
    if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
        npc.getCitizen().addTrait(TriggerTrait.class);
    }
    TriggerTrait trait = npc.getCitizen().getOrAddTrait(TriggerTrait.class);
    switch(Toggle.valueOf(toggle.asString().toUpperCase())) {
        case TOGGLE:
            trait.toggleTrigger(trigger.asString());
            break;
        case TRUE:
            trait.toggleTrigger(trigger.asString(), true);
            break;
        case FALSE:
            trait.toggleTrigger(trigger.asString(), false);
            break;
    }
    if (radius != null) {
        trait.setLocalRadius(trigger.asString(), radius.asInt());
    }
    if (cooldown != null) {
        trait.setLocalCooldown(trigger.asString(), cooldown.getSeconds());
    }
}
Also used : TriggerTrait(com.denizenscript.denizen.npc.traits.TriggerTrait) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Example 80 with ElementTag

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

the class ActionBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
    String text = scriptEntry.getElement("text").asString();
    ScriptTag formatObj = scriptEntry.getObjectTag("format");
    ElementTag perPlayerObj = scriptEntry.getElement("per_player");
    boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
    BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
    if (!perPlayer) {
        text = TagManager.tag(text, context);
    }
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("message", text), db("targets", targets), formatObj, perPlayerObj);
    }
    FormatScriptContainer format = formatObj == null ? null : (FormatScriptContainer) formatObj.getContainer();
    for (PlayerTag player : targets) {
        if (player != null) {
            if (!player.isOnline()) {
                Debug.echoDebug(scriptEntry, "Player is offline, can't send actionbar to them. Skipping.");
                continue;
            }
            String personalText = text;
            if (perPlayer) {
                context.player = player;
                personalText = TagManager.tag(personalText, context);
            }
            player.getPlayerEntity().spigot().sendMessage(ChatMessageType.ACTION_BAR, FormattedTextHelper.parse(format != null ? format.getFormattedText(personalText, scriptEntry) : personalText, ChatColor.WHITE));
        } else {
            Debug.echoError("Sent actionbar to non-existent player!?");
        }
    }
}
Also used : BukkitTagContext(com.denizenscript.denizen.tags.BukkitTagContext) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12