Search in sources :

Example 11 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class dNPC method matches.

public static boolean matches(String string) {
    // If using object notation, assume it's valid
    if (CoreUtilities.toLowerCase(string).startsWith("n@")) {
        return true;
    }
    // Otherwise, let's do checks
    string = string.toUpperCase().replace("N@", "");
    NPC npc;
    if (aH.matchesInteger(string)) {
        npc = CitizensAPI.getNPCRegistry().getById(aH.getIntegerFrom(string));
        if (npc != null) {
            return true;
        }
    } else {
        for (NPC test : CitizensAPI.getNPCRegistry()) {
            if (test.getName().equalsIgnoreCase(string)) {
                return true;
            }
        }
    }
    return false;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC)

Example 12 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class dNPCRegistry method onRemove.

// <--[action]
// @Actions
// remove
// @Triggers when the NPC is removed.
//
// @Context
// None
// -->
/**
     * Removes an NPC from the Registry when removed from Citizens.
     *
     * @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());
    }
    FlagManager.clearNPCFlags(npc.getId());
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) EventHandler(org.bukkit.event.EventHandler)

Example 13 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class AbstractTrigger method getActiveNPCsWithinRangeWithTrigger.

/**
     * This method will find all NPCs within a certain range of a location that
     * have a trigger, and the trigger is enabled.
     *
     * @param location the location to search around
     * @param maxRange how far to search
     * @return The Set of NPCs that are
     */
// TODO: Delete?
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;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC)

Example 14 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class AnchorTags method anchorTags.

@TagManager.TagEvents
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 (((BukkitTagContext) event.getContext()).npc != null) {
        npc = ((BukkitTagContext) event.getContext()).npc.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());
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) Location(org.bukkit.Location)

Example 15 with NPC

use of net.citizensnpcs.api.npc.NPC in project Denizen-For-Bukkit by DenizenScript.

the class DenizenCommand method execute.

@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
    if (!testPermission(commandSender)) {
        return true;
    }
    Map<String, dObject> context = new HashMap<String, dObject>();
    String raw_args = "";
    if (arguments.length > 0) {
        StringBuilder rawArgsBuilder = new StringBuilder();
        for (String arg : arguments) {
            rawArgsBuilder.append(arg).append(' ');
        }
        raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
    }
    List<String> args = Arrays.asList(aH.buildArgs(raw_args));
    context.put("args", new dList(args));
    context.put("raw_args", new Element(raw_args));
    context.put("alias", new Element(commandLabel));
    dPlayer player = null;
    dNPC npc = null;
    if (commandSender instanceof Player) {
        Player pl = (Player) commandSender;
        if (dEntity.isCitizensNPC(pl)) {
            npc = dNPC.fromEntity(pl);
        } else {
            player = dPlayer.mirrorBukkitPlayer(pl);
        }
        context.put("server", Element.FALSE);
    } 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;
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) HashMap(java.util.HashMap) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer)

Aggregations

NPC (net.citizensnpcs.api.npc.NPC)18 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)5 Element (net.aufdemrand.denizencore.objects.Element)5 Player (org.bukkit.entity.Player)4 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)3 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)3 Location (org.bukkit.Location)3 Zombie (org.bukkit.entity.Zombie)3 HashMap (java.util.HashMap)2 Pattern (java.util.regex.Pattern)2 FlagManager (net.aufdemrand.denizen.flags.FlagManager)2 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 Attribute (net.aufdemrand.denizencore.tags.Attribute)2 Age (net.citizensnpcs.trait.Age)2 File (java.io.File)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 UUID (java.util.UUID)1