-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added vault economy support for unlocking research
- Loading branch information
BuildTools
committed
Oct 20, 2023
1 parent
7a8780b
commit 97390e0
Showing
9 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/io/github/thebusybiscuit/slimefun4/integrations/VaultIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.github.thebusybiscuit.slimefun4.integrations; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
|
||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; | ||
import net.milkbowl.vault.economy.Economy; | ||
|
||
/** | ||
* This handles all integrations with Vault's economy. | ||
* Used to unlock research. | ||
* | ||
* @author Mis | ||
* | ||
*/ | ||
public class VaultIntegration { | ||
private RegisteredServiceProvider<Economy> economy; | ||
|
||
public VaultIntegration() { | ||
this.economy = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); | ||
} | ||
|
||
public double getBalance(@Nonnull Player player) { | ||
return this.economy.getProvider().getBalance(player); | ||
} | ||
|
||
public boolean hasBalance(@Nonnull Player player, double amount) { | ||
return this.getBalance(player) >= amount; | ||
} | ||
|
||
public void deposit(@Nonnull Player player, double amount) { | ||
this.economy.getProvider().depositPlayer(player, amount); | ||
} | ||
|
||
public void withdraw(@Nonnull Player player, double amount) { | ||
this.economy.getProvider().withdrawPlayer(player, amount); | ||
} | ||
|
||
/** | ||
* Checks if the player has enough money to buy this research, | ||
* depending on the xp levels required and the price multiplier. | ||
* | ||
* @return whether the player can afford the research or not. | ||
*/ | ||
public boolean hasBalanceForResearch(@Nonnull Player player, int xpCost) { | ||
return this.hasBalance(player, xpCost * Slimefun.getRegistry().getEconomyPriceMultiplier()); | ||
} | ||
|
||
/** | ||
* Withdraws money from the player by the given amount times the price multiplier. | ||
*/ | ||
public void withdrawForResearch(@Nonnull Player player, int xpCost) { | ||
this.withdraw(player, xpCost * Slimefun.getRegistry().getEconomyPriceMultiplier()); | ||
} | ||
|
||
/** | ||
* Returns the formatted price, according to the xp level cost and price multiplier. | ||
* | ||
* @return the formatted price. | ||
*/ | ||
public String getResearchPrice(int xpCost) { | ||
return this.economy.getProvider().format(xpCost * Slimefun.getRegistry().getEconomyPriceMultiplier()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ softdepend: | |
- mcMMO | ||
- ItemsAdder | ||
- Orebfuscator | ||
- Vault | ||
|
||
# Our commands | ||
commands: | ||
|