Experimental baltop fixes and actually use the value of the last name.

This commit is contained in:
AppleDash 2020-02-02 08:53:31 -05:00
parent 2856305330
commit 854c2f5f10
16 changed files with 61 additions and 32 deletions

View File

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

View File

@ -48,7 +48,7 @@ public class BalanceTopCommand extends SaneCommand {
try {
page = Math.abs(Integer.parseInt(args[0]));
} catch (NumberFormatException e) {
this.saneEconomy.getMessenger().sendMessage(sender, "{1} is not a valid number.");
this.saneEconomy.getMessenger().sendMessage(sender, "{1} is not a valid number.", args[0]);
return;
}
}
@ -65,6 +65,12 @@ public class BalanceTopCommand extends SaneCommand {
AtomicInteger index = new AtomicInteger(offset + 1); /* I know it's stupid, but you can't do some_int++ from within the lambda. */
this.saneEconomy.getMessenger().sendMessage(sender, "Top {1} players on page {2}:", topBalances.size(), page);
topBalances.forEach((player, balance) -> this.saneEconomy.getMessenger().sendMessage(sender, "[{1:02d}] {2} - {3}", index.getAndIncrement(), player == null ? "<unknown>" : player, this.saneEconomy.getEconomyManager().getCurrency().formatAmount(balance)));
topBalances.forEach((player, balance) ->
this.saneEconomy.getMessenger().sendMessage(sender, "[{1:02d}] {2} - {3}",
index.getAndIncrement(),
player == null ? "<unknown>" : player,
this.saneEconomy.getEconomyManager().getCurrency().formatAmount(balance))
);
}
}

View File

@ -67,6 +67,14 @@ public interface EconomyStorageBackend {
*/
void waitUntilFlushed();
/**
* Get the last name associated with a unique ID.
*
* @param uuid Unique ID.
* @return Last name, or null if none.
*/
String getLastName(String uuid);
enum EconomableReloadReason {
CROSS_SERVER_SYNC, PLAYER_JOIN
}

View File

@ -64,4 +64,9 @@ public abstract class EconomyStorageBackendCaching implements EconomyStorageBack
this.reloadDatabase();
}
@Override
public String getLastName(String uuid) {
return this.uuidToName.get(uuid);
}
}

View File

