-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change how economy is handled and version check
- Loading branch information
1 parent
d20538a
commit dab2440
Showing
8 changed files
with
132 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package tsp.headdb.economy; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public interface HEconomyProvider { | ||
|
||
default boolean canPurchase(Player player, BigDecimal cost) { | ||
return true; | ||
} | ||
|
||
default void charge(Player player, BigDecimal amount) { | ||
|
||
} | ||
|
||
default void initProvider() { | ||
|
||
} | ||
|
||
} |
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,44 @@ | ||
package tsp.headdb.economy; | ||
|
||
import net.milkbowl.vault.economy.Economy; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
import tsp.headdb.util.Log; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class VaultProvider implements HEconomyProvider { | ||
|
||
private Economy economy; | ||
|
||
@Override | ||
public boolean canPurchase(Player player, BigDecimal cost) { | ||
return economy.has(player, cost.doubleValue()); | ||
} | ||
|
||
@Override | ||
public void charge(Player player, BigDecimal amount) { | ||
economy.withdrawPlayer(player, amount.doubleValue()); | ||
} | ||
|
||
public void initProvider() { | ||
if (!Bukkit.getServer().getPluginManager().isPluginEnabled("Vault")) { | ||
Log.error("Vault is not installed!"); | ||
return; | ||
} | ||
|
||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class); | ||
if (economyProvider == null) { | ||
Log.error("Could not find vault economy provider!"); | ||
return; | ||
} | ||
|
||
economy = economyProvider.getProvider(); | ||
} | ||
|
||
public Economy getProvider() { | ||
return economy; | ||
} | ||
|
||
} |
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