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;
}
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());
}
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;
}
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());
}
}
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;
}
Aggregations