net.milkbowl.vault.economy.EconomyResponse Java Examples

The following examples show how to use net.milkbowl.vault.economy.EconomyResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EconomyOperations.java    From PlayerVaults with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Have a player pay to open a vault.
 *
 * @param player The player to pay.
 * @param number The vault number to open.
 * @return The transaction success.
 */
public static boolean payToOpen(Player player, int number) {
    if (!PlayerVaults.getInstance().isEconomyEnabled() || player.hasPermission("playervaults.free")) {
        return true;
    }

    if (!VaultManager.getInstance().vaultExists(player.getUniqueId().toString(), number)) {
        return payToCreate(player);
    } else {
        if (PlayerVaults.getInstance().getConf().getEconomy().getFeeToOpen() == 0) {
            return true;
        }
        double cost = PlayerVaults.getInstance().getConf().getEconomy().getFeeToOpen();
        EconomyResponse resp = PlayerVaults.getInstance().getEconomy().withdrawPlayer(player, cost);
        if (resp.transactionSuccess()) {
            player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onTutorialEnd(EndTutorialEvent event) {
    Player player = event.getPlayer();
    UUID uuid = Caching.getCaching().getUUID(player);
    if (TutorialManager.getManager().getConfigs().getRewards()) {
        if (!seenTutorial(uuid, event.getTutorial().getName())) {
            if (TutorialEco.getTutorialEco().setupEconomy() && TutorialManager.getManager().getConfigs()
                    .getTutorialMoney()) {
                EconomyResponse ecoResponse = TutorialEco.getTutorialEco().getEcon().depositPlayer(player,
                        TutorialManager.getManager().getConfigs().getPerTutorialMoney());
                if (ecoResponse.transactionSuccess()) {
                    player.sendMessage(ChatColor.BLUE + "You received " + ecoResponse.amount + " for completing " +
                            "the tutorial!");
                } else {
                    plugin.getLogger().log(Level.WARNING, "There was an error processing Economy for player: " +
                            "{0}", player.getName());
                }
            }
            if (TutorialManager.getManager().getConfigs().getTutorialExp()) {
                player.setExp(player.getTotalExperience() + TutorialManager.getManager().getConfigs()
                        .getPerTutorialExp());
            }
        }
    }
    DataLoading.getDataLoading().getPlayerData().set("players." + uuid + ".tutorials." + event.getTutorial()
            .getName(), "true");
    DataLoading.getDataLoading().savePlayerData();
    Caching.getCaching().reCachePlayerData();
}
 
Example #3
Source File: EconomyUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public EconomyResponse withdrawFunds(OfflinePlayer player, double funds) {
    final Double balance = this.vaultProvider.getApi().getBalance(player);
    if (funds < 0) {
        return new EconomyResponse(funds, balance, ResponseType.FAILURE, "Can't deposit negative amount");
    }
    if (balance < funds) {
        return new EconomyResponse(funds, balance, ResponseType.FAILURE, "Not enough funds");
    }

    return this.vaultProvider.getApi().withdrawPlayer(player, funds);
}
 
Example #4
Source File: Main.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void depositPlayer(Player player, double coins) {
    try {
        if (isVault() && instance.configurator.config.getBoolean("vault.enable")) {
            EconomyResponse response = instance.econ.depositPlayer(player, coins);
            if (response.transactionSuccess()) {
                player.sendMessage(i18n("vault_deposite").replace("%coins%", Double.toString(coins)).replace(
                        "%currency%",
                        (coins == 1 ? instance.econ.currencyNameSingular() : instance.econ.currencyNamePlural())));
            }
        }
    } catch (Throwable ignored) {
    }
}
 
Example #5
Source File: VaultProvider.java    From GriefDefender with MIT License 5 votes vote down vote up
public boolean depositPlayer(OfflinePlayer player, double amount) {
    if (this.getApi() == null) {
        return false;
    }

    final EconomyResponse result = this.vaultApi.depositPlayer(player, amount);
    return result.transactionSuccess();
}
 
Example #6
Source File: Econ.java    From ClaimChunk with MIT License 5 votes vote down vote up
@SuppressWarnings("UnusedReturnValue")
public EconomyResponse addMoney(UUID player, double amt) {
    Player ply = getPlayer(player);
    if (ply != null) {
        // Add the (safe) balance to the player
        return econ.depositPlayer(ply, Math.abs(amt));
    }
    return null;
}
 
Example #7
Source File: EconomySaneEconomy.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EconomyResponse depositPlayer(String target, double amount) {
    if (amount == 0) {
        return new EconomyResponse(amount, this.getBalance(target), EconomyResponse.ResponseType.SUCCESS, "");
    }

    return this.transact(new Transaction(
                        SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, this.makeEconomable(target), new BigDecimal(amount), TransactionReason.PLUGIN_GIVE
                    ));
}
 
Example #8
Source File: EconomySaneEconomy.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EconomyResponse withdrawPlayer(OfflinePlayer offlinePlayer, double amount) {
    if (amount == 0) {
        return new EconomyResponse(amount, this.getBalance(offlinePlayer), EconomyResponse.ResponseType.SUCCESS, "");
    }

    if (!this.has(offlinePlayer, amount)) {
        return new EconomyResponse(amount, this.getBalance(offlinePlayer), EconomyResponse.ResponseType.FAILURE, "Insufficient funds.");
    }

    return this.transact(new Transaction(
                        SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.wrap(offlinePlayer), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
                    ));
}
 
Example #9
Source File: EconomySaneEconomy.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EconomyResponse withdrawPlayer(String target, double amount) {
    if (amount == 0) {
        return new EconomyResponse(amount, this.getBalance(target), EconomyResponse.ResponseType.SUCCESS, "");
    }

    return this.transact(new Transaction(
                        SaneEconomy.getInstance().getEconomyManager().getCurrency(), this.makeEconomable(target), Economable.PLUGIN, new BigDecimal(amount), TransactionReason.PLUGIN_TAKE
                    ));
}
 
Example #10
Source File: EconomyExtra.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTradeEnd() {
  if (value1 > 0) {
    if (economy.withdrawPlayer(player1, value1).type.equals(EconomyResponse.ResponseType.SUCCESS))
      economy.depositPlayer(player2, value1 - ((value1 / 100) * taxPercent));
  }
  if (value2 > 0) {
    if (economy.withdrawPlayer(player2, value2).type.equals(EconomyResponse.ResponseType.SUCCESS))
      economy.depositPlayer(player1, value2 - ((value2 / 100) * taxPercent));
  }
}
 
Example #11
Source File: Econ.java    From ClaimChunk with MIT License 5 votes vote down vote up
@SuppressWarnings("UnusedReturnValue")
private EconomyResponse takeMoney(UUID player, double amt) {
    Player ply = getPlayer(player);
    if (ply != null) {
        // Remove the money from the player's balance
        return econ.withdrawPlayer(ply, Math.abs(amt));
    }
    return null;
}
 
Example #12
Source File: Econ.java    From ClaimChunk with MIT License 5 votes vote down vote up
/**
 * Take money from the player.
 *
 * @param ply  Player purchasing.
 * @param cost The cost of the purchase.
 * @return Whether or not the transaction was successful.
 */
public boolean buy(UUID ply, double cost) {
    if (getMoney(ply) >= cost) {
        EconomyResponse response = takeMoney(ply, cost);
        // Return whether the transaction was completed successfully
        return response != null && response.type == EconomyResponse.ResponseType.SUCCESS;
    }
    return false;
}
 
Example #13
Source File: EconomySaneEconomy.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EconomyResponse depositPlayer(OfflinePlayer offlinePlayer, double v) {
    if (v == 0) {
        return new EconomyResponse(v, this.getBalance(offlinePlayer), EconomyResponse.ResponseType.SUCCESS, "");
    }

    return this.transact(new Transaction(
                        SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), new BigDecimal(v), TransactionReason.PLUGIN_GIVE
                    ));
}
 
Example #14
Source File: EconomySaneEconomy.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
private EconomyResponse transact(Transaction transaction) {
    TransactionResult result = SaneEconomy.getInstance().getEconomyManager().transact(transaction);

    if (result.getStatus() == TransactionResult.Status.SUCCESS) {
        return new EconomyResponse(transaction.getAmount().doubleValue(), result.getToBalance().doubleValue(), EconomyResponse.ResponseType.SUCCESS, null);
    }

    return new EconomyResponse(0, 0, EconomyResponse.ResponseType.FAILURE, result.getStatus().toString());
}
 
Example #15
Source File: PlayerSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserialize all aspects of a player, and apply their data. See {@link PlayerSerializer#serialize(PWIPlayer)}
 * for an explanation of the data format number.
 *
 * @param data   The saved player information.
 * @param player The Player to apply the deserialized information to.
 */
public void deserialize(final JsonObject data, final Player player, DeserializeCause cause) {
    ConsoleLogger.debug("[SERIALIZER] Deserializing player '" + player.getName()+ "'");

    int format = 0;
    if (data.has("data-format"))
        format = data.get("data-format").getAsInt();

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS) && data.has("ender-chest"))
        player.getEnderChest().setContents(inventorySerializer.deserializeInventory(data.getAsJsonArray("ender-chest"),
                player.getEnderChest().getSize(), format));
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY) && data.has("inventory"))
        inventorySerializer.setInventory(player, data.getAsJsonObject("inventory"), format);
    if (data.has("stats"))
        statSerializer.deserialize(player, data.getAsJsonObject("stats"), format);
    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        ConsoleLogger.debug("[ECON] Withdrawing " + econ.getBalance(player) + " from '" + player.getName() + "'!");
        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (!er.transactionSuccess()) {
            ConsoleLogger.warning("[ECON] Unable to withdraw funds from '" + player.getName() + "': " + er.errorMessage);
        }

        if (data.has("economy") && er.transactionSuccess()) {
            EconomySerializer.deserialize(econ, data.getAsJsonObject("economy"), player);
        }
    }

    ConsoleLogger.debug("[SERIALIZER] Done deserializing player '" + player.getName()+ "'");

    // Call event to signal loading is done
    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    bukkitService.callEvent(event);
}
 
