예제 #1
0
 public boolean pay(Player p) {
   if (!plugin.useVault) {
     return true;
   }
   Economy econ;
   RegisteredServiceProvider<Economy> rsp =
       plugin.getServer().getServicesManager().getRegistration(Economy.class);
   if (rsp == null) {
     return true; // No Vault found
   }
   econ = rsp.getProvider();
   if (econ == null) {
     return true; // No Vault found
   }
   int money = plugin.warpCreatePrice;
   if (money == 0) {
     return true;
   }
   if (!econ.has(p.getName(), money)) {
     p.sendMessage("You do not have enough money! You need " + econ.format(money) + "!");
     return false;
   }
   econ.withdrawPlayer(p.getName(), money);
   p.sendMessage("Withdrawing " + econ.format(money) + " from your account!");
   return true;
 }
  @EventHandler
  public void winGame(DeathSwapWinEvent event) {
    int payloser = getConfig().getInt("loseramount");
    int paywinner = getConfig().getInt("paywinneramount");
    Player loser = Bukkit.getServer().getPlayer(event.getLoser());
    Player winner = Bukkit.getServer().getPlayer(event.getWinner());
    String payloseroption = getConfig().getString("payloser");

    if (payloseroption.equalsIgnoreCase("give")) {

      econ.depositPlayer(event.getLoser(), payloser);
      loser.sendMessage(
          ChatColor.YELLOW
              + "["
              + ChatColor.GREEN
              + "DeathSwap Payout"
              + ChatColor.YELLOW
              + "]"
              + ChatColor.RED
              + " You've received an award of $"
              + payloser
              + " for participating in the match. Well done.");

    } else if (payloseroption.equalsIgnoreCase("take")) {
      econ.withdrawPlayer(event.getLoser(), payloser);
      loser.sendMessage(
          ChatColor.YELLOW
              + "["
              + ChatColor.GREEN
              + "DeathSwap Payout"
              + ChatColor.YELLOW
              + "]"
              + ChatColor.RED
              + " Unfortunately, because you lost the last match, the amount of $"
              + payloser
              + " has been taken from your account. Better luck next time.");
    }
    if (getConfig().getBoolean("paywinner")) {

      econ.depositPlayer(event.getWinner(), paywinner);

      winner.sendMessage(
          ""
              + ChatColor.YELLOW
              + "["
              + ChatColor.GREEN
              + "DeathSwap Payout"
              + ChatColor.YELLOW
              + "]"
              + ChatColor.RED
              + " You've received an award of $"
              + paywinner
              + " for winning the match. Well done.");
    }
  }
예제 #3
0
 public static void add(String name, double amount) {
   if (!hasEconomy()) {
     throw new IllegalStateException(
         "Tried to perform economy actions but no economy service installed!");
   }
   if (amount > 0) {
     economy.depositPlayer(name, amount);
   } else if (amount < 0) {
     economy.withdrawPlayer(name, Math.abs(amount));
   }
 }
예제 #4
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;
  }
예제 #5
0
 public boolean withdraw(String p, double m) {
   switch (type) {
     case OWNER:
       return economy.withdrawPlayer(p, m).transactionSuccess();
     case BANK:
       return economy.bankWithdraw(bank, m).transactionSuccess();
     case NPC:
       if (money >= m) {
         money -= m;
         return true;
       }
       return false;
     default:
       return true;
   }
 }
예제 #6
0
  @Override
  public boolean move(
      String fromId,
      String toId,
      String byId,
      double amount,
      Collection<String> categories,
      Object message) {
    Economy economy = this.getEconomy();

    // Ensure positive direction
    if (amount < 0) {
      amount *= -1;
      String temp = fromId;
      fromId = toId;
      toId = temp;
    }

    // Ensure the accounts exist
    if (fromId != null) this.ensureExists(fromId);
    if (toId != null) this.ensureExists(toId);

    // Subtract From
    if (fromId != null) {
      if (!economy.withdrawPlayer(fromId, amount).transactionSuccess()) {
        return false;
      }
    }

    // Add To
    if (toId != null) {
      if (!economy.depositPlayer(toId, amount).transactionSuccess()) {
        if (fromId != null) {
          // Undo the withdraw
          economy.depositPlayer(fromId, amount);
        }
        return false;
      }
    }

    return true;
  }
  @EventHandler
  public void newGame(DeathSwapNewGameEvent event) {
    if (getConfig().getBoolean("paytoplay")) {
      int cost = getConfig().getInt("costtoplay");
      econ.withdrawPlayer(event.getNameOne(), cost);
      econ.withdrawPlayer(event.getNameTwo(), cost);
      Player one = Bukkit.getServer().getPlayer(event.getNameOne());
      Player two = Bukkit.getServer().getPlayer(event.getNameTwo());
      one.sendMessage(
          ""
              + ChatColor.YELLOW
              + "["
              + ChatColor.GREEN
              + "DeathSwap Payout"
              + ChatColor.YELLOW
              + "]"
              + ChatColor.RED
              + "This game costs $"
              + cost
              + ". $"
              + cost
              + " has been taken out of your account.");

      two.sendMessage(
          ""
              + ChatColor.YELLOW
              + "["
              + ChatColor.GREEN
              + "DeathSwap Payout"
              + ChatColor.YELLOW
              + "]"
              + ChatColor.RED
              + "This game costs $"
              + cost
              + ". $"
              + cost
              + " has been taken out of your account.");
    }
  }
