Examples of NPC


Examples of net.citizensnpcs.api.npc.NPC

        // @returns Element(Boolean)
        // @description
        // Returns true if the NPC has a nickname.
        // -->
        if (attribute.startsWith("has_nickname")) {
            NPC citizen = getCitizen();
            return new Element(citizen.hasTrait(NicknameTrait.class) && citizen.getTrait(NicknameTrait.class).hasNickname())
                    .getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.name.nickname>
        // @returns Element
        // @description
        // returns the NPC's display name.
        // -->
        if (attribute.startsWith("name.nickname"))
            return new Element(getCitizen().hasTrait(NicknameTrait.class) ? getCitizen().getTrait(NicknameTrait.class)
                    .getNickname() : getName()).getAttribute(attribute.fulfill(2));

        // <--[tag]
        // @attribute <n@npc.name>
        // @returns Element
        // @description
        // returns the name of the NPC.
        // -->
        if (attribute.startsWith("name"))
            return new Element(getName())
                    .getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.list_traits>
        // @returns dList
        // @description
        // Returns a list of all of the NPC's traits.
        // -->
        if (attribute.startsWith("list_traits")) {
            List<String> list = new ArrayList<String>();
            for (Trait trait : getCitizen().getTraits())
                list.add(trait.getName());
            return new dList(list).getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.has_trait[<trait>]>
        // @returns Element(Boolean)
        // @description
        // Returns whether the NPC has a specified trait.
        // -->
        if (attribute.startsWith("has_trait")) {
            if (attribute.hasContext(1)) {
                Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(attribute.getContext(1));
                if (trait != null)
                    return new Element(getCitizen().hasTrait(trait))
                            .getAttribute(attribute.fulfill(1));
            }
        }

        // <--[tag]
        // @attribute <n@npc.has_trigger[<trigger>]>
        // @returns Element(Boolean)
        // @description
        // Returns whether the NPC has a specified trigger.
        // -->
        if (attribute.startsWith("has_trigger")
                && attribute.hasContext(1)) {
            if (!getCitizen().hasTrait(TriggerTrait.class))
                return Element.FALSE.getAttribute(attribute.fulfill(1));
            TriggerTrait trait = getCitizen().getTrait(TriggerTrait.class);
            return new Element(trait.hasTrigger(attribute.getContext(1)))
                    .getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.anchor.list>
        // @returns dList
        // @description
        // returns a list of anchor names currently assigned to the NPC.
        // -->
        if (attribute.startsWith("anchor.list")
                || attribute.startsWith("anchors.list")) {
            List<String> list = new ArrayList<String>();
            for (Anchor anchor : getCitizen().getTrait(Anchors.class).getAnchors())
                list.add(anchor.getName());
            return new dList(list).getAttribute(attribute.fulfill(2));
        }

        // <--[tag]
        // @attribute <n@npc.has_anchors>
        // @returns Element(Boolean)
        // @description
        // returns whether the NPC has anchors assigned.
        // -->
        if (attribute.startsWith("has_anchors")) {
            return (new Element(getCitizen().getTrait(Anchors.class).getAnchors().size() > 0))
                    .getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.anchor[<name>]>
        // @returns dLocation
        // @description
        // returns the location associated with the specified anchor, or null if it doesn't exist.
        // -->
        if (attribute.startsWith("anchor")) {
            if (attribute.hasContext(1)
                    && getCitizen().getTrait(Anchors.class).getAnchor(attribute.getContext(1)) != null)
                return new dLocation(getCitizen().getTrait(Anchors.class)
                        .getAnchor(attribute.getContext(1)).getLocation())
                        .getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.has_flag[<flag_name>]>
        // @returns Element(Boolean)
        // @description
        // returns true if the NPC has the specified flag, otherwise returns false.
        // -->
        if (attribute.startsWith("has_flag")) {
            String flag_name;
            if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
            else return null;
            return new Element(FlagManager.npcHasFlag(this, flag_name)).getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.flag[<flag_name>]>
        // @returns Flag dList
        // @description
        // returns the specified flag from the NPC.
        // -->
         if (attribute.startsWith("flag")) {
            String flag_name;
            if (attribute.hasContext(1)) flag_name = attribute.getContext(1);
            else return null;
            if (attribute.getAttribute(2).equalsIgnoreCase("is_expired")
                    || attribute.startsWith("isexpired"))
                return new Element(!FlagManager.npcHasFlag(this, flag_name))
                        .getAttribute(attribute.fulfill(2));
            if (attribute.getAttribute(2).equalsIgnoreCase("size") && !FlagManager.npcHasFlag(this, flag_name))
                return new Element(0).getAttribute(attribute.fulfill(2));
            if (FlagManager.npcHasFlag(this, flag_name))
                return new dList(DenizenAPI.getCurrentInstance().flagManager()
                        .getNPCFlag(getId(), flag_name))
                        .getAttribute(attribute.fulfill(1));
             return new Element(identify()).getAttribute(attribute);
        }

        // <--[tag]
        // @attribute <n@npc.list_flags[(regex:)<search>]>
        // @returns dList
        // @description
        // Returns a list of an NPC's flag names, with an optional search for
        // names containing a certain pattern.
        // -->
        if (attribute.startsWith("list_flags")) {
            dList allFlags = new dList(DenizenAPI.getCurrentInstance().flagManager().listNPCFlags(getId()));
            dList searchFlags = null;
            if (!allFlags.isEmpty() && attribute.hasContext(1)) {
                searchFlags = new dList();
                String search = attribute.getContext(1).toLowerCase();
                if (search.startsWith("regex:")) {
                    try {
                        Pattern pattern = Pattern.compile(search.substring(6));
                        for (String flag : allFlags)
                            if (pattern.matcher(flag).matches())
                                searchFlags.add(flag);
                    } catch (Exception e) {
                        dB.echoError(e);
                    }
                }
                else {
                    for (String flag : allFlags)
                        if (flag.toLowerCase().contains(search))
                            searchFlags.add(flag);
                }
            }
            return searchFlags == null ? allFlags.getAttribute(attribute.fulfill(1))
                    : searchFlags.getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.constant[<constant_name>]>
        // @returns Element
        // @description
        // returns the specified constant from the NPC.
        // -->
        if (attribute.startsWith("constant")) {
            if (attribute.hasContext(1)) {
                if (getCitizen().hasTrait(ConstantsTrait.class)
                    && getCitizen().getTrait(ConstantsTrait.class).getConstant(attribute.getContext(1)) != null) {
                    return new Element(getCitizen().getTrait(ConstantsTrait.class)
                    .getConstant(attribute.getContext(1))).getAttribute(attribute.fulfill(1));
                }
                else {
                    return null;
                }
            }
        }

        // <--[tag]
        // @attribute <n@npc.has_pose[<name>]>
        // @returns Element(Boolean)
        // @description
        // Returns true if the NPC has the specified pose, otherwise returns false.
        // -->
        if (attribute.startsWith("has_pose")) {
            if (attribute.hasContext(1))
                return new Element(getCitizen().getTrait(Poses.class).hasPose(attribute.getContext(1)))
                        .getAttribute(attribute.fulfill(1));
            else
                return null;
        }

        // <--[tag]
        // @attribute <n@npc.get_pose[<name>]>
        // @returns dLocation
        // @description
        // Returns the pose as a dLocation with x, y, and z set to 0, and the world set to the first
        // possible available world Bukkit knows about.
        // -->
        if (attribute.startsWith("get_pose")) {
            if (attribute.hasContext(1)) {
                Pose pose = getCitizen().getTrait(Poses.class).getPose(attribute.getContext(1));
                return new dLocation(org.bukkit.Bukkit.getWorlds().get(0), 0, 0 ,0, pose.getYaw(), pose.getPitch())
                        .getAttribute(attribute.fulfill(1));
            }
            else
                return null;
        }

        // <--[tag]
        // @attribute <n@npc.is_engaged>
        // @returns Element(Boolean)
        // @description
        // returns whether the NPC is currently engaged.
        // See <@link command Engage>
        // -->
        if (attribute.startsWith("engaged") || attribute.startsWith("is_engaged"))
            return new Element(isEngaged()).getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.id>
        // @returns Element(Number)
        // @description
        // returns the NPC's ID number.
        // -->
        if (attribute.startsWith("id"))
            return new Element(getId()).getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.owner>
        // @returns dPlayer/Element
        // @description
        // returns the owner of the NPC as a dPlayer if it's a player, otherwise as just the name.
        // -->
        if (attribute.startsWith("owner")) {
            if (dPlayer.matches(getOwner())) {
                return dPlayer.valueOf(getOwner()).getAttribute(attribute.fulfill(1));
            }
            else return new Element(getOwner()).getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.has_skin>
        // @returns Element
        // @description
        // returns whether the NPC has a custom skinskin.
        // -->
        if (attribute.startsWith("has_skin"))
            return new Element(getCitizen().data().has(NPC.PLAYER_SKIN_UUID_METADATA)).getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.skin>
        // @returns Element
        // @description
        // returns the NPC's custom skin, if any.
        // -->
        if (attribute.startsWith("skin")) {
            if (getCitizen().data().has(NPC.PLAYER_SKIN_UUID_METADATA))
                return new Element(getCitizen().data().get(NPC.PLAYER_SKIN_UUID_METADATA).toString()).getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.inventory>
        // @returns dInventory
        // @description
        // Returns the dInventory of the NPC.
        // -->
        if (attribute.startsWith("inventory"))
            return getDenizenInventory().getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.is_spawned>
        // @returns Element(Boolean)
        // @description
        // returns whether the NPC is spawned.
        // -->
        if (attribute.startsWith("is_spawned"))
            return new Element(isSpawned()).getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.is_protected>
        // @returns Element(Boolean)
        // @description
        // Returns whether the NPC is protected.
        // -->
        if (attribute.startsWith("is_protected"))
            return new Element(getCitizen().isProtected()).getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.lookclose>
        // @returns Element(Boolean)
        // @description
        // Returns the NPC's "lookclose" value.
        // -->
        if (attribute.startsWith("lookclose")) {
            NPC citizen = 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.getTrait(LookClose.class).toString();
                lookclose = lookclose.substring(10, lookclose.length() - 1);
                return new Element(Boolean.valueOf(lookclose)).getAttribute(attribute.fulfill(1));
            }
            return Element.FALSE.getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.location.previous_location>
        // @returns dLocation
        // @description
        // returns the NPC's previous navigated location.
        // -->
        if (attribute.startsWith("location.previous_location"))
            return (NPCTags.previousLocations.containsKey(getId())
                    ? NPCTags.previousLocations.get(getId()).getAttribute(attribute.fulfill(2))
                    : null);

        // <--[tag]
        // @attribute <n@npc.teleport_on_stuck>
        // @returns dLocation
        // @mechanism dNPC.teleport_on_stuck
        // @description
        // returns whether the NPC teleports when it is stuck.
        // -->
        if (attribute.startsWith("teleport_on_stuck"))
            return new Element(getNavigator().getDefaultParameters().stuckAction() == TeleportStuckAction.INSTANCE)
                    .getAttribute(attribute.fulfill(1));

        // <--[tag]
        // @attribute <n@npc.has_script>
        // @returns Element(Boolean)
        // @description
        // Returns true if the NPC has an assignment script.
        // -->
        if (attribute.startsWith("has_script")) {
            NPC citizen = getCitizen();
            return new Element(citizen.hasTrait(AssignmentTrait.class) && citizen.getTrait(AssignmentTrait.class).hasAssignment())
                    .getAttribute(attribute.fulfill(1));
        }

        // <--[tag]
        // @attribute <n@npc.script>
        // @returns dScript
        // @description
        // returns the NPC's assigned script.
        // -->
        if (attribute.startsWith("script")) {
            NPC citizen = getCitizen();
            if (!citizen.hasTrait(AssignmentTrait.class) || !citizen.getTrait(AssignmentTrait.class).hasAssignment()) {
                return null;
            }
            else {
                return new dScript(citizen.getTrait(AssignmentTrait.class).getAssignment().getName())
                    .getAttribute(attribute.fulfill(1));
            }
        }

        // <--[tag]
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

        return new dEntity(getPlayerEntity());
    }

    public dNPC getSelectedNPC() {
        if (Depends.citizens != null) {
            NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(getPlayerEntity());
            if (npc != null)
                return dNPC.mirrorCitizensNPC(npc);
        }
        return null;
    }
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

            return;
        }

        dB.echoError(event.getAttributes().getScriptEntry().getResidingQueue(), "constant: tags are deprecated! Use <npc.constant[]>!");

        NPC npc = null;
        if (event.getType() != null && event.getType().matches("\\d+"))
            npc = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(event.getType()));
        else if (event.getNPC() != null)
            npc = event.getNPC().getCitizen();

        if (npc == null) {
            dB.echoError("Constant tag '" + event.raw_tag + " does not contain a valid NPC! " +
                    "Has the NPC been removed, or is there no NPC list available? " +
                    "Replacement has been aborted...");
            return;
        }

        Attribute attribute = event.getAttributes();

        if (npc.hasTrait(ConstantsTrait.class)
                && npc.getTrait(ConstantsTrait.class).getConstant(event.getValue()) != null) {
            event.setReplaced(new Element(npc.getTrait(ConstantsTrait.class)
                    .getConstant(event.getValue())).getAttribute(attribute.fulfill(1)));
        }

    }
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

                    npc = dNPC.fromEntity(pl);
                else
                    player = dPlayer.mirrorBukkitPlayer(pl);
            }
            if (Depends.citizens != null && npc == null) {
                NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(target);
                if (citizen != null)
                    npc = dNPC.mirrorCitizensNPC(citizen);
            }
            // <permission> is built into Bukkit... let's keep it here
            for (String line : TagManager.tag(player, npc, permissionMessage.replace("<permission>", getPermission()))
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

        }
        else {
            context.put("server", Element.TRUE);
        }
        if (Depends.citizens != null && npc == null) {
            NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
            if (citizen != null)
                npc = dNPC.mirrorCitizensNPC(citizen);
        }
        script.runCommandScript(player, npc, context);
        return true;
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

        }
        else {
            context.put("server", Element.TRUE);
        }
        if (Depends.citizens != null && npc == null) {
            NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
            if (citizen != null)
                npc = dNPC.mirrorCitizensNPC(citizen);
        }
        return script.runTabCompleteProcedure(player, npc, context);
    }
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

        // @returns dNPC
        // @description
        // Returns the server's currently selected NPC.
        // -->
        if (attribute.startsWith("selected_npc")) {
            NPC npc = ((Citizens) Bukkit.getPluginManager().getPlugin("Citizens"))
                    .getNPCSelector().getSelected(Bukkit.getConsoleSender());
            if (npc == null)
                return;
            else
                event.setReplaced(new dNPC(npc).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.get_npcs_named[<name>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of NPCs with a certain name.
        // -->
        if (attribute.startsWith("get_npcs_named") && Depends.citizens != null && attribute.hasContext(1)) {
            ArrayList<dNPC> npcs = new ArrayList<dNPC>();
            for (NPC npc : CitizensAPI.getNPCRegistry())
                if (npc.getName().equalsIgnoreCase(attribute.getContext(1)))
                    npcs.add(dNPC.mirrorCitizensNPC(npc));
            event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.has_file[<name>]>
        // @returns Element(Boolean)
        // @description
        // Returns true if the specified file exists. The starting path is /plugins/Denizen.
        // -->
        if (attribute.startsWith("has_file") && attribute.hasContext(1)) {
            event.setReplaced(new Element(new File(DenizenAPI.getCurrentInstance().getDataFolder(),
                    attribute.getContext(1)).exists()).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.denizen_version>
        // @returns Element
        // @description
        // Returns the version of Denizen currently being used.
        // -->
        if (attribute.startsWith("denizen_version")) {
            event.setReplaced(new Element(DenizenAPI.getCurrentInstance().getDescription().getVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.bukkit_version>
        // @returns Element
        // @description
        // Returns the version of Bukkit currently being used.
        // -->
        if (attribute.startsWith("bukkit_version")) {
            event.setReplaced(new Element(Bukkit.getBukkitVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.version>
        // @returns Element
        // @description
        // Returns the version string of the server.
        // -->
        if (attribute.startsWith("version")) {
            event.setReplaced(new Element(Bukkit.getServer().getVersion())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.java_version>
        // @returns Element
        // @description
        // Returns the current Java version of the server.
        // -->
        if (attribute.startsWith("java_version")) {
            event.setReplaced(new Element(System.getProperty("java.version"))
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.max_players>
        // @returns Element(Number)
        // @description
        // Returns the maximum number of players allowed on the server.
        // -->
        if (attribute.startsWith("max_players")) {
            event.setReplaced(new Element(Bukkit.getServer().getMaxPlayers())
                    .getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_sql_connections>
        // @returns dList
        // @description
        // Returns a list of all SQL connections opened by <@link command sql>.
        // -->
        if (attribute.startsWith("list_sql_connections")) {
            dList list = new dList();
            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) {
                    dB.echoError(attribute.getScriptEntry().getResidingQueue(), e);
                }
            }
            event.setReplaced(list.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_permission_groups>
        // @returns dList
        // @description
        // Returns a list of all permission groups on the server.
        // -->
        if (attribute.startsWith("list_permission_groups")) {
            if (Depends.permissions == null) {
                dB.echoError("No permission system loaded! Have you installed Vault and a compatible permissions plugin?");
                return;
            }
            event.setReplaced(new dList(Arrays.asList(Depends.permissions.getGroups())).getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_plugin_names>
        // @returns dList
        // @description
        // Gets a list of currently enabled plugin names from the server.
        // -->
        if (attribute.startsWith("list_plugin_names")) {
            dList plugins = new dList();
            for (Plugin plugin : Bukkit.getServer().getPluginManager().getPlugins())
                plugins.add(plugin.getName());
            event.setReplaced(plugins.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.list_scripts>
        // @returns dList(dScript)
        // @description
        // Gets a list of all scripts currently loaded into Denizen.
        // -->
        if (attribute.startsWith("list_scripts")) {
            dList scripts = new dList();
            for (String str : ScriptRegistry._getScriptNames())
                scripts.add("s@" + str);
            event.setReplaced(scripts.getAttribute(attribute.fulfill(1)));
            return;
        }

        // <--[tag]
        // @attribute <server.match_player[<name>]>
        // @returns dPlayer
        // @description
        // Returns the online player that best matches the input name.
        // EG, in a group of 'bo', 'bob', and 'bobby'... input 'bob' returns p@bob,
        // input 'bobb' returns p@bobby, and input 'b' returns p@bo.
        // -->
        if (attribute.startsWith("match_player") && attribute.hasContext(1)) {
            Player matchPlayer = null;
            String matchInput = attribute.getContext(1).toLowerCase();
            for (Player player: Bukkit.getOnlinePlayers()) {
                if (player.getName().toLowerCase().equals(matchInput)) {
                    matchPlayer = player;
                    break;
                }
                else if (player.getName().toLowerCase().contains(matchInput) && matchPlayer == null) {
                    matchPlayer = player;
                }
            }

            if (matchPlayer == null) {
                event.setReplaced("null");
            } else {
                event.setReplaced(new dPlayer(matchPlayer).getAttribute(attribute.fulfill(1)));
            }

            return;
        }

        // <--[tag]
        // @attribute <server.get_npcs_assigned[<assignment_script>]>
        // @returns dList(dNPC)
        // @description
        // Returns a list of all NPCs assigned to a specified script.
        // -->
        if (attribute.startsWith("get_npcs_assigned") && Depends.citizens != null
                && attribute.hasContext(1)) {
            dScript script = dScript.valueOf(attribute.getContext(1));
            if (script == null || !(script.getContainer() instanceof AssignmentScriptContainer)) {
                dB.echoError("Invalid script specified.");
            }
            else {
                ArrayList<dNPC> npcs = new ArrayList<dNPC>();
                for (NPC npc : CitizensAPI.getNPCRegistry()) {
                    if (npc.hasTrait(AssignmentTrait.class) && npc.getTrait(AssignmentTrait.class).hasAssignment()
                            && npc.getTrait(AssignmentTrait.class).getAssignment().getName().equalsIgnoreCase(script.getName()))
                        npcs.add(dNPC.mirrorCitizensNPC(npc));
                }
                event.setReplaced(new dList(npcs).getAttribute(attribute.fulfill(1)));
                return;
            }
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

    @EventHandler
    public void anchorTags(ReplaceableTagEvent event) {
        if (!event.matches("ANCHOR")) return;

        dB.echoError(event.getAttributes().getScriptEntry().getResidingQueue(), "anchor: tags are deprecated! Use <npc.anchor[]>!");
        NPC npc = null;
        if (event.getType() != null
                && event.getType().matches("\\d+"))
            npc = CitizensAPI.getNPCRegistry().getById(Integer.valueOf(event.getType()));
        else if (event.getNPC() != null)
            npc = event.getNPC().getCitizen();
        if (npc == null) return;

        if (npc.getTrait(Anchors.class).getAnchor(event.getValue()) != null) {
            Location anchor = npc.getTrait(Anchors.class).getAnchor(event.getValue()).getLocation();
            event.setReplaced(anchor.getX() + "," + anchor.getY() + "," + anchor.getZ() + "," + anchor.getWorld().getName());
        }
    }
View Full Code Here

Examples of net.citizensnpcs.api.npc.NPC

  public SpoutPlayer _sp;

  public CitizensTwoSupport(int id)
  {
    SpoutPlayer sp = null;
    NPC npc = CitizensAPI.getNPCRegistry().getById(id);
    if ((npc != null) &&
      (npc.getBukkitEntity() != null) &&
      ((npc.getBukkitEntity() instanceof LivingEntity))) {
      sp = SpoutManager.getPlayer((Player)npc.getBukkitEntity());
    }

    this._sp = sp;
  }
View Full Code Here

Examples of org.moparscape.msc.gs.model.Npc

    int damage = Formulae.calcRangeHit(owner.getCurStat(4),
        owner.getRangePoints(), affectedMob.getArmourPoints(), arrowID);

    if (affectedMob instanceof Npc) {
      Npc npc = (Npc) affectedMob;
      if (damage > 1 && npc.getID() == 477)
        damage = damage / 2;
    }
    if (!Formulae.looseArrow(damage)) {
      Item arrows = getArrows(arrowID);
      if (arrows == null) {
        world.registerItem(new Item(arrowID, affectedMob.getX(),
            affectedMob.getY(), 1, owner));
      } else {
        arrows.setAmount(arrows.getAmount() + 1);
      }
    }
    if (firstRun) {
      firstRun = false;
      if (affectedMob instanceof Player) {
        if (((Player) affectedMob).isSleeping()) {
          ((Player) affectedMob).getActionSender().sendWakeUp(false);
        }
        ((Player) affectedMob).getActionSender().sendMessage(
            owner.getUsername() + " is shooting at you!");
      }
    }
    if (affectedMob instanceof Npc) {
      Npc npc = (Npc) affectedMob;
      npc.getSyndicate().addDamage(owner, damage, Damage.RANGE_DAMAGE);
    }
    Projectile projectile = new Projectile(owner, affectedMob, 2);

    ArrayList<Player> playersToInform = new ArrayList<Player>();
    playersToInform.addAll(owner.getViewArea().getPlayersInView());
    playersToInform.addAll(affectedMob.getViewArea().getPlayersInView());
    for (Player p : playersToInform) {
      p.informOfProjectile(projectile);
    }

    if (GameEngine.getTime() - affectedMob.lastTimeShot > 500) {
      affectedMob.lastTimeShot = GameEngine.getTime();
      affectedMob.setLastDamage(damage);
      int newHp = affectedMob.getHits() - damage;
      affectedMob.setHits(newHp);

      for (Player p : playersToInform) {
        p.informOfModifiedHits(affectedMob);
      }
      if (affectedMob instanceof Player) {
        Player affectedPlayer = (Player) affectedMob;
        affectedPlayer.getActionSender().sendStat(3);
      }
      owner.getActionSender().sendSound("shoot");
      owner.setArrowFired();
      if (newHp <= 0) {
        affectedMob.killedBy(owner, false);
        owner.resetRange();
        if (owner instanceof Player) {
          if (affectedMob instanceof Npc) {
            Npc npc = (Npc) affectedMob;

            npc.getSyndicate().distributeExp(npc);
          }
        }
      } else {
        if (owner instanceof Player && affectedMob instanceof Npc) // We're
                                      // ranging
                                      // an
                                      // NPC,
                                      // so
                                      // make
                                      // it
                                      // chase
                                      // the
                                      // player.
        {
          final Npc npc = (Npc) affectedMob;
          final Player player = (Player) owner;

          if (npc.isBusy() || npc.getChasing() != null)
            return;

          npc.resetPath();
          npc.setChasing(player);

          // Radius is 0 to prevent wallhacking by NPCs. Easiest
          // method I
          // can come up with for now.
          Instance.getDelayedEventHandler().add(
              new WalkMobToMobEvent(affectedMob, owner, 0) {
                public void arrived() {
                  if (affectedMob.isBusy() || player.isBusy()) {
                    npc.setChasing(null);
                    this.stop();
                    return;
                  }

                  npc.resetPath();
                  player.setBusy(true);
                  player.resetPath();
                  player.resetAll();

                  player.setStatus(Action.FIGHTING_MOB);
                  player.getActionSender().sendSound(
                      "underattack");
                  player.getActionSender().sendMessage(
                      "You are under attack!");

                  npc.setLocation(player.getLocation(), true);
                  for (Player p : npc.getViewArea()
                      .getPlayersInView())
                    p.removeWatchedNpc(npc);

                  player.setBusy(true);
                  player.setSprite(9);
                  player.setOpponent(npc);
                  player.setCombatTimer();

                  npc.setBusy(true);
                  npc.setSprite(8);
                  npc.setOpponent(player);
                  npc.setCombatTimer();

                  npc.setChasing(null);

                  FightEvent fighting = new FightEvent(
                      player, npc, true);
                  fighting.setLastRun(0);
                  Instance.getDelayedEventHandler().add(
                      fighting);
                  this.stop();
                }

                public void failed() {
                  npc.setChasing(null);
                }
              });
          // target is still alive? is still around?
          if (!npc.isRemoved() || owner.withinRange(npc)) {
            return;
          }
          this.stop();
        }
      }
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.