-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Damnit.. Forgot to commit the implementations.....
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package me.tychsen.enchantgui.Economy; | ||
|
||
import me.tychsen.enchantgui.Main; | ||
import net.milkbowl.vault.economy.Economy; | ||
import net.milkbowl.vault.economy.EconomyResponse; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.RegisteredServiceProvider; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class MoneyPayment implements PaymentStrategy { | ||
private Economy econ = null; | ||
private JavaPlugin plugin; | ||
|
||
public MoneyPayment() { | ||
this.plugin = Main.getInstance(); | ||
|
||
if (!setupEconomy()) { | ||
plugin.getLogger().severe("Dependency (Vault) not found. Disabling the plugin!"); | ||
plugin.getServer().getPluginManager().disablePlugin(plugin); | ||
} | ||
} | ||
|
||
public boolean withdraw(Player p, int amount) { | ||
EconomyResponse r = econ.withdrawPlayer(p, amount); | ||
|
||
if (r.transactionSuccess()) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
private boolean setupEconomy() { | ||
if (plugin.getServer().getPluginManager().getPlugin("Vault") == null) { | ||
return false; | ||
} | ||
RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); | ||
if (rsp == null) { | ||
return false; | ||
} | ||
econ = rsp.getProvider(); | ||
return econ != null; | ||
} | ||
|
||
@Override | ||
public boolean hasSufficientFunds(Player p, int amount) { | ||
return econ.has(p, amount); | ||
} | ||
} |
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,18 @@ | ||
package me.tychsen.enchantgui.Economy; | ||
|
||
import org.bukkit.entity.Player; | ||
|
||
/** | ||
* Used to disable payment. | ||
*/ | ||
public class NullPayment implements PaymentStrategy { | ||
@Override | ||
public boolean withdraw(Player p, int amount) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean hasSufficientFunds(Player p, int amount) { | ||
return true; | ||
} | ||
} |