Skip to content

Commit

Permalink
Damnit.. Forgot to commit the implementations.....
Browse files Browse the repository at this point in the history
  • Loading branch information
dentych committed Jan 26, 2016
1 parent a1634a6 commit eb0f758
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/me/tychsen/enchantgui/Economy/MoneyPayment.java
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);
}
}
18 changes: 18 additions & 0 deletions src/me/tychsen/enchantgui/Economy/NullPayment.java
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;
}
}

0 comments on commit eb0f758

Please sign in to comment.