Example #16
Source File: Main.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void depositPlayer(Player player, double coins) {
    try {
        if (isVault() && instance.configurator.config.getBoolean("vault.enable")) {
            EconomyResponse response = instance.econ.depositPlayer(player, coins);
            if (response.transactionSuccess()) {
                player.sendMessage(i18n("vault_deposite").replace("%coins%", Double.toString(coins)).replace(
                        "%currency%",
                        (coins == 1 ? instance.econ.currencyNameSingular() : instance.econ.currencyNamePlural())));
            }
        }
    } catch (Throwable ignored) {
    }
}
 
Example #17
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean payCost(Player player, double cost) {
	if (econ != null) {
		EconomyResponse rp = econ.withdrawPlayer(player, cost);
		if (rp.transactionSuccess()) {
			return true;
		}
	}
	return false;
}
 
Example #18
Source File: ShopInteractListener.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Create a new shop
 *
 * @param executor  Player, who executed the command, will receive the message and become the vendor of the shop
 * @param location  Where the shop will be located
 * @param product   Product of the Shop
 * @param buyPrice  Buy price
 * @param sellPrice Sell price
 * @param shopType  Type of the shop
 */
private void create(final Player executor, final Location location, final ShopProduct product, final double buyPrice, final double sellPrice, final ShopType shopType) {
    plugin.debug(executor.getName() + " is creating new shop...");

    if (!executor.hasPermission(Permissions.CREATE)) {
        executor.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE));
        plugin.debug(executor.getName() + " is not permitted to create the shop");
        return;
    }

    double creationPrice = (shopType == ShopType.NORMAL) ? Config.shopCreationPriceNormal : Config.shopCreationPriceAdmin;
    Shop shop = new Shop(plugin, executor, product, location, buyPrice, sellPrice, shopType);

    ShopCreateEvent event = new ShopCreateEvent(executor, shop, creationPrice);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled() && !executor.hasPermission(Permissions.CREATE_PROTECTED)) {
        plugin.debug("Create event cancelled");
        executor.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_CREATE_PROTECTED));
        return;
    }

    if (creationPrice > 0) {
        EconomyResponse r = plugin.getEconomy().withdrawPlayer(executor, location.getWorld().getName(), creationPrice);
        if (!r.transactionSuccess()) {
            plugin.debug("Economy transaction failed: " + r.errorMessage);
            executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r.errorMessage)));
            return;
        }
    }

    shop.create(true);

    plugin.debug("Shop created");
    shopUtils.addShop(shop, true);

    Message message = shopType == ShopType.ADMIN ? Message.ADMIN_SHOP_CREATED : Message.SHOP_CREATED;
    executor.sendMessage(LanguageUtils.getMessage(message, new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
}
 
Example #19
Source File: PlayerSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserialize all aspects of a player, and apply their data. See {@link PlayerSerializer#serialize(PWIPlayer)}
 * for an explanation of the data format number.
 *
 * @param data   The saved player information.
 * @param player The Player to apply the deserialized information to.
 */
public void deserialize(final JsonObject data, final Player player, DeserializeCause cause) {
    ConsoleLogger.debug("[SERIALIZER] Deserializing player '" + player.getName()+ "'");

    int format = 0;
    if (data.has("data-format"))
        format = data.get("data-format").getAsInt();

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS) && data.has("ender-chest"))
        player.getEnderChest().setContents(inventorySerializer.deserializeInventory(data.getAsJsonArray("ender-chest"),
                player.getEnderChest().getSize(), format));
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY) && data.has("inventory"))
        inventorySerializer.setInventory(player, data.getAsJsonObject("inventory"), format);
    if (data.has("stats"))
        statSerializer.deserialize(player, data.getAsJsonObject("stats"), format);
    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        ConsoleLogger.debug("[ECON] Withdrawing " + econ.getBalance(player) + " from '" + player.getName() + "'!");
        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (!er.transactionSuccess()) {
            ConsoleLogger.warning("[ECON] Unable to withdraw funds from '" + player.getName() + "': " + er.errorMessage);
        }

        if (data.has("economy") && er.transactionSuccess()) {
            EconomySerializer.deserialize(econ, data.getAsJsonObject("economy"), player);
        }
    }

    ConsoleLogger.debug("[SERIALIZER] Done deserializing player '" + player.getName()+ "'");

    // Call event to signal loading is done
    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    bukkitService.callEvent(event);
}
 
