Java Code Examples for net.milkbowl.vault.economy.Economy#depositPlayer()

The following examples show how to use net.milkbowl.vault.economy.Economy#depositPlayer() . 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: OffsetBounty.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Update the remaining blocks for an active bounty
 * - Requires a Vault-economy plugin to deposit funds
 */
public static OffsetBounty update(GPlayer hunter, int blocksCompleted) {
    OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable();
    OffsetBounty bounty = offsetTable.update(hunter, blocksCompleted);
    if (bounty != null && bounty.getTimeCompleted() != 0) {
        Economy economy = GlobalWarming.getInstance().getEconomy();
        if (economy != null) {
            economy.depositPlayer(hunter.getOfflinePlayer(), bounty.getReward());
            notify(
                    bounty,
                    hunter,
                    String.format(Lang.BOUNTY_COMPLETEDBY.get(), hunter.getOfflinePlayer().getName()),
                    String.format(Lang.BOUNTY_COMPLETED.get(), bounty.getReward()));
        }
    }

    return bounty;
}
 
Example 2
Source File: OffsetBounty.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void cancel(GPlayer gPlayer) {
    int refund = 0;
    OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable();
    List<OffsetBounty> cancelledBounties = offsetTable.cancel(gPlayer);
    Economy economy = GlobalWarming.getInstance().getEconomy();
    if (economy != null) {
        for (OffsetBounty bounty : cancelledBounties) {
            economy.depositPlayer(gPlayer.getOfflinePlayer(), bounty.getReward());
            refund += bounty.getReward();
        }
    }

    gPlayer.sendMsg(String.format(
            Lang.BOUNTY_CANCELLED.get(),
            cancelledBounties.size(),
            refund));
}
 
Example 3
Source File: FlagJackpot.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onPlayerWin(PlayerWinGameEvent event) {
	SpleefPlayer[] winners = event.getWinners();
	FlagEntryFee flagEntryFee = (FlagEntryFee) getParent();
	
	Economy economy = flagEntryFee.getEconomy();
	double jackpot = flagEntryFee.getValue() * playerCount;
	
	double amountPerWinner = jackpot / winners.length;
	for (SpleefPlayer winner : winners) {
		economy.depositPlayer(winner.getBukkitPlayer(), amountPerWinner);
		winner.sendMessage(getI18N().getVarString(Messages.Player.PLAYER_RECEIVE_JACKPOT)
				.setVariable("amount", economy.format(amountPerWinner))
				.toString());
	}
}
 
Example 4
Source File: FlagReward.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onGameWin(PlayerWinGameEvent event) {
	//Call the method to potentially lazy-initialize the economy plugin
	Economy economy = getEconomy();
	List<Double> rewards = getValue();
	double winnerReward = rewards.get(0);
	String[] places = getI18N().getStringArray(Messages.Arrays.PLACES);
	
	for (SpleefPlayer winner : event.getWinners()) {
		economy.depositPlayer(winner.getBukkitPlayer(), winnerReward);
		winner.sendMessage(getI18N().getVarString(Messages.Player.RECEIVED_REWARD_PLACE)
				.setVariable("amount", economy.format(winnerReward))
				.setVariable("place", places[0])
				.toString());
	}
	
	List<SpleefPlayer> losePlaces = event.getLosePlaces();
	for (int i = 0; i < losePlaces.size() && i + 1 < rewards.size(); i++) {
		double reward = rewards.get(i + 1);
		SpleefPlayer loser = losePlaces.get(i);
		
		String placeString = i + 1 < places.length ? places[i + 1] : String.valueOf(i + 1) + '.';
		
		economy.depositPlayer(loser.getBukkitPlayer(), reward);
		loser.sendMessage(getI18N().getVarString(Messages.Player.RECEIVED_REWARD_PLACE)
				.setVariable("amount", economy.format(reward))
				.setVariable("place", placeString)
				.toString());
	}
}
 
Example 5
Source File: GDClaimManager.java    From GriefDefender with MIT License 4 votes vote down vote up
public ClaimResult deleteClaimInternal(Claim claim, boolean deleteChildren) {
    final GDClaim gdClaim = (GDClaim) claim;
    Set<Claim> subClaims = claim.getChildren(false);
    for (Claim child : subClaims) {
        if (deleteChildren || (gdClaim.parent == null && child.isSubdivision())) {
            this.deleteClaimInternal(child, true);
            continue;
        }

        final GDClaim parentClaim = (GDClaim) claim;
        final GDClaim childClaim = (GDClaim) child;
        if (parentClaim.parent != null) {
            migrateChildToNewParent(parentClaim.parent, childClaim);
        } else {
            // move child to parent folder
            migrateChildToNewParent(null, childClaim);
        }
    }

    resetPlayerClaimVisuals(claim);
    // transfer bank balance to owner
    final UUID bankAccount = claim.getEconomyAccountId().orElse(null);
    if (bankAccount != null) {
        final Economy economy = GriefDefenderPlugin.getInstance().getVaultProvider().getApi();
        final GDPlayerData playerData = ((GDClaim) claim).getOwnerPlayerData();
        if (playerData != null) {
            final OfflinePlayer vaultPlayer = playerData.getSubject().getOfflinePlayer();
            if (vaultPlayer != null && !economy.hasAccount(vaultPlayer)) {
                final double bankBalance = economy.bankBalance(claim.getUniqueId().toString()).amount;
                economy.depositPlayer(vaultPlayer, bankBalance);
            }
        }
        economy.deleteBank(claim.getUniqueId().toString());
    }
    this.worldClaims.remove(claim);
    this.claimUniqueIdMap.remove(claim.getUniqueId());
    this.deleteChunkHashes((GDClaim) claim);
    if (gdClaim.parent != null) {
        gdClaim.parent.children.remove(claim);
    }
    for (UUID playerUniqueId : gdClaim.playersWatching) {
        final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(playerUniqueId);
        if (user != null && user.getOnlinePlayer() != null) {
            user.getInternalPlayerData().revertClaimVisual(gdClaim);
        }
    }

    return DATASTORE.deleteClaimFromStorage((GDClaim) claim);
}
 
Example 6
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 7
Source File: EconomySerializer.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
public static void deserialize(Economy econ, JsonObject data, Player player) {
    if (data.has("balance")) {
        ConsoleLogger.debug("[ECON] Depositing " + data.get("balance").getAsDouble() + " to '" + player.getName() + "'!");
        econ.depositPlayer(player, data.get("balance").getAsDouble());
    }
}
 
Example 8
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 9
Source File: EconomySerializer.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
public static void deserialize(Economy econ, JsonObject data, Player player) {
    if (data.has("balance")) {
        ConsoleLogger.debug("[ECON] Depositing " + data.get("balance").getAsDouble() + " to '" + player.getName() + "'!");
        econ.depositPlayer(player, data.get("balance").getAsDouble());
    }
}