コード例 #1
0
ファイル: RACraftConomy.java プロジェクト: fromgate/ReActions
 public static double getBalance(String accountName, String currencyName, String worldName) {
   if (!enabled) return 0;
   Currency currency = craftconomy.getCurrencyManager().getCurrency(currencyName);
   if (currency == null) craftconomy.getCurrencyManager().getDefaultCurrency();
   Account account = getAccount(accountName);
   String world = getWorldName(worldName);
   return account.getBalance(world, currency.getName());
 }
コード例 #2
0
ファイル: RACraftConomy.java プロジェクト: fromgate/ReActions
 public static boolean hasAmount(
     String accountName, double amount, String currencyName, String worldName) {
   if (!enabled) return false;
   Account account = getAccount(accountName);
   if (account == null) return false;
   if (account.hasInfiniteMoney()) return true;
   Currency currency = craftconomy.getCurrencyManager().getCurrency(currencyName);
   if (currency == null) currency = craftconomy.getCurrencyManager().getDefaultCurrency();
   return getAccount(accountName).hasEnough(amount, getWorldName(worldName), currency.getName());
 }
コード例 #3
0
ファイル: RACraftConomy.java プロジェクト: fromgate/ReActions
 public static boolean creditAccount(
     String accountTo, String accountFrom, double amount, String currencyName, String worldName) {
   if (!enabled) return false;
   if (accountTo.isEmpty()) return false;
   Account account = getAccount(accountTo);
   if (account == null) return false;
   Currency currency = craftconomy.getCurrencyManager().getCurrency(currencyName);
   if (currency == null) currency = craftconomy.getCurrencyManager().getDefaultCurrency();
   String world = getWorldName(worldName);
   if (!accountFrom.isEmpty() && !withdrawAccount(accountFrom, amount, currency.getName(), world))
     return false;
   account.deposit(amount, world, currency.getName(), Cause.PLUGIN, null);
   return true;
 }
コード例 #4
0
ファイル: RACraftConomy.java プロジェクト: fromgate/ReActions
 public static boolean withdrawAccount(
     String accountStr, double amount, String currencyName, String worldName) {
   if (!enabled) return false;
   if (accountStr.isEmpty()) return false;
   Account account = getAccount(accountStr);
   if (account == null) return false;
   if (account.hasInfiniteMoney()) return true;
   Currency currency = craftconomy.getCurrencyManager().getCurrency(currencyName);
   if (currency == null) currency = craftconomy.getCurrencyManager().getDefaultCurrency();
   String world = getWorldName(worldName);
   if (!hasAmount(accountStr, amount, currency.getName(), world)) return false;
   account.withdraw(amount, world, currency.getName(), Cause.PLUGIN, null);
   return true;
 }
コード例 #5
0
ファイル: PayCommand.java プロジェクト: AxxiD/craftconomy3
  @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"));
    }
  }
コード例 #6
0
ファイル: SetCommand.java プロジェクト: paulmory/craftconomy3
  @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"));
    }
  }
コード例 #7
0
  @Override
  public void execute(String sender, String[] args) {
    if (Common.getInstance().getAccountManager().exist(args[0], true)) {
      Account bankAccount = Common.getInstance().getAccountManager().getAccount(args[0], true);
      if (Tools.isValidDouble(args[1])) {
        double amount = Double.parseDouble(args[1]);
        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()
                .getPlayerCaller()
                .sendMessage(
                    sender,
                    Common.getInstance().getLanguageManager().getString("currency_not_exist"));
            return;
          }
        }
        String worldName = Account.getWorldGroupOfPlayerCurrentlyIn(sender);
        if (args.length > 3) {
          if (!Common.getInstance().getServerCaller().worldExist(args[3])) {
            Common.getInstance()
                .getServerCaller()
                .getPlayerCaller()
                .sendMessage(
                    sender, Common.getInstance().getLanguageManager().getString("world_not_exist"));
            return;
          }
          worldName = Common.getInstance().getWorldGroupManager().getWorldGroupName(args[3]);
        }

        if (bankAccount.hasEnough(amount, worldName, currency.getName())) {
          bankAccount.withdraw(amount, worldName, currency.getName(), Cause.USER, sender);
          Common.getInstance()
              .getServerCaller()
              .getPlayerCaller()
              .sendMessage(
                  sender,
                  Common.getInstance()
                      .getLanguageManager()
                      .parse(
                          "bank_take_success",
                          Common.getInstance().format(worldName, currency, amount),
                          args[0]));
        } else {
          Common.getInstance()
              .getServerCaller()
              .getPlayerCaller()
              .sendMessage(
                  sender,
                  Common.getInstance().getLanguageManager().getString("bank_not_enough_money"));
        }
      } else {
        Common.getInstance()
            .getServerCaller()
            .getPlayerCaller()
            .sendMessage(
                sender, Common.getInstance().getLanguageManager().getString("invalid_amount"));
      }
    } else {
      Common.getInstance()
          .getServerCaller()
          .getPlayerCaller()
          .sendMessage(
              sender, Common.getInstance().getLanguageManager().getString("account_not_exist"));
    }
  }