Example #20
Source File: BukkitServerBridge.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@Override
public EconomyResponse withdrawPlayer(IPlayer player, double price) {
    if (getEconomy().isPresent()) {
        return getEconomy().get().withdrawPlayer(((BukkitOfflinePlayer) player).getOfflinePlayer(), price);
    } else {
        return null;
    }
}
 
Example #21
Source File: BukkitServerBridge.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
@Override

    public EconomyResponse depositPlayer(IOfflinePlayer player, double price) {
        if (getEconomy().isPresent()) {
            return getEconomy().get().depositPlayer(((BukkitOfflinePlayer) player).getOfflinePlayer(), price);
        } else {
            return null;
        }
    }
 
Example #22
Source File: CmdUndeny.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
private boolean undenyAll(Plot plot, IPlayer player, PlotMapInfo pmi) {
    if (!plot.getDenied().isEmpty()) {
        double price = pmi.getUndenyPlayerPrice();
        PlotRemoveDeniedEvent event = new PlotRemoveDeniedEvent(plot, player, "*");
        if (manager.isEconomyEnabled(pmi)) {

            //noinspection ConstantConditions
            if (serverBridge.has(player, price)) {
                plugin.getEventBus().post(event);
                if (!event.isCancelled()) {
                    EconomyResponse er = serverBridge.withdrawPlayer(player, price);

                    if (!er.transactionSuccess()) {
                        player.sendMessage(er.errorMessage);
                        serverBridge.getLogger().warning(er.errorMessage);
                        return true;
                    }
                } else {
                    return true;
                }
            } else {
                player.sendMessage("It costs " + serverBridge.getEconomy().get().format(price) + " to undeny a player from the plot.");
                return true;
            }
        } else {
            plugin.getEventBus().post(event);
        }

        if (!event.isCancelled()) {
            plot.removeAllDenied();
            plugin.getSqlManager().savePlot(plot);
            player.sendMessage("Undenied all players from the plot.");
            return true;
        }

    }
    return true;
}
 