예제 #8
0
  // Handles death related events.
  @SuppressWarnings("deprecation")
  @EventHandler(priority = EventPriority.NORMAL)
  public void onDeath(EntityDeathEvent event) {

    if (event.getEntity() instanceof Player) {
      Player player = (Player) event.getEntity();

      // Players lose 5% of their money on death.
      Double loss;
      Double amount = econ.getBalance(player.getDisplayName());
      loss = amount * 0.05;
      econ.withdrawPlayer(player.getDisplayName(), loss);
    }

    // Powered Creepers drop diamond when killed.
    if (event.getEntity() instanceof Creeper) {
      if (((Creeper) event.getEntity()).isPowered()) {
        ItemStack item = new ItemStack(Material.DIAMOND);
        event.getDrops().add(item);
      }
    }
  }
예제 #9
0
 public void handlePayment(Player p, double i) {
   if (i > 0) {
     EconomyResponse r = econ.depositPlayer(p.getName(), i);
     if (r.transactionSuccess()) {
       p.sendMessage(ChatColor.GREEN + "You have been awarded $" + i);
     } else {
       p.sendMessage(ChatColor.RED + "PAYMENT FAILED!");
     }
   } else if (i < 0) {
     i = Math.abs(i);
     double bal = econ.getBalance(p.getName());
     if (bal < i) {
       i = bal;
     }
     EconomyResponse r = econ.withdrawPlayer(p.getName(), i);
     if (r.transactionSuccess()) {
       p.sendMessage(ChatColor.RED + "You have been fined $" + i);
     } else {
       p.sendMessage(ChatColor.RED + "PAYMENT FAILED!");
     }
   }
 }
예제 #10
0
  public TransactionResponse ecoPay(Player sender, String reciverName, double amount) {
    if (econ != null && amount > 0) {
      EconomyResponse withdrawResponse = econ.withdrawPlayer(sender.getName(), amount);

      if (withdrawResponse.transactionSuccess()) {
        EconomyResponse depositResponse = econ.depositPlayer(reciverName, amount);

        if (depositResponse.transactionSuccess()) {
          return new TransactionResponse(true, "Transaction success", amount);
        } else {
          return new TransactionResponse(false, depositResponse.errorMessage, 0);
        }

      } else {
        return new TransactionResponse(false, withdrawResponse.errorMessage, 0);
      }
    } else {
      if (amount > 0) return new TransactionResponse(false, "No economy plugin found", 0);
      else {
        return new TransactionResponse(false, "Transction amount is 0", amount);
      }
    }
  }
예제 #11
0
 @Override
 public double removeMoney(Player player, double money) {
   economy.withdrawPlayer(player.getName(), money);
   return getBalance(player);
 }
 public void removeMoney(Player player, float money) {
   if (economy != null) {
     economy.withdrawPlayer(player.getName(), money);
   }
 }
 /**
  * Charge player money
  *
  * @param player
  * @param amount
  * @return
  */
 public boolean playerCharge(Player player, double amount) {
   return economy.withdrawPlayer(player.getName(), amount).transactionSuccess();
 }
