Beispiel #1
0
  @Override
  public void execute(String sender, String[] args) {
    if (!Account.isBankAccount(args[0])
        && Common.getInstance().getAccountManager().exist(args[0])) {
      if (Tools.isValidDouble(args[1])) {
        double amount = Double.parseDouble(args[1]);
        boolean hasEnough = false;
        Currency currency = Common.getInstance().getCurrencyManager().getDefaultCurrency();
        if (args.length > 2) {
          if (Common.getInstance().getCurrencyManager().getCurrency(args[2]) != null) {
            currency = Common.getInstance().getCurrencyManager().getCurrency(args[2]);
          } else {
            Common.getInstance()
                .getServerCaller()
                .sendMessage(
                    sender,
                    Common.getInstance().getLanguageManager().getString("currency_not_exist"));
            return;
          }
        }
        hasEnough =
            Common.getInstance()
                .getAccountManager()
                .getAccount(sender)
                .hasEnough(
                    amount,
                    Common.getInstance()
                        .getAccountManager()
                        .getAccount(sender)
                        .getWorldGroupOfPlayerCurrentlyIn(),
                    currency.getName());

        if (hasEnough) {
          Common.getInstance()
              .getAccountManager()
              .getAccount(sender)
              .withdraw(
                  amount,
                  Common.getInstance()
                      .getAccountManager()
                      .getAccount(sender)
                      .getWorldGroupOfPlayerCurrentlyIn(),
                  currency.getName());
          Common.getInstance()
              .getAccountManager()
              .getAccount(args[0])
              .deposit(
                  amount,
                  Common.getInstance()
                      .getAccountManager()
                      .getAccount(sender)
                      .getWorldGroupOfPlayerCurrentlyIn(),
                  currency.getName());
          Common.getInstance()
              .getServerCaller()
              .sendMessage(
                  sender,
                  String.format(
                      Common.getInstance().getLanguageManager().getString("money_pay_sent"),
                      Common.getInstance().format(null, currency, amount),
                      args[0]));
          if (Common.getInstance().getServerCaller().isOnline(args[0])) {
            Common.getInstance()
                .getServerCaller()
                .sendMessage(
                    args[0],
                    String.format(
                        Common.getInstance().getLanguageManager().getString("money_pay_received"),
                        Common.getInstance().format(null, currency, amount),
                        sender));
          }
        } else {
          Common.getInstance()
              .getServerCaller()
              .sendMessage(
                  sender, Common.getInstance().getLanguageManager().getString("not_enough_money"));
        }
      } else {
        Common.getInstance()
            .getServerCaller()
            .sendMessage(
                sender, Common.getInstance().getLanguageManager().getString("invalid_amount"));
      }
    } else {
      Common.getInstance()
          .getServerCaller()
          .sendMessage(
              sender, Common.getInstance().getLanguageManager().getString("player_not_exist"));
    }
  }
Beispiel #2
0
  @Override
  public void execute(String sender, String[] args) {
    if (!Account.isBankAccount(args[0])
        && Common.getInstance().getAccountManager().exist(args[0])) {
      if (Tools.isValidDouble(args[1])) {
        double amount = Double.parseDouble(args[1]);
        Currency currency =
            Common.getInstance()
                .getCurrencyManager()
                .getCurrency(CurrencyManager.defaultCurrencyID);

        if (args.length > 2) {
          if (Common.getInstance().getCurrencyManager().getCurrency(args[2]) != null) {
            currency = Common.getInstance().getCurrencyManager().getCurrency(args[2]);
          } else {
            Common.getInstance()
                .getServerCaller()
                .sendMessage(
                    sender,
                    Common.getInstance().getLanguageManager().getString("currency_not_exist"));
            return;
          }
        }
        String worldName = "any";
        if (args.length > 3) {
          if (Common.getInstance().getConfigurationManager().isMultiWorld()) {
            if (!Common.getInstance().getServerCaller().worldExist(args[3])) {
              Common.getInstance()
                  .getServerCaller()
                  .sendMessage(
                      sender,
                      Common.getInstance().getLanguageManager().getString("world_not_exist"));
              return;
            }
            worldName = args[3];
          }
        } else {
          if (!Common.getInstance().getServerCaller().isOnline(sender)) {
            worldName = Common.getInstance().getServerCaller().getDefaultWorld();
          } else {
            worldName =
                Common.getInstance()
                    .getAccountManager()
                    .getAccount(sender)
                    .getWorldPlayerCurrentlyIn();
          }
        }

        Common.getInstance()
            .getAccountManager()
            .getAccount(args[0])
            .set(amount, worldName, currency.getName());
        Common.getInstance()
            .getServerCaller()
            .sendMessage(
                sender,
                String.format(
                    Common.getInstance().getLanguageManager().getString("money_set"),
                    args[0],
                    Common.getInstance().format(worldName, currency, amount)));
        if (Common.getInstance().getServerCaller().isOnline(args[0])) {
          Common.getInstance()
              .getServerCaller()
              .sendMessage(
                  args[0],
                  String.format(
                      Common.getInstance().getLanguageManager().getString("money_set_other"),
                      Common.getInstance().format(worldName, currency, amount),
                      sender));
        }
      } else {
        Common.getInstance()
            .getServerCaller()
            .sendMessage(
                sender, Common.getInstance().getLanguageManager().getString("invalid_amount"));
      }
    } else {
      Common.getInstance()
          .getServerCaller()
          .sendMessage(
              sender, Common.getInstance().getLanguageManager().getString("player_not_exist"));
    }
  }