Package net.citizensnpcs.api.npc

Examples of net.citizensnpcs.api.npc.NPC


        else if (((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getEntityType() == EntityType.WOLF) {
            ((Wolf)((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getEntity()).setSitting(false);
        }

        else {
            NPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen();
            SittingTrait trait = npc.getTrait(SittingTrait.class);

            if (!npc.hasTrait(SittingTrait.class)){
                npc.addTrait(SittingTrait.class);
                dB.echoDebug(scriptEntry, "...added sitting trait");
            }

            trait.stand();
            npc.removeTrait(SittingTrait.class);
        }
    }
View Full Code Here


        // Report to dB
        dB.report(scriptEntry, getName(),
                aH.debugObj("NPC", ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().toString()) +
                        aH.debugObj("Toggle", toggle.toString()));

        NPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen();

        boolean vulnerable;

        if (toggle == Toggle.TOGGLE)
            vulnerable = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);

        else vulnerable = Boolean.valueOf(toggle.toString());

        npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, !vulnerable);
    }
View Full Code Here

        Element name = (Element) scriptEntry.getObject("name");

        dB.report(scriptEntry, getName(), name.debug());

        NPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen();

        Location prev = npc.isSpawned() ? npc.getEntity().getLocation() : null;
        npc.despawn(DespawnReason.PENDING_RESPAWN);
        npc.setName(name.asString().length() > 100 ? name.asString().substring(0, 100): name.asString());
        if (prev != null)
            npc.spawn(prev);

    }
View Full Code Here

        // Report to dB
        dB.report(scriptEntry, getName(), state.debug() + target.debug());

        if (target.isNPC()) {
            NPC npc = target.getDenizenNPC().getCitizen();
            if (!npc.hasTrait(InvisibleTrait.class))
                npc.addTrait(InvisibleTrait.class);
            InvisibleTrait trait = npc.getTrait(InvisibleTrait.class);
            switch (Action.valueOf(state.asString().toUpperCase())) {
                case FALSE:
                    trait.setInvisible(false);
                    break;
                case TRUE:
View Full Code Here

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

        Element toggle = scriptEntry.getElement("state");
        Element traitName = scriptEntry.getElement("trait");
        NPC npc = ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getCitizen();

        dB.report(scriptEntry, getName(),
                    traitName.debug() +
                    toggle.debug() +
                    ((BukkitScriptEntryData)scriptEntry.entryData).getNPC().debug());

        Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString());

        if (trait == null) {
            dB.echoError(scriptEntry.getResidingQueue(), "Trait not found: " + traitName.asString());
            return;
        }

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

            case TRUE:
            case ON:
                if (npc.hasTrait(trait))
                    dB.echoError(scriptEntry.getResidingQueue(), "NPC already has trait '" + traitName.asString() + "'");
                else
                    npc.addTrait(trait);
                break;

            case FALSE:
            case OFF:
                if (!npc.hasTrait(trait))
                    dB.echoError(scriptEntry.getResidingQueue(), "NPC does not have trait '" + traitName.asString() + "'");
                else
                    npc.removeTrait(trait);
                break;

            case TOGGLE:
                if (npc.hasTrait(trait))
                    npc.removeTrait(trait);
                else
                    npc.addTrait(trait);
                break;

        }

    }
View Full Code Here

     *
     * @param event NPCRemoveEvent
     */
    @EventHandler
    public void onRemove(NPCRemoveEvent event) {
        NPC npc = event.getNPC();
        getDenizen(npc).action("remove", null);
        if (_isRegistered(npc)) {
            denizenNPCs.remove(npc.getId());
            npcInventories.remove(npc.getId());
        }
        dB.log(ChatColor.RED + "Deconstructing Denizen NPC " + npc.getName() + "/" + npc.getId());
        FlagManager.clearNPCFlags(npc.getId());
    }
View Full Code Here

    public Set<NPC> getActiveNPCsWithinRangeWithTrigger (Location location, int maxRange) {
        Set<NPC> closestNPCs = new HashSet<NPC> ();

        Iterator<NPC>    it = CitizensAPI.getNPCRegistry().iterator();
        while (it.hasNext ()) {
            NPC    npc = it.next ();
            if (npc.isSpawned()
                    && npc.getEntity().getLocation().getWorld().equals(location.getWorld())
                    && npc.getEntity().getLocation().distance(location) < maxRange
                    && npc.hasTrait(TriggerTrait.class)
                    && npc.getTrait(TriggerTrait.class).isEnabled(name)) {
                closestNPCs.add (npc);
            }
        }

        return closestNPCs;
View Full Code Here

    public void setInfected(boolean bool) {

        if (bool) {
            if (infected.isNPC()) {
                NPC infected_npc = infected.getDenizenNPC().getCitizen();
                infected_npc.setBukkitEntityType(EntityType.ZOMBIE);
                if (!infected_npc.getTrait(ZombieModifier.class).toggleVillager())
                    infected_npc.getTrait(ZombieModifier.class).toggleVillager();
            }

            // If it's a Villager, we need to spawn a Zombie instead.
            // This is kind of messy, and can be improved upon.
            // TODO: Improve upon.
View Full Code Here

    }

    public void setBaby(boolean bool) {
        if (ageable.isNPC()) {
            NPC ageable_npc = ageable.getDenizenNPC().getCitizen();
            if (!ageable_npc.hasTrait(Age.class))
                ageable_npc.addTrait(Age.class);
            ageable_npc.getTrait(Age.class).setAge(bool ? -24000 : 0);
        }
        else {
            if (ageable.getBukkitEntity().getType() == EntityType.ZOMBIE)
                ((Zombie) ageable.getBukkitEntity()).setBaby(bool);
View Full Code Here

        }
    }

    public void setAge(int val) {
        if (ageable.isNPC()) {
            NPC ageable_npc = ageable.getDenizenNPC().getCitizen();
            ageable_npc.getTrait(Age.class).setAge(val);
        }
        else {
            if (ageable.getBukkitEntity().getType() == EntityType.ZOMBIE)
                ((Zombie) ageable.getBukkitEntity()).setBaby(val >= 0);
            else
View Full Code Here

TOP

Related Classes of net.citizensnpcs.api.npc.NPC

Copyright © 2018 www.massapicom. 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.