예제 #14
0
  /**
   * Buy a specified amount of an item for the player.
   *
   * @param player The player on behalf of which these actions will be carried out.
   * @param item The desired item in the form of the item name.
   * @param amount The desired amount of the item to purchase.
   * @return true on success, false on failure.
   */
  public boolean buy(Player player, String item, int amount) {

    // Be sure we have a positive amount
    if (amount < 1) {
      player.sendMessage(ChatColor.RED + "Invalid amount.");
      player.sendMessage("No negative numbers or zero, please.");
      return false;
    }

    // retrieve the commodity in question
    Commodities commodity =
        plugin.getDatabase().find(Commodities.class).where().ieq("name", item).findUnique();

    // check that we found something
    if (commodity == null) {
      player.sendMessage(ChatColor.RED + "Not allowed to buy that item.");
      player.sendMessage("Be sure you typed the correct name");
      return false;
    }

    // determine what it will cost
    Invoice invoice = generateInvoice(1, commodity, amount);

    // check the player's wallet
    if (economy.has(player.getName(), invoice.getTotal())) {

      // give 'em the items and drop any extra
      Byte byteData = Byte.valueOf(String.valueOf(commodity.getData()));
      int id = commodity.getNumber();

      HashMap<Integer, ItemStack> overflow =
          player.getInventory().addItem(new ItemStack(id, amount, (short) 0, byteData));
      for (int a : overflow.keySet()) {
        player.getWorld().dropItem(player.getLocation(), overflow.get(a));
      }

      // save the new value
      commodity.setValue(invoice.getValue());
      getDatabase().save(commodity);

      // use BigDecimal to format value for output
      double v = commodity.getValue();
      double max = commodity.getMaxValue();
      double min = commodity.getMinValue();
      BigDecimal value;
      if (v < max && v > min) {
        value = BigDecimal.valueOf(v).setScale(2, RoundingMode.HALF_UP);
      } else if (v <= min) {
        value = BigDecimal.valueOf(min).setScale(2, RoundingMode.HALF_UP);
      } else {
        value = BigDecimal.valueOf(max).setScale(2, RoundingMode.HALF_UP);
      }

      // Give some nice output.
      player.sendMessage(ChatColor.GREEN + "--------------------------------");
      player.sendMessage(
          ChatColor.GREEN
              + "Old Balance: "
              + ChatColor.WHITE
              + BigDecimal.valueOf(economy.getBalance(player.getName()))
                  .setScale(2, RoundingMode.HALF_UP));
      // Subtract the invoice (this is an efficient place to do this)
      economy.withdrawPlayer(player.getName(), invoice.getTotal());

      player.sendMessage(
          ChatColor.GREEN
              + "Cost: "
              + ChatColor.WHITE
              + BigDecimal.valueOf(invoice.getTotal()).setScale(2, RoundingMode.HALF_UP));
      player.sendMessage(
          ChatColor.GREEN
              + "New Balance: "
              + ChatColor.WHITE
              + BigDecimal.valueOf(economy.getBalance(player.getName()))
                  .setScale(2, RoundingMode.HALF_UP));
      player.sendMessage(ChatColor.GREEN + "--------------------------------");
      player.sendMessage(
          ChatColor.GRAY + item + ChatColor.GREEN + " New Price: " + ChatColor.WHITE + value);
      return true;
    } else { // Otherwise, give nice output anyway ;)

      // The idea here is to show how much more money is needed.
      BigDecimal difference =
          BigDecimal.valueOf(economy.getBalance(player.getName()) - invoice.getTotal())
              .setScale(2, RoundingMode.HALF_UP);
      player.sendMessage(ChatColor.RED + "You don't have enough money");
      player.sendMessage(
          ChatColor.GREEN
              + "Balance: "
              + ChatColor.WHITE
              + BigDecimal.valueOf(economy.getBalance(player.getName()))
                  .setScale(2, RoundingMode.HALF_UP));
      player.sendMessage(
          ChatColor.GREEN
              + "Cost: "
              + ChatColor.WHITE
              + BigDecimal.valueOf(invoice.getTotal()).setScale(2, RoundingMode.HALF_UP));
      player.sendMessage(ChatColor.GREEN + "Difference: " + ChatColor.RED + difference);
      return true;
    }
  }