@ -25,6 +25,7 @@ public class EconomyStorageBackendJSON extends EconomyStorageBackendCaching {
@Override
public void setBalance(Economable economable, BigDecimal newBalance) {
this.balances.put(economable.getUniqueIdentifier(), newBalance);
this.uuidToName.put(economable.getUniqueIdentifier(), economable.getName());
this.saveDatabase();
}

View File

@ -105,6 +105,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
while (rs.next()) {
this.balances.put(rs.getString("unique_identifier"), new BigDecimal(rs.getString("balance")));
this.uuidToName.put(rs.getString("unique_identifier"), rs.getString("last_name"));
}
} catch (SQLException e) {
throw new RuntimeException("Failed to reload data from SQL.", e);
@ -115,6 +116,7 @@ public class EconomyStorageBackendMySQL extends EconomyStorageBackendCaching {
public void setBalance(Economable economable, BigDecimal newBalance) {
BigDecimal oldBalance = this.getBalance(economable);
this.balances.put(economable.getUniqueIdentifier(), newBalance);
this.uuidToName.put(economable.getUniqueIdentifier(), economable.getName());
this.dbConn.executeAsyncOperation("set_balance_" + economable.getUniqueIdentifier(), (conn) -> {
try {

View File

@ -31,7 +31,7 @@ public class JoinQuitListener implements Listener {
public void onPlayerJoin(PlayerJoinEvent evt) {
Player player = evt.getPlayer();
Economable economable = Economable.wrap((OfflinePlayer) player);
BigDecimal startBalance = new BigDecimal(this.plugin.getConfig().getDouble("economy.start-balance", 0.0D));
BigDecimal startBalance = BigDecimal.valueOf(this.plugin.getConfig().getDouble("economy.start-balance", 0.0D));
/* A starting balance is configured AND they haven't been given it yet. */
if ((startBalance.compareTo(BigDecimal.ZERO) > 0) && !this.plugin.getEconomyManager().accountExists(economable)) {

View File

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

View File

@ -12,6 +12,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -83,11 +84,11 @@ public class EntityDamageListener implements Listener {
if (offlinePlayer.isOnline()) {
Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
this.plugin.getMessenger().sendMessage(player, "You have been awarded {1} for doing {2:.2f}% of the damage required to kill that {3}!", this.plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(thisAmount), thisPercent, entity.getName());
this.plugin.getMessenger().sendMessage(player, "You have been awarded {1} for doing {2:.2f}% of the damage required to kill that {3}!", this.plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(BigDecimal.valueOf(thisAmount)), thisPercent, entity.getName());
}
this.plugin.getSaneEconomy().getEconomyManager().transact(new Transaction(
this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), thisAmount, TransactionReason.PLUGIN_GIVE
this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), BigDecimal.valueOf(thisAmount), TransactionReason.PLUGIN_GIVE
));
}

View File

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

View File

@ -1,5 +1,6 @@
package org.appledash.saneeconomy.onlinetime;
import java.math.BigDecimal;
import java.util.Map;
/**
@ -8,14 +9,14 @@ import java.util.Map;
*/
public class Payout {
private final int secondsInterval;
private final double amount;
private final BigDecimal amount;
private final String message;
private String permission;
private final long reportInterval;
public Payout(int secondsInterval, double amount, String message, long reportInterval) {
this.secondsInterval = secondsInterval;
this.amount = amount;
this.amount = BigDecimal.valueOf(amount);
this.message = message;
this.reportInterval = reportInterval;
}
@ -24,7 +25,7 @@ public class Payout {
return this.secondsInterval;
}
public double getAmount() {
public BigDecimal getAmount() {
return this.amount;
}

View File

@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import java.math.BigDecimal;
import java.util.*;
/**
@ -18,7 +19,7 @@ import java.util.*;
*/
public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
private final Map<UUID, Long> onlineSeconds = new HashMap<>();
private final Map<UUID, Double> reportingAmounts = new HashMap<>();
private final Map<UUID, BigDecimal> reportingAmounts = new HashMap<>();
private final List<Payout> payouts = new ArrayList<>();
private SaneEconomy saneEconomy;
@ -47,7 +48,7 @@ public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
if ((onlineSeconds % payout.getSecondsInterval()) == 0) {
if (this.reportingAmounts.containsKey(player.getUniqueId())) {
this.reportingAmounts.put(player.getUniqueId(), this.reportingAmounts.get(player.getUniqueId()) + payout.getAmount());
this.reportingAmounts.put(player.getUniqueId(), this.reportingAmounts.get(player.getUniqueId()).add(payout.getAmount()));
} else {
this.reportingAmounts.put(player.getUniqueId(), payout.getAmount());
}
@ -56,8 +57,8 @@ public class SaneEconomyOnlineTime extends SanePlugin implements Listener {
}
if ((onlineSeconds % payout.getReportInterval()) == 0) {
this.getMessenger().sendMessage(player, payout.getMessage(), this.saneEconomy.getEconomyManager().getCurrency().formatAmount(this.reportingAmounts.getOrDefault(player.getUniqueId(), 0.0D)), payout.getReportInterval());
this.reportingAmounts.put(player.getUniqueId(), 0.0D);
this.getMessenger().sendMessage(player, payout.getMessage(), this.saneEconomy.getEconomyManager().getCurrency().formatAmount(this.reportingAmounts.getOrDefault(player.getUniqueId(), BigDecimal.ZERO)), payout.getReportInterval());
this.reportingAmounts.put(player.getUniqueId(), BigDecimal.ZERO);
}
}

View File

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

View File

@ -16,6 +16,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.logging.Logger;
@ -114,7 +115,7 @@ public class InteractListener implements Listener {
private void doSell(SignShop shop, Player player) { // TODO: Selling enchanted items
EconomyManager ecoMan = this.plugin.getSaneEconomy().getEconomyManager();
int quantity = player.isSneaking() ? 1 : shop.getQuantity();
double price = shop.getSellPrice(quantity);
BigDecimal price = shop.getSellPrice(quantity);
if (!player.getInventory().containsAtLeast(new ItemStack(shop.getItemStack()), quantity)) {
this.plugin.getMessenger().sendMessage(player, "You do not have {1} {2}!", quantity, shop.getItemStack().getType().name());

View File

@ -7,6 +7,8 @@ import org.appledash.saneeconomy.economy.transaction.TransactionReason;
import org.appledash.saneeconomysignshop.util.ItemInfo;
import org.bukkit.entity.Player;
import java.math.BigDecimal;
/**
* Created by appledash on 1/1/17.
* Blackjack is still best pony.
@ -18,9 +20,9 @@ public class ShopTransaction {
private final Player player;
private final ItemInfo item;
private final int quantity;
private final double price;
private final BigDecimal price;
public ShopTransaction(Currency currency, TransactionDirection direction, Player player, ItemInfo item, int quantity, double price) {
public ShopTransaction(Currency currency, TransactionDirection direction, Player player, ItemInfo item, int quantity, BigDecimal price) {
this.currency = currency;
this.direction = direction;
this.player = player;
@ -45,7 +47,7 @@ public class ShopTransaction {
return this.quantity;
}
public double getPrice() {
public BigDecimal getPrice() {
return this.price;
}

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.UUID;
/**
@ -20,8 +21,8 @@ public class SignShop implements Serializable {
private final SerializableLocation location;
private final ItemInfo item;
private final int quantity;
private final double buyPrice;
private final double sellPrice;
private final BigDecimal buyPrice;
private final BigDecimal sellPrice;
public SignShop(UUID ownerUuid, Location location, ItemStack item, int quantity, double buyPrice, double sellPrice) {
if ((ownerUuid == null) || (location == null) || (item == null)) {
@ -36,8 +37,8 @@ public class SignShop implements Serializable {
this.location = new SerializableLocation(location);
this.item = new ItemInfo(item);
this.quantity = quantity;
this.buyPrice = buyPrice;
this.sellPrice = sellPrice;
this.buyPrice = BigDecimal.valueOf(buyPrice);
this.sellPrice = BigDecimal.valueOf(sellPrice);
}
/**
@ -68,7 +69,7 @@ public class SignShop implements Serializable {
* Get the price that the player can buy this item from the server for
* @return Buy price for this.getQuantity() items
*/
public double getBuyPrice() {
public BigDecimal getBuyPrice() {
return this.buyPrice;
}
@ -76,7 +77,7 @@ public class SignShop implements Serializable {
* Get the price that the player can sell this item to the server for
* @return Buy price for this.getQuantity() items
*/
public double getSellPrice() {
public BigDecimal getSellPrice() {
return this.sellPrice;
}
@ -86,8 +87,8 @@ public class SignShop implements Serializable {
* @param quantity Quantity of items to price
* @return Price to buy that number of items at this shop
*/
public double getBuyPrice(int quantity) {
return this.buyPrice * ((float)quantity / (float)this.quantity); // TODO: Is this okay?
public BigDecimal getBuyPrice(int quantity) {
return this.buyPrice.multiply(BigDecimal.valueOf((double) quantity / this.quantity)); // TODO: Is this okay?
}
/**
@ -96,8 +97,8 @@ public class SignShop implements Serializable {
* @param quantity Quantity of items to price
* @return Price to sell that number of items at this shop
*/
public double getSellPrice(int quantity) {
return this.sellPrice * ((float)quantity / (float)this.quantity); // TODO: Is this okay?
public BigDecimal getSellPrice(int quantity) {
return this.sellPrice.multiply(BigDecimal.valueOf((double) quantity / this.quantity)); // TODO: Is this okay?
}
/**
@ -105,7 +106,7 @@ public class SignShop implements Serializable {
* @return True if they can, false if they can't
*/
public boolean canBuy() {
return this.buyPrice >= 0;
return this.buyPrice.compareTo(BigDecimal.ZERO) >= 0;
}
/**
@ -113,7 +114,7 @@ public class SignShop implements Serializable {
* @return True if they can, false if they can't
*/
public boolean canSell() {
return this.sellPrice >= 0;
return this.sellPrice.compareTo(BigDecimal.ZERO) >= 0;
}
/**