Java Code Examples for net.milkbowl.vault.economy.Economy#withdrawPlayer()
The following examples show how to use
net.milkbowl.vault.economy.Economy#withdrawPlayer() .
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: PlayerSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * 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 2
Source File: Utils.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Set a player's stats to defaults, and optionally clear their inventory. * * @param plugin {@link PerWorldInventory} for econ. * @param player The player to zero. * @param clearInventory Clear the player's inventory. */ public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) { if (clearInventory) { player.getInventory().clear(); player.getEnderChest().clear(); } player.setExp(0f); player.setFoodLevel(20); if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } else { player.setHealth(player.getMaxHealth()); } player.setLevel(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.setSaturation(5f); player.setFallDistance(0f); player.setFireTicks(0); if (plugin.isEconEnabled()) { Economy econ = plugin.getEconomy(); econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); econ.withdrawPlayer(player, econ.getBalance(player)); } }
Example 3
Source File: PlayerSerializer.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * 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 4
Source File: Utils.java From PerWorldInventory with GNU General Public License v3.0 | 5 votes |
/** * Set a player's stats to defaults, and optionally clear their inventory. * * @param plugin {@link PerWorldInventory} for econ. * @param player The player to zero. * @param clearInventory Clear the player's inventory. */ public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) { if (clearInventory) { player.getInventory().clear(); player.getEnderChest().clear(); } player.setExp(0f); player.setFoodLevel(20); if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } else { player.setHealth(player.getMaxHealth()); } player.setLevel(0); for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.setSaturation(5f); player.setFallDistance(0f); player.setFireTicks(0); if (plugin.isEconEnabled()) { Economy econ = plugin.getEconomy(); econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); econ.withdrawPlayer(player, econ.getBalance(player)); } }
Example 5
Source File: FlagEntryFee.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onGameStart(GameStartEvent event) { double fee = getValue(); Economy economy = getEconomy(); for (SpleefPlayer player : event.getGame().getPlayers()) { economy.withdrawPlayer(player.getBukkitPlayer(), fee); player.sendMessage(getI18N().getVarString(Messages.Player.PAID_ENTRY_FEE) .setVariable("amount", economy.format(fee)) .toString()); } }
Example 6
Source File: OffsetBounty.java From GlobalWarming with GNU Lesser General Public License v3.0 | 4 votes |
/** * Create a new bounty * - Players are limited to how many bounties they can create * - Requires an economy-plugin account with an adequate balance * - Requires a minimum of 1 block and a $1 reward */ public static void create(GPlayer gPlayer, int treeBlocks, int reward) { OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable(); if (offsetTable.getIncompleteBountyCount(gPlayer) >= MAX_BOUNTIES_CREATED_PER_PLAYER) { gPlayer.sendMsg(Lang.BOUNTY_MAXCREATED); } else if (treeBlocks < 1) { gPlayer.sendMsg(Lang.BOUNTY_BLOCKSREQUIRED); } else if (reward < 1) { gPlayer.sendMsg(Lang.BOUNTY_REWARDREQUIRED); } else { //Withdraw from account: boolean isWithdrawn = false; double balance = 0; Economy economy = GlobalWarming.getInstance().getEconomy(); if (economy != null) { EconomyResponse response = economy.withdrawPlayer(gPlayer.getOfflinePlayer(), reward); isWithdrawn = response.transactionSuccess(); balance = economy.getBalance(gPlayer.getOfflinePlayer()); } if (isWithdrawn) { //New bounty: OffsetBounty bounty = new OffsetBounty( GlobalWarming.getInstance().getRandom().nextInt(Integer.MAX_VALUE), gPlayer.getUniqueId(), null, gPlayer.getAssociatedWorldId(), treeBlocks, reward, 0, 0 ); //Local records: offsetTable.addOffset(bounty); //Database: OffsetInsertQuery insertQuery = new OffsetInsertQuery(bounty); AsyncDBQueue.getInstance().queueInsertQuery(insertQuery); //Notify: gPlayer.sendMsg(String.format(Lang.BOUNTY_CREATED.get(), balance)); } else { //Notify: // - Not enough funds or economy plugin issue gPlayer.sendMsg(String.format(Lang.BOUNTY_NOTCREATED.get(), balance)); } } }
Example 7
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Get a player from the cache, and apply the cached inventories and stats * to the actual player. If no matching player is found in the cache, nothing * happens and this method simply returns. * * @param group The {@link Group} the cached player was in. * @param gamemode The GameMode the cached player was in. * @param player The current actual player to apply the data to. * @param cause What triggered the inventory switch; passed on for post-processing. */ private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) { PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId()); if (cachedPlayer == null) { ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache"); return; } ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data"); if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS)) player.getEnderChest().setContents(cachedPlayer.getEnderChest()); if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) { player.getInventory().setContents(cachedPlayer.getInventory()); player.getInventory().setArmorContents(cachedPlayer.getArmor()); } if (settings.getProperty(PwiProperties.LOAD_CAN_FLY)) player.setAllowFlight(cachedPlayer.getCanFly()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME)) player.setDisplayName(cachedPlayer.getDisplayName()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION)) player.setExhaustion(cachedPlayer.getExhaustion()); if (settings.getProperty(PwiProperties.LOAD_EXP)) player.setExp(cachedPlayer.getExperience()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight()) player.setFlying(cachedPlayer.isFlying()); if (settings.getProperty(PwiProperties.LOAD_HUNGER)) player.setFoodLevel(cachedPlayer.getFoodLevel()); if (settings.getProperty(PwiProperties.LOAD_HEALTH)) { if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth()); } else { player.setMaxHealth(cachedPlayer.getMaxHealth()); } if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) { player.setHealth(cachedPlayer.getHealth()); } else { player.setHealth(cachedPlayer.getMaxHealth()); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES))) player.setGameMode(cachedPlayer.getGamemode()); if (settings.getProperty(PwiProperties.LOAD_LEVEL)) player.setLevel(cachedPlayer.getLevel()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) { for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(cachedPlayer.getPotionEffects()); } if (settings.getProperty(PwiProperties.LOAD_SATURATION)) player.setSaturation(cachedPlayer.getSaturationLevel()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE)) player.setFallDistance(cachedPlayer.getFallDistance()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS)) player.setFireTicks(cachedPlayer.getFireTicks()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR)) player.setMaximumAir(cachedPlayer.getMaxAir()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR)) player.setRemainingAir(cachedPlayer.getRemainingAir()); if (settings.getProperty(PwiProperties.USE_ECONOMY)) { Economy econ = plugin.getEconomy(); if (econ == null) { ConsoleLogger.warning("Economy saving is turned on, but no economy found!"); return; } EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player)); if (er.transactionSuccess()) { econ.depositPlayer(player, cachedPlayer.getBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage); } EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); if (bankER.transactionSuccess()) { econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage); } } InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause); Bukkit.getPluginManager().callEvent(event); }
Example 8
Source File: PWIPlayerManager.java From PerWorldInventory with GNU General Public License v3.0 | 4 votes |
/** * Get a player from the cache, and apply the cached inventories and stats * to the actual player. If no matching player is found in the cache, nothing * happens and this method simply returns. * * @param group The {@link Group} the cached player was in. * @param gamemode The GameMode the cached player was in. * @param player The current actual player to apply the data to. * @param cause What triggered the inventory switch; passed on for post-processing. */ private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) { PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId()); if (cachedPlayer == null) { ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache"); return; } ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data"); if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS)) player.getEnderChest().setContents(cachedPlayer.getEnderChest()); if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) { player.getInventory().setContents(cachedPlayer.getInventory()); player.getInventory().setArmorContents(cachedPlayer.getArmor()); } if (settings.getProperty(PwiProperties.LOAD_CAN_FLY)) player.setAllowFlight(cachedPlayer.getCanFly()); if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME)) player.setDisplayName(cachedPlayer.getDisplayName()); if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION)) player.setExhaustion(cachedPlayer.getExhaustion()); if (settings.getProperty(PwiProperties.LOAD_EXP)) player.setExp(cachedPlayer.getExperience()); if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight()) player.setFlying(cachedPlayer.isFlying()); if (settings.getProperty(PwiProperties.LOAD_HUNGER)) player.setFoodLevel(cachedPlayer.getFoodLevel()); if (settings.getProperty(PwiProperties.LOAD_HEALTH)) { if (bukkitService.shouldUseAttributes()) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth()); } else { player.setMaxHealth(cachedPlayer.getMaxHealth()); } if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) { player.setHealth(cachedPlayer.getHealth()); } else { player.setHealth(cachedPlayer.getMaxHealth()); } } if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES))) player.setGameMode(cachedPlayer.getGamemode()); if (settings.getProperty(PwiProperties.LOAD_LEVEL)) player.setLevel(cachedPlayer.getLevel()); if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) { for (PotionEffect effect : player.getActivePotionEffects()) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(cachedPlayer.getPotionEffects()); } if (settings.getProperty(PwiProperties.LOAD_SATURATION)) player.setSaturation(cachedPlayer.getSaturationLevel()); if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE)) player.setFallDistance(cachedPlayer.getFallDistance()); if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS)) player.setFireTicks(cachedPlayer.getFireTicks()); if (settings.getProperty(PwiProperties.LOAD_MAX_AIR)) player.setMaximumAir(cachedPlayer.getMaxAir()); if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR)) player.setRemainingAir(cachedPlayer.getRemainingAir()); if (settings.getProperty(PwiProperties.USE_ECONOMY)) { Economy econ = plugin.getEconomy(); if (econ == null) { ConsoleLogger.warning("Economy saving is turned on, but no economy found!"); return; } EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player)); if (er.transactionSuccess()) { econ.depositPlayer(player, cachedPlayer.getBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage); } EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount); if (bankER.transactionSuccess()) { econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance()); } else { ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage); } } InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause); Bukkit.getPluginManager().callEvent(event); }