コード例 #1
0
ファイル: AnchorCommand.java プロジェクト: GoDieBawb/Denizen
  @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()));
    }
  }