Skip to content

Commit

Permalink
fixed vault purchases
Browse files Browse the repository at this point in the history
  • Loading branch information
jascotty2 committed Nov 11, 2012
1 parent 8ed2492 commit a2e0a68
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
6 changes: 5 additions & 1 deletion changelog
Expand Up @@ -2,7 +2,11 @@
BetterShop Changelog: (the (?) means plugin didn't report that as the version.. sorry :))
===============================================================================

Version 2.1.4 - 2.1.4.1
Version 2.1.4.2 - 11/10/12
fixed a vault-specific logic error that caused purchases to be free


Version 2.1.4.1 - 11/5/12
quick fix to work with 1.4


Expand Down
72 changes: 49 additions & 23 deletions src/me/jascotty2/bettershop/BSEcon.java
Expand Up @@ -24,6 +24,7 @@
import me.jascotty2.bettershop.utils.BetterShopLogger;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -39,7 +40,7 @@ public class BSEcon implements Listener {
protected static Method economyMethod = null;
protected static Methods _econMethods = new Methods();
protected static String methodName = null;
protected static Economy econ = null;
protected static Economy vaultEcon = null;
// iconomy seems to throw alot of errors...
// this is to only display one
static boolean _pastBalanceErr = false;
Expand All @@ -50,7 +51,7 @@ public BSEcon(BetterShop plugin) {
BSEcon.plugin = plugin;
pm = plugin.getServer().getPluginManager();
if (setupEconomy()) {
methodName = econ.getName();
methodName = vaultEcon.getName();
BetterShopLogger.Log("Using " + methodName + " (via Vault) for economy");
}
Methods.setMethod(pm);
Expand All @@ -65,13 +66,13 @@ private boolean setupEconomy() {
if (rsp == null) {
return false;
}
econ = rsp.getProvider();
return econ != null;
vaultEcon = rsp.getProvider();
return vaultEcon != null;
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (econ != null) {
if (vaultEcon != null) {
return;
}
if (!Methods.hasMethod() && Methods.setMethod(plugin.getServer().getPluginManager())) {
Expand All @@ -83,7 +84,7 @@ public void onPluginEnable(PluginEnableEvent event) {

@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (econ != null) {
if (vaultEcon != null) {
return;
}
// Check to see if the plugin thats being disabled is the one we are using
Expand All @@ -96,7 +97,7 @@ public void onPluginDisable(PluginDisableEvent event) {
}

public static boolean active() {
return BetterShop.config.econ != EconMethod.AUTO || econ != null || economyMethod != null;
return BetterShop.config.econ != EconMethod.AUTO || vaultEcon != null || economyMethod != null;
}

public static String getMethodName() {
Expand All @@ -111,7 +112,7 @@ public static String getMethodName() {

public static boolean hasAccount(Player pl) {
return pl != null && (BetterShop.config.econ != EconMethod.AUTO
|| (econ != null && econ.hasAccount(pl.getName()))
|| (vaultEcon != null && vaultEcon.hasAccount(pl.getName()))
|| (economyMethod != null && economyMethod.hasAccount(pl.getName())));
}

Expand Down Expand Up @@ -148,8 +149,8 @@ public static double getBalance(String playerName) {
return p == null ? 0 : p.getTotalExperience();
}
try {
if (econ != null && econ.hasAccount(playerName)) {
return econ.getBalance(playerName);
if (vaultEcon != null && vaultEcon.hasAccount(playerName)) {
return vaultEcon.getBalance(playerName);
} else if (economyMethod != null && economyMethod.hasAccount(playerName)) {
return economyMethod.getAccount(playerName).balance();
}
Expand Down Expand Up @@ -188,12 +189,23 @@ public static void addMoney(String playerName, double amt) {
if (pl != null) {
pl.setTotalExperience(pl.getTotalExperience() + (int) amt);
}
} else if (econ != null) {
if (!econ.hasAccount(playerName)) {
} else if (vaultEcon != null) {
if (!vaultEcon.hasAccount(playerName)) {
// TODO? add methods for creating an account
return;
}
econ.depositPlayer(playerName, amt);
// EconomyResponse r;
if(amt >= 0) {
// r =
vaultEcon.depositPlayer(playerName, amt);
} else {
// r =
vaultEcon.withdrawPlayer(playerName, -amt);
}
// System.out.println(r.type);
// System.out.println(r.errorMessage);
// System.out.println(r.amount);
// System.out.println(r.balance);
} else if (economyMethod != null) {
if (!economyMethod.hasAccount(playerName)) {
// TODO? add methods for creating an account
Expand Down Expand Up @@ -246,12 +258,26 @@ public static void subtractMoney(String playerName, double amt) {
pl.setTotalExperience(0);
}
}
} else if (econ != null) {
if (!econ.hasAccount(playerName)) {
} else if (vaultEcon != null) {
if (!vaultEcon.hasAccount(playerName)) {
// TODO? add methods for creating an account
return;
}
econ.withdrawPlayer(playerName, amt);
EconomyResponse r;
// System.out.println("subtract(" + playerName + ", " + amt + ")");
if(amt >= 0) {
// r =
vaultEcon.withdrawPlayer(playerName, amt);
} else {
// r =
vaultEcon.depositPlayer(playerName, -amt);
}

// System.out.println(r.type);
// System.out.println(r.errorMessage);
// System.out.println(r.amount);
// System.out.println(r.balance);

} else if (economyMethod != null) {
if (!economyMethod.hasAccount(playerName)) {
// TODO? add methods for creating an account
Expand Down Expand Up @@ -352,11 +378,11 @@ private static boolean bankTransaction(String player, double amount) {
&& hasBank(BetterShop.getSettings().BOSBank)) {
if (economyMethod != null) {
BSEcon.addMoney(BetterShop.getSettings().BOSBank, -amount);
} else if (econ != null) {
} else if (vaultEcon != null) {
if (amount < 0) {
econ.bankWithdraw(BetterShop.getSettings().BOSBank, -amount);
vaultEcon.bankWithdraw(BetterShop.getSettings().BOSBank, -amount);
} else {
econ.bankDeposit(BetterShop.getSettings().BOSBank, -amount);
vaultEcon.bankDeposit(BetterShop.getSettings().BOSBank, -amount);
}
}
}
Expand All @@ -367,8 +393,8 @@ && hasBank(BetterShop.getSettings().BOSBank)) {

public static String format(double amt) {
try {
if (econ != null) {
return econ.format(amt);
if (vaultEcon != null) {
return vaultEcon.format(amt);
} else if (economyMethod != null) {
return economyMethod.format(amt);
}
Expand All @@ -388,8 +414,8 @@ public static boolean hasBank(String bank) {

if (economyMethod != null) {
return economyMethod.hasBanks() && economyMethod.hasBank(bank);
} else if (econ != null && econ.hasBankSupport()) {
return econ.bankBalance(bank).transactionSuccess();
} else if (vaultEcon != null && vaultEcon.hasBankSupport()) {
return vaultEcon.bankBalance(bank).transactionSuccess();
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/me/jascotty2/bettershop/BetterShop.java
Expand Up @@ -64,7 +64,7 @@
*/
public class BetterShop extends JavaPlugin {

public final static String lastUpdatedStr = "07/12/12 08:40 -0500"; // "MM/dd/yy HH:mm Z"
public final static String lastUpdatedStr = "11/10/12 20:15 -0500"; // "MM/dd/yy HH:mm Z"
public final static int lastUpdated_gracetime = 20; // how many minutes off before out of date
protected static Plugin bettershopPlugin = null;
protected final static BSConfig config = new BSConfig();
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
@@ -1,6 +1,6 @@
name: BetterShop
main: me.jascotty2.bettershop.BetterShop
version: 2.1.4.1
version: 2.1.4.2
website: http://github.com/BetterShop/BetterShop
author: jascotty2
softdepend: [Spout, Vault]
Expand Down

0 comments on commit a2e0a68

Please sign in to comment.