Search in sources :

Example 16 with NPCTag

use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.

the class FeedCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    PlayerTag player = scriptEntry.getObjectTag("targetplayer");
    NPCTag npc = scriptEntry.getObjectTag("targetnpc");
    ElementTag amount = scriptEntry.getElement("amount");
    ElementTag saturation = scriptEntry.getElement("saturation");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), player, npc, amount, saturation);
    }
    if (npc != null) {
        if (!npc.getCitizen().hasTrait(HungerTrait.class)) {
            Debug.echoError(scriptEntry, "This NPC does not have the HungerTrait enabled! Use /trait hunger");
            return;
        }
        npc.getCitizen().getOrAddTrait(HungerTrait.class).feed(amount.asInt());
    } else {
        int result = Math.max(0, Math.min(20, player.getPlayerEntity().getFoodLevel() + amount.asInt()));
        player.getPlayerEntity().setFoodLevel(result);
        float satResult = Math.max(0, Math.min(20, player.getPlayerEntity().getSaturation() + saturation.asFloat()));
        player.getPlayerEntity().setSaturation(satResult);
        Debug.echoDebug(scriptEntry, "Player food level updated to " + result + " food and " + satResult + " saturation.");
    }
}
Also used : PlayerTag(com.denizenscript.denizen.objects.PlayerTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) HungerTrait(com.denizenscript.denizen.npc.traits.HungerTrait)

Example 17 with NPCTag

use of com.denizenscript.denizen.objects.NPCTag 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 18 with NPCTag

use of com.denizenscript.denizen.objects.NPCTag 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 19 with NPCTag

use of com.denizenscript.denizen.objects.NPCTag 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 20 with NPCTag

use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.

the class BreakCommand method execute.

// <--[action]
// @Actions
// dig
// 
// @Triggers when the NPC breaks a block with the Break Command
// 
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
// 
// -->
@Override
public void execute(ScriptEntry scriptEntry) {
    final LocationTag location = scriptEntry.getObjectTag("location");
    final NPCTag npc = scriptEntry.getObjectTag("npc");
    ElementTag radius = scriptEntry.getElement("radius");
    final HashMap<String, ObjectTag> context = new HashMap<>();
    MaterialTag material = new MaterialTag(location.getBlock());
    context.put("location", location);
    context.put("material", material);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, npc, radius);
    }
    final ScriptEntry se = scriptEntry;
    BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
    config.item(npc.getLivingEntity().getEquipment().getItemInMainHand());
    config.radius(radius.asDouble());
    config.callback(() -> {
        npc.action("dig", null, context);
        se.setFinished(true);
    });
    BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
    if (breaker.shouldExecute()) {
        TaskRunnable run = new TaskRunnable(breaker);
        run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.getInstance(), run, 0, 1);
    } else {
        se.setFinished(true);
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) HashMap(java.util.HashMap) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) BlockBreaker(net.citizensnpcs.api.npc.BlockBreaker) LocationTag(com.denizenscript.denizen.objects.LocationTag) ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Aggregations

NPCTag (com.denizenscript.denizen.objects.NPCTag)72 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)24 EventHandler (org.bukkit.event.EventHandler)22 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)21 Player (org.bukkit.entity.Player)15 LocationTag (com.denizenscript.denizen.objects.LocationTag)12 EntityTag (com.denizenscript.denizen.objects.EntityTag)10 ListTag (com.denizenscript.denizencore.objects.core.ListTag)9 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)8 HashMap (java.util.HashMap)8 NPC (net.citizensnpcs.api.npc.NPC)8 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)7 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)6 Location (org.bukkit.Location)6 TriggerTrait (com.denizenscript.denizen.npc.traits.TriggerTrait)5 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Entity (org.bukkit.entity.Entity)5