예제 #15
0
  @SuppressWarnings("deprecation")
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {
    if (!(sender instanceof Player)) {
      log.info("You must be a player!");
      return true;
    }

    Player player = (Player) sender;

    if (command.getLabel().equalsIgnoreCase("rubies")) {

      if (args.length < 1) {
        int x = (int) econ.getBalance(player.getName());
        sender.sendMessage(
            this.getConfig()
                .getString("rubies-format")
                .replaceAll("<balance>", "" + x)
                .replaceAll("&", "\u00a7"));
      }
      if (args.length >= 1) {
        if (args[0].equalsIgnoreCase("reload")) {
          reloadConfig();
          player.sendMessage(ChatColor.YELLOW + "Rubies config " + ChatColor.WHITE + "reloaded!");
        }
        if (args[0].equalsIgnoreCase("config")) {
          // if (args.length == 1){
          player.sendMessage(ChatColor.YELLOW + "Rubies config: ");
          player.sendMessage(
              ChatColor.GREEN
                  + "\nrubies-format: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("rubies-format"));
          player.sendMessage(
              ChatColor.GREEN
                  + "rubies-see-format: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("rubies-see-format"));
          player.sendMessage(
              ChatColor.GREEN
                  + "give-rubies-permission: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("give-rubies-permission"));
          player.sendMessage(
              ChatColor.GREEN
                  + "rubies-recived-format: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("rubies-recived-format"));
          player.sendMessage(
              ChatColor.GREEN
                  + "rubies-error-message: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("rubies-error-message"));
          player.sendMessage(
              ChatColor.GREEN
                  + "give-rubies-permission: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("give-rubies-permission"));
          player.sendMessage(
              ChatColor.GREEN
                  + "no-give-ruby-perms-message: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("no-give-ruby-perms-message"));
          player.sendMessage(
              ChatColor.GREEN
                  + "take-rubies-permission: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("take-rubies-permission"));
          player.sendMessage(
              ChatColor.GREEN
                  + "rubies-taken-format: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("rubies-taken-format"));
          player.sendMessage(
              ChatColor.GREEN
                  + "no-take-ruby-perms-message: "
                  + ChatColor.GOLD
                  + this.getConfig().getString("no-take-ruby-perms-message"));
          // player.sendMessage(ChatColor.WHITE + "\nUse " + ChatColor.YELLOW + "/rubies config
          // <config section> <new value>" + ChatColor.WHITE + " to edit a config value");
          // }
          /* if (args.length == 2){
          	player.sendMessage("\nProper command use is " + ChatColor.YELLOW + "/rubies config <config section> <new value>");
          }
          if (args.length == 3){
          	if (this.getConfig().getString(args[2]) != null){
          	this.getConfig().set(args[2], args[3]);
          	player.sendMessage(ChatColor.GREEN + args[2] + ChatColor.WHITE + " set to " + ChatColor.GOLD + args[3]);
          	reloadConfig();
          	}
          	if (this.getConfig().getString(args[2]) == null) {
          		player.sendMessage(ChatColor.RED + "Error: " + ChatColor.WHITE + " Config section " + ChatColor.YELLOW + "'" + args[2] + "'" + ChatColor.WHITE + " does not exist!");
          		player.sendMessage("Type " + ChatColor.YELLOW + "/rubies config " + ChatColor.WHITE + "to see avalible options.");
          	}
          }*/
        }

        if (args[0].equalsIgnoreCase("see")) {
          if (args.length == 2) {
            if (player.getServer().getPlayer(args[1]) != null) {

              player.sendMessage(
                  this.getConfig()
                      .getString("rubies-see-format")
                      .replaceAll("<player>", args[1])
                      .replaceAll("<balance>", "" + econ.getBalance(args[1]))
                      .replaceAll("&", "\u00a7"));
            } else {
              player.sendMessage(
                  "Player "
                      + ChatColor.YELLOW
                      + "'"
                      + args[1]
                      + "'"
                      + ChatColor.WHITE
                      + " not found");
            }
          }
          if (args.length != 2) {
            player.sendMessage(
                "Proper Command use is " + ChatColor.YELLOW + "/rubies see <player>");
          }
        }

        if (args[0].equalsIgnoreCase("give")) {
          if (player.hasPermission(this.getConfig().getString("give-rubies-permission"))
              || player.isOp()) {

            if (args.length == 3) {
              if (player.getServer().getPlayer(args[1]) != null) {
                if (isNumeric(args[2])) {
                  double amount = Double.parseDouble(args[2]);
                  EconomyResponse r = econ.depositPlayer(args[1], amount); // Try to give
                  // econ.depositPlayer(args[1], amount);//Try to give
                  if (r.transactionSuccess()) { // Rubies given
                    int x = (int) econ.getBalance(args[1]);
                    player.sendMessage(
                        this.getConfig()
                            .getString("rubies-recived-format")
                            .replaceAll("<given>", "" + r.amount)
                            .replaceAll("<balance>", "" + x)
                            .replaceAll("<player>", args[1])
                            .replaceAll("&", "\u00a7"));

                  } else { // An error has occurred
                    sender.sendMessage(
                        this.getConfig()
                            .getString("rubies-error-message")
                            .replaceAll("<error>", r.errorMessage));
                  }
                } else {
                  player.sendMessage(
                      ChatColor.RED
                          + "Error: "
                          + ChatColor.YELLOW
                          + "'"
                          + args[2]
                          + "'"
                          + ChatColor.WHITE
                          + " must be a number!");
                }
              } else {
                player.sendMessage(
                    "Player "
                        + ChatColor.YELLOW
                        + "'"
                        + args[1]
                        + "'"
                        + ChatColor.WHITE
                        + " not found");
              }
            }
            if (args.length != 3) {
              player.sendMessage(
                  "Proper Command use is " + ChatColor.YELLOW + "/rubies give <player> <amount>");
            }

            if (!player.hasPermission(this.getConfig().getString("give-rubies-permission"))
                || !player.isOp()) { // Player does not have permission
              player.sendMessage(
                  this.getConfig()
                      .getString("no-give-ruby-perms-message")
                      .replaceAll("<balance>", "" + econ.getBalance(player.getName()))
                      .replaceAll("&", "\u00a7"));
            }
          }
        }
        if (args[0].equalsIgnoreCase("take")) {
          if (player.hasPermission(this.getConfig().getString("take-rubies-permission"))
              || player.isOp()) {
            if (args.length == 3) {
              if (player.getServer().getPlayer(args[1]) != null) {
                if (isNumeric(args[2])) {
                  double amount = Double.parseDouble(args[2]);
                  EconomyResponse r = econ.withdrawPlayer(args[1], amount); // Try to take
                  // econ.withdrawPlayer(args[1], amount);//Try to take
                  if (r.transactionSuccess()) { // Rubies taken
                    player.sendMessage(
                        this.getConfig()
                            .getString("rubies-taken-format")
                            .replaceAll("<player>", args[1])
                            .replaceAll("<taken>", "" + r.amount)
                            .replaceAll("<balance>", "" + econ.getBalance(player.getName()))
                            .replaceAll("&", "\u00a7"));

                  } else { // An error has occurred
                    sender.sendMessage(
                        this.getConfig()
                            .getString("rubies-error-message")
                            .replaceAll("<error>", r.errorMessage));
                  }
                } else {
                  player.sendMessage(
                      ChatColor.RED
                          + "Error: "
                          + ChatColor.YELLOW
                          + "'"
                          + args[2]
                          + "'"
                          + ChatColor.WHITE
                          + " must be a number!");
                }
              } else {
                player.sendMessage(
                    "Player "
                        + ChatColor.YELLOW
                        + "'"
                        + args[1]
                        + "'"
                        + ChatColor.WHITE
                        + " not found");
              }
            }
            if (args.length != 3) {
              player.sendMessage(
                  "Proper Command use is " + ChatColor.YELLOW + "/rubies take <player> <amount>");
            }
          }
          if (!player.hasPermission(this.getConfig().getString("take-rubies-permission"))
              || !player.isOp()) { // Player does not have permission
            player.sendMessage(
                this.getConfig()
                    .getString("no-take-ruby-perms-message")
                    .replaceAll("<balance>", "" + econ.getBalance(player.getName()))
                    .replaceAll("&", "\u00a7"));
          }
        }
        if (!args[0].equalsIgnoreCase("reload")
            && !args[0].equalsIgnoreCase("see")
            && !args[0].equalsIgnoreCase("give")
            && !args[0].equalsIgnoreCase("take")
            && !args[0].equalsIgnoreCase("config")) {
          player.sendMessage(
              "Rubies Commands: "
                  + ChatColor.YELLOW
                  + "\n/rubies "
                  + ChatColor.GRAY
                  + ": See how many rubies you have.");
          player.sendMessage(
              ChatColor.YELLOW
                  + "/rubies see <player> "
                  + ChatColor.GRAY
                  + ": See how many rubies a player has.");
          player.sendMessage(
              ChatColor.YELLOW
                  + "/rubies give <player> <amount> "
                  + ChatColor.GRAY
                  + ": Gives rubies to a player.");
          player.sendMessage(
              ChatColor.YELLOW
                  + "/rubies take <player> <amount> "
                  + ChatColor.GRAY
                  + ": Take rubies from a player.");
          player.sendMessage(
              ChatColor.YELLOW + "/rubies config " + ChatColor.GRAY + ": Rubies config options.");
          player.sendMessage(
              ChatColor.YELLOW
                  + "/rubies reload "
                  + ChatColor.GRAY
                  + ": Reloads the rubies config file.");
        }
      }
      return true;
    }
    return false;
  }