Ejemplo n.º 1
0
  public boolean ensureExists(String accountId) {
    Economy economy = this.getEconomy();

    if (economy.hasAccount(accountId)) return true;

    if (!economy.createPlayerAccount(accountId)) return false;

    if (MUtil.isValidPlayerName(accountId)) return true;

    double balance = economy.getBalance(accountId);
    economy.withdrawPlayer(accountId, balance);

    return true;
  }
Ejemplo n.º 2
0
  private void convertCommand(CommandSender sender, String[] args) {
    Collection<RegisteredServiceProvider<Economy>> econs =
        this.getServer().getServicesManager().getRegistrations(Economy.class);
    if (econs == null || econs.size() < 2) {
      sender.sendMessage("You must have at least 2 economies loaded to convert.");
      return;
    } else if (args.length != 2) {
      sender.sendMessage(
          "You must specify only the economy to convert from and the economy to convert to. (without spaces)");
      return;
    }
    Economy econ1 = null;
    Economy econ2 = null;
    for (RegisteredServiceProvider<Economy> econ : econs) {
      String econName = econ.getProvider().getName().replace(" ", "");
      if (econName.equalsIgnoreCase(args[0])) {
        econ1 = econ.getProvider();
      } else if (econName.equalsIgnoreCase(args[1])) {
        econ2 = econ.getProvider();
      }
    }

    if (econ1 == null) {
      sender.sendMessage(
          "Could not find " + args[0] + " loaded on the server, check your spelling");
      return;
    } else if (econ2 == null) {
      sender.sendMessage(
          "Could not find " + args[1] + " loaded on the server, check your spelling");
      return;
    }

    sender.sendMessage("This may take some time to convert, expect server lag.");
    for (OfflinePlayer op : Bukkit.getServer().getOfflinePlayers()) {
      String pName = op.getName();
      if (econ1.hasAccount(pName)) {
        if (econ2.hasAccount(pName)) {
          continue;
        }
        econ2.createPlayerAccount(pName);
        econ2.depositPlayer(pName, econ1.getBalance(pName));
      }
    }
  }