mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-09-27 14:12:58 +02:00
Merge
This commit is contained in:
parent
fc0588281f
commit
b9fbcfcdf5
@ -50,7 +50,7 @@
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>org.mcstats.bukkit:metrics</include>
|
||||
<include>org.mcstats.*:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
|
@ -10,8 +10,10 @@ import org.appledash.saneeconomy.utils.I18n;
|
||||
import org.appledash.saneeconomy.utils.SaneEconomyConfiguration;
|
||||
import org.appledash.saneeconomy.vault.VaultHook;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.mcstats.Metrics;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
@ -62,6 +64,14 @@ public class SaneEconomy extends JavaPlugin implements ISaneEconomy {
|
||||
economyManager.getBackend().reloadTopPlayerBalances();
|
||||
}, 0, (20 * 300) /* Update baltop every 5 minutes */);
|
||||
I18n.getInstance().loadTranslations();
|
||||
|
||||
try {
|
||||
Metrics metrics = new Metrics(this);
|
||||
metrics.start();
|
||||
} catch (IOException e) {
|
||||
getLogger().warning("Failed to start Metrics.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -95,7 +95,7 @@ public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
double newAmount = result.getFromBalance();
|
||||
|
@ -79,11 +79,8 @@ public class EconomyManager {
|
||||
* @return True if they have requiredBalance or more, false otherwise
|
||||
*/
|
||||
public boolean hasBalance(Economable targetPlayer, double requiredBalance) {
|
||||
if (targetPlayer == Economable.CONSOLE) {
|
||||
return true;
|
||||
}
|
||||
return targetPlayer == Economable.CONSOLE || getBalance(targetPlayer) >= requiredBalance;
|
||||
|
||||
return getBalance(targetPlayer) >= requiredBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +146,7 @@ public class EconomyManager {
|
||||
amount = NumberUtils.filterAmount(currency, amount);
|
||||
|
||||
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) {
|
||||
@ -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.
|
||||
* @return TransactionResult describing success or failure of the Transaction.
|
||||
*/
|
||||
public TransactionResult transact(Transaction transaction) {
|
||||
Economable sender = transaction.getSender();
|
||||
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 (!hasBalance(sender, amount) && (transaction.getReason() != TransactionReason.TEST)) {
|
||||
return new TransactionResult(transaction, Status.ERR_NOT_ENOUGH_FUNDS);
|
||||
// If the sender doesn't have the balance AND we're not testing, throw an error.
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user