Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Bayu Aditya H 2018-06-10 15:37:22 +07:00
commit 8b753f31a5
24 changed files with 81 additions and 97 deletions

View File

@ -9,7 +9,7 @@
<version>0</version>
</parent>
<artifactId>SaneEconomyCore</artifactId>
<version>0.13.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
<dependencies>
<dependency>

View File

@ -1,12 +1,12 @@
package org.appledash.saneeconomy;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import org.appledash.saneeconomy.command.*;
import org.appledash.saneeconomy.economy.EconomyManager;
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
import org.appledash.saneeconomy.economy.backend.type.EconomyStorageBackendMySQL;
import org.appledash.saneeconomy.economy.logger.TransactionLogger;
import org.appledash.saneeconomy.event.SaneEconomyTransactionEvent;
@ -74,18 +74,18 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
if (this.getConfig().getBoolean("update-check", true)) {
versionChecker = new GithubVersionChecker("SaneEconomyCore", this.getDescription().getVersion().replace("-SNAPSHOT", ""));
getServer().getScheduler().scheduleAsyncDelayedTask(this, versionChecker::checkUpdateAvailable);
this.getServer().getScheduler().runTaskAsynchronously(this, versionChecker::checkUpdateAvailable);
}
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
economyManager.getBackend().reloadTopPlayerBalances();
}, 0, (20 * this.getConfig().getInt("economy.baltop-update-interval", 300)) /* Update baltop every 5 minutes by default */);
}, 0L, (20L * this.getConfig().getLong("economy.baltop-update-interval", 300L)) /* Update baltop every 5 minutes by default */);
if (this.getConfig().getBoolean("multi-server-sync", false)) {
this.getServer().getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onTransaction(SaneEconomyTransactionEvent evt) { // Trust me, I'm a doctor.
Set<OfflinePlayer> playersToSync = ImmutableSet.of(evt.getTransaction().getSender().tryCastToPlayer(), evt.getTransaction().getReceiver().tryCastToPlayer());
OfflinePlayer[] playersToSync = { evt.getTransaction().getSender().tryCastToPlayer(), evt.getTransaction().getReceiver().tryCastToPlayer() };
Player fakeSender = Iterables.getFirst(SaneEconomy.this.getServer().getOnlinePlayers(), null);
@ -93,7 +93,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
return;
}
playersToSync.stream().filter(p -> p != null && !p.isOnline()).forEach(p -> {
Arrays.stream(playersToSync).filter(p -> (p != null) && !p.isOnline()).forEach(p -> {
ByteArrayDataOutput bado = ByteStreams.newDataOutput();
bado.writeUTF("SaneEconomy");
bado.writeUTF("SyncPlayer");
@ -115,9 +115,9 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
if (opCode.equals("SyncPlayer")) {
String playerUuid = badi.readUTF();
SaneEconomy.this.getEconomyManager().getBackend().reloadEconomable(String.format("player:%s", playerUuid));
this.economyManager.getBackend().reloadEconomable(String.format("player:%s", playerUuid), EconomyStorageBackend.EconomableReloadReason.CROSS_SERVER_SYNC);
} else {
SaneEconomy.this.getLogger().warning("Invalid OpCode received on SaneEconomy plugin message channel: " + opCode);
this.getLogger().warning("Invalid OpCode received on SaneEconomy plugin message channel: " + opCode);
}
}
});
@ -233,6 +233,7 @@ public class SaneEconomy extends SanePlugin implements ISaneEconomy {
return instance.getLogger();
}
@Override
public VaultHook getVaultHook() {
return vaultHook;
}

View File

@ -81,7 +81,7 @@ public class EconomyAdminCommand extends SaneCommand {
}
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);
double newAmount = result.getToBalance();
@ -95,7 +95,7 @@ public class EconomyAdminCommand extends SaneCommand {
}
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);
double newAmount = result.getFromBalance();
@ -117,12 +117,12 @@ public class EconomyAdminCommand extends SaneCommand {
// FIXME: This is a silly hack to get it to log.
if (oldBal > 0.0) {
logger.logTransaction(new Transaction(
economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
ecoMan.getCurrency(), economable, Economable.CONSOLE, oldBal, TransactionReason.ADMIN_TAKE
));
}
logger.logTransaction(new Transaction(
Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
ecoMan.getCurrency(), Economable.CONSOLE, economable, amount, TransactionReason.ADMIN_GIVE
));
});

View File