Example #23
Source File: EconomyBridge.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return true if the operation was successful.
 */
public static boolean takeMoney(Player player, double amount) {
	if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
	if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);

	EconomyResponse response = economy.withdrawPlayer(player.getName(), player.getWorld().getName(), amount);
	boolean result = response.transactionSuccess();

	MenuUtils.refreshMenu(player);

	return result;
}
 
Example #24
Source File: EconomyBridge.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public static boolean giveMoney(Player player, double amount) {
	if (!hasValidEconomy()) throw new IllegalStateException("Economy plugin was not found!");
	if (amount < 0.0) throw new IllegalArgumentException("Invalid amount of money: " + amount);

	EconomyResponse response = economy.depositPlayer(player.getName(), player.getWorld().getName(), amount);
	boolean result = response.transactionSuccess();

	MenuUtils.refreshMenu(player);

	return result;
}
 
Example #25
Source File: EconomyOperations.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Have a player pay to create a vault.
 *
 * @param player The player to pay.
 * @return The transaction success
 */
public static boolean payToCreate(Player player) {
    if (!PlayerVaults.getInstance().isEconomyEnabled() || PlayerVaults.getInstance().getConf().getEconomy().getFeeToCreate() == 0 || player.hasPermission("playervaults.free")) {
        return true;
    }

    double cost = PlayerVaults.getInstance().getConf().getEconomy().getFeeToCreate();
    EconomyResponse resp = PlayerVaults.getInstance().getEconomy().withdrawPlayer(player, cost);
    if (resp.transactionSuccess()) {
        player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString().replaceAll("%price", "" + cost));
        return true;
    }

    return false;
}
 
