Exemplo n.º 1
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Script script = (Script) scriptEntry.getObject("script");
    Duration duration = (Duration) scriptEntry.getObject("duration");
    Type type = (Type) scriptEntry.getObject("type");

    // Report to dB
    dB.report(
        getName(),
        aH.debugObj("Type", type.toString())
            + script.debug()
            + (type == Type.PLAYER ? aH.debugObj("Player", scriptEntry.getPlayer().getName()) : "")
            + duration.debug());

    // Perform cooldown
    if (type == Type.PLAYER)
      setCooldown(
          ((OfflinePlayer) scriptEntry.getObject("player")).getName(),
          duration.getSecondsAsInt(),
          script.getName(),
          false);
    else if (type == Type.GLOBAL)
      setCooldown(null, duration.getSecondsAsInt(), script.getName(), true);
  }
Exemplo n.º 2
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Get objects
    Action action = (Action) scriptEntry.getObject("action");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element range = (Element) scriptEntry.getObject("range");
    Element id = (Element) scriptEntry.getObject("id");

    // Report to dB
    dB.report(
        scriptEntry,
        getName(),
        aH.debugObj("NPC", scriptEntry.getNPC().toString())
            + action.name()
            + id.debug()
            + (location != null ? location.debug() : "")
            + (range != null ? range.debug() : ""));

    dNPC npc = scriptEntry.getNPC();

    switch (action) {
      case ADD:
        npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
        return;

      case ASSUME:
        npc.getEntity()
            .teleport(
                npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation());
        return;

      case WALKNEAR:
        npc.getNavigator()
            .setTarget(
                Utilities.getWalkableLocationNear(
                    npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation(),
                    range.asInt()));
        return;

      case WALKTO:
        npc.getNavigator()
            .setTarget(
                npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation());
        return;

      case REMOVE:
        npc.getCitizen()
            .getTrait(Anchors.class)
            .removeAnchor(npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()));
    }
  }
Exemplo n.º 3
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Get objects from ScriptEntry
    dItem item = (dItem) scriptEntry.getObject("item");
    Duration duration = (Duration) scriptEntry.getObject("duration");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Action action = (Action) scriptEntry.getObject("action");

    // Report to dB
    dB.report(
        getName(),
        aH.debugObj("Action", action.toString())
            + item.debug()
            + (duration != null ? duration.debug() : "")
            + location.debug());

    if (action == Action.PLACE) {

      int ticks = Integer.MAX_VALUE;
      if (duration != null) ticks = duration.getTicksAsInt();

      // Display the item
      if (displayed.containsKey(location.dScriptArgValue())) {
        displayed.get(location.dScriptArgValue()).remove();
        displayed.remove(location.dScriptArgValue());
      }

      // Remember the item entity
      displayed.put(
          location.dScriptArgValue(),
          location
              .getBlock()
              .getLocation()
              .add(0, 1, 0)
              .getWorld()
              .dropItem(location, item.getItemStack()));
      displayed.get(location.dScriptArgValue()).setPickupDelay(Integer.MAX_VALUE);
      displayed.get(location.dScriptArgValue()).setTicksLived(ticks);
    }

    // Remove the item
    else if (action == Action.REMOVE) {
      if (displayed.containsKey(location.dScriptArgValue())) {
        displayed.get(location.dScriptArgValue()).remove();
        displayed.remove(location.dScriptArgValue());
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Report!
    dB.report(
        scriptEntry,
        getName(),
        scriptEntry.getElement("outcome").debug() + scriptEntry.getElement("passively").debug());

    // Fetch
    String outcome = scriptEntry.getElement("outcome").asString();
    Boolean passively = scriptEntry.getElement("passively").asBoolean();

    Long uniqueId = (Long) scriptEntry.getObject("reqId");
    if (uniqueId == null) {
      dB.echoError("Cannot use determine in this queue!");
      return;
    }

    if (outcomes.containsKey(uniqueId)) {
      dB.echoError("This queue already has a determination!");
      return;
    }

    outcomes.put(uniqueId, outcome);

    if (!passively)
      // Stop the queue by clearing the remainder of it.
      scriptEntry.getResidingQueue().clear();
  }
Exemplo n.º 5
0
  private void doCommand(ScriptEntry scriptEntry, String mapName) {
    TreeMap<Integer, ArrayList<String>> commandMap =
        (TreeMap<Integer, ArrayList<String>>) scriptEntry.getObject(mapName);

    if (commandMap == null || commandMap.size() == 0) return;

    List<ScriptEntry> entries = new ArrayList<ScriptEntry>();

    for (Map.Entry<Integer, ArrayList<String>> pairs : commandMap.entrySet()) {
      ArrayList<String> commandArray = pairs.getValue();
      String command = commandArray.get(0);
      commandArray.remove(0);
      String[] arguments = commandArray.toArray(new String[commandArray.size()]);

      try {
        ScriptEntry entry =
            new ScriptEntry(
                    command,
                    arguments,
                    (scriptEntry.getScript() == null
                        ? null
                        : scriptEntry.getScript().getContainer()))
                .setPlayer(scriptEntry.getPlayer())
                .setNPC(scriptEntry.getNPC())
                .setInstant(true)
                .addObject("reqId", scriptEntry.getObject("reqId"));

        entries.add(entry);

      } catch (ScriptEntryCreationException e) {
        dB.echoError("There has been a problem running the Command. Check syntax.");
        dB.echoError(e);
      }
    }

    // Put tracked objects into new script entries.
    for (String tracked_object : scriptEntry.tracked_objects) {
      ScriptBuilder.addObjectToEntries(
          entries, tracked_object, scriptEntry.getObject(tracked_object));
    }

    scriptEntry.getResidingQueue().injectEntries(entries, 0);
  }
Exemplo n.º 6
0
  @Override
  public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

    // Parse Arguments
    for (String arg : scriptEntry.getArguments()) {
      if (aH.matchesState(arg))
        scriptEntry.addObject("state", Action.valueOf(aH.getStringFrom(arg).toUpperCase()));
      else if (aH.matchesArg("NPC, PLAYER", arg))
        scriptEntry.addObject("target", Target.valueOf(aH.getStringFrom(arg).toUpperCase()));
      else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
    }

    if (scriptEntry.getObject("state") == null)
      throw new InvalidArgumentsException("Must specify a state action!");

    if (scriptEntry.getObject("target") == null)
      throw new InvalidArgumentsException("Must specify a target!");

    if ((scriptEntry.getObject("target") == Target.NPC && scriptEntry.getNPC() == null)
        || (scriptEntry.getObject("target") == Target.PLAYER && scriptEntry.getPlayer() == null))
      throw new InvalidArgumentsException("NPC not found!");
  }