@ -75,7 +75,7 @@ public class PayCommand extends SaneCommand {
}
/* 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);
if (result.getStatus() != TransactionResult.Status.SUCCESS) {

View File

@ -81,59 +81,33 @@ public class EconomyManager {
* @return True if they have requiredBalance or more, false otherwise
*/
public boolean hasBalance(Economable targetPlayer, double requiredBalance) {
return targetPlayer == Economable.CONSOLE || getBalance(targetPlayer) >= requiredBalance;
return (targetPlayer == Economable.CONSOLE) || (getBalance(targetPlayer) >= requiredBalance);
}
/**
* Add to a player's balance.
* This does not filter the amount.
* @param targetPlayer Player to add to
* @param amount Amount to add
* @throws IllegalArgumentException If amount is negative
*/
private void addBalance(Economable targetPlayer, double amount) {
amount = NumberUtils.filterAmount(currency, 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);
setBalance(targetPlayer, backend.getBalance(targetPlayer) + amount);
}
/**
* Subtract from a player's balance.
* 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 amount Amount to subtract
* @throws IllegalArgumentException If amount is negative
*/
private void subtractBalance(Economable targetPlayer, double amount) {
amount = NumberUtils.filterAmount(currency, 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);
// Ensure we don't go negative.
setBalance(targetPlayer, Math.max(0.0, backend.getBalance(targetPlayer) - amount));
}
/**
@ -145,10 +119,6 @@ public class EconomyManager {
public void setBalance(Economable targetPlayer, double amount) {
amount = NumberUtils.filterAmount(currency, amount);
if (amount < 0) {
throw new IllegalArgumentException("Cannot subtract a negative amount!");
}
if (targetPlayer == Economable.CONSOLE) {
return;
}
@ -164,9 +134,9 @@ public class EconomyManager {
public TransactionResult transact(Transaction transaction) {
Economable sender = transaction.getSender();
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);
Bukkit.getServer().getPluginManager().callEvent(evt);
if (evt.isCancelled()) {
@ -203,7 +173,7 @@ public class EconomyManager {
uuidBalances.forEach((uuid, balance) -> {
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid);
if (offlinePlayer != null) {
if (this.saneEconomy.getVaultHook() == null || !this.saneEconomy.getVaultHook().hasPermission(offlinePlayer, "saneeconomy.balancetop.hide")) {
if ((this.saneEconomy.getVaultHook() == null) || !this.saneEconomy.getVaultHook().hasPermission(offlinePlayer, "saneeconomy.balancetop.hide")) {
playerBalances.put(Bukkit.getServer().getOfflinePlayer(uuid), balance);
}
}

View File

@ -49,7 +49,7 @@ public interface EconomyStorageBackend {
* Reload data for just the Economable with the given unique identifier.
* @param uniqueIdentifier Unique identifier of Economable to reload data for.
*/
void reloadEconomable(String uniqueIdentifier);
void reloadEconomable(String uniqueIdentifier, EconomableReloadReason reason);
/**
* Reload this backend's top balances.
@ -66,4 +66,8 @@ public interface EconomyStorageBackend {
* Wait until all of the data in memory has been written out to disk.
*/
void waitUntilFlushed();
enum EconomableReloadReason {
CROSS_SERVER_SYNC, PLAYER_JOIN
}
}

View File

@ -57,8 +57,11 @@ public abstract class EconomyStorageBackendCaching implements EconomyStorageBack
}
@Override
public void reloadEconomable(String uniqueIdentifier) {
SaneEconomy.logger().warning("Trying to reload a single Economable from backend which does not support this - " + this.getClass().getSimpleName() + ". Recommend switching to MySQL backend for multi-server support.");
public void reloadEconomable(String uniqueIdentifier, EconomableReloadReason reason) {
if (reason == EconomableReloadReason.CROSS_SERVER_SYNC) {
SaneEconomy.logger().warning("Trying to reload a single Economable from backend which does not support this - " + this.getClass().getSimpleName() + ". Recommend switching to MySQL backend for multi-server support.");
}
this.reloadDatabase();
}
}

View File