Example #26
Source File: EconomyOperations.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Have a player get his money back when vault is deleted.
 *
 * @param player The player to receive the money.
 * @param number The vault number to delete.
 * @return The transaction success.
 */
public static boolean refundOnDelete(Player player, int number) {
    if (!PlayerVaults.getInstance().isEconomyEnabled() || PlayerVaults.getInstance().getConf().getEconomy().getRefundOnDelete() == 0 || player.hasPermission("playervaults.free")) {
        return true;
    }

    File playerFile = new File(PlayerVaults.getInstance().getVaultData(), player.getUniqueId().toString() + ".yml");
    if (playerFile.exists()) {
        YamlConfiguration playerData = YamlConfiguration.loadConfiguration(playerFile);
        if (playerData.getString("vault" + number) == null) {
            player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
            return false;
        }
    } else {
        player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
        return false;
    }

    double cost = PlayerVaults.getInstance().getConf().getEconomy().getRefundOnDelete();
    EconomyResponse resp = PlayerVaults.getInstance().getEconomy().depositPlayer(player, cost);
    if (resp.transactionSuccess()) {
        player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", String.valueOf(cost)));
        return true;
    }

    return false;
}
 
Example #27
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onViewSwitch(ViewSwitchEvent event) {
    Player player = event.getPlayer();
    if (TutorialManager.getManager().getConfigs().getExpCountdown()) {
        player.setExp(player.getExp() - 1f);
    }
    if (TutorialManager.getManager().getConfigs().getRewards()) {
        UUID uuid = Caching.getCaching().getUUID(player);
        if (!seenTutorial(uuid, event.getTutorial().getName())) {
            if (TutorialManager.getManager().getConfigs().getViewExp()) {
                player.setTotalExperience(player.getTotalExperience() + TutorialManager.getManager().getConfigs()
                        .getPerViewExp());
                player.sendMessage(ChatColor.BLUE + "You received " + TutorialManager.getManager().getConfigs()
                        .getViewExp());
            }
            if (TutorialManager.getManager().getConfigs().getViewMoney()) {
                if (TutorialEco.getTutorialEco().setupEconomy()) {
                    EconomyResponse ecoResponse = TutorialEco.getTutorialEco().getEcon().depositPlayer(player,
                            TutorialManager.getManager().getConfigs().getPerViewMoney());
                    if (ecoResponse.transactionSuccess()) {
                        player.sendMessage(ChatColor.BLUE + "You received " + ecoResponse.amount + " New Balance:" +
                                " " + ecoResponse.balance);
                    } else {
                        plugin.getLogger().log(Level.WARNING, "There was an error processing Economy for player: " +
                                "{0}", player.getName());
                    }
                }
            }
        }
    }
}
 
