@Override
 public ScriptEntryData getScriptEntryData() {
   if (entity != null) {
     return new BukkitScriptEntryData(
         entity.isPlayer() ? entity.getDenizenPlayer() : null,
         entity.isCitizensNPC() ? entity.getDenizenNPC() : null);
   }
   return new BukkitScriptEntryData(null, null);
 }
Esempio n. 2
0
  @SuppressWarnings("unchecked")
  @Override
  public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {

    // Get objects
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    dEntity target = (dEntity) scriptEntry.getObject("target");
    boolean cancel = scriptEntry.hasObject("cancel");

    // Report to dB
    dB.report(
        scriptEntry,
        getName(),
        (cancel ? aH.debugObj("cancel", "true") : "")
            + aH.debugObj("entities", entities.toString())
            + (target != null ? aH.debugObj("target", target) : ""));

    // Go through all the entities and make them either attack
    // the target or stop attacking

    for (dEntity entity : entities) {
      if (entity.isCitizensNPC()) {
        Navigator nav = entity.getDenizenNPC().getCitizen().getNavigator();

        if (!cancel) {
          nav.setTarget(target.getBukkitEntity(), true);
        } else {
          // Only cancel navigation if the NPC is attacking something
          if (nav.isNavigating()
              && nav.getTargetType().equals(TargetType.ENTITY)
              && nav.getEntityTarget().isAggressive()) {

            nav.cancelNavigation();
          }
        }
      } else {
        if (!cancel) {
          entity.target(target.getLivingEntity());
        } else {
          entity.target(null);
        }
      }
    }
  }