mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-25 01:49:49 -05:00
Fix counting issue, close #414
Former-commit-id: 255e7395d8ce7cd0c68d7f4fb11f6ebd6dc10184
This commit is contained in:
1 parent
3cba8762e9
commit
e48c9dc906
6 files changed
+57
-9
No files matched your search
@@ -40,6 +40,7 @@ import org.maxgamer.quickshop.event.ShopCreateEvent;
|
||||
import org.maxgamer.quickshop.event.ShopPreCreateEvent;
|
||||
import org.maxgamer.quickshop.event.ShopPurchaseEvent;
|
||||
import org.maxgamer.quickshop.event.ShopSuccessPurchaseEvent;
|
||||
import org.maxgamer.quickshop.util.CalculateUtil;
|
||||
import org.maxgamer.quickshop.util.MsgUtil;
|
||||
import org.maxgamer.quickshop.util.Util;
|
||||
|
||||
@@ -564,8 +565,8 @@ public class ShopManager {
|
||||
return; // Cancelled
|
||||
}
|
||||
// Money handling
|
||||
double tax = getTax(shop,p);
|
||||
double total = amount * shop.getPrice();
|
||||
double tax = getTax(shop, p);
|
||||
double total = CalculateUtil.multiply(amount, shop.getPrice());
|
||||
|
||||
boolean shouldPayOwner = !shop.isUnlimited() || (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners") && shop.isUnlimited());
|
||||
if (shouldPayOwner) {
|
||||
@@ -575,7 +576,7 @@ public class ShopManager {
|
||||
return;
|
||||
}
|
||||
}
|
||||
double depositMoney = total * (1 - tax);
|
||||
double depositMoney = CalculateUtil.multiply(total, CalculateUtil.subtract(1, tax));
|
||||
boolean successB = eco.deposit(p.getUniqueId(), depositMoney); // Deposit player's money
|
||||
if (!successB) {
|
||||
plugin.getLogger().warning("Failed to deposit the money " + depositMoney + " to player " + e.getPlayer().getName());
|
||||
@@ -590,7 +591,7 @@ public class ShopManager {
|
||||
}
|
||||
// Purchase successfully
|
||||
if (tax != 0 && cacheTaxAccount != null) {
|
||||
eco.deposit(cacheTaxAccount, total * tax);
|
||||
eco.deposit(cacheTaxAccount, CalculateUtil.multiply(total, tax));
|
||||
}
|
||||
// Notify the owner of the purchase.
|
||||
String msg = MsgUtil.getMessage("player-sold-to-your-store", p, p.getName(), String.valueOf(amount), "##########" + Util.serialize(shop.getItem()) + "##########");
|
||||
@@ -831,7 +832,7 @@ public class ShopManager {
|
||||
}
|
||||
double tax = getTax(shop,p);
|
||||
// Money handling
|
||||
double total = amount * shop.getPrice();
|
||||
double total = CalculateUtil.multiply(amount, shop.getPrice());
|
||||
|
||||
|
||||
boolean successA = eco.withdraw(p.getUniqueId(), total); // Withdraw owner's money
|
||||
@@ -841,7 +842,7 @@ public class ShopManager {
|
||||
}
|
||||
boolean shouldPayOwner = !shop.isUnlimited() || (plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners") && shop.isUnlimited());
|
||||
if (shouldPayOwner) {
|
||||
double depositMoney = total * (1 - tax);
|
||||
double depositMoney = CalculateUtil.multiply(total, CalculateUtil.subtract(1, tax));
|
||||
boolean successB = eco.deposit(shop.getOwner(), depositMoney);
|
||||
if (!successB) {
|
||||
plugin.getLogger().warning("Failed to deposit the money for player " + Bukkit.getOfflinePlayer(shop.getOwner()));
|
||||
@@ -857,7 +858,7 @@ public class ShopManager {
|
||||
String msg;
|
||||
// Notify the shop owner
|
||||
if (plugin.getConfig().getBoolean("show-tax")) {
|
||||
msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########", Util.format((tax * total)));
|
||||
msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########", Util.format((CalculateUtil.multiply(tax, total))));
|
||||
} else {
|
||||
msg = MsgUtil.getMessage("player-bought-from-your-store", p, p.getName(), "" + amount, "##########" + Util.serialize(shop.getItem()) + "##########");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is a part of project QuickShop, the name is CalculateUtil.java
|
||||
* Copyright (C) sandtechnology <https://github.com/sandtechnology>
|
||||
* Copyright (C) Bukkit Commons Studio and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.maxgamer.quickshop.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
|
||||
public class CalculateUtil {
|
||||
private static final MathContext mathContext = MathContext.DECIMAL32;
|
||||
|
||||
private CalculateUtil() {
|
||||
}
|
||||
|
||||
public static double divide(double number1, double number2) {
|
||||
return (BigDecimal.valueOf(number1).divide(BigDecimal.valueOf(number2), mathContext)).doubleValue();
|
||||
}
|
||||
|
||||
public static double subtract(double number1, double number2) {
|
||||
return (BigDecimal.valueOf(number1).subtract(BigDecimal.valueOf(number2), mathContext)).doubleValue();
|
||||
}
|
||||
|
||||
public static double multiply(double number1, double number2) {
|
||||
return (BigDecimal.valueOf(number1).multiply(BigDecimal.valueOf(number2), mathContext)).doubleValue();
|
||||
}
|
||||
|
||||
public static double add(double number1, double number2) {
|
||||
return (BigDecimal.valueOf(number1).add(BigDecimal.valueOf(number2), mathContext)).doubleValue();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -17,10 +17,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.util.Copied;
|
||||
import org.maxgamer.quickshop.util.mojangapi.AssetJson;
|
||||
import org.maxgamer.quickshop.util.mojangapi.MojangAPI;
|
||||
import org.maxgamer.quickshop.util.ReflectFactory;
|
||||
import org.maxgamer.quickshop.util.Util;
|
||||
import org.maxgamer.quickshop.util.mojangapi.AssetJson;
|
||||
import org.maxgamer.quickshop.util.mojangapi.MojangAPI;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
Reference in new issue
Block a user