@ -143,7 +143,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
@Override
public void reloadEconomable(String uniqueIdentifier) {
public void reloadEconomable(String uniqueIdentifier, EconomableReloadReason reason) {
dbConn.executeAsyncOperation("reload_economable_" + uniqueIdentifier, (conn) -> {
try {
PreparedStatement ps = conn.prepareStatement(String.format("SELECT balance FROM `%s` WHERE `unique_identifier` = ?", dbConn.getTable("saneeconomy_balances")));

View File

@ -1,7 +1,9 @@
package org.appledash.saneeconomy.economy.transaction;
import org.appledash.saneeconomy.economy.Currency;
import org.appledash.saneeconomy.economy.economable.Economable;
import org.appledash.saneeconomy.economy.transaction.TransactionReason.AffectedParties;
import org.appledash.saneeconomy.utils.NumberUtils;
/**
* Created by appledash on 9/21/16.
@ -13,14 +15,15 @@ public class Transaction {
private final double amount;
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) {
throw new IllegalArgumentException("Cannot transact a zero or negative amount!");
}
this.sender = sender;
this.receiver = receiver;
this.amount = amount;
this.amount = NumberUtils.filterAmount(currency, amount);
this.reason = reason;
}

View File

@ -1,6 +1,7 @@
package org.appledash.saneeconomy.listeners;
import org.appledash.saneeconomy.SaneEconomy;
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
import org.appledash.saneeconomy.economy.economable.Economable;
import org.appledash.saneeconomy.economy.transaction.Transaction;
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
@ -33,7 +34,7 @@ public class JoinQuitListener implements Listener {
/* A starting balance is configured AND they haven't been given it yet. */
if ((startBalance > 0) && !plugin.getEconomyManager().accountExists(economable)) {
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)) {
this.plugin.getMessenger().sendMessage(player, "You've been issued a starting balance of {1}!", plugin.getEconomyManager().getCurrency().formatAmount(startBalance));
@ -41,7 +42,7 @@ public class JoinQuitListener implements Listener {
}
/* Update notification */
if (plugin.getVersionChecker() != null && player.hasPermission("saneeconomy.update-notify") && plugin.getVersionChecker().isUpdateAvailable()) {
if ((plugin.getVersionChecker() != null) && player.hasPermission("saneeconomy.update-notify") && plugin.getVersionChecker().isUpdateAvailable()) {
this.plugin.getMessenger().sendMessage(player, "An update is available! The currently-installed version is {1}, but the newest available is {2}. Please go to {3} to update!", plugin.getDescription().getVersion(), plugin.getVersionChecker().getNewestVersion(), GithubVersionChecker.DOWNLOAD_URL);
}
}
@ -49,7 +50,7 @@ public class JoinQuitListener implements Listener {
@EventHandler
public void onPlayerLogin(AsyncPlayerPreLoginEvent evt) {
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getEconomyManager().getBackend().reloadEconomable(String.format("player:%s", evt.getUniqueId())); // TODO: If servers start to lag when lots of people join, this is why.
plugin.getEconomyManager().getBackend().reloadEconomable(String.format("player:%s", evt.getUniqueId()), EconomyStorageBackend.EconomableReloadReason.PLAYER_JOIN); // TODO: If servers start to lag when lots of people join, this is why.
});
}
}

View File

@ -45,7 +45,7 @@ public class NumberUtils {
public static double filterAmount(Currency currency, double amount) {
try {
return NumberFormat.getInstance().parse(currency.getFormat().format(amount)).doubleValue();
return NumberFormat.getInstance().parse(currency.getFormat().format(Math.abs(amount))).doubleValue();
} catch (ParseException e) {
throw new NumberFormatException();
}

View File

@ -120,7 +120,7 @@ public class EconomySaneEconomy implements Economy {
}
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(
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(
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(
Economable.PLUGIN, Economable.wrap(offlinePlayer), v, TransactionReason.PLUGIN_GIVE
SaneEconomy.getInstance().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), v, TransactionReason.PLUGIN_GIVE
));
}

View File

@ -1,5 +1,6 @@
package org.appledash.saneeconomy.vault;
import com.google.common.base.Strings;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.appledash.saneeconomy.SaneEconomy;
@ -31,6 +32,10 @@ public class VaultHook {
public boolean hasPermission(OfflinePlayer offlinePlayer, String permNode) {
RegisteredServiceProvider<Permission> rsp = this.plugin.getServer().getServicesManager().getRegistration(Permission.class);
return rsp != null && rsp.getProvider().playerHas(null, offlinePlayer, permNode);
if ((offlinePlayer == null) || (offlinePlayer.getUniqueId() == null) || Strings.isNullOrEmpty(offlinePlayer.getName())) {
return false;
}
return (rsp != null) && rsp.getProvider().playerHas(null, offlinePlayer, permNode);
}
}

View File

@ -56,23 +56,23 @@ public class EconomyManagerTest {
Assert.assertEquals(0.0, economyManager.getBalance(playerTwo), 0.0);
// 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
Assert.assertEquals(50.0, economyManager.getBalance(playerOne), 0.0);
Assert.assertEquals(50.0, economyManager.getBalance(playerTwo), 0.0);
Assert.assertEquals("Player one should have 50 dollars", 50.0, economyManager.getBalance(playerOne), 0.0);
Assert.assertEquals("Player two should have 50 dollars", 50.0, economyManager.getBalance(playerTwo), 0.0);
// Ensure that balance addition and subtraction works...
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);
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);
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());
// Ensure that hasBalance works
@ -115,11 +115,4 @@ public class EconomyManagerTest {
return true;
}
@Test(expected = IllegalArgumentException.class)
public void testNegativeBalance() {
Economable economable = Economable.wrap(new MockOfflinePlayer("Bob"));
economyManager.setBalance(economable, -1.0);
}
}

View File

@ -16,7 +16,7 @@
<dependency>
<groupId>org.appledash</groupId>
<artifactId>SaneEconomyCore</artifactId>
<version>0.13.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -87,7 +87,7 @@ public class EntityDamageListener implements Listener {
}
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
));
}

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>org.appledash</groupId>
<artifactId>SaneEconomyCore</artifactId>
<version>0.13.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -52,7 +52,7 @@ public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
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) {

View File

@ -10,13 +10,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>SaneEconomySignShop</artifactId>
<version>0.1.6-SNAPSHOT</version>
<version>0.1.7-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.appledash</groupId>
<artifactId>SaneEconomyCore</artifactId>
<version>0.13.0-SNAPSHOT</version>
<version>0.14.0-SNAPSHOT</version>
</dependency>
</dependencies>

View File

@ -84,7 +84,7 @@ public class InteractListener implements Listener {
EconomyManager ecoMan = plugin.getSaneEconomy().getEconomyManager();
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!
if (!plugin.getLimitManager().shouldAllowTransaction(shopTransaction)) {
@ -121,7 +121,7 @@ public class InteractListener implements Listener {
return;
}
ShopTransaction shopTransaction = shop.makeTransaction(player, TransactionDirection.SELL, quantity);
ShopTransaction shopTransaction = shop.makeTransaction(ecoMan.getCurrency(), player, TransactionDirection.SELL, quantity);
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.");

View File

@ -1,5 +1,6 @@
package org.appledash.saneeconomysignshop.signshop;
import org.appledash.saneeconomy.economy.Currency;
import org.appledash.saneeconomy.economy.economable.Economable;
import org.appledash.saneeconomy.economy.transaction.Transaction;
import org.appledash.saneeconomy.economy.transaction.TransactionReason;
@ -11,6 +12,7 @@ import org.bukkit.entity.Player;
* Blackjack is still best pony.
*/
public class ShopTransaction {
private final Currency currency;
// Direction is always what the player is doing. BUY = player is buying from shop.
private final TransactionDirection direction;
private final Player player;
@ -18,7 +20,8 @@ public class ShopTransaction {
private final int quantity;
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.player = player;
this.item = item;
@ -48,9 +51,9 @@ public class ShopTransaction {
public Transaction makeEconomyTransaction() {
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 {
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);
}
}

View File

@ -1,5 +1,6 @@
package org.appledash.saneeconomysignshop.signshop;
import org.appledash.saneeconomy.economy.Currency;
import org.appledash.saneeconomysignshop.signshop.ShopTransaction.TransactionDirection;
import org.appledash.saneeconomysignshop.util.ItemInfo;
import org.appledash.saneeconomysignshop.util.SerializableLocation;
@ -131,7 +132,7 @@ public class SignShop implements Serializable {
return quantity;
}
public ShopTransaction makeTransaction(Player player, TransactionDirection direction, int quantity) {
return new ShopTransaction(direction, player, item, quantity, (direction == TransactionDirection.BUY) ? getBuyPrice(quantity) : getSellPrice(quantity));
public ShopTransaction makeTransaction(Currency currency, Player player, TransactionDirection direction, int quantity) {
return new ShopTransaction(currency, direction, player, item, quantity, (direction == TransactionDirection.BUY) ? getBuyPrice(quantity) : getSellPrice(quantity));
}
}

View File

@ -44,7 +44,7 @@ sell:
- item: RABBIT
limit: 1280
gain: 128
- item: BEEF
- item: RAW_BEEF
limit: 1280
gain: 128
- item: MUTTON

View File

@ -32,7 +32,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.12.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
@ -42,7 +42,7 @@
<dependency>
<groupId>org.appledash</groupId>
<artifactId>sanelib</artifactId>
<version>0.3.6-SNAPSHOT</version>
<version>0.3.7-SNAPSHOT</version>
</dependency>
</dependencies>