This commit is contained in:
AppleDash 2016-09-22 03:54:46 -04:00
parent fc0588281f
commit b9fbcfcdf5
6 changed files with 28 additions and 12 deletions

View File

@ -50,7 +50,7 @@
<configuration> <configuration>
<artifactSet> <artifactSet>
<includes> <includes>
<include>org.mcstats.bukkit:metrics</include> <include>org.mcstats.*:*</include>
</includes> </includes>
</artifactSet> </artifactSet>
</configuration> </configuration>

View File

@ -10,8 +10,10 @@ import org.appledash.saneeconomy.utils.I18n;
import org.appledash.saneeconomy.utils.SaneEconomyConfiguration; import org.appledash.saneeconomy.utils.SaneEconomyConfiguration;
import org.appledash.saneeconomy.vault.VaultHook; import org.appledash.saneeconomy.vault.VaultHook;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.mcstats.Metrics;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -62,6 +64,14 @@ public class SaneEconomy extends JavaPlugin implements ISaneEconomy {
economyManager.getBackend().reloadTopPlayerBalances(); economyManager.getBackend().reloadTopPlayerBalances();
}, 0, (20 * 300) /* Update baltop every 5 minutes */); }, 0, (20 * 300) /* Update baltop every 5 minutes */);
I18n.getInstance().loadTranslations(); I18n.getInstance().loadTranslations();
try {
Metrics metrics = new Metrics(this);
metrics.start();
} catch (IOException e) {
getLogger().warning("Failed to start Metrics.");
e.printStackTrace();
}
} }
@Override @Override

View File

@ -95,7 +95,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
} }
if (subCommand.equalsIgnoreCase("take")) { if (subCommand.equalsIgnoreCase("take")) {
Transaction transaction = new Transaction(Economable.wrap(sender), Economable.wrap(targetPlayer), amount, TransactionReason.ADMIN); Transaction transaction = new Transaction(Economable.wrap(targetPlayer), Economable.wrap(sender), amount, TransactionReason.ADMIN);
TransactionResult result = ecoMan.transact(transaction); TransactionResult result = ecoMan.transact(transaction);
double newAmount = result.getFromBalance(); double newAmount = result.getFromBalance();

View File

@ -79,11 +79,8 @@ public class EconomyManager {
* @return True if they have requiredBalance or more, false otherwise * @return True if they have requiredBalance or more, false otherwise
*/ */
public boolean hasBalance(Economable targetPlayer, double requiredBalance) { public boolean hasBalance(Economable targetPlayer, double requiredBalance) {
if (targetPlayer == Economable.CONSOLE) { return targetPlayer == Economable.CONSOLE || getBalance(targetPlayer) >= requiredBalance;
return true;
}
return getBalance(targetPlayer) >= requiredBalance;
} }
/** /**
@ -149,7 +146,7 @@ public class EconomyManager {
amount = NumberUtils.filterAmount(currency, amount); amount = NumberUtils.filterAmount(currency, amount);
if (amount < 0) { if (amount < 0) {
throw new IllegalArgumentException("Cannot set balance to a negative value!"); throw new IllegalArgumentException("Cannot subtract a negative amount!");
} }
if (targetPlayer == Economable.CONSOLE) { if (targetPlayer == Economable.CONSOLE) {
@ -160,17 +157,20 @@ public class EconomyManager {
} }
/** /**
* Perform a transaction. * Perform a transaction - a transfer of funds from one entity to another.
* @param transaction Transaction to perform. * @param transaction Transaction to perform.
* @return TransactionResult describing success or failure of the Transaction.
*/ */
public TransactionResult transact(Transaction transaction) { public TransactionResult transact(Transaction transaction) {
Economable sender = transaction.getSender(); Economable sender = transaction.getSender();
Economable receiver = transaction.getReceiver(); Economable receiver = transaction.getReceiver();
double amount = transaction.getAmount(); double amount = transaction.getAmount(); // This amount is validated upon creation of Transaction
if (!transaction.isFree()) { // If the transaction is occurring because of another plugin or because of an admin. if (!transaction.isFree()) { // If the transaction is occurring because of another plugin or because of an admin.
if (!hasBalance(sender, amount) && (transaction.getReason() != TransactionReason.TEST)) { // If the sender doesn't have the balance AND we're not testing, throw an error.
return new TransactionResult(transaction, Status.ERR_NOT_ENOUGH_FUNDS); // I don't really know why we check if they're testing, but it breaks if we don't. FIXME.
if (!hasBalance(sender, amount) && transaction.getReason() != TransactionReason.TEST) {
return new TransactionResult(transaction, TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS);
} }
subtractBalance(sender, amount); subtractBalance(sender, amount);

View File

@ -145,7 +145,7 @@ public class EconomySaneEconomy implements Economy {
} }
return transact(new Transaction( return transact(new Transaction(
economable, Economable.PLUGIN, v, TransactionReason.PLUGIN economable, Economable.PLUGIN, v, TransactionReason.PLUGIN
)); ));
} }

View File

@ -42,5 +42,11 @@
<artifactId>VaultAPI</artifactId> <artifactId>VaultAPI</artifactId>
<version>1.6</version> <version>1.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
<version>R8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>