Examples of dNPC


Examples of net.aufdemrand.denizen.objects.dNPC

        dLocation location = scriptEntry.getdObject("location");
        Element katch = scriptEntry.getElement("catch");
        Element stop = scriptEntry.getElement("stop");
        Element percent = scriptEntry.getElement("percent");

        dNPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();
        FishingTrait trait = npc.getFishingTrait();

        dB.report(scriptEntry, getName(), location.debug() + katch.debug() + percent.debug() + stop.debug());

        if (stop.asBoolean()) {
            trait.stopFishing();
            return;
        }

        npc.getEquipmentTrait().set(0, new ItemStack(Material.FISHING_ROD));

        trait.setCatchPercent(percent.asInt());
        trait.setCatchType(FishingTrait.CatchType.valueOf(katch.asString().toUpperCase()));
        trait.startFishing(location);
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

    @Override
    public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

        // Get objects
        TargetType target = (TargetType) scriptEntry.getObject("target");
        dNPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();
        Action action = (Action) scriptEntry.getObject("action");
        String id = (String) scriptEntry.getObject("pose_id");
        dLocation pose_loc = (dLocation) scriptEntry.getObject("pose_loc");

        // Report to dB
        dB.report(scriptEntry, getName(),
                aH.debugObj("Target", target.toString())
                        + (target == TargetType.PLAYER ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().debug() : "")
                        + npc.debug()
                        + aH.debugObj("Action", action.toString())
                        + aH.debugObj("Id", id)
                        + (pose_loc != null ? pose_loc.debug() : ""));

        if (!npc.getCitizen().hasTrait(Poses.class))
            npc.getCitizen().addTrait(Poses.class);

        Poses poses = npc.getCitizen().getTrait(Poses.class);

        switch (action) {

            case ASSUME:
                if (!poses.hasPose(id))
                    throw new CommandExecutionException("Pose \"" + id + "\" doesn't exist for " + npc.toString());

                if (target.name().equals("NPC"))
                    poses.assumePose(id);
                else {
                    Player player = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().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 him/her
                    player.teleport(location);
                }
                break;

            case ADD:
                if (!poses.addPose(id, pose_loc))
                    throw new CommandExecutionException(npc.toString() + " already has that pose!");
                break;

            case REMOVE:
                if (!poses.removePose(id))
                    throw new CommandExecutionException(npc.toString() + " does not have that pose!");
                break;

        }

    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

                aH.debugObj("NPC", ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().toString())
                        + action.name() + id.debug()
                        + (location != null ? location.debug() : "")
                        + (range != null ? range.debug() : "" ));

        dNPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();

        if (!npc.getCitizen().hasTrait(Anchors.class))
            npc.getCitizen().addTrait(Anchors.class);

        switch (action) {

            case ADD:
                npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
                return;

            case ASSUME:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class)
                        .getAnchor(id.asString());
                if (n == null)
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                else
                    npc.getEntity().teleport(n.getLocation());
            }
                return;

            case WALKNEAR:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class)
                        .getAnchor(id.asString());
                if (n == null)
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                else if (range == null)
                    dB.echoError(scriptEntry.getResidingQueue(), "Must specify a range!");
                else
                    npc.getNavigator().setTarget(
                        Utilities.getWalkableLocationNear(n.getLocation(), range.asInt()));
            }
                return;

            case WALKTO:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class)
                        .getAnchor(id.asString());
                if (n == null)
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                else
                    npc.getNavigator().setTarget(n.getLocation());
            }
                return;

            case REMOVE:
            {
                Anchor n = npc.getCitizen().getTrait(Anchors.class)
                        .getAnchor(id.asString());
                if (n == null)
                    dB.echoError(scriptEntry.getResidingQueue(), "Invalid anchor name '" + id.asString() + "'");
                else
                    npc.getCitizen().getTrait(Anchors.class).removeAnchor(n);
            }
        }


    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

        Element toggle = scriptEntry.getElement("toggle");
        Element trigger = scriptEntry.getElement("trigger");
        Element radius = scriptEntry.getElement("radius");
        Duration cooldown = (Duration) scriptEntry.getObject("cooldown");
        dNPC npc = scriptEntry.hasObject("npc") ? (dNPC) scriptEntry.getObject("npc") : ((BukkitScriptEntryData)scriptEntry.entryData).getNPC();

        dB.report(scriptEntry, getName(),
                trigger.debug() + toggle.debug() +
                        (radius != null ? radius.debug(): "") +
                        (cooldown != null ? cooldown.debug(): "") +
                        npc.debug());

        // Add trigger trait
        if (!npc.getCitizen().hasTrait(TriggerTrait.class)) npc.getCitizen().addTrait(TriggerTrait.class);

        TriggerTrait trait = npc.getCitizen().getTrait(TriggerTrait.class);

        switch (Toggle.valueOf(toggle.asString().toUpperCase())) {

            case TOGGLE:
                trait.toggleTrigger(trigger.asString());
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

    public void setPlayer(dPlayer player) {
        if (player != null && player.isOnline() && Depends.citizens != null
                && CitizensAPI.getNPCRegistry().isNPC(player.getPlayerEntity())) {
            dontFixMe = true;
            setNPC(new dNPC(CitizensAPI.getNPCRegistry().getNPC(player.getPlayerEntity())));
        }
        else
            this.player = player;
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

    }

    private static void _registerNPC(NPC npc) {
        if (npc == null) return;
        if (!denizenNPCs.containsKey(npc.getId())) {
            _registerNPC(new dNPC(npc));
        }
        // dB.log("Constructing NPC " + getDenizen(npc).toString());
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

     *
     * @param event NPCDespawnEvent
     */
    @EventHandler
    public void despawn(NPCDespawnEvent event) {
        dNPC npc = getDenizen(event.getNPC().getId());

        // Do world script event 'On NPC Despawns'
        if (npc != null)
            EventManager.doEvents(Arrays.asList("npc despawns"), npc, null, null);

        if (npc != null)
            npc.action("despawn", null);
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        Inventory inventory = event.getInventory();
        if (inventory.getHolder() instanceof dNPC) {
            dNPC npc = (dNPC) inventory.getHolder();
            npc.getInventory().setContents(inventory.getContents());
            Equipment equipment = npc.getEquipmentTrait();
            for (int i = 0; i < 5; i++)
                equipment.set(i, inventory.getItem(i));
        }
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

        // ANY triggers enabled!
        if (!event.getNPC().hasTrait(TriggerTrait.class)) return;

        // The rest of the methods beyond this point require a dNPC object, which can easily be
        // obtained if a valid NPC object is available:
        dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());

        // Now, check if the 'click trigger' specifically is enabled. 'name' is inherited from the
        // super AbstractTrigger and contains the name of the trigger that was use in registration.
        if (!npc.getTriggerTrait().isEnabled(name)) return;

        // We'll get the player too, since it makes reading the next few methods a bit easier:
        dPlayer player = dPlayer.mirrorBukkitPlayer(event.getClicker());

        // Check availability based on the NPC's ENGAGED status and the trigger's COOLDOWN that is
        // provided (and adjustable) by the TriggerTrait. Just use .trigger(...)!
        // If unavailable (engaged or not cool), .trigger calls 'On Unavailable' action and returns false.
        // If available (not engaged, and cool), .trigger sets cool down and returns true.
        TriggerTrait.TriggerContext trigger = npc.getTriggerTrait().trigger(this, player);

        if (!trigger.wasTriggered()) return;

        if (trigger.hasDetermination()
                && trigger.getDetermination().equalsIgnoreCase("cancelled")) {
            event.setCancelled(true);
            return;
        }

        // Note: In some cases, the automatic actions that .trigger offers may not be
        // desired. In this case, it's recommended to at least use .triggerCooldownOnly which
        // only handles cooling down the trigger with the triggertrait if the 'available' criteria
        // is met. This handles the built-in cooldown that TriggerTrait implements.

        // Okay, now we need to know which interact script will be selected for the Player/NPC
        // based on requirements/npc's assignment script. To get that information, use:
        // InteractScriptHelper.getInteractScript(dNPC, Player, Trigger Class)
        // .getInteractScript will check the Assignment for possible scripts, and automatically
        // check requirements for each of them.
        InteractScriptContainer script = npc.getInteractScript(player, getClass());

        // In an Interact Script, Triggers can have multiple scripts to choose from depending on
        // some kind of 'criteria'. For the 'Click Trigger', that criteria is the item the Player
        // has in hand. Let's get the possible criteria to see which 'Click Trigger script', if any,
        // should trigger. For example:
        //
        // Script Name:
        //   type: interact
        //   steps:
        //     current step:
        //       click trigger:
        String id = null;
        if (script != null) {
            Map<String, String> idMap = script.getIdMapFor(this.getClass(), player);
            if (!idMap.isEmpty())
                // Iterate through the different id entries in the step's click trigger
                for (Map.Entry<String, String> entry : idMap.entrySet()) {
                    // Tag the entry value to account for replaceables
                    String entry_value = TagManager.tag(player, npc, entry.getValue());
                    // Check if the item specified in the specified id's 'trigger:' key
                    // matches the item that the player is holding.
                    dItem item = dItem.valueOf(entry_value);
                    if (item == null) {
                        dB.echoError("Invalid click trigger in script '" + script.getName() + "' (null trigger item)!");
                    }
                    if (item != null && item.comparesTo(player.getPlayerEntity().getItemInHand()) >= 0
                            && script.checkSpecificTriggerScriptRequirementsFor(this.getClass(),
                            player, npc, entry.getKey()))
                        id = entry.getKey();
                }
        }

        // If id is still null after this, it's assumed that the trigger's 'base script' will be used.
        // parse() will accept a null id if this is the case.

        // Click trigger is pretty straight forward, so there's not really a whole lot left to do
        // except call the parse() method which will queue up and execute the appropriate script
        // based on the Player/NPCs interact script.
        // Parses the trigger. Requires if parse returns false there probably is no trigger
        // script specified in the interact script that was selected, in which case
        // we'll call the action 'on no click trigger'.
        if (!parse(npc, player, script, id))
            npc.action("no click trigger", player);
    }
View Full Code Here

Examples of net.aufdemrand.denizen.objects.dNPC

                // Fill NPCID/NPC argument
                else if (arg.matchesPrefix("npc, npcid") && !if_ignore) {
                    dB.echoDebug(scriptEntry, "...replacing the linked NPC with " + arg.getValue());
                    String value = TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(), arg.getValue(), false, scriptEntry);
                    dNPC npc = dNPC.valueOf(value);
                    if (npc == null || !npc.isValid()) {
                        dB.echoError(scriptEntry.getResidingQueue(), value + " is an invalid NPC!");
                        return false;
                    }
                    scriptEntry.setNPC(npc);
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.