Beispiel #1
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;
          }
        }
    }
  }