mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-09-29 06:57:31 +02:00
Version bump 0.14.0. Make the API needlessly more complex to try and fix some bugs.
This commit is contained in:
parent
6be741b047
commit
867535bb4d
@ -9,7 +9,7 @@
|
|||||||
<version>0</version>
|
<version>0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>SaneEconomyCore</artifactId>
|
<artifactId>SaneEconomyCore</artifactId>
|
||||||
<version>0.13.1-SNAPSHOT</version>
|
<version>0.14.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -81,7 +81,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (subCommand.equalsIgnoreCase("give")) {
|
if (subCommand.equalsIgnoreCase("give")) {
|
||||||
Transaction transaction = new Transaction(Economable.wrap(sender), Economable.wrap(targetPlayer), amount, TransactionReason.ADMIN_GIVE);
|
Transaction transaction = new Transaction(ecoMan.getCurrency(), Economable.wrap(sender), Economable.wrap(targetPlayer), amount, TransactionReason.ADMIN_GIVE);
|
||||||
TransactionResult result = ecoMan.transact(transaction);
|
TransactionResult result = ecoMan.transact(transaction);
|
||||||
|
|
||||||
double newAmount = result.getToBalance();
|
double newAmount = result.getToBalance();
|
||||||
@ -95,7 +95,7 @@ public class EconomyAdminCommand extends SaneCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (subCommand.equalsIgnoreCase("take")) {
|
if (subCommand.equalsIgnoreCase("take")) {
|
||||||
Transaction transaction = new Transaction(Economable.wrap(targetPlayer), Economable.wrap(sender), amount, TransactionReason.ADMIN_TAKE);
|
Transaction transaction = new Transaction(ecoMan.getCurrency(), Economable.wrap(targetPlayer), Economable.wrap(sender), amount, TransactionReason.ADMIN_TAKE);
|
||||||
TransactionResult result = ecoMan.transact(transaction);
|
TransactionResult result = ecoMan.transact(transaction);
|
||||||
|
|
||||||
double newAmount = result.getFromBalance();
|
double newAmount = result.getFromBalance();
|
||||||
@ -117,12 +117,12 @@ public class EconomyAdminCommand extends SaneCommand {
|
|||||||
// FIXME: This is a silly hack to get it to log.
|
// FIXME: This is a silly hack to get it to log.
|
||||||
if (oldBal > 0.0) {
|
if (oldBal > 0.0) {
|
||||||
logger.logTransaction(new Transaction(
|
logger.logTransaction(new Transaction(
|
||||||
economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
|
ecoMan.getCurrency(), economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.logTransaction(new Transaction(
|
logger.logTransaction(new Transaction(
|
||||||
Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
|
ecoMan.getCurrency(), Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class PayCommand extends SaneCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the actual transfer. False == They didn't have enough money */
|
/* Perform the actual transfer. False == They didn't have enough money */
|
||||||
Transaction transaction = new Transaction(Economable.wrap(fromPlayer), Economable.wrap(toPlayer), amount, TransactionReason.PLAYER_PAY);
|
Transaction transaction = new Transaction(ecoMan.getCurrency(), Economable.wrap(fromPlayer), Economable.wrap(toPlayer), amount, TransactionReason.PLAYER_PAY);
|
||||||
TransactionResult result = ecoMan.transact(transaction);
|
TransactionResult result = ecoMan.transact(transaction);
|
||||||
|
|
||||||
if (result.getStatus() != TransactionResult.Status.SUCCESS) {
|
if (result.getStatus() != TransactionResult.Status.SUCCESS) {
|
||||||
|
@ -87,53 +87,27 @@ public class EconomyManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add to a player's balance.
|
* Add to a player's balance.
|
||||||
|
* This does not filter the amount.
|
||||||
* @param targetPlayer Player to add to
|
* @param targetPlayer Player to add to
|
||||||
* @param amount Amount to add
|
* @param amount Amount to add
|
||||||
* @throws IllegalArgumentException If amount is negative
|
* @throws IllegalArgumentException If amount is negative
|
||||||
*/
|
*/
|
||||||
private void addBalance(Economable targetPlayer, double amount) {
|
private void addBalance(Economable targetPlayer, double amount) {
|
||||||
amount = NumberUtils.filterAmount(currency, amount);
|
setBalance(targetPlayer, backend.getBalance(targetPlayer) + amount);
|
||||||
|
|
||||||
if (amount < 0) {
|
|
||||||
throw new IllegalArgumentException("Cannot add a negative amount!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetPlayer == Economable.CONSOLE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double newAmount = backend.getBalance(targetPlayer) + amount;
|
|
||||||
|
|
||||||
setBalance(targetPlayer, newAmount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subtract from a player's balance.
|
* Subtract from a player's balance.
|
||||||
* If the subtraction would result in a negative balance, the balance is instead set to 0.
|
* If the subtraction would result in a negative balance, the balance is instead set to 0.
|
||||||
|
* This does not filter the amount.
|
||||||
|
*
|
||||||
* @param targetPlayer Player to subtract from
|
* @param targetPlayer Player to subtract from
|
||||||
* @param amount Amount to subtract
|
* @param amount Amount to subtract
|
||||||
* @throws IllegalArgumentException If amount is negative
|
* @throws IllegalArgumentException If amount is negative
|
||||||
*/
|
*/
|
||||||
private void subtractBalance(Economable targetPlayer, double amount) {
|
private void subtractBalance(Economable targetPlayer, double amount) {
|
||||||
amount = NumberUtils.filterAmount(currency, amount);
|
// Ensure we don't go negative.
|
||||||
|
setBalance(targetPlayer, Math.max(0.0, backend.getBalance(targetPlayer) - amount));
|
||||||
if (amount < 0) {
|
|
||||||
throw new IllegalArgumentException("Cannot subtract a negative amount!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetPlayer == Economable.CONSOLE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double newAmount = backend.getBalance(targetPlayer) - amount;
|
|
||||||
|
|
||||||
|
|
||||||
/* Subtracting that much would result in a negative balance - don't do that */
|
|
||||||
if (newAmount <= 0.0D) {
|
|
||||||
newAmount = 0.0D;
|
|
||||||
}
|
|
||||||
|
|
||||||
setBalance(targetPlayer, newAmount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -145,10 +119,6 @@ public class EconomyManager {
|
|||||||
public void setBalance(Economable targetPlayer, double amount) {
|
public void setBalance(Economable targetPlayer, double amount) {
|
||||||
amount = NumberUtils.filterAmount(currency, amount);
|
amount = NumberUtils.filterAmount(currency, amount);
|
||||||
|
|
||||||
if (amount < 0) {
|
|
||||||
throw new IllegalArgumentException("Cannot subtract a negative amount!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetPlayer == Economable.CONSOLE) {
|
if (targetPlayer == Economable.CONSOLE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -164,9 +134,9 @@ public class EconomyManager {
|
|||||||
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(); // This amount is validated upon creation of Transaction
|
double amount = transaction.getAmount(); // This amount is validated and filtered upon creation of Transaction
|
||||||
|
|
||||||
if (Bukkit.getServer().getPluginManager() != null) { // Bukkit.getServer() == null from our JUnit tests.
|
if (Bukkit.getServer().getPluginManager() != null) { // Bukkit.getServer().getPluginManager() == null from our JUnit tests.
|
||||||
SaneEconomyTransactionEvent evt = new SaneEconomyTransactionEvent(transaction);
|
SaneEconomyTransactionEvent evt = new SaneEconomyTransactionEvent(transaction);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(evt);
|
Bukkit.getServer().getPluginManager().callEvent(evt);
|
||||||
if (evt.isCancelled()) {
|
if (evt.isCancelled()) {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package org.appledash.saneeconomy.economy.transaction;
|
package org.appledash.saneeconomy.economy.transaction;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomy.economy.Currency;
|
||||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||||
import org.appledash.saneeconomy.economy.transaction.TransactionReason.AffectedParties;
|
import org.appledash.saneeconomy.economy.transaction.TransactionReason.AffectedParties;
|
||||||
|
import org.appledash.saneeconomy.utils.NumberUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by appledash on 9/21/16.
|
* Created by appledash on 9/21/16.
|
||||||
@ -13,14 +15,15 @@ public class Transaction {
|
|||||||
private final double amount;
|
private final double amount;
|
||||||
private final TransactionReason reason;
|
private final TransactionReason reason;
|
||||||
|
|
||||||
public Transaction(Economable sender, Economable receiver, double amount, TransactionReason reason) {
|
public Transaction(Currency currency, Economable sender, Economable receiver, double amount, TransactionReason reason) {
|
||||||
if (amount <= 0.0) {
|
if (amount <= 0.0) {
|
||||||
throw new IllegalArgumentException("Cannot transact a zero or negative amount!");
|
throw new IllegalArgumentException("Cannot transact a zero or negative amount!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.receiver = receiver;
|
this.receiver = receiver;
|
||||||
this.amount = amount;
|
this.amount = NumberUtils.filterAmount(currency, amount);
|
||||||
this.reason = reason;
|
this.reason = reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class JoinQuitListener implements Listener {
|
|||||||
/* A starting balance is configured AND they haven't been given it yet. */
|
/* A starting balance is configured AND they haven't been given it yet. */
|
||||||
if ((startBalance > 0) && !plugin.getEconomyManager().accountExists(economable)) {
|
if ((startBalance > 0) && !plugin.getEconomyManager().accountExists(economable)) {
|
||||||
plugin.getEconomyManager().transact(new Transaction(
|
plugin.getEconomyManager().transact(new Transaction(
|
||||||
Economable.CONSOLE, economable, startBalance, TransactionReason.STARTING_BALANCE
|
plugin.getEconomyManager().getCurrency(), Economable.CONSOLE, economable, startBalance, TransactionReason.STARTING_BALANCE
|
||||||
));
|
));
|
||||||
if (plugin.getConfig().getBoolean("economy.notify-start-balance", true)) {
|
if (plugin.getConfig().getBoolean("economy.notify-start-balance", true)) {
|
||||||
this.plugin.getMessenger().sendMessage(player, "You've been issued a starting balance of {1}!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
|
this.plugin.getMessenger().sendMessage(player, "You've been issued a starting balance of {1}!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
|
||||||
|
@ -45,7 +45,7 @@ public class NumberUtils {
|
|||||||
|
|
||||||
public static double filterAmount(Currency currency, double amount) {
|
public static double filterAmount(Currency currency, double amount) {
|
||||||
try {
|
try {
|
||||||
return NumberFormat.getInstance().parse(currency.getFormat().format(amount)).doubleValue();
|
return NumberFormat.getInstance().parse(currency.getFormat().format(Math.abs(amount))).doubleValue();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ public class EconomySaneEconomy implements Economy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return transact(new Transaction(
|
return transact(new Transaction(
|
||||||
makeEconomable(target), Economable.PLUGIN, amount, TransactionReason.PLUGIN_TAKE
|
SaneEconomy.getInstance().getEconomyManager().getCurrency(), makeEconomable(target), Economable.PLUGIN, amount, TransactionReason.PLUGIN_TAKE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public class EconomySaneEconomy implements Economy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return transact(new Transaction(
|
return transact(new Transaction(
|
||||||
Economable.wrap(offlinePlayer), Economable.PLUGIN, amount, TransactionReason.PLUGIN_TAKE
|
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.wrap(offlinePlayer), Economable.PLUGIN, amount, TransactionReason.PLUGIN_TAKE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ public class EconomySaneEconomy implements Economy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return transact(new Transaction(
|
return transact(new Transaction(
|
||||||
Economable.PLUGIN, makeEconomable(target), amount, TransactionReason.PLUGIN_GIVE
|
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, makeEconomable(target), amount, TransactionReason.PLUGIN_GIVE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ public class EconomySaneEconomy implements Economy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return transact(new Transaction(
|
return transact(new Transaction(
|
||||||
Economable.PLUGIN, Economable.wrap(offlinePlayer), v, TransactionReason.PLUGIN_GIVE
|
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), v, TransactionReason.PLUGIN_GIVE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,23 +56,23 @@ public class EconomyManagerTest {
|
|||||||
Assert.assertEquals(0.0, economyManager.getBalance(playerTwo), 0.0);
|
Assert.assertEquals(0.0, economyManager.getBalance(playerTwo), 0.0);
|
||||||
|
|
||||||
// One should be able to transfer to two
|
// One should be able to transfer to two
|
||||||
Assert.assertTrue(economyManager.transact(new Transaction(playerOne, playerTwo, 50.0, TransactionReason.PLAYER_PAY)).getStatus() == TransactionResult.Status.SUCCESS);
|
Assert.assertTrue(economyManager.transact(new Transaction(economyManager.getCurrency(), playerOne, playerTwo, 50.0, TransactionReason.PLAYER_PAY)).getStatus() == TransactionResult.Status.SUCCESS);
|
||||||
|
|
||||||
// One should now have only 50 left, two should have 50 now
|
// One should now have only 50 left, two should have 50 now
|
||||||
Assert.assertEquals(50.0, economyManager.getBalance(playerOne), 0.0);
|
Assert.assertEquals("Player one should have 50 dollars", 50.0, economyManager.getBalance(playerOne), 0.0);
|
||||||
Assert.assertEquals(50.0, economyManager.getBalance(playerTwo), 0.0);
|
Assert.assertEquals("Player two should have 50 dollars", 50.0, economyManager.getBalance(playerTwo), 0.0);
|
||||||
|
|
||||||
// Ensure that balance addition and subtraction works...
|
// Ensure that balance addition and subtraction works...
|
||||||
Assert.assertEquals(25.0, economyManager.transact(
|
Assert.assertEquals(25.0, economyManager.transact(
|
||||||
new Transaction(playerOne, Economable.CONSOLE, 25.0, TransactionReason.TEST_TAKE)
|
new Transaction(economyManager.getCurrency(), playerOne, Economable.CONSOLE, 25.0, TransactionReason.TEST_TAKE)
|
||||||
).getFromBalance(), 0.0);
|
).getFromBalance(), 0.0);
|
||||||
|
|
||||||
Assert.assertEquals(50.0, economyManager.transact(
|
Assert.assertEquals(50.0, economyManager.transact(
|
||||||
new Transaction(Economable.CONSOLE, playerOne, 25.0, TransactionReason.TEST_GIVE)
|
new Transaction(economyManager.getCurrency(), Economable.CONSOLE, playerOne, 25.0, TransactionReason.TEST_GIVE)
|
||||||
).getToBalance(), 0.0);
|
).getToBalance(), 0.0);
|
||||||
|
|
||||||
Assert.assertEquals(TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS, economyManager.transact(
|
Assert.assertEquals(TransactionResult.Status.ERR_NOT_ENOUGH_FUNDS, economyManager.transact(
|
||||||
new Transaction(playerTwo, Economable.CONSOLE, Double.MAX_VALUE, TransactionReason.TEST_TAKE)
|
new Transaction(economyManager.getCurrency(), playerTwo, Economable.CONSOLE, Double.MAX_VALUE, TransactionReason.TEST_TAKE)
|
||||||
).getStatus());
|
).getStatus());
|
||||||
|
|
||||||
// Ensure that hasBalance works
|
// Ensure that hasBalance works
|
||||||
@ -115,11 +115,4 @@ public class EconomyManagerTest {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testNegativeBalance() {
|
|
||||||
Economable economable = Economable.wrap(new MockOfflinePlayer("Bob"));
|
|
||||||
economyManager.setBalance(economable, -1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.appledash</groupId>
|
<groupId>org.appledash</groupId>
|
||||||
<artifactId>SaneEconomyCore</artifactId>
|
<artifactId>SaneEconomyCore</artifactId>
|
||||||
<version>0.13.1-SNAPSHOT</version>
|
<version>0.14.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class EntityDamageListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin.getSaneEconomy().getEconomyManager().transact(new Transaction(
|
plugin.getSaneEconomy().getEconomyManager().transact(new Transaction(
|
||||||
Economable.PLUGIN, Economable.wrap(offlinePlayer), thisAmount, TransactionReason.PLUGIN_GIVE
|
this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), thisAmount, TransactionReason.PLUGIN_GIVE
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.appledash</groupId>
|
<groupId>org.appledash</groupId>
|
||||||
<artifactId>SaneEconomyCore</artifactId>
|
<artifactId>SaneEconomyCore</artifactId>
|
||||||
<version>0.13.1-SNAPSHOT</version>
|
<version>0.14.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
|
|||||||
this.reportingAmounts.put(player.getUniqueId(), payout.getAmount());
|
this.reportingAmounts.put(player.getUniqueId(), payout.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saneEconomy.getEconomyManager().transact(new Transaction(Economable.PLUGIN, Economable.wrap(player), payout.getAmount(), TransactionReason.PLUGIN_GIVE));
|
this.saneEconomy.getEconomyManager().transact(new Transaction(this.saneEconomy.getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(player), payout.getAmount(), TransactionReason.PLUGIN_GIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((onlineSeconds % payout.getReportInterval()) == 0) {
|
if ((onlineSeconds % payout.getReportInterval()) == 0) {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.appledash</groupId>
|
<groupId>org.appledash</groupId>
|
||||||
<artifactId>SaneEconomyCore</artifactId>
|
<artifactId>SaneEconomyCore</artifactId>
|
||||||
<version>0.13.1-SNAPSHOT</version>
|
<version>0.14.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class InteractListener implements Listener {
|
|||||||
EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager();
|
EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager();
|
||||||
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
|
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
|
||||||
|
|
||||||
ShopTransaction shopTransaction = shop.makeTransaction(player, TransactionDirection.BUY, quantity);
|
ShopTransaction shopTransaction = shop.makeTransaction(ecoMan.getCurrency(), player, TransactionDirection.BUY, quantity);
|
||||||
|
|
||||||
/* No buy limits for now!
|
/* No buy limits for now!
|
||||||
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
||||||
@ -121,7 +121,7 @@ public class InteractListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopTransaction shopTransaction = shop.makeTransaction(player, TransactionDirection.SELL, quantity);
|
ShopTransaction shopTransaction = shop.makeTransaction(ecoMan.getCurrency(), player, TransactionDirection.SELL, quantity);
|
||||||
|
|
||||||
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
|
||||||
this.plugin.getMessenger().sendMessage(player, "You have reached your selling limit for the time being. Try back in an hour or so.");
|
this.plugin.getMessenger().sendMessage(player, "You have reached your selling limit for the time being. Try back in an hour or so.");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.appledash.saneeconomysignshop.signshop;
|
package org.appledash.saneeconomysignshop.signshop;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomy.economy.Currency;
|
||||||
import org.appledash.saneeconomy.economy.economable.Economable;
|
import org.appledash.saneeconomy.economy.economable.Economable;
|
||||||
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
import org.appledash.saneeconomy.economy.transaction.Transaction;
|
||||||
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
|
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
|
||||||
@ -11,6 +12,7 @@ import org.bukkit.entity.Player;
|
|||||||
* Blackjack is still best pony.
|
* Blackjack is still best pony.
|
||||||
*/
|
*/
|
||||||
public class ShopTransaction {
|
public class ShopTransaction {
|
||||||
|
private final Currency currency;
|
||||||
// Direction is always what the player is doing. BUY = player is buying from shop.
|
// Direction is always what the player is doing. BUY = player is buying from shop.
|
||||||
private final TransactionDirection direction;
|
private final TransactionDirection direction;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
@ -18,7 +20,8 @@ public class ShopTransaction {
|
|||||||
private final int quantity;
|
private final int quantity;
|
||||||
private final double price;
|
private final double price;
|
||||||
|
|
||||||
public ShopTransaction(TransactionDirection direction, Player player, ItemInfo item, int quantity, double price) {
|
public ShopTransaction(Currency currency, TransactionDirection direction, Player player, ItemInfo item, int quantity, double price) {
|
||||||
|
this.currency = currency;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.item = item;
|
this.item = item;
|
||||||
@ -48,9 +51,9 @@ public class ShopTransaction {
|
|||||||
|
|
||||||
public Transaction makeEconomyTransaction() {
|
public Transaction makeEconomyTransaction() {
|
||||||
if (direction == TransactionDirection.BUY) {
|
if (direction == TransactionDirection.BUY) {
|
||||||
return new Transaction(Economable.wrap(player), Economable.PLUGIN, price, TransactionReason.PLUGIN_TAKE);
|
return new Transaction(this.currency, Economable.wrap(player), Economable.PLUGIN, price, TransactionReason.PLUGIN_TAKE);
|
||||||
} else {
|
} else {
|
||||||
return new Transaction(Economable.PLUGIN, Economable.wrap(player), price, TransactionReason.PLUGIN_GIVE);
|
return new Transaction(this.currency, Economable.PLUGIN, Economable.wrap(player), price, TransactionReason.PLUGIN_GIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.appledash.saneeconomysignshop.signshop;
|
package org.appledash.saneeconomysignshop.signshop;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomy.economy.Currency;
|
||||||
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
|
||||||
import org.appledash.saneeconomysignshop.util.ItemInfo;
|
import org.appledash.saneeconomysignshop.util.ItemInfo;
|
||||||
import org.appledash.saneeconomysignshop.util.SerializableLocation;
|
import org.appledash.saneeconomysignshop.util.SerializableLocation;
|
||||||
@ -131,7 +132,7 @@ public class SignShop implements Serializable {
|
|||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopTransaction makeTransaction(Player player, TransactionDirection direction, int quantity) {
|
public ShopTransaction makeTransaction(Currency currency, Player player, TransactionDirection direction, int quantity) {
|
||||||
return new ShopTransaction(direction, player, item, quantity, (direction == TransactionDirection.BUY) ? getBuyPrice(quantity) : getSellPrice(quantity));
|
return new ShopTransaction(currency, direction, player, item, quantity, (direction == TransactionDirection.BUY) ? getBuyPrice(quantity) : getSellPrice(quantity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user