Example #28
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public boolean payCost(Player player, double cost) {
	if (econ != null) {
		EconomyResponse rp = econ.withdrawPlayer(player, cost);
           return rp.transactionSuccess();
	}
	return false;
}
 
Example #29
Source File: TaxApplyTask.java    From GriefDefender with MIT License 4 votes vote down vote up
private void handleClaimTax(GDClaim claim, GDPlayerData playerData, boolean inTown) {
    final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(playerData.getUniqueId());
    final OfflinePlayer player = user.getOfflinePlayer();
    double taxRate = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Double.class), user, Options.TAX_RATE, claim);
    double taxOwed = claim.getEconomyData().getTaxBalance() + (claim.getClaimBlocks() * taxRate);
    GDTaxClaimEvent event = new GDTaxClaimEvent(claim, taxRate, taxOwed);
    GriefDefender.getEventManager().post(event);
    if (event.cancelled()) {
        return;
    }
    final double taxBalance = claim.getEconomyData().getTaxBalance();
    taxRate = event.getTaxRate();
    taxOwed = taxBalance + (claim.getClaimBlocks() * taxRate);
    final EconomyResponse response = EconomyUtil.getInstance().withdrawFunds(player, taxOwed);
    if (!response.transactionSuccess()) {
        final Instant localNow = Instant.now();
        Instant taxPastDueDate = claim.getEconomyData().getTaxPastDueDate();
        if (taxPastDueDate == null) {
            claim.getEconomyData().setTaxPastDueDate(Instant.now());
        } else {
            final int taxExpirationDays = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), user, Options.TAX_EXPIRATION, claim).intValue();
            if (taxExpirationDays > 0) {
                claim.getInternalClaimData().setExpired(true);
                if (taxExpirationDays == 0) {
                    claim.getInternalClaimData().setExpired(true);
                    claim.getData().save();
                } else if (taxPastDueDate.plus(Duration.ofDays(taxExpirationDays)).isBefore(localNow)) {
                    claim.getInternalClaimData().setExpired(true);
                    claim.getData().save();
                }
            }
        }
        final double totalTaxOwed = taxBalance + taxOwed;
        claim.getEconomyData().setTaxBalance(totalTaxOwed);
        claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.FAIL, Instant.now(), taxOwed));
    } else {
        claim.getEconomyData().addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
        claim.getEconomyData().setTaxPastDueDate(null);
        claim.getEconomyData().setTaxBalance(0);
        claim.getInternalClaimData().setExpired(false);

        if (inTown) {
            final GDClaim town = claim.getTownClaim();
            town.getData()
                .getEconomyData()
                .addPaymentTransaction(new GDPaymentTransaction(TransactionType.TAX, TransactionResultType.SUCCESS, Instant.now(), taxOwed));
            if (town.getEconomyAccountId().isPresent()) {
                this.economy.bankDeposit(town.getEconomyAccountId().get().toString(), taxOwed);
            }
        }
        claim.getData().save();
    }
}
 