Exemplo n.º 7
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Grab comparables from the ScriptEntry
    List<Comparable> comparables = (List<Comparable>) scriptEntry.getObject("comparables");

    int counter = 1;

    // Evaluate comparables
    for (Comparable com : comparables) {
      com.determineOutcome();

      // Show outcome of Comparable
      dB.echoDebug(
          scriptEntry,
          ChatColor.YELLOW + "Comparable " + counter + ": " + ChatColor.WHITE + com.toString());
      counter++;
    }

    // Compare outcomes

    int ormet = 0;
    for (Comparable comparable : comparables) {
      if (comparable.bridge == Comparable.Bridge.OR) if (comparable.outcome) ormet++;
    }

    int andcount = 0;
    int andmet = 0;
    for (Comparable comparable : comparables) {
      if (comparable.bridge == Comparable.Bridge.AND) {
        if (comparable.outcome) andmet++;
        andcount++;
      }
    }

    boolean do_then;

    if (comparables.size() > 1) {
      do_then = (ormet > 0) || (andcount == andmet && comparables.get(0).outcome == true);
    } else do_then = comparables.get(0).outcome;

    // Determine outcome -- then, or else?
    if (do_then) {
      // dB.log("then: " + scriptEntry.getObject("then-outcome").toString());
      doCommand(scriptEntry, "then-outcome");
    } else {
      // dB.log("else: " + scriptEntry.getObject("else-outcome").toString());
      doCommand(scriptEntry, "else-outcome");
    }
  }
Exemplo n.º 8
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Action action = (Action) scriptEntry.getObject("state");
    Target target = (Target) scriptEntry.getObject("target");

    // Report to dB
    dB.report(
        getName(),
        aH.debugObj("Toggle", action.name())
            + aH.debugObj(
                "Target",
                target == Target.NPC
                    ? scriptEntry.getNPC().toString()
                    : scriptEntry.getPlayer().getName()));

    switch (target) {
      case NPC:
        if (!scriptEntry.getNPC().getCitizen().hasTrait(InvisibleTrait.class))
          scriptEntry.getNPC().getCitizen().addTrait(InvisibleTrait.class);
        InvisibleTrait trait = scriptEntry.getNPC().getCitizen().getTrait(InvisibleTrait.class);

        switch (action) {
          case FALSE:
            trait.setInvisible(false);
            break;

          case TRUE:
            trait.setInvisible(true);
            break;

          case TOGGLE:
            trait.toggle();
            break;
        }

        break;

      case PLAYER:
        if (scriptEntry.getPlayer() != null) {

          Player player = scriptEntry.getPlayer().getPlayerEntity();
          PotionEffect invis =
              new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1);

          switch (action) {
            case FALSE:
              player.removePotionEffect(PotionEffectType.INVISIBILITY);
              break;

            case TRUE:
              invis.apply(player);
              break;

            case TOGGLE:
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
                player.removePotionEffect(PotionEffectType.INVISIBILITY);
              else invis.apply(player);

              break;
          }
        }
    }
  }