diff --git a/src/main/java/me/waterarchery/litsellchest/configuration/config/Config.java b/src/main/java/me/waterarchery/litsellchest/configuration/config/Config.java index acd4ed5..705424e 100644 --- a/src/main/java/me/waterarchery/litsellchest/configuration/config/Config.java +++ b/src/main/java/me/waterarchery/litsellchest/configuration/config/Config.java @@ -30,6 +30,8 @@ public void initializeDefaults() { ))); addDefault(new ConfigPart("SoundsEnabled", true, Collections.emptyList())); addDefault(new ConfigPart("NotSellingNotification", true, Collections.emptyList())); + addDefault(new ConfigPart("PaymentFormatting", true, Collections.emptyList())); + addDefault(new ConfigPart("EcoPayRoundupDecimals", 2, Collections.emptyList())); addDefault(new ConfigPart("SoundsVolume", 5, Collections.emptyList())); addDefault(ConfigPart.of("Sounds", null, Arrays.asList("You can completely disable all sounds above.", "", "Please use only the sounds that in here", "https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html"))); diff --git a/src/main/java/me/waterarchery/litsellchest/listeners/ShopMenuListener.java b/src/main/java/me/waterarchery/litsellchest/listeners/ShopMenuListener.java index 712af48..494dbfc 100644 --- a/src/main/java/me/waterarchery/litsellchest/listeners/ShopMenuListener.java +++ b/src/main/java/me/waterarchery/litsellchest/listeners/ShopMenuListener.java @@ -19,9 +19,19 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.joml.RoundingMode; + +import java.math.BigDecimal; public class ShopMenuListener implements Listener { + private double round(double value) { + if (decimals < 0) {decimals = 2;} + BigDecimal bd = new BigDecimal(Double.toString(value)); + bd = bd.setScale(decimals, RoundingMode.HALF_UP); + return bd.doubleValue(); + } + @EventHandler public void onShopMenuClick(InventoryClickEvent event) { Inventory inventory = event.getClickedInventory(); @@ -49,9 +59,14 @@ public void onShopMenuClick(InventoryClickEvent event) { economy.withdrawPlayer(player, price); ItemStack placeItem = sellChestType.toItemStack(); player.getInventory().addItem(placeItem); - String mes = ConfigHandler.getInstance().getMessageLang("ChestBought") + String msg = ConfigHandler.getInstance().getMessageLang("ChestBought") .replace("%money%", (balance - price) + ""); - libs.getMessageHandler().sendMessage(player, mes); + if(LitSellChest.getInstance().getConfig().getBoolean("PaymentFormatting",false)) { + BigDecimal bd = new BigDecimal(Double.toString(balance)); + bd = bd.setScale(LitSellChest.getInstance().getConfig().getInt("EcoPayRoundupDecimals",2), RoundingMode.HALF_UP); + msg.replace("%money%",String.valueOf(bd.doubleValue())); + } + libs.getMessageHandler().sendMessage(player, msg); SoundManager.sendSound(player, "ChestReceive"); } else { diff --git a/src/main/java/me/waterarchery/litsellchest/models/SellTask.java b/src/main/java/me/waterarchery/litsellchest/models/SellTask.java index 24ff6fa..bf1fbdb 100644 --- a/src/main/java/me/waterarchery/litsellchest/models/SellTask.java +++ b/src/main/java/me/waterarchery/litsellchest/models/SellTask.java @@ -24,23 +24,35 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.BoundingBox; +import org.joml.RoundingMode; +import java.math.BigDecimal; import java.util.Collection; public class SellTask extends BukkitRunnable { private final int interval; private final LitLibs libs; + private int decimals; + private final boolean RoundingEnabled; + private final boolean checkForOnline; + private final boolean NotSellingNot; public SellTask(int interval, LitLibs libs) { this.interval = interval; this.libs = libs; + this.RoundingEnabled = LitSellChest.getInstance().getConfig().getBoolean("PaymentFormatting"); + this.checkForOnline = LitSellChest.getInstance().getConfig().getBoolean("OnlyWorkOnlinePlayers"); + this.NotSellingNot = LitSellChest.getInstance().getConfig().getBoolean("NotSellingNotification"); + if(RoundingEnabled) { + this.decimals = LitSellChest.getInstance().getConfig().getInt("EcoPayRoundupDecimals"); + } } @Override public void run() { ChestHandler chestHandler = ChestHandler.getInstance(); - boolean checkForOnline = ConfigHandler.getInstance().getConfig().getYml().getBoolean("OnlyWorkOnlinePlayers", true); + //boolean checkForOnline = ConfigHandler.getInstance().getConfig().getYml().getBoolean("OnlyWorkOnlinePlayers", true); for (SellChest sellChest : chestHandler.getLoadedChests()) { if (sellChest.isLoaded() && (!checkForOnline || Bukkit.getPlayer(sellChest.getOwner()) != null)) { @@ -67,9 +79,16 @@ public void run() { } } + private double round(double value) { + if (decimals < 0) {decimals = 2;} + BigDecimal bd = new BigDecimal(Double.toString(value)); + bd = bd.setScale(decimals, RoundingMode.HALF_UP); + return bd.doubleValue(); + } + public void handleSelling(SellChest sellChest) { - boolean isSellWithLore = LitSellChest.getInstance().getConfig().getBoolean("SellOnlyItemsWithLore"); - boolean notifyOnUnsellable = ConfigHandler.getInstance().getConfig().getYml().getBoolean("NotSellingNotification", true); + //boolean isSellWithLore = LitSellChest.getInstance().getConfig().getBoolean("SellOnlyItemsWithLore"); + //boolean notifyOnUnsellable = ConfigHandler.getInstance().getConfig().getYml().getBoolean("NotSellingNotification", true); new BukkitRunnable() { @Override public void run() { @@ -125,6 +144,9 @@ public void run() { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sellChest.getOwner()); double tax = totalPrice * (sellChest.getChestType().getTax() / 100); totalPrice -= tax; + if(RoundingEnabled) { + totalPrice = round(totalPrice); + } econ.depositPlayer(offlinePlayer, totalPrice); if (offlinePlayer.isOnline()) { Player player = offlinePlayer.getPlayer(); @@ -136,7 +158,7 @@ public void run() { messageHandler.sendMessage(player, msg); } } - if(hasInvalids && notifyOnUnsellable) { + if(hasInvalids && NotSellingNot) { String msg = configHandler.getMessageLang("InvalidPriceOrFree"); messageHandler.sendMessage(player,msg); }