Example #30
Source File: CmdBiome.java    From PlotMe-Core with GNU General Public License v3.0 4 votes vote down vote up
public boolean execute(ICommandSender sender, String[] args) {
    if (args.length > 4) {
        sender.sendMessage(getUsage());
        return true;
    }

    IPlayer player = (IPlayer) sender;
    if (player.hasPermission(PermissionNames.USER_BIOME)) {
        IWorld world = player.getWorld();
        PlotMapInfo pmi = manager.getMap(world);
        if (manager.isPlotWorld(world)) {
            Plot plot = manager.getPlot(player);
            if (plot != null) {
                Optional<String> biome = Optional.absent();
                if (args.length == 2) {
                    biome = serverBridge.getBiome(args[1]);
                } else if (args.length == 3) {
                    biome = serverBridge.getBiome(args[1] + " " + args[2]);
                } else if (args.length == 4) {
                    biome = serverBridge.getBiome(args[1] + " " + args[2] + " " + args[3]);
                }
                if (!biome.isPresent()) {
                    player.sendMessage(C("InvalidBiome", biome.get()));
                    return true;
                }

                String playerName = player.getName();

                if (player.getUniqueId().equals(plot.getOwnerId())) {

                    double price = 0.0;

                    PlotBiomeChangeEvent event = new PlotBiomeChangeEvent(plot, player, biome.get());
                    plugin.getEventBus().post(event);

                    if (manager.isEconomyEnabled(pmi)) {
                        price = pmi.getBiomeChangePrice();

                        if (!serverBridge.has(player, price)) {
                            player.sendMessage("It costs " + serverBridge.getEconomy().get().format(price) + " to change the biome.");
                            return true;
                        } else if (!event.isCancelled()) {
                            EconomyResponse er = serverBridge.withdrawPlayer(player, price);

                            if (!er.transactionSuccess()) {
                                player.sendMessage(er.errorMessage);
                                serverBridge.getLogger().warning(er.errorMessage);
                                return true;
                            }
                        } else {
                            return true;
                        }
                    }

                    if (!event.isCancelled()) {
                        plot.setBiome(biome.get());
                        manager.setBiome(plot);
                        plugin.getSqlManager().savePlot(plot);

                        player.sendMessage(C("BiomeChanged", biome.get()));

                        if (isAdvancedLogging()) {
                            if (price == 0) {
                                serverBridge.getLogger()
                                        .info(playerName + " " + C("MsgChangedBiome") + " " + plot.getId() + " " + C("WordTo") + " "
                                                + biome.get());
                            } else {
                                serverBridge.getLogger()
                                        .info(playerName + " " + C("MsgChangedBiome") + " " + plot.getId() + " " + C("WordTo") + " "
                                                + biome.get() + (" " + C("WordFor") + " " + price));
                            }
                        }
                    }
                } else {
                    player.sendMessage(C("MsgThisPlot") + "(" + plot.getId() + ") " + C("MsgNotYoursNotAllowedBiome"));
                }
            } else {
                player.sendMessage(C("MsgThisPlot") + C("MsgHasNoOwner"));
            }
        } else {
            player.sendMessage(C("NotPlotWorld"));
            return true;
        }
    } else {
        return false;
    }
    return true;
}